NeoPZ
pzflowcmesh.cpp
Go to the documentation of this file.
1 
6 #include "pzflowcmesh.h"
7 #include "TPZCompElDisc.h"
8 #include "pzintel.h"
9 
10 using namespace std;
11 
13 TPZCompMesh(gr) {
14 
15 }
16 
18 TPZCompMesh() {
19 
20 }
21 
23 
24  int nel = ElementVec().NElements(), i, nstate, dim, elDim;
25  TPZManVector<STATE> density(1), velocity(1);// sol(nstate);
26  //TPZManVector<STATE> density(1), sol, velocity(1);// sol(nstate);
27  REAL maxvel = 0.0, veloc, sound, gamma;
28  STATE press;
29  TPZVec<REAL> param(3,0.);
30  TPZSolVec sol;
31  TPZGradSolVec dsol;
33  // loop over all elements, computing the velocity for
34  // the non-interface elements.
35  i = 0;
36  for(i=0;i<nel;i++){
37 
38  TPZCompEl *pElComp = ElementVec()[i];
39  if(!pElComp)
40  continue;
41 
42  TPZMaterial * mat = pElComp->Material();
43  if(!mat)PZError << "TPZFlowCompMesh::MaxVelocityOfMesh ERROR: null material.\n";
44 
45  TPZGeoEl *pElGeo = pElComp->Reference();
46  if(!pElGeo)PZError << "TPZFlowCompMesh::MaxVelocityOfMesh ERROR: null element.\n";
47 
48  dim = mat->Dimension();
49  elDim = pElGeo->Dimension();
50 
51  if(elDim == dim /*&& pElDisc*/){ // if the dimension of the material fits the
52  // dimension of the element and if the element is discontinuous.
53 
54  TPZConservationLaw *law = dynamic_cast<TPZConservationLaw *>(mat);
55  if(!law)PZError << "TPZFlowCompMesh::MaxVelocityOfMesh2 ERROR: non-fluid material.\n";
56  // number of state variables for this material.
57  nstate = law->NStateVariables();
58 
59  // getting the center point of the internal side.
60  pElGeo->CenterPoint(pElGeo->NSides()-1,param);//com->Solution(sol,j+100,sol2);
61  // verifying the density answer
62  pElComp->Solution(param,1,density);
63  if(density[0] < 0.0)PZError << "TPZFlowCompMesh::MaxVelocityOfMesh: Negative density\n";
64 
65  // Getting the velocity answers
66  pElComp->Solution(param,6,velocity);
67  // getting the whole vector of solutions
68  sol.Resize(nstate);
69  pElComp->ComputeSolution(param, sol, dsol, axes);
70 
71  press = law->Pressure(sol[0]);
72 
73 #ifndef STATE_COMPLEX
74  if(press < 0.0)PZError << "TPZFlowCompMesh::MaxVelocityOfMesh Negative pressure\n";
75 #endif
76  // retrieving the constant of gas.
77  gamma = law->Gamma();
78 
79  sound = sqrt(gamma*press/density[0]);
80 
81  // maximal eigenvalue velocity
82  veloc = velocity[0] + sound;
83  if(veloc > maxvel) maxvel = veloc;
84  }else{
85 
86  }
87  }
88  return maxvel;
89 
90 }
91 
93 {
94  std::map<int, TPZMaterial * >::iterator matit;
95 
96  // buffering the fluid materials
97  for(matit = fMaterialVec.begin(); matit != fMaterialVec.end(); matit++)
98  {
99  TPZConservationLaw * pConsLaw;
100  pConsLaw = dynamic_cast<TPZConservationLaw *>(matit->second);
101  if(pConsLaw)
102  {
103  int index = pConsLaw->Id();
104  fFluidMaterial[index] = matit->second;
105  }
106  }
107 }
108 
110 {
111  REAL maxVel = MaxVelocityOfMesh();
112  REAL deltax = LesserEdgeOfMesh();
113 
114  int nel = fElementVec.NElements();
115  int iel;
116  REAL meanTimeStep = 0.;
117  int numcontr = 0;
118 
119  for(iel=0; iel<nel; iel++)
120  {
121  TPZCompEl *cel = fElementVec[iel];
122  if(!cel)continue;
123  TPZCompElDisc *disc = dynamic_cast<TPZCompElDisc *>(cel);
124  int porder = 0;
125  if(disc)
126  {
127  porder = disc->Degree();
128  }
129  TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel);
130  if(intel)
131  {
132  porder = intel->PreferredSideOrder(intel->Reference()->NSides()-1);
133  }
134  TPZConservationLaw *mat = dynamic_cast<TPZConservationLaw *>( cel->Material());
135  if(!mat) continue;
136  meanTimeStep += mat->SetTimeStep(maxVel, deltax, porder);
137  numcontr++;
138  }
139 
140  return meanTimeStep / (double)numcontr;
141 }
142 
147 #define FL(A) dynamic_cast<TPZConservationLaw *>(A->second)
148 
153 #define MAXCFL 1.e6
154 
156 {
157  if(CFL > MAXCFL) CFL = MAXCFL;
158  std::map<int, TPZMaterial * >::iterator matit;
159  for(matit=fFluidMaterial.begin(); matit!=fFluidMaterial.end(); matit++)
160  {
161  FL(matit)->SetCFL(CFL);
162  }
163 }
164 
166 {
167  std::map<int, TPZMaterial * >::iterator matit;
168  for(matit=fFluidMaterial.begin(); matit!=fFluidMaterial.end(); matit++)
169  {
170  REAL newCFL = FL(matit)->CFL()*scale;
171  if(newCFL > MAXCFL) newCFL = MAXCFL;
172  cout << "CFL = " << newCFL << endl;
173  FL(matit)->SetCFL(newCFL);
174  }
175 }
176 
177 
179 {
180  std::map<int, TPZMaterial * >::iterator matit;
181  for(matit=fFluidMaterial.begin(); matit!=fFluidMaterial.end(); matit++)
182  {
183  FL(matit)->SetContributionTime(time);
184  }
185 }
186 
188 {
189  std::map<int, TPZMaterial * >::iterator matit;
190  for(matit=fFluidMaterial.begin(); matit!=fFluidMaterial.end(); matit++)
191  {
192  FL(matit)->SetForcingFunction(fp);
193  }
194 }
195 
197 {
200 }
201 
202 
204 {
205  return fFluidMaterial.size();
206 }
207 
210 {
211  TPZMaterial * result = NULL;
212  if(fFluidMaterial.size())
213  {
214  return fFluidMaterial.begin()->second;
215  } else
216  {
217  return result;
218  }
219 }
220 
222 {
223  std::map<int, TPZMaterial * >::iterator matit;
224  for(matit=fFluidMaterial.begin(); matit!=fFluidMaterial.end(); matit++)
225  {
226  FL(matit)->SetResidualType(type);
227  }
228 }
229 
231  return Hash("TPZFlowCompMesh") ^ TPZCompMesh::ClassId() << 1;
232 }
233 
234 #ifndef BORLAND
235 template class
237 #endif
238 
239 void TPZFlowCompMesh::Write(TPZStream &buf, int withclassid) const
240 {
241  TPZCompMesh::Write(buf,0);
242 }
243 
244 void TPZFlowCompMesh::Read(TPZStream &buf, void *context)
245 {
246  TPZCompMesh::Read(buf, context);
248 }
249 
251 {
252  int nFluid = fFluidMaterial.size();
253 
254  if(nFluid != 1)
255  {
256  PZError << "\nTPZFlowCompMesh::ExpandSolution - Wrong number of fluid materials\n";
257  }
258 
259  int nstate = fFluidMaterial.begin()->second->NStateVariables();
260 
261  fBlock.Resequence();
262  int ibl,nblocks = fBlock.NBlocks();
263 
264  int ic, cols = fSolution.Cols();
265  for(ic=0; ic<cols; ic++) {
266  for(ibl = 0;ibl<nblocks;ibl++) {
267  int size = fSolutionBlock.Size(ibl);
268  int position = fSolutionBlock.Position(ibl);
269  int lastStatePos = position + size - nstate;
270  int ieq;
271  //REAL temp;
272  STATE temp;
273  for(ieq=0; ieq<nstate; ieq++) {
274  temp = fSolution(position+ieq,ic);
275  fSolution(position+ieq,ic) = fSolution(lastStatePos+ieq,ic);
276  fSolution(lastStatePos+ieq,ic) = temp;
277  }
278  }
279  }
280 
282 
283  for(ic=0; ic<cols; ic++) {
284  for(ibl = 0;ibl<nblocks;ibl++) {
285  int size = fSolutionBlock.Size(ibl);
286  int position = fSolutionBlock.Position(ibl);
287  int lastStatePos = position + size - nstate;
288  int ieq;
289  //REAL temp;
290  STATE temp;
291  for(ieq=0; ieq<nstate; ieq++) {
292  temp = fSolution(position+ieq,ic);
293  fSolution(position+ieq,ic) = fSolution(lastStatePos+ieq,ic);
294  fSolution(lastStatePos+ieq,ic) = temp;
295  }
296  }
297  }
298 }
virtual int NStateVariables() const override=0
Number of state variables according to the dimension.
REAL ComputeTimeStep()
Computes the current time step for the mesh.
int Position(const int block_diagonal) const
Returns the position of first element block dependent on matrix diagonal.
Definition: pzblock.h:177
void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
int NFlowMaterials()
Returns the number of Flow materials.
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
void SetTimeStep(REAL timeStep)
Sets the time step used for time integration.
Definition: pzconslaw.h:302
TPZFMatrix< STATE > fSolution
Solution vector.
Definition: pzcmesh.h:72
TPZAdmChunkVector< TPZCompEl * > fElementVec
List of pointers to elements.
Definition: pzcmesh.h:60
void ScaleCFL(REAL scale)
Scales the CFL of all materials.
int ClassId() const override
Returns the unique identifier for reading/writing objects to streams.
Definition: pzcmesh.cpp:1969
REAL LesserEdgeOfMesh()
Definition: pzcmesh.cpp:1849
void CollectFluidMaterials()
Should be called after all materials have been added to the mesh.
Definition: pzflowcmesh.cpp:92
virtual int Dimension() const =0
Returns the integrable dimension of the material.
int64_t NElements() const
Access method to query the number of elements of the vector.
virtual int NSides() const =0
Returns the number of connectivities of the element.
virtual void ExpandSolution2()
Adapt the solution vector to new block dimensions.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
virtual STATE Pressure(TPZVec< STATE > &U)=0
Thermodynamic pressure determined by the law of an ideal gas.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
virtual void CenterPoint(int side, TPZVec< REAL > &masscent) const =0
It returns the coordinates from the center of the side of the element in the element coordinate space...
Computational mesh with additional data for CFD problems. Computational Mesh.
Definition: pzflowcmesh.h:27
virtual TPZMaterial * Material() const
Identify the material object associated with the element.
Definition: pzcompel.cpp:959
#define MAXCFL
Maxime value to CFL coefficient.
int ClassId() const override
Returns the unique identifier for reading/writing objects to streams.
TPZMaterial * GetFlowMaterial()
Returns the first flow material in the mesh.
REAL MaxVelocityOfMesh()
According to each material settings, it returns the greatest velocity in the mesh.
Definition: pzflowcmesh.cpp:22
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
TPZResidualType
Which terms are being contributed.
Definition: pzconslaw.h:58
void SetContributionTime(TPZContributeTime time)
Informs the time at which the current solution in the computational mesh belongs, so that the materia...
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
std::map< int, TPZMaterial *> fFluidMaterial
This vector of pointers represent the collection of all fluid materials in the mesh.
Definition: pzflowcmesh.h:94
void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
Definition: pzcmesh.cpp:2006
virtual void ExpandSolution()
Adapt the solution vector to new block dimensions.
Definition: pzcmesh.cpp:396
void SetResidualType(TPZResidualType type)
Sets the kind of residual to be computed.
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
Contains declaration of TPZCompelDisc class which implements a computational element for discontinuou...
void SetFlowforcingFunction(TPZAutoPointer< TPZFunction< STATE > > fp)
Sets the forcing funtion for all fluid materials in the mesh.
virtual int PreferredSideOrder(int iside)=0
Returns the preferred order of the polynomial along side iside.
virtual void ComputeSolution(TPZVec< REAL > &qsi, TPZMaterialData &data)
Definition: pzcompel.h:462
TPZBlock< STATE > fBlock
Block structure to right construction of the stiffness matrix and load vector.
Definition: pzcmesh.h:80
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
long double gamma(unsigned int n)
Evaluate the factorial of a integer.
int NBlocks() const
Returns number of blocks on diagonal.
Definition: pzblock.h:165
TPZBlock< STATE > fSolutionBlock
Block structure of the solution vector ????
Definition: pzcmesh.h:68
Implements the interface for conservation laws, keeping track of the timestep as well.
Definition: pzconslaw.h:71
virtual void AutoBuild() override
Creates the computational elements, and the degree of freedom nodes.
#define FL(A)
Function for dynamic cast of the material based on map A (second data)
virtual int Dimension() const =0
Returns the dimension of the element.
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
Contains declaration of TPZFlowCompMesh class which is a computational mesh with additional data for ...
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int Size(const int block_diagonal) const
Returns block dimension.
Definition: pzblock.h:171
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
virtual void Solution(TPZVec< REAL > &qsi, int var, TPZVec< STATE > &sol)
Calculates the solution - sol - for the variable var at point qsi, where qsi is expressed in terms of...
Definition: pzcompel.cpp:421
void SetCFL(REAL CFL)
Informs all materials the CFL number.
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
int Id() const
Definition: TPZMaterial.h:170
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual int Degree() const
Returns the degree of interpolation of the element.
std::map< int, TPZMaterial *> fMaterialVec
Map of pointers to materials.
Definition: pzcmesh.h:65
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
clarg::argInt porder("-porder", "polinomial order", 1)
This class implements a discontinuous element (for use with discontinuous Galerkin). Computational Element.
Definition: TPZCompElDisc.h:35
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
TPZContributeTime
Indicates which term is put in the right hand side and tangent matrix.
Definition: pzconslaw.h:47
virtual void AutoBuild()
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.h:474
void Write(TPZStream &buf, int withclassid) const override
Save the element data to a stream.
Definition: pzcmesh.cpp:1975
Implements computational element based on an interpolation space. Computational Element.
Definition: pzintel.h:27
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
int Resequence(const int start=0)
Resequences blocks positioning.
Definition: pzblock.cpp:150
REAL Gamma()
Returns the value of Gamma (constant of gas)
Definition: pzconslaw.h:297
This class implements a reference counter mechanism to administer a dynamically allocated object...