VertexCFD  0.0-dev
VertexCFD_BoundaryState_IncompressibleRotatingWall_impl.hpp
1 #ifndef VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLEROTATINGWALL_IMPL_HPP
2 #define VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLEROTATINGWALL_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 #include <Panzer_Workset_Utilities.hpp>
8 
9 namespace VertexCFD
10 {
11 namespace BoundaryCondition
12 {
13 //---------------------------------------------------------------------------//
14 template<class EvalType, class Traits, int NumSpaceDim>
15 IncompressibleRotatingWall<EvalType, Traits, NumSpaceDim>::IncompressibleRotatingWall(
16  const panzer::IntegrationRule& ir,
17  const Teuchos::ParameterList& fluid_params,
18  const Teuchos::ParameterList& bc_params,
19  const bool is_edac)
20  : _boundary_lagrange_pressure("BOUNDARY_lagrange_pressure", ir.dl_scalar)
21  , _boundary_grad_lagrange_pressure("BOUNDARY_GRAD_lagrange_pressure",
22  ir.dl_vector)
23  , _boundary_temperature("BOUNDARY_temperature", ir.dl_scalar)
24  , _boundary_grad_temperature("BOUNDARY_GRAD_temperature", ir.dl_vector)
25  , _ir_degree(ir.cubature_degree)
26  , _set_lagrange_pressure(bc_params.isType<double>("Lagrange Pressure"))
27  , _lp_wall(std::numeric_limits<double>::quiet_NaN())
28  , _solve_temp(fluid_params.get<bool>("Build Temperature Equation"))
29  , _is_edac(is_edac)
30  , _T_wall(std::numeric_limits<double>::quiet_NaN())
31  , _lagrange_pressure("lagrange_pressure", ir.dl_scalar)
32  , _grad_lagrange_pressure("GRAD_lagrange_pressure", ir.dl_vector)
33  , _grad_temperature("GRAD_temperature", ir.dl_vector)
34  , _normals("Side Normal", ir.dl_vector)
35 {
36  // Compute the coefficients for the linear ramping in time f(x) = a * time
37  // + b
38  _time_init = bc_params.isType<double>("Time Initial")
39  ? bc_params.get<double>("Time Initial")
40  : 0.0;
41  _time_final = bc_params.isType<double>("Time Final")
42  ? bc_params.get<double>("Time Final")
43  : 1.0E-06;
44 
45  if (_set_lagrange_pressure)
46  _lp_wall = bc_params.get<double>("Lagrange Pressure");
47 
48  const auto angular_velocity_final
49  = bc_params.get<double>("Angular Velocity");
50  const auto angular_velocity_init = bc_params.isType<double>(
51  "Angular Velocity "
52  "Initial")
53  ? bc_params.get<double>(
54  "Angular Velocity "
55  "Initial")
56  : angular_velocity_final;
57  const double dt = _time_final - _time_init;
58  _a_vel = (angular_velocity_final - angular_velocity_init) / dt;
59  _b_vel = angular_velocity_init - _a_vel * _time_init;
60 
61  // Add evaluated fields
62  this->addEvaluatedField(_boundary_lagrange_pressure);
63  if (_is_edac)
64  this->addEvaluatedField(_boundary_grad_lagrange_pressure);
65 
66  Utils::addEvaluatedVectorField(
67  *this, ir.dl_scalar, _boundary_velocity, "BOUNDARY_velocity_");
68 
69  Utils::addEvaluatedVectorField(*this,
70  ir.dl_vector,
71  _boundary_grad_velocity,
72  "BOUNDARY_GRAD_velocity_");
73  if (_solve_temp)
74  {
75  _T_wall = bc_params.get<double>("Wall Temperature");
76  this->addEvaluatedField(_boundary_temperature);
77  this->addEvaluatedField(_boundary_grad_temperature);
78  }
79 
80  // Add dependent fields
81  this->addDependentField(_lagrange_pressure);
82  if (_is_edac)
83  {
84  this->addDependentField(_grad_lagrange_pressure);
85  this->addDependentField(_normals);
86  }
87 
88  Utils::addDependentVectorField(
89  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
90 
91  if (_solve_temp)
92  this->addDependentField(_grad_temperature);
93 
94  this->setName("Boundary State Incompressible Rotating Wall "
95  + std::to_string(num_space_dim) + "D");
96 }
97 
98 //---------------------------------------------------------------------------//
99 template<class EvalType, class Traits, int NumSpaceDim>
100 void IncompressibleRotatingWall<EvalType, Traits, NumSpaceDim>::postRegistrationSetup(
101  typename Traits::SetupData sd, PHX::FieldManager<Traits>&)
102 {
103  _ir_index = panzer::getIntegrationRuleIndex(_ir_degree, (*sd.worksets_)[0]);
104 }
105 
106 //---------------------------------------------------------------------------//
107 template<class EvalType, class Traits, int NumSpaceDim>
108 void IncompressibleRotatingWall<EvalType, Traits, NumSpaceDim>::evaluateFields(
109  typename Traits::EvalData workset)
110 {
111  // Update time and make sure that 'time' only varies between '_time_init'
112  // and '_time_final'
113  const double time = workset.time < _time_init ? _time_init
114  : workset.time >= _time_final ? _time_final
115  : workset.time;
116  _angular_velocity = _a_vel * time + _b_vel;
117 
118  _ip_coords = workset.int_rules[_ir_index]->ip_coordinates;
119  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
120  workset.num_cells);
121  Kokkos::parallel_for(this->getName(), policy, *this);
122 }
123 
124 //---------------------------------------------------------------------------//
125 template<class EvalType, class Traits, int NumSpaceDim>
126 KOKKOS_INLINE_FUNCTION void
127 IncompressibleRotatingWall<EvalType, Traits, NumSpaceDim>::operator()(
128  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
129 {
130  const int cell = team.league_rank();
131  const int num_point = _lagrange_pressure.extent(1);
132  const int num_grad_dim = _boundary_grad_velocity[0].extent(2);
133 
134  Kokkos::parallel_for(
135  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
136  // Set lagrange pressure
137  if (_set_lagrange_pressure)
138  _boundary_lagrange_pressure(cell, point) = _lp_wall;
139 
140  else
141  _boundary_lagrange_pressure(cell, point)
142  = _lagrange_pressure(cell, point);
143 
144  // Set wall temperature
145  if (_solve_temp)
146  _boundary_temperature(cell, point) = _T_wall;
147 
148  // Set boundary values for velocity components
149  Kokkos::Array<double, num_space_dim> vel_bnd{};
150  vel_bnd[0] = -_angular_velocity * _ip_coords(cell, point, 1);
151  vel_bnd[1] = _angular_velocity * _ip_coords(cell, point, 0);
152  for (int vel_dim = 0; vel_dim < num_space_dim; ++vel_dim)
153  _boundary_velocity[vel_dim](cell, point) = vel_bnd[vel_dim];
154 
155  // Set gradients at boundaries.
156  for (int d = 0; d < num_grad_dim; ++d)
157  {
158  if (_is_edac)
159  {
160  // Set lagrange pressure gradient
161  _boundary_grad_lagrange_pressure(cell, point, d)
162  = _grad_lagrange_pressure(cell, point, d);
163 
164  for (int grad_dim = 0; grad_dim < num_space_dim; ++grad_dim)
165  {
166  _boundary_grad_lagrange_pressure(cell, point, d)
167  -= (_grad_lagrange_pressure(cell, point, grad_dim)
168  * _normals(cell, point, grad_dim))
169  * _normals(cell, point, d);
170  }
171  }
172 
173  for (int vel_dim = 0; vel_dim < num_space_dim; ++vel_dim)
174  {
175  _boundary_grad_velocity[vel_dim](cell, point, d)
176  = _grad_velocity[vel_dim](cell, point, d);
177  }
178 
179  if (_solve_temp)
180  {
181  _boundary_grad_temperature(cell, point, d)
182  = _grad_temperature(cell, point, d);
183  }
184  }
185  });
186 }
187 
188 //---------------------------------------------------------------------------//
189 
190 } // end namespace BoundaryCondition
191 } // end namespace VertexCFD
192 
193 #endif // VERTEXCFD_BOUNDARYSTATE_INCOMPRESSIBLEROTATINGWALL_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23