NeoPZ
TPZVecL2.cpp
Go to the documentation of this file.
1 
6 #include "TPZVecL2.h"
7 #include "pzmaterialdata.h"
8 #include "pzerror.h"
9 #include "pzvec.h"
10 #include "pzbndcond.h"
11 #include "pzreal.h"
12 #include "pzadmchunk.h"
13 #include "tpzintpoints.h"
14 
15 #include "pzlog.h"
16 
17 #ifdef LOG4CXX
18 #ifdef PZDEBUG
19 #define DEBUG2
20 #endif
21 static LoggerPtr logger(Logger::getLogger("pz.material"));
22 #endif
23 
24 
25 
27 TPZMaterial() {
28  fDim=-1;
29 }
30 
32 TPZMaterial(id) {
33  fDim=-1;
34 }
35 
37 {
38 }
39 
40 
42 TPZMaterial(mat) {
43  this->operator =(mat);
44 }
45 
47  fDim = mat.fDim;
48  return *this;
49 }
50 
51 
52 void TPZVecL2::Print(std::ostream & out) {
53  out << __PRETTY_FUNCTION__ << std::endl;
54  TPZMaterial::Print(out);
55 
56 }
57 
58 int TPZVecL2::VariableIndex(const std::string &name) {
59  if(!strcmp(name.c_str(),"state")) return 0;
60  if(!strcmp(name.c_str(),"State")) return 0;
61  if(!strcmp(name.c_str(),"Solution")) return 0;
62 
63  return TPZMaterial::VariableIndex(name );
64 }
65 
67 #ifdef STATE_COMPLEX
68  if(index == 0) return NStateVariables()*2;
69 #else
70  if(index == 0) return 3;
71 #endif
72  return TPZMaterial::NSolutionVariables(index);
73 }
74 
75 void TPZVecL2::Solution(TPZMaterialData &data, int var, TPZVec<STATE> &Solout){
76  int numbersol = data.dsol.size();
77  if (numbersol != 1) {
78  DebugStop();
79  }
80  this->Solution(data.sol[0], data.dsol[0], data.axes, var, Solout);
81 }
82 
83 void TPZVecL2::Solution(TPZVec<TPZMaterialData> &datavec, int var, TPZVec<STATE> &Solout){
84  DebugStop();
85 }
86 
87 void TPZVecL2::Solution(TPZMaterialData &data, TPZVec<TPZMaterialData> &dataleftvec, TPZVec<TPZMaterialData> &datarightvec, int var, TPZVec<STATE> &Solout)
88 {
89  this->Solution(data,dataleftvec,datarightvec, var, Solout);
90 }
91 
92 void TPZVecL2::Solution(TPZMaterialData &data, TPZVec<TPZMaterialData> &dataleftvec, TPZVec<TPZMaterialData> &datarightvec, int var, TPZVec<STATE> &Solout, TPZCompEl *left, TPZCompEl *right)
93 {
94  this->Solution(data,dataleftvec,datarightvec, var, Solout, left, right);
95 }
96 
98  TPZVec<STATE> &Solout){
99  if(var == 0) Solout = Sol;
100 
101  else if (var==1){
102  STATE val = 0.;
103  for(int i=0; i<fDim; i++){
104  val += DSol(i,i);
105  }
106  Solout[0] = val;
107  }
108 
109  else
110  {
111  TPZMaterial::Solution(Sol, DSol,axes,var,Solout);
112  }
113 }
114 
115 
117  return new TPZVecL2(*this);
118 }
119 
121  TPZFMatrix<STATE> fakeek(ef.Rows(), ef.Rows(), 0.);
122  this->Contribute(data, weight, fakeek, ef);
123 }
124 
126  TPZFMatrix<STATE> fakeek(ef.Rows(), ef.Rows(), 0.);
127  this->ContributeBC(data, weight, fakeek, ef, bc);
128 }
129 
131  int nref=datavec.size();
132  if (nref== 1) {
133  this->Contribute(datavec[0], weight, ek,ef);
134  }
135 }
136 
137 
138 
139 
140 int TPZVecL2::ClassId() const{
141  return Hash("TPZVecL2") ^ TPZMaterial::ClassId() << 1;
142 }
143 
144 /* Saves the element data to a stream */
145 void TPZVecL2::Write(TPZStream &buf, int withclassid) const
146 {
147  TPZMaterial::Write(buf,withclassid);
148  if (fDim < 1 || fDim >3) {
149  DebugStop();
150  }
151  buf.Write(&fDim);
152 }
153 
154 /* Reads the element data from a stream */
155 void TPZVecL2::Read(TPZStream &buf, void *context)
156 {
157  TPZMaterial::Read(buf,context);
158  buf.Read(&fDim);
159 #ifdef PZDEBUG
160  if (fDim < 1 || fDim >3) {
161  DebugStop();
162  }
163 #endif
164 }
165 
166 template class TPZRestoreClass<TPZVecL2>;
175 {
176 
177  TPZManVector<STATE,3> force(3);
178  force.Fill(0.);
179  if(fForcingFunction) {
180  fForcingFunction->Execute(data.x,force);
181  }
182  if(fNState != 1)
183  {
184  std::cout << "Please implement this extension\n";
185  DebugStop();
186  }
187 
188 
189  // Setting the phis
190  TPZFMatrix<REAL> &phiQ = data.phi;
191 
192  int phrq;
193  phrq = data.fVecShapeIndex.NElements();
194 
195  //Calculate the matrix contribution for flux. Matrix A
196  for(int iq=0; iq<phrq; iq++)
197  {
198  //ef(iq, 0) += 0.;
199  int ivecind = data.fVecShapeIndex[iq].first;
200  int ishapeind = data.fVecShapeIndex[iq].second;
201  TPZFNMatrix<3,REAL> ivec(3,1,0.);
202  for(int id=0; id<3; id++){
203  ivec(id,0) = data.fNormalVec(id,ivecind);
204  }
205  STATE ff = 0.;
206  for (int i=0; i<3; i++) {
207  ff += ivec(i,0)*force[i];
208  }
209 
210  ef(iq,0) += weight*ff*phiQ(ishapeind,0);
211 
212  for (int jq=0; jq<phrq; jq++)
213  {
214  TPZFNMatrix<3,REAL> jvec(3,1,0.);
215  int jvecind = data.fVecShapeIndex[jq].first;
216  int jshapeind = data.fVecShapeIndex[jq].second;
217 
218  for(int id=0; id<3; id++){
219  jvec(id,0) = data.fNormalVec(id,jvecind);
220  }
221 
222  //jvecZ.Print("mat1 = ");
223  REAL prod1 = ivec(0,0)*jvec(0,0) + ivec(1,0)*jvec(1,0) + ivec(2,0)*jvec(2,0);
224  ek(iq,jq) += weight*phiQ(ishapeind,0)*phiQ(jshapeind,0)*prod1;
225 
226  }
227  }
228 }
229 
231 
232 
233  TPZFMatrix<REAL> &phiQ = data.phi;
234  int phrq = phiQ.Rows();
235 
236  //AQUIFRANREAL v2;
237  STATE v2;
238  if(bc.HasForcingFunction())
239  {
241  bc.ForcingFunction()->Execute(data.x,res);
242  v2 = res[0];
243  }else
244  {
245  v2 = bc.Val2()(0,0);
246  }
247 
248  switch (bc.Type()) {
249  case 0 : // Dirichlet condition
250  //primeira equacao
251  for(int iq=0; iq<phrq; iq++)
252  {
253  //the contribution of the Dirichlet boundary condition appears in the flow equation
254  ef(iq,0) += STATE(-1.)*v2*phiQ(iq,0)*weight;
255  }
256  break;
257 
258  case 1 : // Neumann condition
259  //primeira equacao
260  for(int iq=0; iq<phrq; iq++)
261  {
262  ef(iq,0)+= gBigNumber*v2*phiQ(iq,0)*weight;
263  for (int jq=0; jq<phrq; jq++) {
264 
265  ek(iq,jq)+= gBigNumber*phiQ(iq,0)*phiQ(jq,0)*weight;
266  }
267  }
268  break;
269 
270  case 2 : // mixed condition
271  for(int iq = 0; iq < phrq; iq++) {
272 
273  ef(iq,0) += v2*phiQ(iq,0)*weight;
274  for (int jq = 0; jq < phrq; jq++) {
275  ek(iq,jq) += weight*bc.Val1()(0,0)*phiQ(iq,0)*phiQ(jq,0);
276  }
277  }
278 
279  break;
280  }
281 
282 }
283 
285 
286  values.Fill(0.0);
287  TPZVec<STATE> sol(1,0.),dsol(fDim,0.),div(1,0.);
288 
289 
290  Solution(data,0,dsol);//fluxo
291  Solution(data,1,div);//divergente
292 
293 #ifdef LOG4CXX
294  if(logger->isDebugEnabled()){
295  std::stringstream sout;
296  sout<< "\n";
297  sout << " Pto " << data.x << std::endl;
298  sout<< " ---- "<<std::endl;
299  sout<< " fluxo exato " <<du_exact(0,0)<<", " << du_exact(1,0)<<std::endl;
300  sout<< " fluxo aprox " <<dsol<<std::endl;
301  sout<< " ---- "<<std::endl;
302  if(du_exact.Rows()>fDim) sout<< " div exato " <<du_exact(2,0)<<std::endl;
303  sout<< " div aprox " <<div<<std::endl;
304  LOGPZ_DEBUG(logger,sout.str())
305  }
306 #endif
307 
308 
309  //values[1] : flux error using L2 norm
310  for(int id=0; id<fDim; id++) {
311  REAL diffFlux = fabs(dsol[id] - du_exact(id,0));
312  values[0] += diffFlux*diffFlux;
313  }
314  if(du_exact.Rows()>fDim){
315  //values[2] : divergence using L2 norm
316  REAL diffDiv = fabs(div[0] - du_exact(fDim,0));
317  values[1]=diffDiv*diffDiv;
318  //values[3] : Hdiv norm => values[1]+values[2];
319  values[2]= values[0]+values[1];
320  }
321 }
322 
virtual int VariableIndex(const std::string &name) override
Returns the variable index associated with the name.
Definition: TPZVecL2.cpp:58
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout)
Returns the solution associated with the var index based on the finite element approximation.
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
clarg::argBool bc("-bc", "binary checkpoints", false)
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to the stiffness matrix and load vector at one integration point...
Definition: TPZVecL2.cpp:174
int Type()
Definition: pzbndcond.h:249
Templated vector implementation.
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
Defines PZError.
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout) override
Returns the solution associated with the var index based on the finite element approximation.
Definition: TPZVecL2.cpp:75
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
Declarates the TPZBlock<REAL>class which implements block matrices.
virtual ~TPZVecL2()
Default destructor.
Definition: TPZVecL2.cpp:36
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
Definition: TPZVecL2.cpp:66
void ErrorsHdiv(TPZMaterialData &data, TPZVec< STATE > &u_exact, TPZFMatrix< STATE > &du_exact, TPZVec< REAL > &values) override
Definition: TPZVecL2.cpp:284
virtual void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: TPZVecL2.cpp:145
int fNState
Number of state variables.
Definition: TPZVecL2.h:109
TPZFMatrix< STATE > & Val2(int loadcase=0)
Definition: pzbndcond.h:255
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
virtual void Print(std::ostream &out=std::cout)
Prints out the data associated with the material.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
TPZAutoPointer< TPZFunction< STATE > > & ForcingFunction()
Returns a procedure as source function for the material.
Definition: TPZMaterial.h:397
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZVecL2.h:22
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZFNMatrix< 180 > fNormalVec
list of normal vectors
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZFNMatrix< 9, REAL > axes
axes indicating the directions of the derivatives of the shapefunctions
string res
Definition: test.py:151
TPZFMatrix< STATE > & Val1()
Definition: pzbndcond.h:253
TPZVecL2()
Default constructor.
Definition: TPZVecL2.cpp:26
Contains the TPZMaterialData class which implements an interface between TPZCompEl::CalcStiff and TPZ...
virtual int HasForcingFunction()
Directive that gives true if the material has a forcing function.
Definition: TPZMaterial.h:472
virtual int NStateVariables() const override
Returns the number of state variables associated with the material.
Definition: TPZVecL2.h:63
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual TPZMaterial * NewMaterial() override
To create another material of the same type.
Definition: TPZVecL2.cpp:116
int ClassId() const override
Unique identifier for serialization purposes.
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
virtual void Print(std::ostream &out=std::cout) override
Prints out the data associated with the material.
Definition: TPZVecL2.cpp:52
Contains the TPZIntPoints class which defines integration rules.
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
virtual int ClassId() const override
Unique identifier for serialization purposes.
Definition: TPZVecL2.cpp:140
def values
Definition: rdt.py:119
virtual void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: TPZVecL2.cpp:155
TPZManVector< std::pair< int, int64_t > > fVecShapeIndex
correspondence between normal vector index and index of the shape functions
TPZVecL2 & operator=(const TPZVecL2 &mat)
Definition: TPZVecL2.cpp:46
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
TPZSolVec sol
vector of the solutions at the integration point
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to the stiffness matrix and load vector at one BC integration point...
Definition: TPZVecL2.cpp:230
int fDim
Problem dimension.
Definition: TPZVecL2.h:106
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
virtual void Read(bool &val)
Definition: TPZStream.cpp:91