NeoPZ
pzmattest3d.cpp
Go to the documentation of this file.
1 
6 #include "pzmattest3d.h"
7 #include "pzelmat.h"
8 #include "pzbndcond.h"
9 #include "pzmatrix.h"
10 #include "pzfmatrix.h"
11 #include "pzerror.h"
12 #include "pzadmchunk.h"
13 #include <math.h>
14 #include <cmath>
15 
16 #include "pzlog.h"
17 
18 #ifdef LOG4CXX
19 static LoggerPtr logger(Logger::getLogger("pz.material.tpzmattest3d"));
20 #endif
21 using namespace std;
22 int TPZMaterialTest3D::geq3 = -1;//Cedric : para testes no programa main 3dmaterial.c
23 
26 TPZMaterial(), fXf()
27 {
28 }
29 
31 TPZMaterial(nummat), fXf()
32 {
33 }
34 
36 {
37 }
38 
40 {
41  return 1;
42 }
43 
44 void TPZMaterialTest3D::Print(std::ostream &out)
45 {
46  std::stringstream sout;
47  sout << " Name of material : " << Name() << "properties: " ;
48  fXf.Print( sout.str().c_str(),out,EFormatted );
49  sout << " Common properties: " ;
50  TPZMaterial::Print(out);
51 }
52 
55 {
56  TPZFMatrix<REAL> &dphi = data.dphix;
57  TPZFMatrix<REAL> &phi = data.phi;
58  TPZManVector<REAL,3> &x = data.x;
59 
60  int phr = phi.Rows();
61  if(fForcingFunction) { // phi(in, 0) = phi_in
63  fForcingFunction->Execute(x,res); // dphi(i,j) = dphi_j/dxi
64  fXf(0,0) = res[0];
65  }
66  if(geq3==0) {
67  for( int in = 0; in < phr; in++ )
68  {
69  ef(in, 0) += weight * fXf(0,0) * phi(in, 0);
70  for( int jn = 0; jn < phr; jn++ )
71  {
72  ek(in,jn) += weight * phi(in,0) * phi(jn,0);
73  }
74  }
75  }else if( geq3==1 )
76  {
77  //Equa�o de Poisson
78  for( int in = 0; in < phr; in++ )
79  {
80  ef(in, 0) += weight * fXf(0,0) * phi(in, 0);
81  for( int jn = 0; jn < phr; jn++ )
82  {
83  ek(in,jn) += weight * ( dphi(0,in) * dphi(0,jn) + dphi(1,in) * dphi(1,jn) );//
84  if(dphi.Rows() == 3) ek(in,jn) += weight * dphi(2,in) * dphi(2,jn);// );
85  }
86  }
87  }
88 }
89 
92 {
93  TPZFMatrix<REAL> &phi = data.phi;
94 
95  int phr = phi.Rows();
96  short in,jn;
97  STATE v2[1];
98  v2[0] = bc.Val2()(0,0);
99 
100  switch (bc.Type())
101  {
102  case 0 : // Dirichlet condition
103  {
104  for(in = 0 ; in < phr; in++)
105  {
106  ef(in,0) += gBigNumber * v2[0] * phi(in,0) * weight;
107  for (jn = 0 ; jn < phr; jn++)
108  {
109  ek(in,jn) += gBigNumber * phi(in,0) * phi(jn,0) * weight;
110  }
111  }
112  break;
113  }
114  case 1 : // Neumann condition
115  {
116  for(in = 0 ; in < phi.Rows(); in++)
117  {
118  ef(in,0) += v2[0] * phi(in,0) * weight;
119  }
120  break;
121  }
122  case 2 : // condicao mista
123  {
124  for(in = 0 ; in < phi.Rows(); in++)
125  {
126  ef(in, 0) += v2[0] * phi(in, 0) * weight;
127  for (jn = 0 ; jn < phi.Rows(); jn++)
128  {
129  // peso de contorno => integral de contorno
130  ek(in,jn) += bc.Val1()(0,0) * phi(in,0) * phi(jn,0) * weight;
131  }
132  }
133  }
134  }
135 }
136 
138 int TPZMaterialTest3D::VariableIndex(const std::string &name)
139 {
140  if(!strcmp("Displacement6",name.c_str()))return 0;
141  if(!strcmp("Solution",name.c_str())) return 1;
142  if(!strcmp("Derivate",name.c_str())) return 2;
143  return TPZMaterial::VariableIndex(name);
144 }
145 
147 {
148  if(var == 0 || var == 1 || var == 2 || var == 10) return 1;
150 }
151 
152 
154  TPZFMatrix<REAL> &axes,int var,TPZVec<STATE> &Solout)
155 {
156  if(var == 0 || var == 1) Solout[0] = Sol[0];//function
157  else if(var == 2)
158  {
159  Solout[0] = DSol(0,0);//derivate
160  Solout[1] = DSol(1,0);//derivate
161  if(DSol.Rows()>2) Solout[2] = DSol(2,0);//derivate
162  }
163  else TPZMaterial::Solution(Sol,DSol,axes,var,Solout);
164 }
165 
166 
168  TPZFMatrix<REAL> &/*axes*/, TPZVec<STATE> &/*flux*/)
169 {
170  //Flux(TPZVec<REAL> &x, TPZVec<STATE> &Sol, TPZFMatrix<STATE> &DSol, TPZFMatrix<REAL> &axes, TPZVec<STATE> &flux)
171  LOGPZ_WARN( logger,"ERROR - Not Implemented yet!");
172 }
173 
174 
176  TPZFMatrix<REAL> &axes, TPZVec<STATE> &/*flux*/,TPZVec<STATE> & u_exact,
178 {
179  TPZManVector<STATE> sol(1),dsol(3);
180  Solution(u,dudx,axes,1,sol);
181  Solution(u,dudx,axes,2,dsol);
182  if(dudx.Rows()<3)
183  {
184  STATE dx = du_exact(0,0)*axes(0,0)+du_exact(1,0)*axes(0,1);
185  STATE dy = du_exact(0,0)*axes(1,0)+du_exact(1,0)*axes(1,1);
186  STATE parc1 = fabs(dx-dudx(0,0));
187  STATE parc2 = fabs(dy-dudx(1,0));
188  //Norma L2
189  values[1] = pow(fabs(u[0] - u_exact[0]),(STATE)2.0);
190  //seminorma
191  values[2] = pow(parc1,(STATE)2.)+pow(parc2,(STATE)2.);
192  //Norma Energia
193  values[0] = values[1]+values[2];
194  return;
195  }
196  //values[1] : eror em norma L2
197  values[1] = pow(sol[0] - u_exact[0],(STATE)2.0);
198  //values[2] : erro em semi norma H1
199  values[2] = pow(dsol[0] - du_exact(0,0),(STATE)2.0);
200  if(dudx.Rows()>1) values[2] += pow(dsol[1] - du_exact(1,0),(STATE)2.0);
201  if(dudx.Rows()>2) values[2] += pow(dsol[2] - du_exact(2,0),(STATE)2.0);
202  //values[0] : erro em norma H1 <=> norma Energia
203  values[0] = values[1]+values[2];
204 }
205 
207 {
208  int matid = Id();
209  TPZMaterialTest3D *mat = new TPZMaterialTest3D(matid);
210  mat->fXf = fXf;
211  return mat;
212 }
213 
215 {
216  fXf = xfin;
217 }
218 
220 {
221  return 3;
222 }
223 
224 void TPZMaterialTest3D::Read(TPZStream &buf, void *context)
225 {
226  TPZMaterial::Read(buf,context);
227  fXf.Read( buf,0 );
228  buf.Read( &geq3, 1);
229 #ifdef PZDEBUG2
230  int classid = -1;
231  buf.Read( &classid,1 );
232  if( classid != ClassId() )
233  {
234  std::stringstream sout;
235  sout << "Error restoring object " << __PRETTY_FUNCTION__
236  << " waiting for ClassId() = " << ClassId()
237  << " restored : " << classid;
238  LOGPZ_ERROR( logger,sout.str().c_str() );
239  }
240 #endif
241 }
242 
243 void TPZMaterialTest3D::Write(TPZStream &buf, int withclassid) const
244 {
245  TPZMaterial::Write(buf,withclassid);
246  fXf.Write( buf,0);
247  buf.Write( &geq3,1 );
248 #ifdef PZDEBUG2
249  int classid = ClassId();
250  buf.Write( &classid,1 );
251 #endif
252 }
253 
255  return Hash("TPZMaterialTest3D") ^ TPZMaterial::ClassId() << 1;
256 }
257 
258 #ifndef BORLAND
260 #endif
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
virtual int ClassId() const override
Define the class id associated with the class.
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: pzmattest3d.cpp:90
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
virtual void Print(std::ostream &out) override
Prints the object data structure.
Definition: pzmattest3d.cpp:44
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 Solution(TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, int var, TPZVec< STATE > &Solout) override
int Type()
Definition: pzbndcond.h:249
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
Defines PZError.
virtual void Flux(TPZVec< REAL > &x, TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux) override
Computes the value of the flux function to be used by ZZ error estimator.
virtual std::string Name() override
Returns the name of the material.
Definition: pzmattest3d.h:46
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Declarates the TPZBlock<REAL>class which implements block matrices.
#define LOGPZ_WARN(A, B)
Define log for warnings.
Definition: pzlog.h:91
static int geq3
Cedric : para testes no programa main 3dmaterial.c.
Definition: pzmattest3d.h:34
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)
void SetMaterial(TPZFMatrix< STATE > &xfin)
Set the flow.
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: pzmattest3d.cpp:53
TPZFNMatrix< 660, REAL > dphix
values of the derivative of the shape functions
virtual void Errors(TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &dudx, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux, TPZVec< STATE > &u_exact, TPZFMatrix< STATE > &du_exact, TPZVec< REAL > &values) override
Computes the error due to the difference between the interpolated flux and the flux computed based o...
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 declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
expr_ dx(i) *cos(expr_.val())
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
Contains TPZMatrixclass which implements full matrix (using column major representation).
Implements a three dimensional linear material for test.
Definition: pzmattest3d.h:16
Contains the TPZMaterialTest3D class. Three-dimensional test.
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
virtual int Dimension() const override
Returns the integrable dimension of the material.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
string res
Definition: test.py:151
TPZFMatrix< STATE > & Val1()
Definition: pzbndcond.h:253
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
virtual int NStateVariables() const override
Returns the number of state variables associated with the material.
Definition: pzmattest3d.cpp:39
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
Contains TPZMatrix<TVar>class, root matrix class.
TPZMaterialTest3D()
Default empty constructor.
Definition: pzmattest3d.cpp:24
int ClassId() const override
Unique identifier for serialization purposes.
virtual int VariableIndex(const std::string &name) override
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.cpp:2205
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
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
int Id() const
Definition: TPZMaterial.h:170
TPZFMatrix< STATE > fXf
Source.
Definition: pzmattest3d.h:21
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
virtual TPZMaterial * NewMaterial() override
To create another material of the same type.
def values
Definition: rdt.py:119
virtual void Read(TPZStream &buf, void *context) override
read objects from the stream
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.cpp:2225
virtual ~TPZMaterialTest3D()
Destructor.
Definition: pzmattest3d.cpp:35
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
virtual void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.