VertexCFD  0.0-dev
VertexCFD_BoundaryState_TurbulenceInletOutlet_impl.hpp
1 #ifndef VERTEXCFD_BOUNDARYSTATE_TURBULENCEINLETOUTLET_IMPL_HPP
2 #define VERTEXCFD_BOUNDARYSTATE_TURBULENCEINLETOUTLET_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 BoundaryCondition
12 {
13 //---------------------------------------------------------------------------//
14 // Inlet/outlet boundary condition for turbulence quantities
15 //---------------------------------------------------------------------------//
16 template<class EvalType, class Traits, int NumSpaceDim>
17 TurbulenceInletOutlet<EvalType, Traits, NumSpaceDim>::TurbulenceInletOutlet(
18  const panzer::IntegrationRule& ir,
19  const Teuchos::ParameterList& bc_params,
20  const std::string variable_name)
21  : _boundary_variable("BOUNDARY_" + variable_name, ir.dl_scalar)
22  , _boundary_grad_variable("BOUNDARY_GRAD_" + variable_name, ir.dl_vector)
23  , _variable(variable_name, ir.dl_scalar)
24  , _grad_variable("GRAD_" + variable_name, ir.dl_vector)
25  , _normals("Side Normal", ir.dl_vector)
26  , _inlet_value(bc_params.get<double>(variable_name + " Inlet Value"))
27 {
28  // Add evaluated fields
29  this->addEvaluatedField(_boundary_variable);
30  this->addEvaluatedField(_boundary_grad_variable);
31 
32  // Add dependent fields
33  Utils::addDependentVectorField(*this, ir.dl_scalar, _velocity, "velocity_");
34  this->addDependentField(_variable);
35  this->addDependentField(_grad_variable);
36  this->addDependentField(_normals);
37 
38  this->setName(variable_name
39  + " Boundary State Turbulence Model Inlet/Outlet "
40  + std::to_string(num_space_dim) + "D");
41 }
42 
43 //---------------------------------------------------------------------------//
44 template<class EvalType, class Traits, int NumSpaceDim>
45 void TurbulenceInletOutlet<EvalType, Traits, NumSpaceDim>::evaluateFields(
46  typename Traits::EvalData workset)
47 {
48  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
49  workset.num_cells);
50  Kokkos::parallel_for(this->getName(), policy, *this);
51 }
52 
53 //---------------------------------------------------------------------------//
54 template<class EvalType, class Traits, int NumSpaceDim>
55 KOKKOS_INLINE_FUNCTION void
56 TurbulenceInletOutlet<EvalType, Traits, NumSpaceDim>::operator()(
57  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
58 {
59  const int cell = team.league_rank();
60  const int num_point = _grad_variable.extent(1);
61  const int num_grad_dim = _grad_variable.extent(2);
62  const double smooth_ramp = 1.0e-8;
63 
64  Kokkos::parallel_for(
65  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
66  // Compute \vec{vel} \cdot \vec{n}
67  scalar_type vel_dot_n = 0.0;
68  for (int dim = 0; dim < num_grad_dim; ++dim)
69  {
70  vel_dot_n += _velocity[dim](cell, point)
71  * _normals(cell, point, dim);
72  }
73 
74  // Ramping function for inlet/outlet
75  const scalar_type outlet
76  = SmoothMath::ramp(vel_dot_n, -smooth_ramp, smooth_ramp);
77 
78  // Assign boundary values
79  _boundary_variable(cell, point) = (1.0 - outlet) * _inlet_value
80  + outlet * _variable(cell, point);
81 
82  // Assign gradient
83  for (int d = 0; d < num_grad_dim; ++d)
84  {
85  _boundary_grad_variable(cell, point, d)
86  = _grad_variable(cell, point, d);
87  }
88  });
89 }
90 
91 //---------------------------------------------------------------------------//
92 
93 } // end namespace BoundaryCondition
94 } // end namespace VertexCFD
95 
96 #endif // end VERTEXCFD_BOUNDARYSTATE_TURBULENCEINLETOUTLET_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23