NeoPZ
pzconvectionproblem.cpp
Go to the documentation of this file.
1 //
2 // pzconvectionproblem.cpp
3 // PZ
4 //
5 // Created by Agnaldo Farias on 4/2/13.
6 //
7 //
8 
9 #include "pzconvectionproblem.h"
10 #include "pzmaterialdata.h"
11 #include "pzbndcond.h"
12 #include "pzaxestools.h"
13 #include "pzlog.h"
14 
15 
16 using namespace std;
17 
20 
21  fDim = 1;
23  fConvDir[0]=0.;
24  fRho = 0.;
25  fXf = 0.;
26  fTimeStep = 0.;
27  fTimeValue = 0.;
28  fmatId = 0;
29  fRungeKuttaTwo = false;
30 }
31 
34 
35  if(dim<0 || dim >2){
36  DebugStop();
37  }
38 
39  fDim = dim;
40  fConvDir.Resize(fDim, 0.);
41  fRho = 0.;
42  fXf = 0.;
43  fTimeStep = 0.;
44  fTimeValue = 0.;
45  fmatId = matid;
46  fRungeKuttaTwo = false;
47 }
48 
50 }
51 
54 
55  this->operator=(copy);
56 }
57 
59 
61  fXf = copy.fXf;
62  fDim = copy.fDim;
63  fConvDir = copy.fConvDir;
64  fRho = copy.fRho;
65  fTimeStep = copy.fTimeStep ;
66  fTimeValue = copy.fTimeValue;
67  fmatId = copy.fmatId;
69 
70  return *this;
71 }
72 
74  return 1;
75 }
76 
78  fXf = flux;
79 }
80 
82 
83  fRho = rho;
84  for(int d=0; d<fDim; d++) fConvDir[d] = convdir[d];
85 }
86 
88 
89  rho = fRho;
90  for(int d=0; d<fDim; d++) convdir[d] = fConvDir[d];
91 }
92 
93 
94 void TPZMatConvectionProblem::Print(std::ostream &out) {
95  out << "name of material : " << Name() << "\n";
96  out << "Dimesion of problem " << fDim << endl;
97  out << "Coeficient that multiply temporal derivative "<< fRho << endl;
98  out << "Term of convection direction "<< fConvDir << endl;
99  out << "Forcing vector f " << fXf << endl;
100  out << "Time step " << fTimeStep << endl;
101  out << "Base Class properties :";
102  TPZMaterial::Print(out);
103  out << "\n";
104 }
105 
107 
108 
109  TPZFMatrix<REAL> &phi = data.phi;
110  //TPZFMatrix<REAL> &dphi = data.dphix;
111  TPZVec<REAL> &x = data.x;
112  TPZFMatrix<REAL> &axes = data.axes;
113  int phr = phi.Rows();
114 
115  //current state n+1: stiffness matrix
116  if(gState == ECurrentState)
117  {
118  REAL fXfLoc = fXf;
119  if(fForcingFunction) {
121  fForcingFunction->Execute(x,res);
122  fXfLoc = res[0];
123  }
124 
125  for(int in = 0; in < phr; in++ ) {
126 
127  ef(in, 0) += fTimeStep*weight*fXfLoc*phi(in,0);
128 
129  for(int jn = 0; jn < phr; jn++ )
130  {
131  ek(in,jn) += weight*fRho*phi(in,0)*phi(jn,0);
132  }
133  }
134  }//end stiffness matrix
135 
136 
137  //Last state (n): mass matrix
138  if(gState == ELastState)
139  {
140  //apenas para criar uma matriz auxiliar
141  if(fRungeKuttaTwo == true)
142  {
143  for(int in = 0; in < phr; in++) {
144 
145  for(int jn = 0; jn < phr; jn++)
146  {
147  ek(in,jn) += weight*fRho*phi(in,0)*phi(jn,0);
148  }
149  }
150  }
151  else {
152  TPZVec<STATE> ConvDirAx;
153  ConvDirAx.Resize(fDim, 0.);
154 
155  int di,dj;
156  for(di=0; di<fDim; di++){
157  for(dj=0; dj<fDim; dj++){
158  ConvDirAx[di] += axes(di,dj)*fConvDir[dj];
159  }
160  }
161 
162  //int kd;
163  for(int in = 0; in < phr; in++) {
164 
165  for(int jn = 0; jn < phr; jn++)
166  {
167  ek(in,jn) += weight*fRho*phi(in,0)*phi(jn,0);
168 
169 // for(kd=0; kd<fDim; kd++)
170 // {
171 // ek(in,jn) += weight*(fTimeStep*ConvDirAx[kd]*dphi(kd,in)*phi(jn,0));
172 // }
173  }
174  }
175  }
176  }
177 
178 }
179 
181 
182 
183  std::cout<<" This class uses only discontinuous functions"<<std::endl;
184  DebugStop();
185 }
186 
187 
189 
190  if(gState == ECurrentState){
191  return;
192  }
193 
194  if(fRungeKuttaTwo == true) return;
195 
196  TPZFMatrix<REAL> &dphiLdAxes = dataleft.dphix;
197  TPZFMatrix<REAL> &dphiRdAxes = dataright.dphix;
198  TPZFMatrix<REAL> &phiL = dataleft.phi;
199  TPZFMatrix<REAL> &phiR = dataright.phi;
200  TPZManVector<REAL,3> &normal = data.normal;
201 
202  TPZFNMatrix<660> dphiL, dphiR;
203  TPZAxesTools<REAL>::Axes2XYZ(dphiLdAxes, dphiL, dataleft.axes);
204  TPZAxesTools<REAL>::Axes2XYZ(dphiRdAxes, dphiR, dataright.axes);
205 
206 
207  int nrowl = phiL.Rows();
208  int nrowr = phiR.Rows();
209  int il,jl,ir,jr,id;
210 
211  //Convection term
212  REAL ConvNormal = 0.;
213  for(id=0; id<fDim; id++) ConvNormal += fConvDir[id]*normal[id];
214  if(ConvNormal > 0.)
215  {
216  for(il=0; il<nrowl; il++)
217  {
218  for(jl=0; jl<nrowl; jl++)
219  {
220  ek(il,jl) += (-1.)*weight*(fTimeStep*ConvNormal*phiL(il,0)*phiL(jl,0));
221  }
222  }
223  for(ir=0; ir<nrowr; ir++)
224  {
225  for(jl=0; jl<nrowl; jl++)
226  {
227  ek(ir+nrowl,jl) -= (-1.)*weight*(fTimeStep*ConvNormal*phiR(ir,0)*phiL(jl,0));
228  }
229  }
230  } else{
231  for(ir=0; ir<nrowr; ir++)
232  {
233  for(jr=0; jr<nrowr; jr++)
234  {
235  ek(ir+nrowl,jr+nrowl) -= (-1.)*weight*(fTimeStep*ConvNormal*phiR(ir,0)*phiR(jr,0));
236  }
237  }
238  for(il=0; il<nrowl; il++)
239  {
240  for(jr=0; jr<nrowr; jr++)
241  {
242  ek(il,jr+nrowl) += (-1.)*weight*(fTimeStep*ConvNormal*phiL(il,0)*phiR(jr,0));
243  }
244  }
245  }
246 }
247 
248 
250 
251  if(gState == ELastState){
252  return;
253  }
254 
255 
256  TPZFMatrix<REAL> &phiL = dataleft.phi;
257  TPZManVector<REAL,3> &normal = data.normal;
258 
259  int il,jl,nrowl,id;
260  nrowl = phiL.Rows();
261  REAL ConvNormal = 0.;
262 
263  for(id=0; id<fDim; id++) ConvNormal += fConvDir[id]*normal[id];
264 
265  switch(bc.Type()) {
266  case 0: // DIRICHLET
267 
268  //convection
269  if(ConvNormal > 0.)
270  {
271  for(il=0; il<nrowl; il++){
272  for(jl=0; jl<nrowl; jl++)
273  {
274  ek(il,jl) += weight*fTimeStep*ConvNormal*phiL(il)*phiL(jl);
275  }
276  }
277  }
278  else{
279  for(il=0; il<nrowl; il++)
280  {
281  ef(il,0) -= weight*fTimeStep*ConvNormal*bc.Val2()(0,0)*phiL(il);
282  }
283  }
284 
285  break;
286 
287 
288  case 1: // Neumann
289  for(il=0; il<nrowl; il++) {
290  ef(il,0) += 0.;//ainda nao temos condicao de Neumann
291  }
292  break;
293 
294  case 3: // outflow condition
295  if(ConvNormal > 0.) {
296  for(il=0; il<nrowl; il++) {
297  for(jl=0; jl<nrowl; jl++) {
298  ek(il,jl) += weight*fTimeStep*ConvNormal*phiL(il)*phiL(jl);
299  }
300  }
301  }
302  else {
303  if (ConvNormal < 0.) std::cout << "Boundary condition error: inflow detected in outflow boundary condition: ConvNormal = " << ConvNormal << "\n";
304  }
305  break;
306 
307  default:
308  PZError << __PRETTY_FUNCTION__ << " - Wrong boundary condition type\n";
309  break;
310  }
311 }
312 
314 int TPZMatConvectionProblem::VariableIndex(const std::string &name){
315  if(!strcmp("Solution",name.c_str())) return 1;
316  if(!strcmp("ConvDirGradU",name.c_str())) return 2;
317  if(!strcmp("Derivative",name.c_str())) return 3;
318  if(!strcmp("Flux",name.c_str())) return 4;
319  if(!strcmp("ExactSolution",name.c_str())) return 5;
320 
321  return TPZMaterial::VariableIndex(name);
322 }
323 
325  if((var == 1) || (var == 2)|| (var == 5)) return 1;
326  if((var == 3) || (var == 4)) return fDim;
328 }
329 
331 
332  Solout.Resize(this->NSolutionVariables(var));
333 
334  TPZVec<STATE> Sol_u;
335  TPZFMatrix<STATE> DSol_u;
336  TPZFMatrix<REAL> axes_u;
337  TPZVec<STATE> ExactSol(1);
338  TPZFMatrix<STATE> deriv(3,1);
339 
340  Sol_u=data.sol[0];
341  DSol_u = data.dsol[0];
342  axes_u=data.axes;
343  ExactSol.Resize(1, 0.);
344 
345  if(var == 1){
346  Solout[0] = Sol_u[0];//function (state variable u)
347  return;
348  }
349 
350  if(var == 2){
351  int id;
352  for(id=0 ; id<fDim; id++) {
353  TPZFNMatrix<9,STATE> dsoldx;
354  TPZAxesTools<STATE>::Axes2XYZ(DSol_u, dsoldx, axes_u);
355  Solout[0] += fConvDir[id]*dsoldx(id,0);//derivate of u
356  }
357  return;
358  }
359 
360  if(var == 3) {
361  int id;
362  for(id=0 ; id<fDim; id++) {
363  TPZFNMatrix<9,STATE> dsoldx;
364  TPZAxesTools<STATE>::Axes2XYZ(DSol_u, dsoldx, axes_u);
365  Solout[id] = dsoldx(id,0);//derivate of u
366  }
367  return;
368  }//var == 3
369 
370  if(var == 4) {
371  int id;
372  for(id=0 ; id<fDim; id++) {
373  Solout[id] =fConvDir[id]*Sol_u[0];
374  }
375  return;
376  }//var == 4
377 
378  if(var == 5){
379 
380  fForcingFunctionExact->Execute(data.x, ExactSol, deriv);
381  Solout[0] = ExactSol[0];
382  return;
383  }
384 }
385 
387  TPZFMatrix<STATE> &dudx, TPZFMatrix<REAL> &axes, TPZVec<STATE> &/*flux*/,
388  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values) {
389 
390  int dim = Dimension();
391  int nstate = NStateVariables();
392 
393  TPZMaterialData data;
394  data.axes.Redim(dim,3);
395  data.x.Resize(3);
396  data.sol[0].Resize(nstate);
397  data.dsol[0].Redim(dim,nstate);
398 
399  data.x = x;
400  data.sol[0] = u;
401  data.dsol[0] = dudx;
402  data.axes = axes;
403 
405  Solution(data,1,sol);
406 
407  //values[1] : eror em norma L2
408  REAL diff;
409  diff = fabs(sol[0] - u_exact[0]);
410  values[1] = diff*diff;
411 }
412 
414  return Hash("TPZMatConvectionProblem") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
415 }
Defines the interface which material objects need to implement for discontinuous Galerkin formulation...
Definition: pzdiscgal.h:20
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
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 int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
REAL fXf
Forcing function value.
TPZManVector< REAL, 3 > normal
normal to the element at the integration point
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
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)
TPZMatConvectionProblem & operator=(const TPZMatConvectionProblem &copy)
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
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
TPZMaterial & operator=(const TPZMaterial &copy)
operator =
Definition: TPZMaterial.cpp:62
void GetParameters(REAL &rho, TPZVec< REAL > &convdir)
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...
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...
virtual int NStateVariables() const override
Returns the number of state variables associated with the material.
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
int Dimension() const override
Returns the integrable dimension of the material.
virtual int ClassId() const override
Unique identifier for serialization purposes.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
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 SetParameters(REAL rho, TPZVec< REAL > &convdir)
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.
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
REAL fRho
Coeficient which multiplies the temporal derivative.
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
virtual std::string Name() override
Returns the name of the material.
virtual int VariableIndex(const std::string &name) override
#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
Contains the TPZMatConvectionProblem class which implements a convection problem 2D with time depende...
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZFNMatrix< 9, REAL > axes
axes indicating the directions of the derivatives of the shapefunctions
string res
Definition: test.py:151
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout) override
It return a solution to multiphysics simulation.
Contains the TPZMaterialData class which implements an interface between TPZCompEl::CalcStiff and TPZ...
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual void ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to stiffness matrix and load vector at one BC integration point...
virtual void ContributeInterface(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to stiffness matrix and load vector at one BC integration point...
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...
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
Contains declaration of the TPZAxesTools class which implements verifications over axes...
def values
Definition: rdt.py:119
TPZSolVec sol
vector of the solutions at the integration point
int fDim
Problem dimension.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
TPZVec< REAL > fConvDir
convection term (direction velocity)