NeoPZ
pzpostprocmat.cpp
Go to the documentation of this file.
1 
5 #include "pzpostprocmat.h"
6 //#include "poroelastoplasticid.h"
7 #include "pzbndcond.h"
8 
9 #ifdef LOG4CXX
10 #include "pzlog.h"
11 static LoggerPtr postprocLogger(Logger::getLogger("material.pzPostProcMat"));
12 #endif
13 
14 
16 {
17  fVars.Resize(0);
18  fDimension = -1;
19 }
20 
22 {
23  fVars.Resize(0);
24  fDimension = -1;
25 }
26 
28 {
29 }
30 
32 {
33 #ifdef PZDEBUG
34  std::cout << "TPZPostProcMat:: Material Id = " << Id() << ", it is being deleted. " << std::endl;
35 #endif
36 
37 }
38 
39 void TPZPostProcMat::Print(std::ostream &out)
40 {
41  out << this->Name();
42  out << "\n Base material Data:\n";
44  out << "Dimension " << fDimension << std::endl;
45  int64_t nVars = fVars.NElements();
46  out << "\n Post Process Variables\n";
47  for(int64_t i = 0; i < nVars; i++)
48  {
49  out << fVars[i].fName << " of size " << fVars[i].fNumEq << " and index " << fVars[i].fIndex << std::endl;
50  }
51 }
52 
53 int TPZPostProcMat::VariableIndex(const std::string &name)
54 {
55  int64_t i, nVars = fVars.NElements();
56 
57  i = 0;
58 
59  while(i < nVars && strcmp(fVars[i].fName.c_str(), name.c_str()))i++;
60 
61  if(i >= nVars)
62  {
63  PZError << "TPZPostProcMat::Variable " << name << " not found\n";
64  return -1; // variable not found
65  }
66 
67  return fVars[i].fIndex;
68 }
69 
71 {
72  int64_t i, nVars = fVars.NElements();
73 
74  i = 0;
75 
76  while(i < nVars && var != fVars[i].fIndex)i++;
77 
78  if(i >= nVars) return -1; // variable not found
79 
80  return fVars[i].fNumEq;
81 }
82 
84 {
85  int64_t i, nVars = fVars.NElements(), size = 0;
86  for(i = 0; i < nVars; i++) size += fVars[i].fNumEq;
87  return size;
88 }
89 
91 {
92 
93 #ifdef LOG4CXX_keep
94  {
95  std::stringstream sout;
96  sout << ">>> TPZPostProcMat::Solution() *** called for variable index = " << var;
97  LOGPZ_DEBUG(postprocLogger,sout.str().c_str());
98  }
99 #endif
100 
101  int64_t i, nVars = fVars.NElements(), offset = 0;
102 
103  i = 0;
104 
105  while(i < nVars && var != fVars[i].fIndex)
106  {
107  offset += fVars[i].fNumEq;
108  i++;
109  }
110 
111  if(i >= nVars)return; // variable not found
112 
113  int64_t numeq = fVars[i].fNumEq;
114 
115  Solout.Resize(numeq);
116 
117  for(i = 0; i < numeq; i++)Solout[i] = data.sol[0][offset+i];
118 }
119 
121 {
122 
123  TPZFMatrix<REAL> &phi = data.phi;
124  TPZVec<STATE> &sol = data.sol[0];
125  int nstate = NStateVariables();
126 
127  int64_t nshape = phi.Rows();
128  int64_t i, j, i_var;
129 
130  for(i = 0; i < nshape; i++)
131  for(j = 0; j < nshape; j++)
132  ek(i,j) += phi(i,0) * phi(j,0);
133 
134  for(i = 0; i < nstate; i++)
135  {
136  int64_t eqOffset = i*nshape;
137  for(i_var = 0; i_var < nshape; i_var++)
138  ef(eqOffset+i_var,0) += (STATE)phi(i_var,0) * sol[i];
139  }
140 }
141 
143 {
144  PZError << "Error at " << __PRETTY_FUNCTION__ << " TPZPostProcMat::Contribute(ef) should never be called\n";
145  return;
146 }
147 
149 {
150  PZError << "Error at " << __PRETTY_FUNCTION__ << " TPZPostProcMat::ContributeBC() should never be called\n";
151  return;
152 }
153 
155  // do nothing
156 }
157 
159  // do nothing
160 }
161 
163  return Hash("TPZPostProcMat") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
164 }
165 
166 std::string TPZPostProcMat::Name() {
167  return "TPZPostProcMat";
168 }
169 
170 void TPZPostProcMat::Write(TPZStream &buf, int withclassid) const
171 {
172 
173  TPZDiscontinuousGalerkin::Write(buf, withclassid);
174  buf.Write(fVars);
175  buf.Write(&fDimension);
176 }
177 
178 void TPZPostProcMat::Read(TPZStream &buf, void *context)
179 {
180  TPZDiscontinuousGalerkin::Read(buf, context);
181 
182  buf.Read(fVars);
183  buf.Read(&fDimension);
184 }
185 
187 
189  data.SetAllRequirements(false);
190  data.fNeedsSol = true;
191 }
192 
194 {
195  int64_t i, n = fVars.NElements();
196  varIndexList.Resize(n);
197 
198  for(i = 0; i < n; i++)varIndexList[i] = fVars[i].fIndex;
199 }
200 
202 {
203  if(!pRefMat)
204  {
205  PZError << "Error at " << __PRETTY_FUNCTION__ << " TPZPostProcMat::SetPostProcessVarIndexList() without valid reference material to post process\n";
206  return;
207  }
208 
209  int64_t i, n = varIndexNames.NElements(), k = 0;
210  int varindex;
211  fVars.Resize(n);
212 
213  for(i = 0; i < n; i++)
214  {
215  varindex = pRefMat->VariableIndex(varIndexNames[i]);
216  if(varindex >= 0)
217  {
218  fVars[k].fIndex = varindex;
219  fVars[k].fNumEq = pRefMat->NSolutionVariables(varindex);
220  fVars[k].fName = varIndexNames[i];
221  k++;
222  }
223  }
224 
225  fVars.Resize(k);
226  fDimension = pRefMat->Dimension();
227 
228 }
229 
231 {
232  return fDimension;
233 }
234 
236  return Hash("TPZPostProcVar");
237 }
238 
239 void TPZPostProcVar::Read(TPZStream& buf, void* context) {
240  buf.Read(&fIndex);
241  buf.Read(&fName);
242  buf.Read(&fNumEq);
243 }
244 
245 void TPZPostProcVar::Write(TPZStream& buf, int withclassid) const {
246  buf.Write(&fIndex);
247  buf.Write(&fName);
248  buf.Write(&fNumEq);
249 }
250 
251 template class TPZRestoreClass<TPZPostProcVar>;
252 template class TPZRestoreClass<TPZPostProcMat>;
Defines the interface which material objects need to implement for discontinuous Galerkin formulation...
Definition: pzdiscgal.h:20
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 ...
int ClassId() const override
Define the class id associated with the class.
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
TPZPostProcMat()
Default constructor.
TPZManVector< TPZPostProcVar, 20 > fVars
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)
virtual void Write(TPZStream &buf, int withclassid) const override
Save the element data to a stream.
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: pzdiscgal.cpp:118
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...
void SetPostProcessVarIndexList(TPZVec< std::string > &varIndexNames, TPZMaterial *pRefMat)
Informs the vector with all the variable indexes requested for post processing and the reference to t...
virtual void ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to stiffness matrix and load vector at one BC integration point...
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
void Read(TPZStream &buf, void *context) override
read objects from the stream
void SetAllRequirements(bool set)
Set all flags at once.
virtual int Dimension() const =0
Returns the integrable dimension of the material.
virtual ~TPZPostProcMat()
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...
virtual void FillDataRequirements(TPZMaterialData &data) override
Defining what parameters the material needs. In particular this material needs the evaluation of norm...
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
virtual int ClassId() const override
Unique identifier for serialization purposes.
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
virtual void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
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...
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 VariableIndex(const std::string &name) override
returns the variable index associated with the name
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: pzdiscgal.cpp:114
virtual void FillDataRequirements(TPZMaterialData &data)
Fill material data parameter with necessary requirements for the.
Definition: TPZMaterial.cpp:81
#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
virtual void ContributeInterface(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to stiffness matrix and load vector at one integration point...
virtual void Print(std::ostream &out=std::cout) override
print out the data associated with the material
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
void GetPostProcessVarIndexList(TPZVec< int > &varIndexList)
Returns a vector with all the variable indexes requested for post processing and an the total number ...
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
int Id() const
Definition: TPZMaterial.h:170
virtual int Dimension() const override
returns the integrable dimension of the material
virtual int NStateVariables() const override
returns the number of state variables associated with the material
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
int fDimension
virtual std::string Name() override
returns the name of the material
virtual int NSolutionVariables(int var) override
returns the number of variables associated with the variable indexed by var. var is obtained by calli...
TPZSolVec sol
vector of the solutions at the integration point
Definition: pzpostprocmat.h:51
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
#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
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.