VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleLSVOFVariableProperties_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFVARIABLEPROPERTIES_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFVARIABLEPROPERTIES_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_PhaseLayout.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 #include <Panzer_Workset_Utilities.hpp>
8 
9 #include <Phalanx_DataLayout_DynamicLayout.hpp>
10 
11 #include <Sacado_Traits.hpp>
12 
13 #include <string>
14 
15 namespace VertexCFD
16 {
17 namespace ClosureModel
18 {
19 //---------------------------------------------------------------------------//
20 template<class EvalType, class Traits>
21 IncompressibleLSVOFVariableProperties<EvalType, Traits>::
22  IncompressibleLSVOFVariableProperties(
23  const panzer::IntegrationRule& ir,
24  const Teuchos::ParameterList& lsvof_params,
25  const std::vector<std::string>& phase_names,
26  const bool& build_dxdts,
27  const std::string& field_prefix)
28  : _rho(field_prefix + "density", ir.dl_scalar)
29  , _mu(field_prefix + "dynamic_viscosity", ir.dl_scalar)
30  , _dxdt_rho("DXDT_density", ir.dl_scalar)
31  , _build_dxdts(build_dxdts)
32  , _phase_layout(
33  Utils::buildPhaseLayout(ir.dl_scalar, phase_names.size() - 1))
34  , _alphas(field_prefix + "volume_fractions", _phase_layout)
35  , _dxdt_alphas(field_prefix + "DXDT_volume_fractions", _phase_layout)
36  , _alpha_n(phase_names[lsvof_params.get<int>("Number of Phases") - 1],
37  ir.dl_scalar)
38  , _phase_rho(Kokkos::ViewAllocateWithoutInitializing("Density"),
39  lsvof_params.get<int>("Number of Phases"))
40  , _phase_mu(Kokkos::ViewAllocateWithoutInitializing("Dynamic "
41  "viscosity"),
42  lsvof_params.get<int>("Number of Phases"))
43 {
44  // Evaluated fields
45  this->addEvaluatedField(_rho);
46  this->addEvaluatedField(_mu);
47  if (_build_dxdts)
48  {
49  this->addEvaluatedField(_dxdt_rho);
50  }
51 
52  // Dependent fields
53  this->addDependentField(_alphas);
54  if (_build_dxdts)
55  {
56  this->addDependentField(_dxdt_alphas);
57  }
58  this->addDependentField(_alpha_n);
59  auto prho_host
60  = Kokkos::create_mirror_view(Kokkos::HostSpace{}, _phase_rho);
61  auto pmu_host = Kokkos::create_mirror_view(Kokkos::HostSpace{}, _phase_mu);
62 
63  // read phase properties
64  for (int phase = 0; phase < lsvof_params.get<int>("Number of Phases");
65  ++phase)
66  {
67  // Phase numbering starts from 1
68  const std::string list_name = "Phase " + std::to_string(phase + 1);
69  const Teuchos::ParameterList phase_list
70  = lsvof_params.sublist(list_name);
71  prho_host[phase] = phase_list.get<double>("Density");
72  pmu_host[phase] = phase_list.get<double>("Dynamic viscosity");
73  }
74 
75  Kokkos::deep_copy(_phase_rho, prho_host);
76  Kokkos::deep_copy(_phase_mu, pmu_host);
77  this->setName("Incompressible LSVOF Variable Properties");
78 }
79 
80 //---------------------------------------------------------------------------//
81 template<class EvalType, class Traits>
82 void IncompressibleLSVOFVariableProperties<EvalType, Traits>::evaluateFields(
83  typename Traits::EvalData workset)
84 {
85  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
86  workset.num_cells);
87  Kokkos::parallel_for(this->getName(), policy, *this);
88 }
89 
90 //---------------------------------------------------------------------------//
91 template<class EvalType, class Traits>
92 KOKKOS_INLINE_FUNCTION void
93 IncompressibleLSVOFVariableProperties<EvalType, Traits>::operator()(
94  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
95 {
96  const int cell = team.league_rank();
97  const int num_point = _rho.extent(1);
98  const size_t nb_phase = _alphas.extent(2);
99 
100  Kokkos::parallel_for(
101  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
102  _rho(cell, point) = 0.0;
103  _mu(cell, point) = 0.0;
104  if (_build_dxdts)
105  {
106  _dxdt_rho(cell, point) = 0.0;
107  }
108 
109  // calculate mixture properties
110  for (size_t phase = 0; phase < nb_phase; ++phase)
111  {
112  _rho(cell, point) += _phase_rho[phase]
113  * _alphas(cell, point, phase);
114  _mu(cell, point) += _phase_mu[phase]
115  * _alphas(cell, point, phase);
116  if (_build_dxdts)
117  {
118  _dxdt_rho(cell, point)
119  += ((_phase_rho[phase] - _phase_rho[nb_phase])
120  * _dxdt_alphas(cell, point, phase));
121  }
122  }
123  _rho(cell, point) += _phase_rho[nb_phase] * _alpha_n(cell, point);
124  _mu(cell, point) += _phase_mu[nb_phase] * _alpha_n(cell, point);
125  });
126 }
127 
128 //---------------------------------------------------------------------------//
129 
130 } // end namespace ClosureModel
131 } // end namespace VertexCFD
132 
133 #endif // end VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFVARIABLEPROPERTIES_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23