www.mooseframework.org
CNSFVGreenGaussSlopeReconstruction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<SlopeReconstructionMultiD>();
15 
16  params.addClassDescription("A user object that performs Green-Gauss slope reconstruction to get "
17  "the slopes of the P0 primitive variables.");
18 
19  params.addRequiredCoupledVar("rho", "Density at P0 (constant monomial)");
20 
21  params.addRequiredCoupledVar("rhou", "X-momentum at P0 (constant monomial)");
22 
23  params.addCoupledVar("rhov", "Y-momentum at P0 (constant monomial)");
24 
25  params.addCoupledVar("rhow", "Z-momentum at P0 (constant monomial)");
26 
27  params.addRequiredCoupledVar("rhoe", "Total energy at P0 (constant monomial)");
28 
29  params.addRequiredParam<UserObjectName>("fluid_properties",
30  "Name for fluid properties user object");
31 
32  return params;
33 }
34 
36  const InputParameters & parameters)
37  : SlopeReconstructionMultiD(parameters),
38  _rho(getVar("rho", 0)),
39  _rhou(getVar("rhou", 0)),
40  _rhov(isCoupled("rhov") ? getVar("rhov", 0) : nullptr),
41  _rhow(isCoupled("rhow") ? getVar("rhow", 0) : nullptr),
42  _rhoe(getVar("rhoe", 0)),
43  _fp(getUserObject<SinglePhaseFluidProperties>("fluid_properties"))
44 {
45 }
46 
47 void
49 {
50  const Elem * elem = _current_elem;
51 
53  dof_id_type elemID = elem->id();
54 
56  unsigned int nside = elem->n_sides();
57 
59  unsigned int nvars = 5;
60 
62  std::vector<RealGradient> ugrad(nvars, RealGradient(0., 0., 0.));
63 
65  Point scent = Point(0., 0., 0.);
66 
68  Point snorm = Point(0., 0., 0.);
69 
71  Real sarea = 0.;
72 
74  Point dcent = Point(0., 0., 0.);
75 
77  std::vector<std::vector<Real>> ucell(nside + 1, std::vector<Real>(nvars, 0.));
78 
81 
82  Real rhoc = _rho->getElementalValue(elem);
83  Real rhomc = 1. / rhoc;
84  Real rhouc = _rhou->getElementalValue(elem);
85  Real rhovc = 0.;
86  Real rhowc = 0.;
87  Real rhoec = _rhoe->getElementalValue(elem);
88  if (_rhov != nullptr)
89  rhovc = _rhov->getElementalValue(elem);
90  if (_rhow != nullptr)
91  rhowc = _rhow->getElementalValue(elem);
92 
93  ucell[0][1] = rhouc * rhomc;
94  ucell[0][2] = rhovc * rhomc;
95  ucell[0][3] = rhowc * rhomc;
96  Real eintc =
97  rhoec * rhomc -
98  0.5 * (ucell[0][1] * ucell[0][1] + ucell[0][2] * ucell[0][2] + ucell[0][3] * ucell[0][3]);
99  ucell[0][0] = _fp.pressure(rhomc, eintc);
100  ucell[0][4] = _fp.temperature(rhomc, eintc);
101 
103  _avars[elemID] = ucell[0];
104 
106  Real dES = 0.;
107  Real dNS = 0.;
108  Real wESN = 0.;
109 
111 
112  for (unsigned int is = 0; is < nside; is++)
113  {
114  unsigned int in = is + 1;
115  const Elem * neig = elem->neighbor_ptr(is);
116 
118 
119  if (neig != nullptr && this->hasBlocks(neig->subdomain_id()))
120  {
121  dof_id_type neigID = neig->id();
122 
124  {
125  scent = getSideCentroid(elemID, neigID);
126  snorm = getSideNormal(elemID, neigID);
127  sarea = getSideArea(elemID, neigID);
128  }
129  else
130  {
131  _assembly.reinit(elem, is);
132 
133  scent = _side_elem->centroid();
134  snorm = _normals_face[0];
135  sarea = _side_volume;
136 
137  _side_centroid[std::pair<dof_id_type, dof_id_type>(elemID, neigID)] = scent;
138  _side_normal[std::pair<dof_id_type, dof_id_type>(elemID, neigID)] = snorm;
139  _side_area[std::pair<dof_id_type, dof_id_type>(elemID, neigID)] = sarea;
140  }
141 
144 
145  Real v = 1. / _rho->getElementalValue(neig);
146 
147  ucell[in][1] = _rhou->getElementalValue(neig) * v;
148  if (_rhov != nullptr)
149  ucell[in][2] = _rhov->getElementalValue(neig) * v;
150  if (_rhow != nullptr)
151  ucell[in][3] = _rhow->getElementalValue(neig) * v;
152 
153  Real e = _rhoe->getElementalValue(neig) * v -
154  0.5 * (ucell[in][1] * ucell[in][1] + ucell[in][2] * ucell[in][2] +
155  ucell[in][3] * ucell[in][3]);
156 
157  ucell[in][0] = _fp.pressure(v, e);
158  ucell[in][4] = _fp.temperature(v, e);
159 
161  dcent = elem->centroid() - scent;
162  dES = std::sqrt(dcent * dcent);
163 
165  dcent = neig->centroid() - scent;
166  dNS = std::sqrt(dcent * dcent);
167 
169  wESN = dES / (dES + dNS);
170 
172  _avars[neigID] = ucell[in];
173  }
174 
176 
177  else
178  {
180  {
181  scent = getBoundarySideCentroid(elemID, is);
182  snorm = getBoundarySideNormal(elemID, is);
183  sarea = getBoundarySideArea(elemID, is);
184  }
185  else
186  {
187  _assembly.reinit(elem, is);
188 
189  scent = _side_elem->centroid();
190  snorm = _normals_face[0];
191  sarea = _side_volume;
192 
193  _bnd_side_centroid[std::pair<dof_id_type, unsigned int>(elemID, is)] = scent;
194  _bnd_side_normal[std::pair<dof_id_type, unsigned int>(elemID, is)] = snorm;
195  _bnd_side_area[std::pair<dof_id_type, unsigned int>(elemID, is)] = sarea;
196  }
197 
199 
200  std::vector<BoundaryID> bndID = _mesh.getBoundaryIDs(elem, is);
201 
202  for (unsigned int ib = 0; ib < bndID.size(); ib++)
203  {
204  BoundaryID currentID = bndID[ib];
205 
206  std::map<BoundaryID, UserObjectName>::const_iterator pos = _bnd_uo_name_map.find(currentID);
207 
208  if (pos != _bnd_uo_name_map.end())
209  {
210  const BCUserObject & bcuo =
211  GeneralUserObject::_fe_problem.getUserObject<BCUserObject>(pos->second);
212 
213  std::vector<Real> uvec1 = {rhoc, rhouc, rhovc, rhowc, rhoec};
214 
215  ucell[in] = bcuo.getGhostCellValue(is, elem->id(), uvec1, snorm);
216 
218 
219  Real rhog = ucell[in][0];
220  Real rhoug = ucell[in][1];
221  Real rhovg = ucell[in][2];
222  Real rhowg = ucell[in][3];
223  Real rhoeg = ucell[in][4];
224 
225  Real rhomg = 1. / rhog;
226 
227  ucell[in][1] = rhoug * rhomg;
228  ucell[in][2] = rhovg * rhomg;
229  ucell[in][3] = rhowg * rhomg;
230 
231  Real eintg = rhoeg * rhomg -
232  0.5 * (ucell[in][1] * ucell[in][1] + ucell[in][2] * ucell[in][2] +
233  ucell[in][3] * ucell[in][3]);
234 
235  ucell[in][0] = _fp.pressure(rhomg, eintg);
236  ucell[in][4] = _fp.temperature(rhomg, eintg);
237  }
238  }
239 
241  wESN = 0.5;
242 
244  _bnd_avars[std::pair<dof_id_type, unsigned int>(elemID, is)] = ucell[in];
245  }
246 
248  snorm *= sarea / _current_elem_volume;
249  for (unsigned int iv = 0; iv < nvars; iv++)
250  ugrad[iv] += (wESN * ucell[0][iv] + (1. - wESN) * ucell[in][iv]) * snorm;
251  }
252 
253  _rslope[elemID] = ugrad;
254 }
MooseVariable * _rhoe
the input total energy
virtual Real temperature(Real v, Real u) const =0
Temperature as a function of specific internal energy and specific volume.
virtual void reconstructElementSlope()
compute the slope of the cell
std::map< std::pair< dof_id_type, dof_id_type >, Real > _side_area
store the side area into this map indexed by pair of element ID and neighbor ID
std::map< dof_id_type, std::vector< Real > > _avars
store the average variable values into this map indexed by element ID
virtual const Point & getSideCentroid(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side centroid
MooseVariable * _rhou
the input x-momentum
CNSFVGreenGaussSlopeReconstruction(const InputParameters &parameters)
virtual const Real & getBoundarySideArea(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side area
std::map< std::pair< dof_id_type, dof_id_type >, Point > _side_normal
store the side normal into this map indexed by pair of element ID and neighbor ID ...
std::map< BoundaryID, UserObjectName > _bnd_uo_name_map
store the pair of boundary ID and user object name
std::map< dof_id_type, std::vector< RealGradient > > _rslope
store the reconstructed slopes into this map indexed by element ID
Common class for single phase fluid properties.
MooseVariable * _rhov
the input y-momentum
MooseVariable * _rhow
the input z-momentum
InputParameters validParams< SlopeReconstructionMultiD >()
std::map< std::pair< dof_id_type, unsigned int >, Point > _bnd_side_normal
store the boundary side normal into this map indexed by pair of element ID and local side ID ...
virtual const Point & getBoundarySideNormal(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side centroid
const MooseArray< Point > & _normals_face
const SinglePhaseFluidProperties & _fp
fluid properties user object
virtual std::vector< Real > getGhostCellValue(unsigned int iside, dof_id_type ielem, const std::vector< Real > &uvec1, const RealVectorValue &dwave) const =0
compute the ghost cell variable values
A base class of user object for calculating the variable values in ghost element according to specifi...
Definition: BCUserObject.h:42
std::map< std::pair< dof_id_type, dof_id_type >, Point > _side_centroid
store the side centroid into this map indexed by pair of element ID and neighbor ID ...
std::map< std::pair< dof_id_type, unsigned int >, Point > _bnd_side_centroid
store the boundary side centroid into this map indexed by pair of element ID and local side ID ...
std::map< std::pair< dof_id_type, unsigned int >, Real > _bnd_side_area
store the boundary side area into this map indexed by pair of element ID and local side ID ...
virtual const Point & getBoundarySideCentroid(dof_id_type elementid, unsigned int side) const
accessor function call to get cached boundary side centroid
InputParameters validParams< CNSFVGreenGaussSlopeReconstruction >()
virtual const Point & getSideNormal(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side normal
virtual Real pressure(Real v, Real u) const =0
Pressure as a function of specific internal energy and specific volume.
bool _side_geoinfo_cached
flag to indicated if side geometry info is cached
virtual const Real & getSideArea(dof_id_type elementid, dof_id_type neighborid) const
accessor function call to get cached internal side area
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _bnd_avars
store the boundary average variable values into this map indexed by pair of element ID and local side...
Multi-dimensional piecewise linear slope reconstruction to get the slopes of cell average variables...