NeoPZ
TPZDualPoisson.cpp
Go to the documentation of this file.
1 //
2 // TPZDualPoisson.cpp
3 // PZ
4 //
5 // Created by omar on 04/07/2016.
6 //
7 //
8 
9 #include "TPZDualPoisson.h"
10 
11 
13 
14 }
15 
17 
18 }
19 
21 
22 }
23 
25 
26 }
27 
29  return new TPZDualPoisson(*this);
30 }
31 
33 
34  if (this != & other) // prevent self-assignment
35  {
37  }
38  return *this;
39 }
40 
41 int TPZDualPoisson::Dimension() const { return 3;}
42 
44 {
45  return 1;
46 }
47 
48 void TPZDualPoisson::Print(std::ostream & out){
49  TPZMaterial::Print(out);
50 }
51 
52 std::string TPZDualPoisson::Name() { return "TPZDualPoisson"; }
53 
54 
56 {
57  data.SetAllRequirements(false);
58  data.fNeedsSol = true;
59 }
60 
62 {
63  data.SetAllRequirements(false);
64  data.fNeedsSol = true;
65 }
66 
68 {
69  int ndata = datavec.size();
70  for (int idata=0; idata < ndata ; idata++) {
71  datavec[idata].SetAllRequirements(false);
72  datavec[idata].fNeedsSol = true;
73  }
74 }
75 
77 {
78  int ndata = datavec.size();
79  for (int idata=0; idata < ndata ; idata++) {
80  datavec[idata].SetAllRequirements(false);
81  datavec[idata].fNeedsSol = true;
82  }
83 }
84 
86  return Hash("TPZDualPoisson") ^ TPZMaterial::ClassId() << 1;
87 }
88 
89 void TPZDualPoisson::Write(TPZStream &buf, int withclassid) const{
90  DebugStop();
91 }
92 
93 
94 void TPZDualPoisson::Read(TPZStream &buf, void *context){
95  DebugStop();
96 }
97 
98 
108 
109  DebugStop();
110 
111 }
112 
113 
116 
117  DebugStop();
118 }
119 
120 
123 
124  DebugStop();
125 
126 }
127 
128 
131 
132  DebugStop();
133 
134 }
135 
136 
147 
148  int ub = 0;
149  int pb = 1;
150 
151  TPZFNMatrix<100,REAL> phi_us = datavec[ub].phi;
152  TPZFNMatrix<100,REAL> phi_ps = datavec[pb].phi;
153  TPZFNMatrix<300,REAL> dphi_us = datavec[ub].dphix;
154  TPZFNMatrix<100,REAL> dphi_ps = datavec[pb].dphix;
155 
156 
157  TPZFNMatrix<40, REAL> div_on_master = datavec[ub].divphi;
158  STATE divu = datavec[ub].divsol[0][0];
159  STATE divflux;
160  REAL jac_det = datavec[ub].detjac;
161 
162  int nphiu = datavec[ub].fVecShapeIndex.NElements();
163  int nphip = phi_ps.Rows();
164  int firstu = 0;
165  int firstp = nphiu + firstu;
166 
167  TPZManVector<STATE,3> u = datavec[ub].sol[0];
168  STATE p = datavec[pb].sol[0][0];
169 
170  TPZFNMatrix<10,STATE> Graduaxes = datavec[ub].dsol[0];
171 
172  TPZFNMatrix<3,STATE> phi_u_i(3,1), phi_u_j(3,1);
173 
174  int s_i, s_j;
175  int v_i, v_j;
176 
177  for (int iu = 0; iu < nphiu; iu++)
178  {
179 
180  v_i = datavec[ub].fVecShapeIndex[iu].first;
181  s_i = datavec[ub].fVecShapeIndex[iu].second;
182 
183  STATE u_dot_phi_u_i = 0.0;
184  for (int i = 0; i < u.size(); i++) {
185  phi_u_i(i,0) = phi_us(s_i,0) * datavec[ub].fNormalVec(i,v_i);
186  u_dot_phi_u_i += u[i]*phi_u_i(i,0);
187  }
188 
189  ef(iu + firstu) += weight * ( u_dot_phi_u_i - p * div_on_master(iu,0));
190 
191  for (int ju = 0; ju < nphiu; ju++)
192  {
193 
194  v_j = datavec[ub].fVecShapeIndex[ju].first;
195  s_j = datavec[ub].fVecShapeIndex[ju].second;
196 
197  STATE phi_u_j_dot_phi_u_i = 0.0;
198  for (int j = 0; j < u.size(); j++) {
199  phi_u_j(j,0) = phi_us(s_j,0) * datavec[ub].fNormalVec(j,v_j);
200  phi_u_j_dot_phi_u_i += phi_u_j(j,0)*phi_u_i(j,0);
201  }
202 
203  ek(iu + firstu,ju + firstu) += weight * phi_u_j_dot_phi_u_i;
204  }
205 
206  for (int jp = 0; jp < nphip; jp++)
207  {
208  ek(iu + firstu, jp + firstp) += weight * ( - div_on_master(iu,0) ) * phi_ps(jp,0);
209  }
210 
211  }
212 
213  TPZManVector<STATE,1> f(1,0.0);
214  if (this->HasForcingFunction()) {
215  this->fForcingFunction->Execute(datavec[ub].x, f);
216  }
217 
218  for (int ip = 0; ip < nphip; ip++)
219  {
220 
221  ef(ip + firstp) += -1.0 * weight * (divu - f[0]) * phi_ps(ip,0);
222 
223  for (int ju = 0; ju < nphiu; ju++)
224  {
225  ek(ip + firstp, ju + firstu) += -1.0 * weight * div_on_master(ju,0) * phi_ps(ip,0);
226  }
227 
228  }
229 
230 }
231 
234  TPZFMatrix<STATE> ekfake(ef.Rows(),ef.Rows(),0.0);
235  this->Contribute(datavec, weight, ekfake, ef);
236 }
237 
238 
241 {
242  TPZFMatrix<STATE> ekfake(ef.Rows(),ef.Rows(),0.0);
243  this->ContributeBC(datavec, weight, ekfake, ef, bc);
244 }
245 
246 
249 
250  int ub = 0;
251  TPZFNMatrix<100,REAL> phi_us = datavec[ub].phi;
252 
253  int nphiu = phi_us.Rows();
254  int firstu = 0;
255 
256  TPZManVector<STATE,3> u = datavec[ub].sol[0];
257 
258  TPZManVector<STATE,1> bc_data(1,0.0);
259  bc_data[0] = bc.Val2()(0,0);
260  if (bc.HasForcingFunction()) {
261  bc.ForcingFunction()->Execute(datavec[ub].x, bc_data);
262  }
263 
264  switch (bc.Type()) {
265  case 0 : // Dirichlet BC PD
266  {
267  STATE p_D = bc_data[0];
268  for (int iu = 0; iu < nphiu; iu++)
269  {
270  ef(iu + firstu) += weight * p_D * phi_us(iu,0);
271  }
272  }
273  break;
274 
275  case 1 : // Neumann BC QN
276  {
277 
278  for (int iu = 0; iu < nphiu; iu++)
279  {
280  STATE un_N = bc_data[0], un = u[0];
281  ef(iu + firstu) += weight * gBigNumber * (un - un_N) * phi_us(iu,0);
282 
283  for (int ju = 0; ju < nphiu; ju++)
284  {
285 
286  ek(iu + firstu,ju + firstu) += weight * gBigNumber * phi_us(ju,0) * phi_us(iu,0);
287  }
288 
289  }
290 
291  }
292  break;
293 
294  default: std::cout << "This BC doesn't exist." << std::endl;
295  {
296 
297  DebugStop();
298  }
299  break;
300  }
301 
302  return;
303 }
304 
305 
315 
316 int TPZDualPoisson::VariableIndex(const std::string &name){
317 
318  if(!strcmp("q",name.c_str())) return 1;
319  if(!strcmp("p",name.c_str())) return 2;
320  if(!strcmp("q_exact",name.c_str())) return 3;
321  if(!strcmp("p_exact",name.c_str())) return 4;
322  if(!strcmp("f_exact",name.c_str())) return 5;
323  if(!strcmp("div_q",name.c_str())) return 6;
324 
325  return TPZMaterial::VariableIndex(name);
326 }
327 
329  if(var == 1) return this->Dimension();
330  if(var == 2) return 1;
331  if(var == 3) return this->Dimension();
332  if(var == 4) return 1;
333  if(var == 5) return 1;
334  if(var == 6) return 1;
335 
337 }
338 
340 
341  DebugStop();
342 
343 }
344 
346 
347  int ub = 0;
348  int pb = 1;
349 
350  Solout.Resize( this->NSolutionVariables(var));
351  TPZManVector<STATE,3> p, u, f;
352 
353  u = datavec[ub].sol[0];
354  p = datavec[pb].sol[0];
355 
356  STATE div_u = datavec[ub].divsol[0][0];
357 
358  if(var == 1){
359  for (int i=0; i < this->Dimension(); i++)
360  {
361  Solout[i] = u[i];
362  }
363  return;
364  }
365 
366  if(var == 2){
367  Solout[0] = p[0];
368  return;
369  }
370 
371  if(var == 3){
372  TPZManVector<STATE,1> f(1,0.0);
373  TPZFNMatrix<4,STATE> df(4,1,0.0);
374  if (this->HasForcingFunctionExact()) {
375  this->fForcingFunctionExact->Execute(datavec[ub].x, f, df);
376  }
377 
378  for (int i=0; i < this->Dimension(); i++)
379  {
380  Solout[i] = df(i,0);
381  }
382  return;
383  }
384 
385  if(var == 4){
386  TPZManVector<STATE,1> f(1,0.0);
387  TPZFNMatrix<4,STATE> df(4,1,0.0);
388  if (this->HasForcingFunctionExact()) {
389  this->fForcingFunctionExact->Execute(datavec[ub].x, f, df);
390  }
391  Solout[0] = f[0];
392  return;
393  }
394 
395  if(var == 5){
396  TPZManVector<STATE,1> f(1,0.0);
397  TPZFNMatrix<4,STATE> df(4,1,0.0);
398  if (this->HasForcingFunctionExact()) {
399  this->fForcingFunctionExact->Execute(datavec[ub].x, f, df);
400  }
401  Solout[0] = df(3,0);
402  return;
403  }
404 
405  if(var == 6){
406  Solout[0] = div_u;
407  return;
408  }
409 
410 
411  DebugStop();
412 }
413 
415 {
416 
417  errors.Fill(0.0);
418 
419  int ub = 0;
420  int pb = 1;
421  TPZManVector<STATE,3> p, u, f;
422 
423  u = data[ub].sol[0];
424  p = data[pb].sol[0];
425 
426  TPZFMatrix<STATE> dudx = data[ub].dsol[0];
427 
428  STATE div_u = 0.0;
429  for(int i = 0; i < this->Dimension(); i++) {
430  div_u += dudx(i,i);
431  }
432 
433  STATE div_error = div_u - du_exact(3,0); // using f source term on the fourth position of du_exact
434 
436  STATE p_error = p[0] - u_exact[0];
437  errors[0] = p_error*p_error;
438 
440  for(int i = 0; i < this->Dimension(); i++) {
441  STATE d_error = u[i] - du_exact(i,0);
442  errors[1] += d_error*d_error;
443  }
444 
446  errors[2]= div_error * div_error;
447 }
448 
450 
451  DebugStop();
452 
453 }
454 
This material consider exactly just laplace equation (i.e. coefficient equal to 1) ...
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
int NSolutionVariables(int var) override
size of the current variable (1 -> scalar, 3-> vector, 9 -> Tensor )
TPZDualPoisson()
default constructor
clarg::argBool bc("-bc", "binary checkpoints", false)
int Type()
Definition: pzbndcond.h:249
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.
void SetAllRequirements(bool set)
Set all flags at once.
int VariableIndex(const std::string &name) override
Variable index based on variable naming.
TPZDualPoisson & operator=(const TPZDualPoisson &other)
assignment operator
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
int Dimension() const override
return the euclidean dimension of the weak statement
TPZFMatrix< STATE > & Val2(int loadcase=0)
Definition: pzbndcond.h:255
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
void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout) override
Postprocess required variables.
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
f
Definition: test.py:287
int NEvalErrors() override
Number of errors being computed = { 0-> h1, 1 ->L2 primal, 2 L2 dual}.
void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
Boundary contribute without jacobian matrix.
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
Volumetric contribute without jacobian matrix.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunctionExact
Pointer to exact solution function, needed to calculate exact error.
Definition: TPZMaterial.h:50
virtual int ClassId() const override
unique class identifier
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
std::string Name() override
print material name
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
~TPZDualPoisson()
default desconstructor
virtual int NStateVariables() const override
return the number of state variables associated with each trial function
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
void Read(TPZStream &buf, void *context) override
write class from disk
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual void Write(TPZStream &buf, int withclassid) const override
write class in disk
int ClassId() const override
Unique identifier for serialization purposes.
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
void FillBoundaryConditionDataRequirement(int type, TPZMaterialData &data) override
fill requirements for bounadry contribute methods
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
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
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
TPZMaterial * NewMaterial() override
return a material object from a this object
void FillDataRequirements(TPZMaterialData &data) override
fill requirements for volumetric contribute methods
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!!!
void Print(std::ostream &out) override
print all material information
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716