NeoPZ
pzmaterialdata.cpp
Go to the documentation of this file.
1 
6 #include "pzmaterialdata.h"
7 #include "TPZMaterial.h"
8 #include "pzcompel.h"
9 #include "pzelmat.h"
10 #include <sstream>
11 #include "pzerror.h"
12 #include "TPZInterfaceEl.h"
13 #include "pzdiscgal.h"
14 #include "pzaxestools.h"
15 #include "pzlog.h"
16 
17 #ifdef LOG4CXX
18 static LoggerPtr logger(Logger::getLogger("pz.matrix.tpzfmatrix"));
19 static LoggerPtr loggerCheck(Logger::getLogger("pz.checkconsistency"));
20 #endif
21 
22 TPZMaterialData::TPZMaterialData() : TPZRegisterClassId(&TPZMaterialData::ClassId), fShapeType(EEmpty), numberdualfunctions(0){
23  this->SetAllRequirements(false);
24  this->fNeedsNormalVecFad = false;
25  this->intLocPtIndex = -1;
26  this->intGlobPtIndex = -1;
27  this->NintPts = -1;
28  this->sol.Resize(1);
29  this->dsol.Resize(1);
30  this->gelElId = -1;
31  this->HSize = 0.;
32  this->detjac = 0.;
33  this->numberdualfunctions = 0;
34  this->gelElId = -1;
35  this->fDirectionsOnMaster = 0;
36 #ifdef _AUTODIFF
37  this->fNormalVecFad = 0;
38 #endif
39 }
40 
44  this->operator =(cp);
45 }
46 
48  this->fShapeType = cp.fShapeType;
49  this->fNeedsSol = cp.fNeedsSol;
51  this->fNeedsHSize = cp.fNeedsHSize;
53  this->fNeedsNormal = cp.fNeedsNormal;
55  this->phi = cp.phi;
56  this->dphi = cp.dphi;
57  this->dphix = cp.dphix;
58  this->divphi = cp.divphi;
59  this->axes = cp.axes;
60  this->jacobian = cp.jacobian;
61  this->jacinv = cp.jacinv;
62  this->normal = cp.normal;
63  this->x = cp.x;
64  this->p = cp.p;
65  this->sol = cp.sol;
66  this->dsol = cp.dsol;
67  this->divsol = cp.divsol;
68  this->HSize = cp.HSize;
69  this->detjac = cp.detjac;
70  this->intLocPtIndex = cp.intLocPtIndex;
71  this->intGlobPtIndex = cp.intGlobPtIndex;
72  this->NintPts = cp.NintPts;
73  this->XCenter = cp.XCenter;
75  this->fVecShapeIndex = cp.fVecShapeIndex;
76  this->fNormalVec = cp.fNormalVec;
77 #ifdef _AUTODIFF
78  this->fNormalVecFad = cp.fNormalVecFad;
79 #endif
81  this->gelElId = cp.gelElId;
82 
83  return *this;
84 }
85 
87  //NOTHING TO BE DONE!
88 }
89 
91  this->fNeedsSol = set;
92  this->fNeedsNeighborSol = set;
93  this->fNeedsHSize = set;
94  this->fNeedsNeighborCenter = set;
95  this->fNeedsNormal = set;
96 }
97 
100 bool TPZMaterialData::Compare(TPZSavable *copy, bool override)
101 {
102  TPZMaterialData *comp = dynamic_cast<TPZMaterialData *>(copy);
103  if(!comp) return false;
104  bool result = true;
105  bool locres;
106  locres = phi.Compare(&comp->phi,override);
107  if(!locres)
108  {
109  LOGPZ_DEBUG(loggerCheck,"phi different")
110  }
111  result = result && locres;
112  locres = dphi.Compare(&comp->dphi,override);
113  if(!locres)
114  {
115  LOGPZ_DEBUG(loggerCheck,"dphi different")
116  }
117  result = result && locres;
118  locres = dphix.Compare(&comp->dphix,override);
119  if(!locres)
120  {
121  LOGPZ_DEBUG(loggerCheck,"dphix different")
122  }
123  result = result && locres;
124  locres = divphi.Compare(&comp->divphi,override);
125  if(!locres)
126  {
127  LOGPZ_DEBUG(loggerCheck,"dphix different")
128  }
129  result = result && locres;
130  locres = axes.Compare(&comp->axes,override);
131  if(!locres)
132  {
133  LOGPZ_DEBUG(loggerCheck,"axes different")
134  }
135  result = result && locres;
136  locres = jacobian.Compare(&comp->jacobian,override);
137  if(!locres)
138  {
139  LOGPZ_DEBUG(loggerCheck,"jacobian different")
140  }
141  result = result && locres;
142  locres = jacinv.Compare(&comp->jacinv,override);
143  if(!locres)
144  {
145  LOGPZ_DEBUG(loggerCheck,"jacinv different")
146  }
147  result = result && locres;
148  return result;
149 }
150 
151 // Compare the object for identity with the object pointed to, eventually copy the object
152 /*
153  * compare both objects bitwise for identity. Put an entry in the log file if different
154  * overwrite the calling object if the override flag is true
155  */
156 bool TPZMaterialData::Compare(TPZSavable *copy, bool override) const
157 {
158  DebugStop();
159  return true;
160 }
161 
163 void TPZMaterialData::Print(std::ostream &out) const
164 {
165  phi.Print("phi",out);
166  dphi.Print("dphi",out);
167  dphix.Print("dphix",out);
168  divphi.Print("div phi",out);
169  axes.Print("axes",out);
170  jacobian.Print("jacobian",out);
171  jacinv.Print("jacinv",out);
172  out << "normal " << normal << std::endl;
173  out << "x " << x << std::endl;
174  out << "p " << p << std::endl;
175  out << "sol " << sol << std::endl;
176  int nsol = dsol.size();
177  for (int is=0; is<nsol; is++) {
178  dsol[is].Print("dsol",out);
179 
180  }
181  out << "divsol " << divsol << std::endl;
182  out << "HSize " << HSize << std::endl;
183  out << "detjac " << detjac << std::endl;
184  out << "XCenter " << XCenter << std::endl;
185  out << "fDirectionsOnMaster" << fDirectionsOnMaster << std::endl;
186  out << "intLocPtIndex " << intLocPtIndex << std::endl;
187  out << "intGlobPtIndex " << intGlobPtIndex << std::endl;
188  out << "NintPts " << NintPts << std::endl;
189  out << "gelElId " << gelElId << std::endl;
190 }
191 
193 void TPZMaterialData::PrintMathematica(std::ostream &out) const
194 {
195  phi.Print("phi = ",out,EMathematicaInput);
196  dphi.Print("dphi = ",out,EMathematicaInput);
197  dphix.Print("dphix = ",out,EMathematicaInput);
198  axes.Print("axes = ",out,EMathematicaInput);
199  jacobian.Print("jacobian = ",out,EMathematicaInput);
200  jacinv.Print("jacinv = ",out,EMathematicaInput);
201  out << "normal = {" << normal << "};" << std::endl;
202  out << "x = {" << x << "};" << std::endl;
203  out << "p = " << p << ";" << std::endl;
204  out << "sol = { " << sol << "};" << std::endl;
205  int nsol=dsol.size();
206  for (int is=0; is<nsol; is++) {
207  std::stringstream sout;
208  sout << "dsol" << is << " = ";
209  dsol[is].Print(sout.str().c_str(),out,EMathematicaInput);
210  }
211  out << "divsol = { " << divsol << "};" << std::endl;
212 
213  out << "HSize = " << HSize << ";" << std::endl;
214  out << "detjac = " << detjac << ";" << std::endl;
215  out << "XCenter = {" << XCenter << "};" << std::endl;
216  out << "fDirectionsOnMaster" << fDirectionsOnMaster << std::endl;
217  out << "intLocPtIndex = " << intLocPtIndex << ";" <<std::endl;
218  out << "intGlobPtIndex = " << intGlobPtIndex << ";" <<std::endl;
219  out << "NintPts = " << NintPts << ";" <<std::endl;
220  out << "gelElId = " << gelElId << ";" <<std::endl;
221 }
222 
224 void TPZMaterialData::Write(TPZStream &buf, int withclassid) const
225 {
226  int shapetype = fShapeType;
227  buf.Write(&shapetype);
228  phi.Write(buf,0);
229  dphi.Write(buf,0);
230  dphix.Write(buf,0);
231  divphi.Write(buf, 0);
232  axes.Write(buf,0);
233  jacobian.Write(buf,0);
234  jacinv.Write(buf,0);
235  buf.Write(normal.begin(),normal.size());
236  buf.Write(x.begin(),x.size());
237  buf.Write(&p,1);
238  int nsol = sol.size();
239  buf.Write(&nsol);
240  for (int is=0; is<nsol; is++) {
241  buf.Write(sol[is].begin(),sol[is].size());
242  }
243 
244  nsol = dsol.size();
245  buf.Write(&nsol);
246  for (int is=0; is<nsol; is++) {
247  dsol[is].Write(buf,0);
248  }
249  nsol = divsol.size();
250  buf.Write(&nsol);
251  for (int is=0; is<nsol; is++) {
252  buf.Write(divsol[is].begin(),divsol[is].size());
253  }
254 
255  buf.Write(&HSize,1);
256  buf.Write(&detjac,1);
257  buf.Write(XCenter.begin(),XCenter.size());
258  buf.Write(&intLocPtIndex,1);
259  buf.Write(&intGlobPtIndex,1);
260  buf.Write(&NintPts,1);
261  buf.Write(&gelElId,1);
262 }
263 
265 void TPZMaterialData::Read(TPZStream &buf, void *context)
266 {
267  int shapetype;
268  buf.Read(&shapetype);
269  fShapeType = (MShapeFunctionType) shapetype;
270  phi.Read(buf,0);
271  dphi.Read(buf,0);
272  dphix.Read(buf,0);
273  divphi.Read(buf, 0);
274  axes.Read(buf,0);
275  jacobian.Read(buf,0);
276  jacinv.Read(buf,0);
277  buf.Read(normal);
278  buf.Read(x);
279  buf.Read(&p,1);
280  int nsol;
281  buf.Read(&nsol,1);
282  for (int is=0; is<nsol; is++) {
283  buf.Read(sol[is]);
284  }
285  buf.Read(&nsol,1);
286  for (int is = 0; is<nsol; is++) {
287  dsol[is].Read(buf,0);
288  }
289  buf.Read(&nsol,1);
290  for (int is=0; is<nsol; is++) {
291  buf.Read(divsol[is]);
292  }
293 
294  buf.Read(&HSize,1);
295  buf.Read(&detjac,1);
296  buf.Read(XCenter);
297  buf.Read(&intLocPtIndex,1);
298  buf.Read(&intGlobPtIndex,1);
299  buf.Read(&NintPts,1);
300  buf.Read(&gelElId,1);
301 }
302 
304  return Hash("TPZMaterialData");
305 }
306 
309 
310  if (fShapeType != EVecandShape) {
311  std::cout << __PRETTY_FUNCTION__ << "works only for Vec and Shape type." << std::endl;
312  return;
313  }
314 
315  int n_shape = fVecShapeIndex.size();
316  fluxes.Redim(3, n_shape);
317 
318  for (int i = 0; i < n_shape; i++) {
319  int i_v = fVecShapeIndex[i].first;
320  int i_s = fVecShapeIndex[i].second;
321 
322  for (int j = 0; j < 3; j++) {
323  fluxes(j,i) = phi(i_s,0) * fNormalVec(j,i_v);
324  }
325  }
326 
327 }
328 
331 {
332 
333  // Getting test and basis functions
334  TPZFMatrix<REAL> dphi_s = dphi; // Derivative For H1 test functions
335 
336  int n_phi_v = fVecShapeIndex.NElements();
337  divphi.Redim(n_phi_v,1);
338  REAL det_jac = detjac;
339 
340  int i_vec = 0;
341  int i_phi_s = 0;
342 
343  for (int iq = 0; iq < n_phi_v; iq++)
344  {
345  i_vec = fVecShapeIndex[iq].first;
346  i_phi_s = fVecShapeIndex[iq].second;
347 
348  int n_dir = dphi_s.Rows();
349  for (int k = 0; k < n_dir; k++) {
350  divphi(iq,0) += dphi(k,i_phi_s)*fDirectionsOnMaster(k,i_vec)/detjac;
351  }
352  }
353 
354 
355 }
356 
357 
358 
359 template class TPZRestoreClass<TPZMaterialData>;
void Print(std::ostream &out=std::cout)
Prints the structural information of the vector object to the output stream. This method will not p...
Definition: pzvec.h:482
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.h:789
void ComputeFluxValues(TPZFMatrix< REAL > &fluxes)
Computes the flux values based on a Material of Hdiv approx space.
TPZManVector< REAL, 3 > normal
normal to the element at the integration point
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
TPZMaterialData & operator=(const TPZMaterialData &cp)
TPZFNMatrix< 660, REAL > dphi
values of the derivative of the shape functions over the master element
Contains declaration of TPZCompEl class which defines the interface of a computational element...
int NintPts
amount of points in the integrstion rule
Defines PZError.
void SetAllRequirements(bool set)
Set all flags at once.
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
MShapeFunctionType fShapeType
TPZFNMatrix< 9, REAL > jacinv
value of the inverse of the jacobian at the integration point
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
TPZFNMatrix< 9, REAL > jacobian
value of the jacobian at the integration point
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
int p
maximum polinomial order of the shape functions
TPZFNMatrix< 660, REAL > dphix
values of the derivative of the shape functions
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
~TPZMaterialData()
Default destructor.
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
TPZFNMatrix< 220, REAL > divphi
values of the divergence of the shapefunctions in the mapped element (only applicable to H(div)) spac...
TPZManVector< REAL, 3 > XCenter
value of the coordinate at the center of the element
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.h:783
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
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
Contains declaration of TPZInterfaceElement class which computes the contribution over an interface b...
TPZFNMatrix< 180 > fNormalVec
list of normal vectors
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
TPZFNMatrix< 180 > fDirectionsOnMaster
Directions on the master element.
void PrintMathematica(std::ostream &out) const
Prints the data in a format suitable for Mathematica.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
int numberdualfunctions
number of dual function (e.g. pressure in HDiv approximations)
TPZFNMatrix< 9, REAL > axes
axes indicating the directions of the derivatives of the shapefunctions
T * begin() const
Casting operator. Returns The fStore pointer.
Definition: pzvec.h:450
Contains the TPZMaterialData class which implements an interface between TPZCompEl::CalcStiff and TPZ...
REAL HSize
measure of the size of the element
int intGlobPtIndex
global point index
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
int intLocPtIndex
Index of the current integration point being evaluated.
int ClassId() const override
Define the class id associated with the class.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TPZSolVec divsol
vector of the divergence of the solution at the integration point (only of hdiv spaces) ...
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compares the object for identity with the object pointed to, eventually copy the object.
Contains declaration of the TPZAxesTools class which implements verifications over axes...
void ComputeFunctionDivergence()
Computes the flux divergence values based on a Material of Hdiv approx space.
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
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 TPZDiscontinuousGalerkin class which implements the interface for discontinuous Galerkin...
TPZManVector< std::pair< int, int64_t > > fVecShapeIndex
correspondence between normal vector index and index of the shape functions
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
Definition: pzfmatrix.cpp:2236
TPZSolVec sol
vector of the solutions at the integration point
REAL detjac
determinant of the jacobian
TPZMaterialData()
Default constructor.
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
void Print(std::ostream &out) const
Prints the data.