VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleLiftDrag_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLELIFTDRAG_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLELIFTDRAG_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_SmoothMath.hpp"
5 #include "utils/VertexCFD_Utils_VectorField.hpp"
6 
7 #include <Panzer_HierarchicParallelism.hpp>
8 
9 namespace VertexCFD
10 {
11 namespace ClosureModel
12 {
13 //---------------------------------------------------------------------------//
14 template<class EvalType, class Traits, int NumSpaceDim>
15 IncompressibleLiftDrag<EvalType, Traits, NumSpaceDim>::IncompressibleLiftDrag(
16  const panzer::IntegrationRule& ir,
17  const Teuchos::ParameterList& user_params,
18  const bool use_turbulence_model)
19  : _normals("Side Normal", ir.dl_vector)
20  , _lagrange_pressure("lagrange_pressure", ir.dl_scalar)
21  , _rho("density", ir.dl_scalar)
22  , _nu("kinematic_viscosity", ir.dl_scalar)
23  , _nu_t("turbulent_eddy_viscosity", ir.dl_scalar)
24  , _use_turbulence_model(use_turbulence_model)
25  , _use_compressible_formula(user_params.isType<bool>("Compressible "
26  "Formula")
27  ? user_params.get<bool>("Compressible "
28  "Formula")
29  : false)
30 {
31  // Add evaluated field
32  Utils::addEvaluatedVectorField(
33  *this, ir.dl_scalar, _shear_tensor, "shear_tensor_");
34  Utils::addEvaluatedVectorField(
35  *this, ir.dl_scalar, _viscous_force, "viscous_force_");
36  Utils::addEvaluatedVectorField(
37  *this, ir.dl_scalar, _pressure_force, "pressure_force_");
38  Utils::addEvaluatedVectorField(
39  *this, ir.dl_scalar, _total_force, "total_force_");
40 
41  // Add dependent field
42  this->addDependentField(_normals);
43  this->addDependentField(_lagrange_pressure);
44  Utils::addDependentVectorField(
45  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
46  this->addDependentField(_rho);
47  this->addDependentField(_nu);
48 
49  if (_use_turbulence_model)
50  {
51  this->addDependentField(_nu_t);
52  }
53 
54  this->setName("Incompressible Lift/Drag " + std::to_string(num_space_dim)
55  + "D");
56 }
57 
58 //---------------------------------------------------------------------------//
59 template<class EvalType, class Traits, int NumSpaceDim>
60 void IncompressibleLiftDrag<EvalType, Traits, NumSpaceDim>::evaluateFields(
61  typename Traits::EvalData workset)
62 {
63  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
64  workset.num_cells);
65  Kokkos::parallel_for(this->getName(), policy, *this);
66 }
67 
68 //---------------------------------------------------------------------------//
69 template<class EvalType, class Traits, int NumSpaceDim>
70 KOKKOS_INLINE_FUNCTION void
71 IncompressibleLiftDrag<EvalType, Traits, NumSpaceDim>::operator()(
72  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
73 {
74  const int cell = team.league_rank();
75  const int num_point = _lagrange_pressure.extent(1);
76  Kokkos::parallel_for(
77  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
78  // Calculate wall shear tensor (grad.U + transpose(grad.U))
79  for (int i = 0; i < num_space_dim; ++i)
80  {
81  _shear_tensor[i](cell, point) = 0;
82  for (int j = 0; j < num_space_dim; ++j)
83  {
84  _shear_tensor[i](cell, point)
85  += (_grad_velocity[j](cell, point, i)
86  + _grad_velocity[i](cell, point, j))
87  * _normals(cell, point, j);
88  // If compressible formula div.U != 0 hence calculate
89  // deviatoric part
90  if (_use_compressible_formula)
91  {
92  _shear_tensor[i](cell, point)
93  -= 2.0 * _grad_velocity[j](cell, point, j)
94  / num_space_dim * _normals(cell, point, i);
95  }
96  }
97  _pressure_force[i](cell, point)
98  = _lagrange_pressure(cell, point)
99  * _normals(cell, point, i);
100  _viscous_force[i](cell, point)
101  = -_rho(cell, point) * _nu(cell, point)
102  * _shear_tensor[i](cell, point);
103  if (_use_turbulence_model)
104  {
105  _viscous_force[i](cell, point)
106  -= _rho(cell, point) * _nu_t(cell, point)
107  * _shear_tensor[i](cell, point);
108  }
109  _total_force[i](cell, point)
110  = _viscous_force[i](cell, point)
111  + _pressure_force[i](cell, point);
112  }
113  });
114 }
115 
116 //---------------------------------------------------------------------------//
117 
118 } // end namespace ClosureModel
119 } // end namespace VertexCFD
120 
121 #endif // end VERTEXCFD_CLOSURE_INCOMPRESSIBLELIFTDRAG_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23