VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleCLSLambda_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLECLSLAMBDA_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLECLSLAMBDA_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 <Teuchos_StandardParameterEntryValidators.hpp>
10 
11 #include <string>
12 
13 namespace VertexCFD
14 {
15 namespace ClosureModel
16 {
17 //---------------------------------------------------------------------------//
18 template<class EvalType, class Traits, int NumSpaceDim>
19 IncompressibleCLSLambda<EvalType, Traits, NumSpaceDim>::IncompressibleCLSLambda(
20  const panzer::IntegrationRule& ir,
21  const Teuchos::ParameterList& lsvof_params,
22  const Teuchos::RCP<panzer::GlobalData>& global_data)
23  : _lambda("CLS_lambda", ir.dl_scalar)
24  , _mag_phi("level_set_magnitude", ir.dl_scalar)
25  , _d_phi("d_level_set", ir.dl_scalar)
26  , _phi("level_set", ir.dl_scalar)
27  , _epsilon("CLS_epsilon", ir.dl_scalar)
28  , _global_data(global_data)
29  , _domain_volume(lsvof_params.get<double>("Domain Volume"))
30  , _C_lambda(10.0)
31  , _C_alpha(1.5)
32 {
33  // Check for non-default regularization coefficient
34  if (lsvof_params.isType<double>("Regularization Coefficient"))
35  {
36  _C_lambda = lsvof_params.get<double>("Regularization Coefficient");
37  }
38 
39  // Check for non-default alpha coefficient
40  if (lsvof_params.isType<double>("Interface Thickness Coefficient"))
41  {
42  _C_alpha = lsvof_params.get<double>("Interface Thickness Coefficient");
43  }
44 
45  // Evaluated fields
46  this->addEvaluatedField(_lambda);
47  this->addEvaluatedField(_mag_phi);
48  this->addEvaluatedField(_d_phi);
49 
50  // Dependent fields
51  this->addDependentField(_phi);
52  this->addDependentField(_epsilon);
53  Utils::addDependentVectorField(*this, ir.dl_scalar, _velocity, "velocity_");
54 
55  this->setName("Incompressible CLS Lambda " + std::to_string(num_space_dim)
56  + "D");
57 }
58 
59 //---------------------------------------------------------------------------//
60 template<class EvalType, class Traits, int NumSpaceDim>
61 void IncompressibleCLSLambda<EvalType, Traits, NumSpaceDim>::evaluateFields(
62  typename Traits::EvalData workset)
63 {
64  using std::max;
65 
66  const auto& pl = *_global_data->pl;
67 
68  // Names for response functions
69  const std::string mag_phi_int_name
70  = "Level Set Magnitude - level_set_magnitude";
71  const std::string d_phi_max_name = "Max Dphi - d_level_set";
72  const std::string cfl_name = "Min global_cfl_time_step - local_dt";
73 
74  // Get average and max values
75  _avg_mag_phi = pl.getValue<EvalType>(mag_phi_int_name) / _domain_volume;
76  _max_d_phi = pl.getValue<EvalType>(d_phi_max_name);
77  _cfl = workset.step_size / max(pl.getValue<EvalType>(cfl_name), 1e-8);
78 
79  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
80  workset.num_cells);
81  Kokkos::parallel_for(this->getName(), policy, *this);
82 }
83 
84 //---------------------------------------------------------------------------//
85 template<class EvalType, class Traits, int NumSpaceDim>
86 KOKKOS_INLINE_FUNCTION void
87 IncompressibleCLSLambda<EvalType, Traits, NumSpaceDim>::operator()(
88  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
89 {
90  const int cell = team.league_rank();
91  const int num_point = _lambda.extent(1);
92 
93  using Kokkos::abs;
94  using Kokkos::max;
95 
96  const double tol = 1e-10;
97 
98  Kokkos::parallel_for(
99  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
100  // Update mag(phi) and phi - mag(phi)
101  _mag_phi(cell, point) = abs(_phi(cell, point));
102  _d_phi(cell, point) = abs(_mag_phi(cell, point) - _avg_mag_phi);
103 
104  // Find max velocity component
105  _lambda(cell, point) = abs(_velocity[0](cell, point));
106 
107  for (int dim = 1; dim < num_space_dim; ++dim)
108  {
109  _lambda(cell, point) = max(_lambda(cell, point),
110  abs(_velocity[dim](cell, point)));
111  }
112 
113  // Set lambda
114  _lambda(cell, point)
115  *= (_C_lambda / _cfl
116  * (_epsilon(cell, point)
117  / (_C_alpha * SmoothMath::max(_max_d_phi, tol, 0.0))));
118  });
119 }
120 
121 //---------------------------------------------------------------------------//
122 
123 } // end namespace ClosureModel
124 } // end namespace VertexCFD
125 
126 #endif // end
127  // VERTEXCFD_CLOSURE_INCOMPRESSIBLECLSLAMBDA_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23