VertexCFD  0.0-dev
VertexCFD_BoundaryState_IncompressibleNoSlip_impl.hpp
1 #ifndef VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLENOSLIP_IMPL_HPP
2 #define VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLENOSLIP_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 #include <Panzer_Workset_Utilities.hpp>
8 #include <Teuchos_StandardParameterEntryValidators.hpp>
9 
10 namespace VertexCFD
11 {
12 namespace BoundaryCondition
13 {
14 //---------------------------------------------------------------------------//
15 template<class EvalType, class Traits, int NumSpaceDim>
16 IncompressibleNoSlip<EvalType, Traits, NumSpaceDim>::IncompressibleNoSlip(
17  const panzer::IntegrationRule& ir,
18  const Teuchos::ParameterList& fluid_params,
19  const Teuchos::ParameterList& bc_params,
20  const bool is_edac)
21  : _boundary_lagrange_pressure("BOUNDARY_lagrange_pressure", ir.dl_scalar)
22  , _boundary_grad_lagrange_pressure("BOUNDARY_GRAD_lagrange_pressure",
23  ir.dl_vector)
24  , _boundary_temperature("BOUNDARY_temperature", ir.dl_scalar)
25  , _boundary_grad_temperature("BOUNDARY_GRAD_temperature", ir.dl_vector)
26  , _lagrange_pressure("lagrange_pressure", ir.dl_scalar)
27  , _temperature("temperature", ir.dl_scalar)
28  , _grad_lagrange_pressure("GRAD_lagrange_pressure", ir.dl_vector)
29  , _grad_temperature("GRAD_temperature", ir.dl_vector)
30  , _normals("Side Normal", ir.dl_vector)
31  , _kappa("thermal_conductivity", ir.dl_scalar)
32  , _solve_temp(fluid_params.get<bool>("Build Temperature Equation"))
33  , _set_lagrange_pressure(bc_params.isType<double>("Lagrange Pressure"))
34  , _lp_wall(std::numeric_limits<double>::quiet_NaN())
35  , _is_edac(is_edac)
36  , _T_wall(std::numeric_limits<double>::quiet_NaN())
37  , _wall_flux(std::numeric_limits<double>::quiet_NaN())
38  , _temperature_profile(TempProfile::isothermal)
39 {
40  // Get temperature profile
41  if (bc_params.isType<std::string>("Temperature Profile"))
42  {
43  const auto type_validator = Teuchos::rcp(
44  new Teuchos::StringToIntegralParameterEntryValidator<TempProfile>(
45  Teuchos::tuple<std::string>("Isothermal", "Adiabatic", "Flux"),
46  "Isothermal"));
47  _temperature_profile = type_validator->getIntegralValue(
48  bc_params.get<std::string>("Temperature Profile"));
49  }
50 
51  if (_set_lagrange_pressure)
52  _lp_wall = bc_params.get<double>("Lagrange Pressure");
53 
54  // Evaluated fields
55  this->addEvaluatedField(_boundary_lagrange_pressure);
56  if (_is_edac)
57  this->addEvaluatedField(_boundary_grad_lagrange_pressure);
58 
59  Utils::addEvaluatedVectorField(
60  *this, ir.dl_scalar, _boundary_velocity, "BOUNDARY_velocity_");
61  Utils::addEvaluatedVectorField(*this,
62  ir.dl_vector,
63  _boundary_grad_velocity,
64  "BOUNDARY_GRAD_velocity_");
65  if (_solve_temp)
66  {
67  this->addEvaluatedField(_boundary_temperature);
68  this->addEvaluatedField(_boundary_grad_temperature);
69  }
70 
71  // Dependent fields
72  this->addDependentField(_lagrange_pressure);
73  if (_is_edac)
74  {
75  this->addDependentField(_grad_lagrange_pressure);
76  this->addDependentField(_normals);
77  }
78 
79  Utils::addDependentVectorField(
80  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
81 
82  if (_solve_temp)
83  {
84  this->addDependentField(_grad_temperature);
85  if (_temperature_profile == TempProfile::isothermal)
86  {
87  _T_wall = bc_params.get<double>("Wall Temperature");
88  }
89  else if (_temperature_profile == TempProfile::adiabatic)
90  {
91  this->addDependentField(_temperature);
92  if (!_is_edac)
93  this->addDependentField(_normals);
94  }
95  else if (_temperature_profile == TempProfile::flux)
96  {
97  this->addDependentField(_temperature);
98  this->addDependentField(_kappa);
99  if (!_is_edac)
100  this->addDependentField(_normals);
101  _wall_flux = bc_params.get<double>("Wall Flux");
102  }
103  }
104 
105  this->setName("Boundary State Incompressible No-Slip");
106 }
107 
108 //---------------------------------------------------------------------------//
109 template<class EvalType, class Traits, int NumSpaceDim>
110 void IncompressibleNoSlip<EvalType, Traits, NumSpaceDim>::evaluateFields(
111  typename Traits::EvalData workset)
112 {
113  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
114  workset.num_cells);
115  Kokkos::parallel_for(this->getName(), policy, *this);
116 }
117 
118 //---------------------------------------------------------------------------//
119 template<class EvalType, class Traits, int NumSpaceDim>
120 KOKKOS_INLINE_FUNCTION void
121 IncompressibleNoSlip<EvalType, Traits, NumSpaceDim>::operator()(
122  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
123 {
124  const int cell = team.league_rank();
125  const int num_point = _boundary_lagrange_pressure.extent(1);
126  const int num_grad_dim = _boundary_grad_velocity[0].extent(2);
127 
128  Kokkos::parallel_for(
129  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
130  // Set lagrange pressure
131  if (_set_lagrange_pressure)
132  {
133  _boundary_lagrange_pressure(cell, point) = _lp_wall;
134  }
135  else
136  {
137  _boundary_lagrange_pressure(cell, point)
138  = _lagrange_pressure(cell, point);
139  }
140 
141  // Set boundary values
142  for (int vel_dim = 0; vel_dim < num_space_dim; ++vel_dim)
143  _boundary_velocity[vel_dim](cell, point) = 0.0;
144 
145  if (_solve_temp)
146  {
147  if (_temperature_profile == TempProfile::isothermal)
148  {
149  _boundary_temperature(cell, point) = _T_wall;
150  }
151  else
152  {
153  _boundary_temperature(cell, point)
154  = _temperature(cell, point);
155  }
156  }
157 
158  // Set gradients at the boundaries.
159  for (int d = 0; d < num_grad_dim; ++d)
160  {
161  if (_is_edac)
162  {
163  // Set lagrange pressure gradient
164  _boundary_grad_lagrange_pressure(cell, point, d)
165  = _grad_lagrange_pressure(cell, point, d);
166 
167  for (int grad_dim = 0; grad_dim < num_space_dim; ++grad_dim)
168  {
169  _boundary_grad_lagrange_pressure(cell, point, d)
170  -= (_grad_lagrange_pressure(cell, point, grad_dim)
171  * _normals(cell, point, grad_dim))
172  * _normals(cell, point, d);
173  }
174  }
175 
176  for (int vel_dim = 0; vel_dim < num_space_dim; ++vel_dim)
177  {
178  _boundary_grad_velocity[vel_dim](cell, point, d)
179  = _grad_velocity[vel_dim](cell, point, d);
180  }
181 
182  if (_solve_temp)
183  {
184  _boundary_grad_temperature(cell, point, d)
185  = _grad_temperature(cell, point, d);
186 
187  if (_temperature_profile != TempProfile::isothermal)
188  {
189  for (int grad_dim = 0; grad_dim < num_space_dim;
190  ++grad_dim)
191  {
192  _boundary_grad_temperature(cell, point, d)
193  -= (_grad_temperature(cell, point, grad_dim)
194  * _normals(cell, point, grad_dim))
195  * _normals(cell, point, d);
196  }
197  if (_temperature_profile == TempProfile::flux)
198  {
199  _boundary_grad_temperature(cell, point, d)
200  += (_wall_flux / _kappa(cell, point))
201  * _normals(cell, point, d);
202  }
203  }
204  }
205  }
206  });
207 }
208 
209 //---------------------------------------------------------------------------//
210 
211 } // end namespace BoundaryCondition
212 } // end namespace VertexCFD
213 
214 #endif // VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLENOSLIP_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23