VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleViscousFlux_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLEVISCOUSFLUX_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLEVISCOUSFLUX_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 
8 namespace VertexCFD
9 {
10 namespace ClosureModel
11 {
12 //---------------------------------------------------------------------------//
13 template<class EvalType, class Traits, int NumSpaceDim>
14 IncompressibleViscousFlux<EvalType, Traits, NumSpaceDim>::IncompressibleViscousFlux(
15  const panzer::IntegrationRule& ir,
16  const Teuchos::ParameterList& fluid_params,
17  const Teuchos::ParameterList& user_params,
18  const bool use_turbulence_model,
19  const std::string& flux_prefix,
20  const std::string& gradient_prefix)
21  : _continuity_flux(flux_prefix + "VISCOUS_FLUX_continuity", ir.dl_vector)
22  , _energy_flux(flux_prefix + "VISCOUS_FLUX_energy", ir.dl_vector)
23  , _rho("density", ir.dl_scalar)
24  , _nu("kinematic_viscosity", ir.dl_scalar)
25  , _cp("specific_heat_capacity", ir.dl_scalar)
26  , _k("thermal_conductivity", ir.dl_scalar)
27  , _grad_press(gradient_prefix + "GRAD_lagrange_pressure", ir.dl_vector)
28  , _grad_temp(gradient_prefix + "GRAD_temperature", ir.dl_vector)
29  , _nu_t(flux_prefix + "turbulent_eddy_viscosity", ir.dl_scalar)
30  , _gamma(std::numeric_limits<double>::quiet_NaN())
31  , _beta(fluid_params.get<double>("Artificial compressibility"))
32  , _solve_temp(fluid_params.get<bool>("Build Temperature Equation"))
33  , _use_turbulence_model(use_turbulence_model)
34  , _continuity_model_name(fluid_params.isType<std::string>("Continuity "
35  "Model")
36  ? fluid_params.get<std::string>("Continuity "
37  "Model")
38  : "AC")
39  , _is_edac(_continuity_model_name == "EDAC" ? true : false)
40  , _Pr_t(_solve_temp
41  ? (user_params.isType<double>("Turbulent Prandtl Number")
42  ? user_params.get<double>("Turbulent Prandtl Number")
43  : 0.85)
44  : std::numeric_limits<double>::quiet_NaN())
45 {
46  // Add evaludated fields
47  this->addEvaluatedField(_continuity_flux);
48  Utils::addEvaluatedVectorField(*this, ir.dl_vector, _momentum_flux,
49  flux_prefix + "VISCOUS_FLUX_"
50  "momentum_");
51  this->addEvaluatedField(_energy_flux);
52 
53  // Add dependent fields
54  Utils::addDependentVectorField(*this,
55  ir.dl_vector,
56  _grad_velocity,
57  gradient_prefix + "GRAD_velocity_");
58 
59  this->addDependentField(_rho);
60  this->addDependentField(_nu);
61  if (_is_edac)
62  {
63  this->addDependentField(_grad_press);
64  if (_solve_temp)
65  _gamma = fluid_params.get<double>("Heat capacity ratio");
66  }
67 
68  if (_solve_temp)
69  {
70  this->addDependentField(_k);
71  this->addDependentField(_cp);
72  this->addDependentField(_grad_temp);
73  }
74 
75  if (_use_turbulence_model)
76  {
77  this->addDependentField(_nu_t);
78  }
79 
80  this->setName("Incompressible Viscous Flux "
81  + std::to_string(num_space_dim) + "D");
82 }
83 
84 //---------------------------------------------------------------------------//
85 template<class EvalType, class Traits, int NumSpaceDim>
86 void IncompressibleViscousFlux<EvalType, Traits, NumSpaceDim>::evaluateFields(
87  typename Traits::EvalData workset)
88 {
89  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
90  workset.num_cells);
91  Kokkos::parallel_for(this->getName(), policy, *this);
92 }
93 
94 //---------------------------------------------------------------------------//
95 template<class EvalType, class Traits, int NumSpaceDim>
96 KOKKOS_INLINE_FUNCTION void
97 IncompressibleViscousFlux<EvalType, Traits, NumSpaceDim>::operator()(
98  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
99 {
100  const int cell = team.league_rank();
101  const int num_point = _continuity_flux.extent(1);
102 
103  Kokkos::parallel_for(
104  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
105  // Loop over spatial dimension
106  for (int i = 0; i < num_space_dim; ++i)
107  {
108  // Set stress tensor for EDAC continuity model
109  if (_is_edac)
110  {
111  if (_solve_temp)
112  {
113  _continuity_flux(cell, point, i)
114  = _gamma * _k(cell, point)
115  * _grad_press(cell, point, i)
116  / (_beta * _rho(cell, point) * _cp(cell, point));
117  }
118  else
119  {
120  _continuity_flux(cell, point, i)
121  = _rho(cell, point) * _nu(cell, point)
122  * _grad_press(cell, point, i) / _beta;
123  }
124  }
125  // Set stress tensor to zero for AC continuity model
126  else
127  {
128  _continuity_flux(cell, point, i) = 0.0;
129  }
130 
131  // Temperature equation
132  if (_solve_temp)
133  {
134  _energy_flux(cell, point, i)
135  = _k(cell, point) * _grad_temp(cell, point, i);
136  if (_use_turbulence_model)
137  {
138  _energy_flux(cell, point, i)
139  += _nu_t(cell, point) * _rho(cell, point)
140  * _cp(cell, point) * _grad_temp(cell, point, i)
141  / _Pr_t;
142  }
143  }
144 
145  // Loop over velocity/momentum components
146  for (int j = 0; j < num_space_dim; ++j)
147  {
148  _momentum_flux[j](cell, point, i)
149  = _rho(cell, point) * _nu(cell, point)
150  * _grad_velocity[j](cell, point, i);
151  if (_use_turbulence_model)
152  {
153  _momentum_flux[j](cell, point, i)
154  += _rho(cell, point) * _nu_t(cell, point)
155  * _grad_velocity[j](cell, point, i);
156  }
157  }
158  }
159  });
160 }
161 
162 //---------------------------------------------------------------------------//
163 
164 } // end namespace ClosureModel
165 } // end namespace VertexCFD
166 
167 #endif // end VERTEXCFD_CLOSURE_INCOMPRESSIBLEVISCOUSFLUX_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23