NeoPZ
TPZMaterial.cpp
Go to the documentation of this file.
1 
6 #include "TPZMaterial.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 #include "TPZPersistenceManager.h"
17 
18 #ifdef LOG4CXX
19 #ifdef PZDEBUG
20 #define DEBUG2
21 #endif
22 static LoggerPtr logger(Logger::getLogger("pz.material"));
23 #endif
24 
26 
27 using namespace std;
28 REAL TPZMaterial::gBigNumber = 1.e12;
29 
30 
31 TPZMaterial::TPZMaterial() : fNumLoadCases(1), fPostProcIndex(0) {
32  this->fId = -666;
33  this->fForcingFunction = NULL;
34  this->fLinearContext = true;
35 }
36 
38  this->SetId(id);
39  fForcingFunction = 0;
40  this->fLinearContext = true;
41 }
42 
44 {
45  this->fId = -999;
46 }
47 
48 
50  fId = material.fId;
57  fLinearContext = material.fLinearContext;
58  fNumLoadCases = material.fNumLoadCases;
59  fPostProcIndex = material.fPostProcIndex;
60 }
61 
63 {
64  fId = material.fId;
71  fLinearContext = material.fLinearContext;
72  fNumLoadCases = material.fNumLoadCases;
73  fPostProcIndex = material.fPostProcIndex;
74  return *this;
75 }
76 
77 void TPZMaterial::SetLinearContext(bool IsLinear){
78  fLinearContext = IsLinear;
79 }
80 
82 {
83  data.SetAllRequirements(true);
84  data.fNeedsNeighborSol = false;
85  data.fNeedsNeighborCenter = false;
86  data.fNeedsNormal = false;
87 
88 }
89 
91 {
92  int nref = datavec.size();
93  for(int i = 0; i<nref; i++ )
94  {
95  datavec[i].SetAllRequirements(true);
96  datavec[i].fNeedsNeighborSol = false;
97  datavec[i].fNeedsNeighborCenter = false;
98  datavec[i].fNeedsNormal = false;
99  }
100 
101 }
102 
103 void TPZMaterial::Print(std::ostream & out) {
104  out << __PRETTY_FUNCTION__ << std::endl;
105  out << std::endl << "Material Id = " << fId << std::endl;
106  out << "Linear context " << fLinearContext << std::endl;
107  out << "Num loadcases " << fNumLoadCases << std::endl;
108  out << "Big number " << gBigNumber << std::endl;
109 
110  if (!fForcingFunction) {
111  out << "Has no forcing function\n";
112  }
113  else {
114  out << "Forcing function\n";
115  fForcingFunction->Print(out);
116  }
117  if (!fForcingFunctionExact) {
118  out << "Has no exact forcing function\n";
119  }
120  else {
121  out << "Forcing function exact\n";
123  }
125  out << "Has no time dependent forcing function\n";
126  }
127  else {
128  out << "Time dependent forcing function\n";
130  }
132  out << "No time dependent forcing function exact\n";
133  }
134  else {
135  out << "Time dependent forcing function exact\n";
137  }
138 
139 }
140 
141 int TPZMaterial::VariableIndex(const std::string &name) {
142  if(!strcmp(name.c_str(),"state")) return 0;
143  if(!strcmp(name.c_str(),"State")) return 0;
144  if(!strcmp(name.c_str(),"Solution")) return 0;
145  if(!strcmp(name.c_str(),"GradState")) return 1;
146  if(!strcmp(name.c_str(),"POrder")) return 99;
147  if(!strcmp(name.c_str(),"Error")) return 100;
148  if(!strcmp(name.c_str(),"TrueError")) return 101;
149  if(!strcmp(name.c_str(),"EffectivityIndex")) return 102;
150 
151  if(!strcmp(name.c_str(),"L2Error")) return 103;
152  if(!strcmp(name.c_str(),"SemiH1Error")) return 104;
153  if(!strcmp(name.c_str(),"H1Error")) return 105;
154 
155  if(!strcmp(name.c_str(),"L2ErrorPerArea")) return 106;
156  if(!strcmp(name.c_str(),"SemiH1ErrorPerArea")) return 107;
157  if(!strcmp(name.c_str(),"H1ErrorPerArea")) return 108;
158  if(!strcmp(name.c_str(),"dudxErrorPerArea")) return 109;
159  if(!strcmp(name.c_str(),"dudyErrorPerArea")) return 110;
160  if(!strcmp(name.c_str(),"ContDisc")) return 111;
161  if(!strcmp(name.c_str(),"MaterialId")) return 98;
162 
163 
164 // std::cout << __PRETTY_FUNCTION__ << " Variable " << name << " not found\n";
165 
166 #ifdef LOG4CXX2
167  {
168  std::stringstream sout;
169  sout << "Variable " << name << " not found";
170  LOGPZ_ERROR(logger,sout.str())
171  }
172 #endif
173  return -1;
174 }
175 
177 #ifdef STATE_COMPLEX
178  if(index == 0) return NStateVariables()*2;
179 #else
180  if(index == 0) return NStateVariables();
181 #endif
182  if(index == 99 || index == 98) return 1;
183  if(index == 100) return 1;
184  if(index == 101) return 1;
185  if(index == 102) return 1;
186  if (index == 103) return 1;
187  if (index == 104) return 1;
188  if (index == 105) return 1;
189  if (index == 106) return 1;
190  if (index == 107) return 1;
191  if (index == 108) return 1;
192  if (index == 109) return 1;
193  if (index == 110) return 1;
194  if (index == 111) return 1;
195  PZError << "TPZMaterial::NSolutionVariables called index = " << index << "\n";
196  DebugStop();
197  return 0;
198 }
199 
201  int numbersol = data.dsol.size();
202  if (numbersol != 1) {
203  DebugStop();
204  }
205  this->Solution(data.sol[0], data.dsol[0], data.axes, var, Solout);
206 }
207 
209  int nvec = datavec.size();
210  int numdata = 0;
211  int dataindex = -1;
212  for (int iv=0; iv<nvec; iv++) {
213  if(datavec[iv].fShapeType != TPZMaterialData::EEmpty)
214  {
215  numdata++;
216  dataindex = iv;
217  }
218  }
219  if (numdata == 1) {
220  Solution(datavec[dataindex], var, Solout);
221  return;
222  }
223  DebugStop();
224 }
225 
227 {
228  this->Solution(data,dataleftvec,datarightvec, var, Solout);
229 }
230 
231 void TPZMaterial::Solution(TPZMaterialData &data, TPZVec<TPZMaterialData> &dataleftvec, TPZVec<TPZMaterialData> &datarightvec, int var, TPZVec<STATE> &Solout, TPZCompEl *left, TPZCompEl *ritgh)
232 {
233  this->Solution(data,dataleftvec,datarightvec, var, Solout, left, ritgh);
234 }
235 
237  TPZVec<STATE> &Solout){
238  if(var == 98){
239  Solout[0] = this->Id();
240  return;
241  }
242 #ifdef STATE_COMPLEX
243  if(var == 0)
244  {
245  Solout[0] = Sol[0].real();
246  Solout[1] = Sol[0].imag();
247  }
248  else if(var == 99 || var == 100 || var == 101 || var == 102) {
249  PZError << "TPZMaterial var = "<< var << " the element should treat this case\n";
250  Solout[0] = Sol[0].real(); // = 0.;
251  }
252  else
253  {
254  Solout.Resize(0);
255  }
256 #else
257  if(var == 0) Solout = Sol;
258  else if(var == 99 || var == 100 || var == 101 || var == 102) {
259  PZError << "TPZMaterial var = "<< var << " the element should treat this case\n";
260  Solout[0] = Sol[0]; // = 0.;
261  } else if(var == 1)
262  {
263  Solout.resize(Sol.size()*3);
264  int64_t nsol = Sol.size();
265  Solout.Fill(0.);
266  int64_t dim = axes.Rows();
267  for (int64_t is=0; is<nsol; is++) {
268  for (int64_t d=0; d<dim; d++) {
269  for (int64_t jco=0; jco<3; jco++) {
270  Solout[jco+3*is] += axes(d,jco)*DSol(d,is);
271  }
272  }
273  }
274  } else
275  {
276  DebugStop();
277  Solout.Resize(0);
278  }
279 #endif
280 }
281 
283  return new TPZBndCond(reference,id,typ,val1,val2);
284 }
285 
286 void TPZMaterial::SetData(std::istream &data) {
287  PZError << "TPZMaterial::SetData is called.\n";
288  data >> fId;
289 }
290 
292  PZError << "TPZMaterial::NewMaterial is called.\n";
293  return 0;
294 }
295 
297  TPZFMatrix<STATE> fakeek(ef.Rows(), ef.Rows(), 0.);
298  this->Contribute(data, weight, fakeek, ef);
299 }
300 
302  TPZFMatrix<STATE> fakeek(ef.Rows(), ef.Rows(), 0.);
303  this->ContributeBC(data, weight, fakeek, ef, bc);
304 }
305 
307  int nref=datavec.size();
308  int ndif = 0;
309  int onemat = 0;
310  for (int ir = 0; ir < nref; ir++) {
311  int nphis=datavec[ir].phi.Rows();
312  if (datavec[ir].phi.Rows()) {
313  onemat = ir;
314  ndif++;
315  }
316  }
317  if (ndif == 1) {
318  this->Contribute(datavec[onemat], weight, ek,ef);
319  }
320  else
321  {
322  DebugStop();
323  }
324 }
325 
328  int nref=datavec.size();
329  if (nref== 1) {
330  this->ContributeBC(datavec[0], weight, ek,ef,bc);
331  }
332  else
333  {
334  DebugStop();
335  }
336 }
337 
338 void TPZMaterial::Clone(std::map<int, TPZMaterial * >&matvec) {
339  int matid = Id();
340  std::map<int, TPZMaterial * >::iterator matit;
341  matit = matvec.find(matid);
342  if(matit != matvec.end()) return;
343  TPZMaterial * newmat = NewMaterial();
344  matvec[matid] = newmat;
345 }
346 
349 int TPZMaterial::IntegrationRuleOrder(int elPMaxOrder) const
350 {
351  int order = 0;
352  if(fForcingFunction){
354  }
355 
356  int pmax = elPMaxOrder;
357  int integrationorder = 2*pmax;
358  if (pmax < order) {
359  integrationorder = order+pmax;
360  }
361  return integrationorder;
362 }
363 
365  int order = 0;
366  if (fForcingFunction) {
368  }
369 
370  int pmax = 0;
371  for (int ip = 0; ip < elPMaxOrder.size(); ip++) {
372  if (elPMaxOrder[ip] > pmax) pmax = elPMaxOrder[ip];
373  }
374  int integrationorder = 2 * pmax;
375  if (pmax < order) {
376  integrationorder = order + pmax;
377  }
378 
379  return integrationorder;
380 }
381 
383  return Hash("TPZMaterial");
384 }
385 
386 /* Saves the element data to a stream */
387 void TPZMaterial::Write(TPZStream &buf, int withclassid) const {
388  buf.Write(&fId, 1);
389  buf.Write(&gBigNumber, 1);
396  buf.Write(fLinearContext);
397  buf.Write(&fNumLoadCases);
398  buf.Write(&fPostProcIndex);
399 }
400 
401 /* Reads the element data from a stream */
402 void TPZMaterial::Read(TPZStream &buf, void *context) {
403  buf.Read(&fId, 1);
404  buf.Read(&gBigNumber, 1);
405  fForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
406  fForcingFunctionExact = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
407  fTimeDependentForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
408  fTimedependentFunctionExact = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
409  fBCForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
410  fTimedependentBCForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
411  buf.Read(fLinearContext);
412  buf.Read(&fNumLoadCases);
413  buf.Read(&fPostProcIndex);
414 }
415 
bool fLinearContext
Defines whether the equation context is linear solver or non linear.
Definition: TPZMaterial.h:70
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout)
Returns the solution associated with the var index based on the finite element approximation.
int fNumLoadCases
Defines the number of load cases generated by this material.
Definition: TPZMaterial.h:76
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.
clarg::argBool bc("-bc", "binary checkpoints", false)
TPZAutoPointer< TPZFunction< STATE > > fBCForcingFunction
Pointer to bc forcing function, it is a variable boundary condition at differential equation...
Definition: TPZMaterial.h:59
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
virtual void Print(std::ostream &out)
Print a brief statement.
Definition: pzfunction.h:77
virtual TPZMaterial * NewMaterial()
To create another material of the same type.
Templated vector implementation.
TPZMaterial & operator=(const TPZMaterial &copy)
operator =
Definition: TPZMaterial.cpp:62
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
Defines PZError.
void SetAllRequirements(bool set)
Set all flags at once.
virtual int NStateVariables() const =0
Returns the number of state variables associated with the material.
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.
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
TPZMaterial()
Default constructor.
Definition: TPZMaterial.cpp:31
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef)=0
It computes a contribution to the stiffness matrix and load vector at one integration point...
virtual void Print(std::ostream &out=std::cout)
Prints out the data associated with the material.
int fPostProcIndex
indicates which solution should be used for post processing
Definition: TPZMaterial.h:79
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
TPZAutoPointer< TPZFunction< STATE > > fTimedependentBCForcingFunction
Pointer to time dependent bc forcing function, it is a variable boundary condition at differential eq...
Definition: TPZMaterial.h:62
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
virtual int IntegrationRuleOrder(int elPMaxOrder) const
Gets the order of the integration rule necessary to integrate an element with polinomial order p...
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
virtual void FillDataRequirements(TPZMaterialData &data)
Fill material data parameter with necessary requirements for the.
Definition: TPZMaterial.cpp:81
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZAutoPointer< TPZFunction< STATE > > fForcingFunctionExact
Pointer to exact solution function, needed to calculate exact error.
Definition: TPZMaterial.h:50
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
TPZVec< void(*)(const TPZVec< REAL > &, TPZVec< STATE > &) > GFORCINGVEC
Extern variable - Vector of force values.
Definition: TPZMaterial.cpp:25
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
Contains the TPZMaterialData class which implements an interface between TPZCompEl::CalcStiff and TPZ...
virtual ~TPZMaterial()
Default destructor.
Definition: TPZMaterial.cpp:43
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc)=0
It computes a contribution to the stiffness matrix and load vector at one BC integration point...
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
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
TPZAutoPointer< TPZFunction< STATE > > fTimedependentFunctionExact
Pointer to time dependent exact solution function, needed to calculate exact error.
Definition: TPZMaterial.h:56
int ClassId() const override
Unique identifier for serialization purposes.
virtual TPZBndCond * CreateBC(TPZMaterial *reference, int id, int typ, TPZFMatrix< STATE > &val1, TPZFMatrix< STATE > &val2)
Creates an object TPZBndCond derived of TPZMaterial.
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
virtual void Clone(std::map< int, TPZMaterial * > &matvec)
Creates a copy of the material object and put it in the vector which is passed on.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
int Id() const
Definition: TPZMaterial.h:170
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
Contains the TPZIntPoints class which defines integration rules.
void SetId(int id)
Definition: TPZMaterial.h:171
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void SetLinearContext(bool IsLinear)
Sets fLinearContext attribute.
Definition: TPZMaterial.cpp:77
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
TPZSolVec sol
vector of the solutions at the integration point
virtual int PolynomialOrder() const
Polynomial order of this function. In case of non-polynomial function it can be a reasonable approxim...
Definition: pzfunction.h:66
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
virtual void SetData(std::istream &data)
Reads data of the material from a istream (file data)
TPZAutoPointer< TPZFunction< STATE > > fTimeDependentForcingFunction
Pointer to time dependent forcing function, it is the right member at differential equation...
Definition: TPZMaterial.h:53