NeoPZ
TPZMatDualHybridPoisson.cpp
Go to the documentation of this file.
1 
3 #include "pzbndcond.h"
4 #include "pzaxestools.h"
5 
6 //int TPZMatDualHybridPoisson::mydim = 2;
7 
8 TPZMatDualHybridPoisson::TPZMatDualHybridPoisson(int nummat, REAL f, REAL betaZero)
10 TPZDiscontinuousGalerkin(nummat),fXf(f), fBetaZero(betaZero){
11  mydim = 0;
12 }
13 
16 fXf(0.), fBetaZero(0.)
17 {
18  mydim = 0;
19 
20 }
21 
24  mydim = 0;
25 }
26 
29  mydim = copy.mydim;
30  fXf = copy.fXf;
31  fBetaZero = copy.fBetaZero;
32 }
33 
35 
36 }
37 
38 void TPZMatDualHybridPoisson::Print(std::ostream & out){
39  out << "\n" << this->Name() << "\n";
40  out << "fXf = " << fXf << "\n";
41  out << "fBetaZero = " << fBetaZero << "\n";
43 }
44 
46  REAL weight,
48  TPZFMatrix<STATE> &ef){
49  if(mydim==0) DebugStop();
50 
51  TPZFMatrix<REAL> &phi = data.phi;
52  TPZFMatrix<REAL> &dphi = data.dphix;
53  TPZVec<REAL> &x = data.x;
54  const int nshape = phi.Rows();
55  // const REAL beta = this->Beta(data.p,data.HSize);
56 
57  if(dphi.Rows() == mydim-1){
58 
59  return;
60 
61  }
62  else if(dphi.Rows() == mydim){
63 
64  STATE Fval = fXf;
65  if(this->HasForcingFunction()){
67  TPZFMatrix<STATE> dres(Dimension(),1);
68  fForcingFunction->Execute(x,res,dres);
69  Fval = res[0];
70  }
71 
73  for( int in = 0; in < nshape; in++ ) {
74  ef(in, 0) += weight * Fval * phi(in,0);
75  for( int jn = 0; jn < nshape; jn++ ) {
76  //ek(in,jn) += weight * ( dphi(0,in) * dphi(0,jn) + dphi(1,in) * dphi(1,jn) );
77 
78  REAL temp=0.;
79  for(int k =0; k<mydim; k++){
80  temp += dphi(k,in) * dphi(k,jn);
81  }
82  ek(in,jn) += weight*temp;
83  }
84  }
85 
86  return;
87 
88  }
89  else DebugStop();
90 
91 }
92 
94  REAL weight,
97  TPZBndCond &bc){
98 
99  TPZFMatrix<REAL> &phi = data.phi;
100  const int nshape = phi.Rows();
101  STATE valBC;
102  valBC = bc.Val2()(0,0);
103 
104  if(bc.HasForcingFunction()) {
106  bc.ForcingFunction()->Execute(data.x,res);
107  valBC = res[0];
108  }
109 
110  if(bc.Type() == 0)
111  { // Dirichlet condition
112  for(int i = 0; i < nshape; i++){
113  ef(i,0) += weight * gBigNumber * phi(i,0) * valBC;
114  for (int j = 0; j < nshape; j++){
115  ek(i,j) += weight * gBigNumber * phi(i,0) * phi(j,0);
116  }
117  }
118  return;
119  }
120  // else{
121  // PZError << "TPZMatDualHybridPoisson::ContributeBC error. BC type not implemented\n";
122  // DebugStop();
123  // }
124 
125 
126  if(bc.Type()==1){//Neumann
127  for(int i = 0; i < nshape; i++) {
128  ef(i,0) += weight*phi(i,0)*valBC;
129  }
130  return;
131  }
132 
133 
134 }
135 
137  TPZMaterialData &dataleft,
138  TPZMaterialData &dataright,
139  REAL weight,
140  TPZFMatrix<STATE> &ek,
141  TPZFMatrix<STATE> &ef){
142 
143  TPZFMatrix<REAL> &dphiLdAxes = dataleft.dphix;
144  TPZFMatrix<REAL> &dphiRdAxes = dataright.dphix;
145  TPZFMatrix<REAL> &phiL = dataleft.phi;
146  TPZFMatrix<REAL> &phiR = dataright.phi;
147  TPZManVector<REAL,3> &normal = data.normal;
148  const REAL faceSize = data.HSize;
149  const REAL beta = this->Beta(data.p,faceSize);
150 
151  const int nshapeL = phiL.Rows();
152  const int nshapeR = phiR.Rows();
153 
154  TPZFNMatrix<660> dphiL, dphiR;
155  TPZAxesTools<REAL>::Axes2XYZ(dphiLdAxes, dphiL, dataleft.axes);
156  TPZAxesTools<REAL>::Axes2XYZ(dphiRdAxes, dphiR, dataright.axes);
157 
158  const REAL theta = +1;
159 
160  if(dphiRdAxes.Rows() != mydim-1 || dphiLdAxes.Rows() != mydim) DebugStop(); //o multiplicador de Lagrange foi assumido como direito
163 
165  for(int il = 0; il < nshapeL; il++){
166  for(int jl = 0; jl < nshapeL; jl++){
167  //ek(il,jl) += weight * (-1.)* (dphiL(0,jl)*normal[0]+dphiL(1,jl)*normal[1]) * phiL(il,0);
168 
169  REAL temp = 0.;
170  for(int k=0; k<mydim; k++){
171  temp += dphiL(k,jl)*normal[k];
172  }
173  ek(il,jl) += weight * (-1.)* temp * phiL(il,0);
174  }
175  }
176 
178  for(int il = 0; il < nshapeL; il++){
179  for(int jl = 0; jl < nshapeL; jl++){
180  //ek(il,jl) += weight * theta * (-1.)* (dphiL(0,il)*normal[0]+dphiL(1,il)*normal[1]) * phiL(jl,0);
181 
182  REAL temp = 0.;
183  for(int k=0; k<mydim; k++){
184  temp += dphiL(k,il)*normal[k];
185  }
186  ek(il,jl) += weight * theta * (-1.)* temp * phiL(jl,0);
187  }
188  }
189 
191  for(int il = 0; il < nshapeL; il++){
192  for(int jr = 0; jr < nshapeR; jr++){
193  //ek(il,nshapeL+jr) += weight * theta * (+1.)* (dphiL(0,il)*normal[0]+dphiL(1,il)*normal[1]) * phiR(jr,0);
194 
195  REAL temp = 0.;
196  for(int k=0; k<mydim; k++){
197  temp += dphiL(k,il)*normal[k];
198  }
199  ek(il,nshapeL+jr) += weight * theta * (+1.)* temp * phiR(jr,0);
200  }
201  }
202 
204  for(int il = 0; il < nshapeL; il++){
205  for(int jl = 0; jl < nshapeL; jl++){
206  ek(il,jl) += weight * beta * phiL(il,0) * phiL(jl,0);
207  }
208  }
209 
211  for(int il = 0; il < nshapeL; il++){
212  for(int jr = 0; jr < nshapeR; jr++){
213  ek(il,nshapeL+jr) += weight * (-1.) * beta * phiL(il,0) * phiR(jr,0);
214  }
215  }
216 
218  for(int ir = 0; ir < nshapeR; ir++){
219  for(int jl = 0; jl < nshapeL; jl++){
220  // ek(nshapeL+ir,jl) += weight * ( dphiL(0,jl)*normal[0] + dphiL(1,jl)*normal[1] ) * phiR(ir,0);
221  // ek(nshapeL+ir,jl) += weight * (-beta) * phiL(jl,0) * phiR(ir,0);
222 
223  REAL temp = 0.;
224  for(int k=0; k<mydim; k++){
225  temp += dphiL(k,jl)*normal[k];
226  }
227  ek(nshapeL+ir,jl) += weight * temp * phiR(ir,0);
228  ek(nshapeL+ir,jl) += weight * (-beta) * phiL(jl,0) * phiR(ir,0);
229 
230  }
231  }
232 
234  for( int i = 0; i < nshapeR; i++ ) {
235  for( int j = 0; j < nshapeR; j++ ) {
236  ek(i+nshapeL,j+nshapeL) += weight * (beta) * phiR(i,0) * phiR(j,0);
237  }
238  }
239 
240 
241 }
242 
244  TPZMaterialData &dataleft,
245  REAL weight,
246  TPZFMatrix<STATE> &ek,
247  TPZFMatrix<STATE> &ef,
248  TPZBndCond &bc){
249  //PZError << "TPZMatDualHybridPoisson::ContributeBCInterface should never be called in this formulation\n";
250  //DebugStop();
251 }
252 
253 int TPZMatDualHybridPoisson::VariableIndex(const std::string &name){
254  if(!strcmp("Solution",name.c_str())) return 1;
255  if(!strcmp("ExactSolution",name.c_str())) return 2;
256  if(!strcmp("Grad",name.c_str())) return 3;
257  if(!strcmp("ExactGrad",name.c_str())) return 4;
258  return TPZMaterial::VariableIndex(name);
259 }
260 
262  if(var == 1 || var==99 || var==2) return 1;
263  if(var == 3 || var==4) return Dimension();
265 }
266 
268  Solout.Resize( this->NSolutionVariables( var ) );
269 
270  if(var == 1){
271  Solout[0] = data.sol[0][0];//solution - escalar
272  return;
273  }
274 
275  if(var == 99){
276  Solout[0] = data.p;//solution - escalar
277  return;
278  }
279 
280  TPZVec<REAL> ptx(3);
281  TPZVec<STATE> solExata(1);
282  TPZFMatrix<STATE> flux(mydim,1);
283 
284  //Exact soluion
285  if(var == 2){
286  fForcingFunctionExact->Execute(data.x, solExata,flux);
287  Solout[0] = solExata[0];
288  return;
289  }//var6
290 
291  if(var == 3) {
292  int id;
293  for(id=0 ; id<Dimension(); id++) {
294  TPZFNMatrix<9,STATE> dsoldx;
295  TPZAxesTools<STATE>::Axes2XYZ(data.dsol[0], dsoldx, data.axes);
296  Solout[id] = dsoldx(id,0);//derivate
297  }
298  return;
299  }
300 
301  if(var == 4) {
302  int id;
303  fForcingFunctionExact->Execute(data.x, solExata,flux);
304  for(id=0 ; id<mydim; id++) {
305  Solout[id] = flux(id,0);
306  }
307  return;
308  }
309 
310  TPZMaterial::Solution(data,var,Solout);
311 }
312 
314  TPZFMatrix<STATE> &dudaxes, TPZFMatrix<REAL> &axes, TPZVec<STATE> &flux,
315  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values){
316  values.Resize(3);
317  values.Fill(0.);
318  TPZFNMatrix<20,STATE> dudx(dudaxes.Rows(),dudaxes.Cols());
319  TPZAxesTools<STATE>::Axes2XYZ(dudaxes, dudx, axes);
320  if (dudx.Rows() < mydim) {
321  // this is a lagrange multiplier element
322  return;
323  }
325  values[1] = (u[0] - u_exact[0])*(u[0] - u_exact[0]);
327  values[2] = 0.;
328  for(int i = 0; i < mydim; i++){
329  values[2] += (dudx(i,0) - du_exact(i,0))*(dudx(i,0) - du_exact(i,0));
330  }
332  values[0] = values[1]+values[2];
333 }
334 
336  return Hash("TPZMatDualHybridPoisson") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
337 }
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)
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
Contains the TPZMatLaplacian class.
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
TPZManVector< REAL, 3 > normal
normal to the element at the integration point
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
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)
static void Axes2XYZ(const TPZFMatrix< TVar > &dudaxes, TPZFMatrix< TVar > &dudx, const TPZFMatrix< REAL > &axesv, bool colMajor=true)
Makes the basis transformation from axes basis to euclidian basis.
Definition: pzaxestools.h:61
virtual int Dimension() const override
Returns the integrable dimension of the material.
REAL fXf
Forcing function value.
int Type()
Definition: pzbndcond.h:249
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
virtual int VariableIndex(const std::string &name) override
Returns the variable index associated with the name.
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)
int p
maximum polinomial order of the shape functions
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.
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.
virtual int ClassId() const override
Unique identifier for serialization purposes.
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
TPZAutoPointer< TPZFunction< STATE > > & ForcingFunction()
Returns a procedure as source function for the material.
Definition: TPZMaterial.h:397
REAL Beta(int p, REAL size) const
virtual void ContributeInterface(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
void
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
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
void
#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 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...
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
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...
TPZFNMatrix< 9, REAL > axes
axes indicating the directions of the derivatives of the shapefunctions
string res
Definition: test.py:151
REAL HSize
measure of the size of the element
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
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
virtual ~TPZMatDualHybridPoisson() override
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
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
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
Contains declaration of the TPZAxesTools class which implements verifications over axes...
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
def values
Definition: rdt.py:119
virtual void ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
void
TPZSolVec sol
vector of the solutions at the integration point
virtual std::string Name() override
Returns the name of the material.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716