VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleLSVOFArtificialCompression_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFARTIFICIALCOMPRESSION_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFARTIFICIALCOMPRESSION_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 #include <string>
10 
11 namespace VertexCFD
12 {
13 namespace ClosureModel
14 {
15 //---------------------------------------------------------------------------//
16 template<class EvalType, class Traits, int NumSpaceDim>
17 IncompressibleLSVOFArtificialCompression<EvalType, Traits, NumSpaceDim>::
18  IncompressibleLSVOFArtificialCompression(
19  const panzer::IntegrationRule& ir,
20  const Teuchos::ParameterList& closure_params,
21  const std::string& scalar_name,
22  const std::string& equation_name,
23  const std::string& flux_prefix,
24  const std::string& gradient_prefix,
25  const std::string& field_prefix)
26  : _scalar_flux(flux_prefix + "ARTIFICIAL_COMPRESSION_" + equation_name,
27  ir.dl_vector)
28  , _interface_velocity("interface_velocity", ir.dl_vector)
29  , _scalar(field_prefix + scalar_name, ir.dl_scalar)
30  , _grad_scalar(gradient_prefix + "GRAD_" + scalar_name, ir.dl_vector)
31  , _C_alpha(closure_params.get<double>("Compression Factor"))
32 {
33  // Evaluated fields
34  this->addEvaluatedField(_scalar_flux);
35  this->addEvaluatedField(_interface_velocity);
36 
37  // Dependent fields
38  this->addDependentField(_scalar);
39  this->addDependentField(_grad_scalar);
40 
41  Utils::addDependentVectorField(
42  *this, ir.dl_scalar, _velocity, field_prefix + "velocity_");
43 
44  this->setName(equation_name
45  + " Incompressible LSVOF Artificial Compression "
46  + std::to_string(num_space_dim) + "D");
47 }
48 
49 //---------------------------------------------------------------------------//
50 template<class EvalType, class Traits, int NumSpaceDim>
51 void IncompressibleLSVOFArtificialCompression<EvalType, Traits, NumSpaceDim>::
52  evaluateFields(typename Traits::EvalData workset)
53 {
54  // Allocate space for thread-local temporaries
55  size_t bytes;
56  if constexpr (Sacado::IsADType<scalar_type>::value)
57  {
58  const int fad_size
59  = Kokkos::dimension_scalar(_interface_velocity.get_view());
60  bytes = scratch_view::shmem_size(
61  _interface_velocity.extent(1), NUM_TMPS, fad_size);
62  }
63  else
64  {
65  bytes = scratch_view::shmem_size(_interface_velocity.extent(1),
66  NUM_TMPS);
67  }
68 
69  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
70  workset.num_cells);
71  policy.set_scratch_size(0, Kokkos::PerTeam(bytes));
72  Kokkos::parallel_for(this->getName(), policy, *this);
73 }
74 
75 //---------------------------------------------------------------------------//
76 template<class EvalType, class Traits, int NumSpaceDim>
77 KOKKOS_INLINE_FUNCTION void
78 IncompressibleLSVOFArtificialCompression<EvalType, Traits, NumSpaceDim>::operator()(
79  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
80 {
81  using Kokkos::sqrt;
82  const int cell = team.league_rank();
83  const int num_point = _scalar_flux.extent(1);
84  const double max_tol = 1e-10;
85 
86  scratch_view tmp_field;
87  if constexpr (Sacado::IsADType<scalar_type>::value)
88  {
89  const int fad_size
90  = Kokkos::dimension_scalar(_interface_velocity.get_view());
91  tmp_field
92  = scratch_view(team.team_shmem(), num_point, NUM_TMPS, fad_size);
93  }
94  else
95  {
96  tmp_field = scratch_view(team.team_shmem(), num_point, NUM_TMPS);
97  }
98 
99  Kokkos::parallel_for(
100  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
101  auto&& mag_u = tmp_field(point, MAG_U);
102  auto&& mag_grad_scalar = tmp_field(point, MAG_GRAD_SCALAR);
103  mag_u = 0.0;
104  mag_grad_scalar = 0.0;
105 
106  for (int d = 0; d < num_space_dim; ++d)
107  {
108  mag_u += pow(_velocity[d](cell, point), 2.0);
109  mag_grad_scalar += pow(_grad_scalar(cell, point, d), 2.0);
110  }
111 
112  for (int dim = 0; dim < num_space_dim; ++dim)
113  {
114  _scalar_flux(cell, point, dim)
115  = _scalar(cell, point) * (1.0 - _scalar(cell, point));
116 
117  _interface_velocity(cell, point, dim)
118  = _C_alpha
119  * sqrt(mag_u
120  / SmoothMath::max(mag_grad_scalar, max_tol, 0))
121  * _grad_scalar(cell, point, dim);
122 
123  _scalar_flux(cell, point, dim)
124  *= _interface_velocity(cell, point, dim);
125  }
126  });
127 }
128 
129 //---------------------------------------------------------------------------//
130 
131 } // end namespace ClosureModel
132 } // end namespace VertexCFD
133 
134 #endif // end
135  // VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFARTIFICIALCOMPRESSION_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23