VertexCFD  0.0-dev
VertexCFD_InitialCondition_IncompressibleLSVOFBubble_impl.hpp
1 #ifndef VERTEXCFD_INITIALCONDITION_INCOMPRESSIBLELSVOFBUBBLE_IMPL_HPP
2 #define VERTEXCFD_INITIALCONDITION_INCOMPRESSIBLELSVOFBUBBLE_IMPL_HPP
3 
4 #include <Panzer_GlobalIndexer.hpp>
5 #include <Panzer_HierarchicParallelism.hpp>
6 #include <Panzer_PureBasis.hpp>
7 #include <Panzer_Workset_Utilities.hpp>
8 
9 #include <Teuchos_Array.hpp>
10 #include <Teuchos_StandardParameterEntryValidators.hpp>
11 
12 #include <cmath>
13 #include <string>
14 
15 namespace VertexCFD
16 {
17 namespace InitialCondition
18 {
19 //---------------------------------------------------------------------------//
20 template<class EvalType, class Traits, int NumSpaceDim>
21 IncompressibleLSVOFBubble<EvalType, Traits, NumSpaceDim>::IncompressibleLSVOFBubble(
22  const Teuchos::ParameterList& ic_params, const panzer::PureBasis& basis)
23  : _alpha(ic_params.get<std::string>("Phase Name"), basis.functional)
24  , _basis_name(basis.name())
25  , _radius(ic_params.get<double>("Bubble Radius"))
26  , _phase_type(PhaseType::Dispersed)
27 {
28  // Check phase type
29  if (ic_params.isType<std::string>("Phase Type"))
30  {
31  const auto type_validator = Teuchos::rcp(
32  new Teuchos::StringToIntegralParameterEntryValidator<PhaseType>(
33  Teuchos::tuple<std::string>("Dispersed", "Continuous"),
34  "Dispersed"));
35 
36  _phase_type = type_validator->getIntegralValue(
37  ic_params.get<std::string>("Phase Type"));
38  }
39 
40  // Get location from IC params
41  const auto location
42  = ic_params.get<Teuchos::Array<double>>("Bubble Location");
43 
44  for (int d = 0; d < num_space_dim; ++d)
45  {
46  _location[d] = location[d];
47  }
48 
49  this->addEvaluatedField(_alpha);
50  this->addUnsharedField(_alpha.fieldTag().clone());
51 
52  this->setName("LSVOF " + ic_params.get<std::string>("Phase Name")
53  + " Bubble Initial Condition");
54 }
55 
56 //---------------------------------------------------------------------------//
57 template<class EvalType, class Traits, int NumSpaceDim>
58 void IncompressibleLSVOFBubble<EvalType, Traits, NumSpaceDim>::postRegistrationSetup(
59  typename Traits::SetupData sd, PHX::FieldManager<Traits>&)
60 {
61  _basis_index = panzer::getPureBasisIndex(
62  _basis_name, (*sd.worksets_)[0], this->wda);
63 }
64 
65 //---------------------------------------------------------------------------//
66 template<class EvalType, class Traits, int NumSpaceDim>
67 void IncompressibleLSVOFBubble<EvalType, Traits, NumSpaceDim>::evaluateFields(
68  typename Traits::EvalData workset)
69 {
70  _basis_coords = this->wda(workset).bases[_basis_index]->basis_coordinates;
71  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
72  workset.num_cells);
73  Kokkos::parallel_for(this->getName(), policy, *this);
74 }
75 
76 //---------------------------------------------------------------------------//
77 template<class EvalType, class Traits, int NumSpaceDim>
78 KOKKOS_INLINE_FUNCTION void
79 IncompressibleLSVOFBubble<EvalType, Traits, NumSpaceDim>::operator()(
80  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
81 {
82  const int cell = team.league_rank();
83  const int num_basis = _alpha.extent(1);
84 
85  using Kokkos::pow;
86 
87  Kokkos::parallel_for(
88  Kokkos::TeamThreadRange(team, 0, num_basis), [&](const int basis) {
89  double r = 0.0;
90 
91  for (int d = 0; d < num_space_dim; ++d)
92  {
93  r += pow(_location[d] - _basis_coords(cell, basis, d), 2.0);
94  }
95 
96  r = pow(r, 0.5);
97 
98  if (r <= _radius)
99  {
100  if (_phase_type == PhaseType::Dispersed)
101  {
102  _alpha(cell, basis) = 1.0;
103  }
104  else
105  {
106  _alpha(cell, basis) = 0.0;
107  }
108  }
109  else
110  {
111  if (_phase_type == PhaseType::Dispersed)
112  {
113  _alpha(cell, basis) = 0.0;
114  }
115  else
116  {
117  _alpha(cell, basis) = 1.0;
118  }
119  }
120  });
121 }
122 
123 //---------------------------------------------------------------------------//
124 
125 } // end namespace InitialCondition
126 } // end namespace VertexCFD
127 
128 #endif // end VERTEXCFD_INITIALCONDITION_INCOMPRESSIBLELSVOFBUBBLE_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23