NeoPZ
TPZPrimalPoisson.cpp
Go to the documentation of this file.
1 //
2 // TPZPrimalPoisson.cpp
3 // PZ
4 //
5 // Created by omar on 04/07/2016.
6 //
7 //
8 
9 #include "TPZPrimalPoisson.h"
10 
12 
13 }
14 
16 
17 }
18 
20 
21 }
22 
24 
25 }
26 
28  return new TPZPrimalPoisson(*this);
29 }
30 
32  if (this != & other) // prevent self-assignment
33  {
34  }
35  return *this;
36 }
37 
38 int TPZPrimalPoisson::Dimension() const { return 3;}
39 
40 int TPZPrimalPoisson::NStateVariables() const {return 1;}
41 
42 void TPZPrimalPoisson::Print(std::ostream & out){
43  TPZMaterial::Print(out);
44 }
45 
46 std::string TPZPrimalPoisson::Name() { return "TPZPrimalPoisson"; }
47 
48 
50 {
51  data.SetAllRequirements(false);
52  data.fNeedsSol = true;
53 }
54 
56 {
57  data.SetAllRequirements(false);
58  data.fNeedsSol = true;
59 }
60 
62 {
63  int ndata = datavec.size();
64  for (int idata=0; idata < ndata ; idata++) {
65  datavec[idata].SetAllRequirements(false);
66  datavec[idata].fNeedsSol = true;
67  }
68 }
69 
71 {
72  int ndata = datavec.size();
73  for (int idata=0; idata < ndata ; idata++) {
74  datavec[idata].SetAllRequirements(false);
75  datavec[idata].fNeedsSol = true;
76  }
77 }
78 
80  return Hash("TPZPrimalPoisson") ^ TPZMaterial::ClassId() << 1;
81 }
82 
83 void TPZPrimalPoisson::Write(TPZStream &buf, int withclassid) const{
84  DebugStop();
85 }
86 
87 
88 void TPZPrimalPoisson::Read(TPZStream &buf, void *context){
89  DebugStop();
90 }
91 
92 
95 
96  TPZFNMatrix<220,REAL> &phi = data.phi;
97  TPZFNMatrix<660,REAL> &dphix = data.dphix;
98 
99  TPZFNMatrix<15,STATE> &dpdx = data.dsol[0];
100 
101  int nphi_p = phi.Rows();
102 
103  TPZManVector<STATE,1> f(1,0.0);
105  if (this->HasForcingFunction()) {
106  this->fForcingFunction->Execute(data.x, f, df);
107  }
108 
109  int dim = this->Dimension();
110 
111  for (int ip = 0; ip < nphi_p; ip++) {
112 
113  STATE dp_dot_dphi_i = 0.0;
114  for (int i = 0; i < dim; i++) {
115  dp_dot_dphi_i += dpdx[i]*dphix(i,ip);
116  }
117 
118  ef(ip,0) += weight * (dp_dot_dphi_i - f[0] * phi(ip,0));
119 
120  for (int jp = 0; jp < nphi_p; jp++) {
121 
122  STATE dphi_j_dot_dphi_i = 0.0;
123  for (int i = 0; i < this->Dimension(); i++) {
124  dphi_j_dot_dphi_i += dphix(i,jp)*dphix(i,ip);
125  }
126 
127  ek(ip,jp) += weight * dphi_j_dot_dphi_i;
128  }
129 
130  }
131 
132 }
133 
134 
137 
138  TPZFNMatrix<220,REAL> &phi = data.phi;
139  TPZFNMatrix<660,REAL> &dphix = data.dphix;
140 
141  TPZFNMatrix<15,STATE> &dpdx = data.dsol[0];
142 
143  int nphi_p = phi.Rows();
144 
145  TPZManVector<STATE,1> f(1,0.0);
147  if (this->HasForcingFunction()) {
148  this->fForcingFunction->Execute(data.x, f, df);
149  }
150 
151  for (int ip = 0; ip < nphi_p; ip++) {
152 
153  STATE dp_dot_dphi_i = 0.0;
154  for (int i = 0; i < this->Dimension(); i++) {
155  dp_dot_dphi_i += dpdx[i]*dphix(i,ip);
156  }
157 
158  ef(ip,0) += weight * (dp_dot_dphi_i - f[0] * phi(ip,0));
159 
160  }
161 
162 }
163 
164 
167 
168  TPZFMatrix<REAL> &phi = data.phi;
169  TPZVec<STATE> &p = data.sol[0];
170 
171  int nphi_p = phi.Rows();
172 
173  TPZManVector<STATE,1> bc_data(1,0.0);
174  bc_data[0] = bc.Val2()(0,0);
175  if (bc.HasForcingFunction()) {
176  bc.ForcingFunction()->Execute(data.x, bc_data);
177  }
178 
179 
180  switch (bc.Type()) {
181  case 0 : { // Dirichlet condition
182  STATE p_D = bc_data[0];
183  for(int ip = 0 ; ip < nphi_p; ip++) {
184  ef(ip,0) += weight * gBigNumber * ( p[0] - p_D ) * phi(ip,0);
185  }
186  }
187  break;
188 
189  case 1 : { // Neumann condition
190  STATE q_N = bc_data[0];
191  for(int ip = 0 ; ip < nphi_p; ip++) {
192  ef(ip,0) += weight * q_N * phi(ip,0);
193  }
194  }
195  break;
196  default :{
197  PZError << __PRETTY_FUNCTION__ << " at line " << __LINE__ << " - Error! boundary condition not implemented\n";
198  DebugStop();
199  }
200  break;
201  }
202 }
203 
204 
207 
208  TPZFMatrix<REAL> &phi = data.phi;
209  TPZVec<STATE> &p = data.sol[0];
210 
211  int nphi_p = phi.Rows();
212 
213  TPZManVector<STATE,1> bc_data(1,0.0);
214  bc_data[0] = bc.Val2()(0,0);
215  if (bc.HasForcingFunction()) {
216  //TPZFMatrix<STATE> df;
217  bc.ForcingFunction()->Execute(data.x, bc_data);
218  }
219 
220 
221  switch (bc.Type()) {
222  case 0 : { // Dirichlet condition
223  STATE p_D = bc_data[0];
224  for(int ip = 0 ; ip < nphi_p; ip++) {
225  ef(ip,0) += weight * gBigNumber * ( p[0] - p_D ) * phi(ip,0);
226  for (int jp = 0 ; jp < nphi_p; jp++) {
227  ek(ip,jp) += gBigNumber * phi(ip,0) * phi(jp,0) * weight;
228  }
229  }
230  }
231  break;
232 
233  case 1 : { // Neumann condition
234  STATE q_N = bc_data[0];
235  for(int ip = 0 ; ip < nphi_p; ip++) {
236  ef(ip,0) += weight * q_N * phi(ip,0);
237  }
238  }
239  break;
240  default :{
241  PZError << __PRETTY_FUNCTION__ << " at line " << __LINE__ << " - Error! boundary condition not implemented\n";
242  DebugStop();
243  }
244  break;
245  }
246 
247 }
248 
249 
254  DebugStop();
255 }
256 
259  DebugStop();
260 }
261 
262 
265 {
266  DebugStop();
267 }
268 
269 
272  DebugStop();
273 }
274 
275 
277 
278 int TPZPrimalPoisson::VariableIndex(const std::string &name){
279 
280  if(!strcmp("q",name.c_str())) return 1;
281  if(!strcmp("p",name.c_str())) return 2;
282  if(!strcmp("q_exact",name.c_str())) return 3;
283  if(!strcmp("p_exact",name.c_str())) return 4;
284  if(!strcmp("f_exact",name.c_str())) return 5;
285 
286  return TPZMaterial::VariableIndex(name);
287 }
288 
290  if(var == 1) return this->Dimension();
291  if(var == 2) return 1;
292  if(var == 3) return this->Dimension();
293  if(var == 4) return 1;
294  if(var == 5) return 1;
295 
297 }
298 
300 
301  Solout.Resize( this->NSolutionVariables(var));
302  TPZVec<STATE> p, q, f;
303 
304  if(var == 1){
305  for (int i=0; i < this->Dimension(); i++)
306  {
307  Solout[i] = -data.dsol[0][i];
308  }
309  return;
310  }
311 
312  if(var == 2){
313  Solout[0] = data.sol[0][0];
314  return;
315  }
316 
317  if(var == 3){
318  TPZManVector<STATE,1> f(1,0.0);
319  TPZFNMatrix<4,STATE> df(4,1,0.0);
320  if (this->HasForcingFunctionExact()) {
321  this->fForcingFunctionExact->Execute(data.x, f, df);
322  }
323 
324  for (int i=0; i < this->Dimension(); i++)
325  {
326  Solout[i] = df(i,0);
327  }
328  return;
329  }
330 
331  if(var == 4){
332  TPZManVector<STATE,1> f(1,0.0);
333  TPZFNMatrix<4,STATE> df(4,1,0.0);
334  if (this->HasForcingFunctionExact()) {
335  this->fForcingFunctionExact->Execute(data.x, f, df);
336  }
337  Solout[0] = f[0];
338  return;
339  }
340 
341  if(var == 5){
342  TPZManVector<STATE,1> f(1,0.0);
343  TPZFNMatrix<4,STATE> df(4,1,0.0);
344  if (this->HasForcingFunctionExact()) {
345  this->fForcingFunctionExact->Execute(data.x, f, df);
346  }
347  Solout[0] = df(3,0);
348  return;
349  }
350 
351  DebugStop();
352 
353 }
354 
356  DebugStop();
357 }
358 
360 
361  error.Fill(0.0);
362  // q = - grad (p)
363  du *= -1.0;
364 
366  STATE p_error = u[0] - u_exact[0];
367  error[0] = p_error*p_error;
368 
370  for(int i = 0; i < this->Dimension(); i++) {
371  STATE d_error = du(i,0) - du_exact(i,0);
372  error[1] += d_error*d_error;
373  }
374 
376  error[2]= error[1];
377 
378 }
379 
380 
virtual void Write(TPZStream &buf, int withclassid) const override
write class in disk
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
int VariableIndex(const std::string &name) override
Variable index based on variable naming.
void Print(std::ostream &out) override
print all material information
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
void Errors(TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &du, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux, TPZVec< STATE > &u_exact, TPZFMatrix< STATE > &du_exact, TPZVec< REAL > &error) override
Compute errors, no comments!!!
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
clarg::argBool bc("-bc", "binary checkpoints", false)
int NEvalErrors() override
Number of errors being computed = { 0-> h1, 1 ->L2 primal, 2 L2 dual}.
virtual int NStateVariables() const override
return the number of state variables associated with each trial function
int Type()
Definition: pzbndcond.h:249
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
void SetAllRequirements(bool set)
Set all flags at once.
TPZPrimalPoisson & operator=(const TPZPrimalPoisson &other)
assignment operator
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
void FillBoundaryConditionDataRequirement(int type, TPZMaterialData &data) override
fill requirements for bounadry contribute methods
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
TPZMaterial * NewMaterial() override
return a material object from a this object
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 ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
Boundary contribute with jacobian matrix.
TPZFNMatrix< 660, REAL > dphix
values of the derivative of the shape functions
virtual void Print(std::ostream &out=std::cout)
Prints out the data associated with the material.
void error(char *string)
Definition: testShape.cc:7
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
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
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
void FillDataRequirements(TPZMaterialData &data) override
fill requirements for volumetric contribute methods
f
Definition: test.py:287
#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
virtual int HasForcingFunctionExact()
Directive that gives true if the material has a function exact.
Definition: TPZMaterial.h:475
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual int HasForcingFunction()
Directive that gives true if the material has a forcing function.
Definition: TPZMaterial.h:472
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
std::string Name() override
print material name
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
int ClassId() const override
Unique identifier for serialization purposes.
void Read(TPZStream &buf, void *context) override
write class from disk
virtual int ClassId() const override
unique class identifier
int Dimension() const override
return the euclidean dimension of the weak statement
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout) override
Postprocess required variables.
void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
Volumetric contribute with jacobian matrix.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
This material consider exactly just laplace equation (i.e. coefficient equal to 1) ...
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
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
~TPZPrimalPoisson()
default desconstructor
TPZSolVec sol
vector of the solutions at the integration point
TPZPrimalPoisson()
default constructor
int NSolutionVariables(int var) override
size of the current variable (1 -> scalar, 3-> vector, 9 -> Tensor )
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15