NeoPZ
pzeuler.cpp
Go to the documentation of this file.
1 
6 #include "pzeuler.h"
7 
8 #include "pzartdiff.h"
9 #include "pzelmat.h"
10 #include "pzbndcond.h"
11 #include "pzmatrix.h"
12 #include "pzfmatrix.h"
13 #include "pzerror.h"
14 #include "pzreal.h"
15 #include <math.h>
16 #include "pzstring.h"
17 #include "pzerror.h"
18 
20 
21 STATE TPZEulerEquation::gGamma = 1.4;
22 
23 #ifdef LinearConvection
24 void TPZEulerEquation::SetLinearConvection(TPZCompMesh * cmesh, TPZVec<REAL> &Celerity){
25  std::map<int, TPZMaterial * >::iterator w;
26  for(w = cmesh->MaterialVec().begin(); w != cmesh->MaterialVec().end(); w++){
27  TPZMaterial * mat = w->second.operator->();
28  TPZEulerEquation * matcast = dynamic_cast< TPZEulerEquation * >(mat);
29  if(matcast){
30  cout << "old celerity = ";
31  for(int i = 0; i < matcast->fCelerity.NElements(); i++) cout << matcast->fCelerity[i] << " ";
32  cout << "\n";
33  matcast->fCelerity = Celerity;
34  cout << "new celerity = ";
35  for(int i = 0; i < matcast->fCelerity.NElements(); i++) cout << matcast->fCelerity[i] << " ";
36  cout << "\n";
37  }
38  }
39 }
40 #endif
41 
43 
44 #ifdef LinearConvection
45  return;
46 #endif
47 
48  double keepP = sol[4];
49  //sol = {rho, u, v, w, p}
50  double rhoE = 0.5*sol[0]*(sol[1]*sol[1]+sol[2]*sol[2]+sol[3]*sol[3])+sol[4]/(gamma-1.);
51  sol[1] = sol[1]*sol[0];
52  sol[2] = sol[2]*sol[0];
53  sol[3] = sol[3]*sol[0];
54  sol[4] = rhoE;
55  double p = TPZEulerEquation::Pressure(sol,gamma);
56  if(fabs(p-keepP) > 1e-4){
57  std::cout << "\np = " << p << " keepP = " << keepP << "\n";
58  }
59 }//void
60 
62 
63 #ifdef LinearConvection
64  return;
65 #endif
66  // The material must to have not null density
67  if(IsZero(sol[0])) {
68  PZError << "\nTPZEulerEquation::FromConservativeToPrimitive: Density almost null\n" << "Density = " << sol[0] << std::endl;
69  DebugStop();
70  }
71 
72  double p = TPZEulerEquation::Pressure(sol,gamma);
73  sol[1] = sol[1]/sol[0];
74  sol[2] = sol[2]/sol[0];
75  sol[3] = sol[3]/sol[0];
76  sol[4] = p;
77 }//void
78 
80 
81 }
82 
86  gGamma = gamma;
87 }
88 
92 
93 }
94 
98 
99 }
100 
102  return new TPZEulerEquation(*this);
103 }
104 
106  return 5; //U = (rho, rhou, rhov, rhow, rhoe)
107 }
108 
110  return 3;
111 }
112 
113 void TPZEulerEquation::Print(std::ostream &out) {
115  out << "gGamma = " << gGamma << "\n";
116 }
117 
118 int TPZEulerEquation::VariableIndex(const std::string &name) {
119  if( !strcmp(name.c_str(),"density") ) return 1;//rho
120  if( !strcmp(name.c_str(),"velocity") ) return 2;//(u,v,w)
121  if( !strcmp(name.c_str(),"energy") ) return 3;//rhoE
122  if( !strcmp(name.c_str(),"pressure") ) return 4;//p
123  if( !strcmp(name.c_str(),"solution") ) return 5;//(ro,u,v,w,E)
124  if( !strcmp(name.c_str(),"normvelocity") ) return 6;//sqrt(u+v+w)
125  if( !strcmp(name.c_str(),"Mach") ) return 7;//sqrt(u+v+w)/c
126  std::cout << "TPZEulerEquation::VariableIndex not defined\n";
127  return TPZMaterial::VariableIndex(name);
128 }
129 
131 
132  if(var == 1 || var == 3 || var == 4 || var == 6 || var == 7) return 1;
133  if(var == 2) return Dimension();
134  if(var == 5) return NStateVariables();
135 
136  std::cout << "TPZEulerEquation::NSolutionVariables not defined\n";
137  return 0;
138 }
139 
141 
142 #ifndef LinearConvection
143  if(IsZero(Sol[0])){
144  PZError << "\nTPZEulerEquation::Solution: Density almost null\n" << "Density = " << Sol[0] << std::endl;
145  DebugStop();
146  }
147 #endif
148 
149  if(var == 1) {
150  Solout.Resize(1);
151  Solout[0] = Sol[0];//density
152  return;
153  } else if(var == 2) {
154  int dim = Dimension();
155  Solout.Resize(dim);
156  for(int i=0;i<dim;i++) Solout[i] = Sol[i+1]/Sol[0];//velocity vector
157  return;
158  } else if(var == 3) {
159  Solout.Resize(1);
160  int pos = Dimension() + 1;
161  Solout[0] = Sol[pos];//energy = rhoE
162  return;
163  } else if(var == 4) {
164  Solout.Resize(1);
165  Solout[0] = Pressure(Sol,gGamma);//pressure
166  return;
167  } else if(var == 5) {
168  int nstate = NStateVariables();
169  Solout.Resize(nstate);
170  for(int i=0;i<nstate;i++) Solout[i] = Sol[i];//(ro,ro*u,ro*v,ro*w,E)
171  return;
172  } else if(var == 6) {
173  int nstate = NStateVariables();
174  Solout.Resize(1);
175  REAL ro2 = Sol[0]*Sol[0];
176  REAL veloc = 0.0;
177  for(int i=1;i<nstate-1;i++) veloc += Sol[i]*Sol[i];//velocity vector
178  Solout[0] = sqrt(veloc/ro2);
179  return;
180  } else if(var == 7) {
181  // int nstate = NStateVariables();
182  Solout.Resize(1);
183  const REAL cspeed = this->cSpeed(Sol);
184  const REAL us = this->uRes(Sol);
185  Solout[0] = us / cspeed;
186  return;
187  } else {
188  //cout << "TPZEulerEquation::Solution variable in the base class\n";
189  TPZMaterial::Solution(Sol,DSol,axes,var,Solout);
190  }
191 }
192 
194  //nothing to be done here
195  std::cout << "\nWarning at " << __PRETTY_FUNCTION__ << " - this method should not be called";
196 }
197 
199  //nothing to be done here
200  std::cout << "\nWarning at " << __PRETTY_FUNCTION__ << " - this method should not be called";
201 }
202 
204  this->ContributeInterface(data,dataleft,dataright,weight,ef);
205  std::cout << "\nWarning at " << __PRETTY_FUNCTION__ << " - this method should not be called";
206 }
207 
208 
210 #ifdef LinearConvection
211  if(gType == EFlux){
214  double dot = 0.;
215  for(int i = 0; i < 3; i++) dot += data.normal[i]*fCelerity[i];
216  if(dot > 0.){
217  Flux[0] = dot*dataleft.sol[0];
218  }
219  else{
220  Flux[0] = dot*dataright.sol[0];
221  }
222 
223  for(int i = 0; i < 5; i++) ef(i,0) += +1. * weight*Flux[i];
224  for(int i = 0; i < 5; i++) ef(i+20,0) += -1. * weight*Flux[i];
225  }
226  if(gType == EGradient){
228  fGradientFlux.ComputeFlux(dataleft.sol,dataright.sol,data.normal,Flux);
229 
230  for(int i = 0; i < 15; i++) ef(i+5,0) += +1. * weight*Flux[i];
231  for(int i = 0; i < 15; i++) ef(i+20+5,0) += -1. * weight*Flux[i];
232  }
233  return;
234 #endif
235  int numbersol = dataleft.sol.size();
236  if (numbersol != 1) {
237  DebugStop();
238  }
239 
240  if(gType == EFlux){
241  fGradientFlux.ApplyLimiter(data,dataleft,dataright);
245  fAUSMFlux.ComputeFlux(dataleft.sol[0],dataright.sol[0],data.normal,Flux);
246 
247  for(int i = 0; i < 5; i++) ef(i,0) += +1. * weight*Flux[i];
248  for(int i = 0; i < 5; i++) ef(i+20,0) += -1. * weight*Flux[i];
249  }
250  if(gType == EGradient){
252  fGradientFlux.ComputeFlux(dataleft.sol[0],dataright.sol[0],data.normal,Flux);
253 
254  for(int i = 0; i < 15; i++) ef(i+5,0) += +1. * weight*Flux[i];
255  for(int i = 0; i < 15; i++) ef(i+20+5,0) += -1. * weight*Flux[i];
256  }
257 
258 }//void
259 
261  REAL weight,
263  TPZBndCond &bc) {
264  std::cout << __PRETTY_FUNCTION__ << " - this method should not be called for Finite Volume Method\n";
265  DebugStop();
266 }
267 
269  REAL weight,
271  TPZBndCond &bc) {
272  this->ContributeBCInterface(data,dataleft,weight,ef,bc);
273  std::cout << "\nWarning at " << __PRETTY_FUNCTION__ << " - this method should not be called";
274 }//void
275 
277  REAL weight,
278  TPZFMatrix<STATE> &ef,
279  TPZBndCond &bc) {
280 
281  int numbersol = dataleft.sol.size();
282  if (numbersol != 1) {
283  DebugStop();
284  }
285 
286 #ifdef LinearConvection
287  if(gType == EFlux) {
288  if (bc.Type() == EFreeSlip){
289  TPZFNMatrix<100> fakeef(2*ef.Rows(),ef.Cols(),0);
290  dataright.sol = dataleft.sol;
291  this->ContributeInterface(data,weight,fakeef);
292  for(int i = 0; i < ef.Rows(); i++) ef(i,0) += fakeef(i,0);
293  }//if FreeSlip
294  }
295  if(gType == EGradient){
296  if (bc.Type() == EFreeSlip){
298  fGradientFlux.ComputeFlux(dataleft.sol[0],dataleft.sol[0],data.normal,Flux);
299  for(int i = 0; i < 15; i++) ef(i+5,0) += +1. * weight*Flux[i];
300  }//if FreeSlip
301  }
302  return;
303 #endif
304  if(gType == EFlux){
306  if (bc.Type() == EFreeSlip){
308 // #warning One needs to invert the velocity component
309  fAUSMFlux.ComputeFlux(dataleft.sol[0],dataleft.sol[0],data.normal,Flux);
310  for(int i = 0; i < 5; i++) ef(i,0) += +1. * weight*Flux[i];
311  }//if FreeSlip
312  }
313  if(gType == EGradient){
314  if (bc.Type() == EFreeSlip){
316  fGradientFlux.ComputeFlux(dataleft.sol[0],dataleft.sol[0],data.normal,Flux);
317  for(int i = 0; i < 15; i++) ef(i+5,0) += +1. * weight*Flux[i];
318  }//if FreeSlip
319  }
320 }
321 
323 
324  if(U[0] < REAL(1e-10)){
325  PZError << "TPZEulerEquation::Pressure - Negative or too small density "
326  << U[0] << std::endl;
327  DebugStop();
328  }
329 
330  REAL press = 0.0;
331 
332  //U = (U0,U1,U2,U3,U4) = (ro , ro u , ro v , ro w , ro e)
333  REAL rho_velocity = ( U[1]*U[1] + U[2]*U[2] + U[3]*U[3] )/U[0];
334  press = ((gamma-1.)*( U[4] - 0.5 * rho_velocity ));
335 
336  if(press < 0){
337  REAL temp = (gamma-1.)*U[4];
338  PZError << "TPZEulerEquation::Pressure Negative pressure: " << press << " (gama-1)*E = " << temp << std::endl;
339  DebugStop();
340  }
341  return press;
342 
343 }//method
344 
345 
347 
348  if(sol[0] < REAL(1e-10)){
349  PZError << "TPZEulerEquation(::cSpeed Too small or negative density " << sol[0] << std::endl;
350  DebugStop();
351  }
352 
353  const REAL press = this->Pressure(sol,gGamma);
354  const REAL temp = gGamma * press;
355 
356  if(temp < REAL(1e-10)) // too low or negative
357  {
358  PZError << "TPZEulerEquation::cSpeed Too low or negative numerator\n";
359  }
360  const REAL c = sqrt(gGamma * press/ sol[0]);
361  return c;
362 
363 }//method
364 
366  const REAL temp = sol[1]*sol[1] + sol[2]*sol[2] + sol[3]*sol[3];
367  if(temp < REAL(1e-40)){
368  PZError << "TPZEulerEquation::uRes Zero Velocity\n";
369  DebugStop();
370  }
371  const REAL us = sqrt(temp)/sol[0];
372  return us;
373 }
374 
376  const double rho = sol[0];
377  const double rhoU = sol[1];
378  const double rhoV = sol[2];
379  const double rhoW = sol[3];
380  const double rhoE = sol[4];
381  const double u = rhoU/rho;
382  const double v = rhoV/rho;
383  const double w = rhoW/rho;
384  const double p = this->Pressure(sol,gGamma);
385  F.Resize(5,3);
386  F(0,0) = rhoU; F(0,1) = rhoV; F(0,2) = rhoW;
387  F(1,0) = rhoU*u+p; F(1,1) = rhoU*v; F(1,2) = rhoU*w;
388  F(2,0) = rhoV*u; F(2,1) = rhoV*v+p; F(2,2) = rhoV*w;
389  F(3,0) = rhoW*u; F(3,1) = rhoW*v; F(3,2) = rhoW*w+p;
390  F(4,0) = (rhoE+p)*u; F(4,1) = (rhoE+p)*v; F(4,2) = (rhoE+p)*w;
391 }//void
392 
393 
395  return Hash("TPZEulerEquation") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
396 }
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.
Contains the TPZEulerEquation class which implements the weak statement of the compressible euler equ...
static void FromPrimitiveToConservative(TPZVec< STATE > &sol, STATE gamma)
Convert from primitive to conservative variables.
Definition: pzeuler.cpp:42
CALCType
Type of flux computing.
Definition: pzeuler.h:58
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 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 integration point...
Definition: pzeuler.cpp:203
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
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
This material implements the weak statement of the three-dimensional compressible euler equations...
Definition: pzeuler.h:52
clarg::argBool bc("-bc", "binary checkpoints", false)
static REAL Pressure(TPZVec< STATE > &U, double gamma)
Returns the pressure value.
Definition: pzeuler.cpp:322
virtual void Solution(TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, int var, TPZVec< STATE > &Solout) override
Definition: pzeuler.cpp:140
int Type()
Definition: pzbndcond.h:249
void ApplyLimiter(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright)
Apply limiter.
TPZAUSMFlux fAUSMFlux
Convective flux object.
Definition: pzeuler.h:84
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
Defines PZError.
void ComputeFlux(TPZVec< STATE > &solL, TPZVec< STATE > &solR, const TPZVec< REAL > &normal, TPZVec< STATE > &F)
Computes numerical flux.
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
Definition: pzeuler.cpp:130
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...
Definition: pzeuler.cpp:193
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...
Definition: pzeuler.cpp:268
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 declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual int Dimension() const override
Object-based overload.
Definition: pzeuler.cpp:109
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
Definition: pzeuler.cpp:113
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
String implementation.
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
virtual void Flux(TPZVec< REAL > &x, TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux)
Computes the value of the flux function to be used by ZZ error estimator.
Definition: TPZMaterial.h:255
TPZMaterial * NewMaterial() override
Creates a copy of this.
Definition: pzeuler.cpp:101
static STATE gGamma
Ratio between specific heat at constant pressure and the specific heat at constant volume of a polytr...
Definition: pzeuler.h:81
virtual int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzeuler.cpp:394
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
STATE uRes(TPZVec< STATE > &sol)
Returns .
Definition: pzeuler.cpp:365
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
~TPZEulerEquation()
Default destructor.
Definition: pzeuler.cpp:79
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZGradientFlux fGradientFlux
Gradient flux object.
Definition: pzeuler.h:87
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
STATE cSpeed(TPZVec< STATE > &sol)
Computes sound speed.
Definition: pzeuler.cpp:346
virtual int NStateVariables() const override
Object-based overload.
Definition: pzeuler.cpp:105
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
std::map< int,TPZMaterial *> & MaterialVec()
Returns a reference to the material pointers vector.
Definition: pzcmesh.h:203
long double gamma(unsigned int n)
Evaluate the factorial of a integer.
Contains TPZMatrix<TVar>class, root matrix class.
Contains the TPZArtDiff class which implements a numerical diffusivity coefficient.
TPZEulerEquation()
Default constructor.
Definition: pzeuler.cpp:89
void ComputeEulerFlux(TPZVec< STATE > &sol, TPZFMatrix< STATE > &F)
Compute Euler Flux.
Definition: pzeuler.cpp:375
void ComputeFlux(TPZVec< STATE > &solL, TPZVec< STATE > &solR, TPZVec< REAL > &normal, TPZVec< STATE > &F)
Computes numerical flux.
Definition: pzausmflux.cpp:20
static void FromConservativeToPrimitive(TPZVec< STATE > &sol, STATE gamma)
Convert from conservative to primitive variables.
Definition: pzeuler.cpp:61
static CALCType gType
Definition: pzeuler.h:78
virtual int VariableIndex(const std::string &name) override
Returns the variable index associated with the name.
Definition: pzeuler.cpp:118
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
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...
Definition: pzeuler.cpp:260
TPZSolVec sol
vector of the solutions at the integration point
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