NeoPZ
TPZLinearConvecDiff.cpp
Go to the documentation of this file.
1 
2 
3 #include "TPZLinearConvecDiff.h"
4 #include "pzaxestools.h"
5 #include "pzbndcond.h"
6 
7 TPZLinearConvecDiff::TPZLinearConvecDiff(int nummat, REAL k, const TPZVec<REAL> &conv, REAL f, REAL SD)
9  fK = k;
10  fConvDir[0] = conv[0];
11  fConvDir[1] = conv[1];
12  fXf = f;
13  fSD = SD;
14 }
15 
18  fConvDir[0] = 0.;
19  fConvDir[1] = 0.;
20 }
21 
24  fConvDir[0] = 0.;
25  fConvDir[1] = 0.;
26 }
27 
30  fK = c.fK;
31  fConvDir[0] = c.fConvDir[0];
32  fConvDir[1] = c.fConvDir[1];
33  fXf = c.fXf;
34  fSD = c.fSD;
35 }
36 
39 }
40 
41 void TPZLinearConvecDiff::Print(std::ostream & out){
42  out << "name of material : " << Name() << "\n";
43  out << "fK "<< fK << std::endl;
44  out << "Convection vector " << fConvDir[0] << "\t" << fConvDir[1] << std::endl;
45  out << "fXf " << fXf << std::endl;
46  out << "fSD " << fSD << std::endl;
47  out << "Base Class properties :";
48  TPZMaterial::Print(out);
49  out << "\n";
50 }
51 
53 
54  TPZFMatrix<REAL> &phi = data.phi;
55  TPZFMatrix<REAL> &dphidaxes = data.dphix;
56  TPZFNMatrix<200,REAL> dphi(dphidaxes.Rows(),dphidaxes.Cols(),0.);
57  TPZAxesTools<REAL>::Axes2XYZ(dphidaxes, dphi, data.axes);
58 
59  TPZVec<REAL> &x = data.x;
60 // TPZFMatrix<REAL> &axes = data.axes;
61 // TPZFMatrix<REAL> &jacinv = data.jacinv;
62  const int nshape = phi.Rows();
63 
64  STATE FVal = this->fXf;
65  if(fForcingFunction) {
67  TPZFMatrix<STATE> dres(Dimension(),1);
68  fForcingFunction->Execute(x,res,dres);
69  FVal = res[0];
70  }
71  const REAL normaConveccao = sqrt(fConvDir[0]*fConvDir[0]+fConvDir[1]*fConvDir[1]);
72 
73  const REAL h = data.HSize;
74  for( int in = 0; in < nshape; in++ ) {
75  const REAL gradVBeta = this->fConvDir[0] * dphi(0,in) + this->fConvDir[1] * dphi(1,in);
76  ef(in, 0) += weight * FVal * ( phi(in,0) + this->fSD*(0.5*h/normaConveccao)*gradVBeta );
77  for( int jn = 0; jn < nshape; jn++ ) {
78  ek(in,jn) += weight * (
79  +fK * ( dphi(0,in) * dphi(0,jn) + dphi(1,in) * dphi(1,jn) )
80  - ( (dphi(0,in) * phi(jn)) * fConvDir[0] + (dphi(1,in) * phi(jn)) * fConvDir[1] )
81  + this->fSD*(0.5*h/normaConveccao)*(
82  (fConvDir[0]*dphi(0,jn))*(fConvDir[0]*dphi(0,in)) +
83  (fConvDir[1]*dphi(1,jn))*(fConvDir[1]*dphi(1,in)) )
84  );
85  }
86  }
87 }
88 
91  TPZFMatrix<REAL> &phi = data.phi;
92  TPZFMatrix<REAL> &axes = data.axes;
93  const int nshape = phi.Rows();
94  STATE v2 = bc.Val2()(0,0);
95 
96  if(bc.HasForcingFunction()) {
98  bc.ForcingFunction()->Execute(data.x,res);
99  v2 = res[0];
100  }
101 
102  switch (bc.Type()) {
103  case 0 : // Dirichlet condition
104  for(int in = 0 ; in < nshape; in++) {
105  ef(in,0) += weight * gBigNumber* phi(in,0) * v2;
106  for (int jn = 0 ; jn < nshape; jn++) {
107  ek(in,jn) += weight * gBigNumber * phi(in,0) * phi(jn,0);
108  }
109  }
110  break;
111  case 1 : // Neumann condition
112  for(int in = 0 ; in < nshape; in++) {
113  ef(in,0) += weight * v2 * phi(in,0);
114  }
115  break;
116  case 3: // outflow condition
117  REAL normal[2];
118  normal[0] = axes(0,1);
119  normal[1] = axes(1,1);
120 
121  REAL ConvNormal = 0.;
122  for(int id = 0; id < 2; id++) ConvNormal += fConvDir[id]*normal[id];
123  if(ConvNormal > 0.){
124  for(int il = 0; il < nshape; il++){
125  for(int jl = 0; jl < nshape; jl++){
126  ek(il,jl) += weight * ConvNormal * phi(il)*phi(jl);
127  }
128  }
129  }
130  else{
131  if (ConvNormal < 0.) std::cout << "Boundary condition error: inflow detected in outflow boundary condition: ConvNormal = " << ConvNormal << "\n";
132  }
133  break;
134  }
135 
136 }
137 
138 int TPZLinearConvecDiff::VariableIndex(const std::string &name){
139  if(!strcmp("Solution",name.c_str())) return 1;
140  if(!strcmp("Derivative",name.c_str())) return 2;
141  return TPZMaterial::VariableIndex(name);
142 }
143 
145  if(var == 1) return 1;
146  if(var == 2) return 2;
148 }
149 
151 
152  Solout.Resize( this->NSolutionVariables( var ) );
153 
154  if(var == 1){
155  Solout[0] = data.sol[0][0];//solution - escalar
156  return;
157  }
158  if(var == 2) {
159  TPZFNMatrix<9,STATE> dsoldx;
160  TPZAxesTools<STATE>::Axes2XYZ(data.dsol[0], dsoldx, data.axes);
161  for(int id = 0 ; id < 2; id++) {
162  Solout[id] = dsoldx(id,0);//derivative - vetorial
163  }
164  return;
165  }//var == 2
166 
167  return TPZMaterial::Solution(data,var,Solout);
168 }
169 
172  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values){
173 
174  values.Resize(3);
176  values[1] = (u[0] - u_exact[0])*(u[0] - u_exact[0]);
178  values[2] = 0.;
179  for(int i = 0; i < 2; i++){
180  values[2] += (dudx(i,0) - du_exact(i,0))*(dudx(i,0) - du_exact(i,0));
181  }
183  values[0] = values[1]+values[2];
184 
185 }
186 
188  return Hash("TPZLinearConvecDiff") ^ TPZMaterial::ClassId() << 1;
189 }
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 void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
void
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)
REAL fConvDir[2]
Convection vector.
virtual std::string Name() override
Returns the name of the material.
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
int Type()
Definition: pzbndcond.h:249
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
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...
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
clarg::argBool h("-h", "help message", false)
STATE fK
Coeficient which multiplies the Laplacian operator.
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.
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)
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.
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...
TPZAutoPointer< TPZFunction< STATE > > & ForcingFunction()
Returns a procedure as source function for the material.
Definition: TPZMaterial.h:397
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 int ClassId() const override
Define the class id associated with the class.
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
virtual int VariableIndex(const std::string &name) override
Returns the variable index associated with the name.
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
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
virtual int Dimension() const override
Returns the integrable dimension of the material.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
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.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
Contains declaration of the TPZAxesTools class which implements verifications over axes...
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
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...
def values
Definition: rdt.py:119
Convecção-difusão linear 2D.
STATE fXf
Forcing function value.
STATE fSD
Multiplication value for the streamline diffusion term.
TPZSolVec sol
vector of the solutions at the integration point
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716