VertexCFD  0.0-dev
VertexCFD_EquationSet_RAD_impl.hpp
1 #ifndef VERTEXCFD_EQUATIONSET_RAD_IMPL_HPP
2 #define VERTEXCFD_EQUATIONSET_RAD_IMPL_HPP
3 
4 #include <Panzer_BasisIRLayout.hpp>
5 #include <Panzer_IntegrationRule.hpp>
6 
7 #include <Panzer_Integrator_BasisTimesScalar.hpp>
8 #include <Panzer_Integrator_GradBasisDotVector.hpp>
9 
10 #include <Phalanx_FieldManager.hpp>
11 
12 #include <Teuchos_ParameterList.hpp>
13 #include <Teuchos_RCP.hpp>
14 #include <Teuchos_StandardParameterEntryValidators.hpp>
15 
16 namespace VertexCFD
17 {
18 namespace EquationSet
19 {
20 //---------------------------------------------------------------------------//
21 template<class EvalType>
22 RAD<EvalType>::RAD(const Teuchos::RCP<Teuchos::ParameterList>& params,
23  const int& default_integration_order,
24  const panzer::CellData& cell_data,
25  const Teuchos::RCP<panzer::GlobalData>& global_data,
26  const bool build_transient_support)
27  : panzer::EquationSet_DefaultImpl<EvalType>(params,
28  default_integration_order,
29  cell_data,
30  global_data,
31  build_transient_support)
32 {
33  // This equation set is always transient.
34  if (!this->buildTransientSupport())
35  {
36  throw std::logic_error(
37  "Transient support is required for solving all equation sets.");
38  }
39 
40  // Get the number of space dimensions.
41  _num_space_dim = cell_data.baseCellDimension();
42  if (!(_num_space_dim == 2 || _num_space_dim == 3))
43  {
44  throw std::runtime_error("Number of space dimensions not supported");
45  }
46 
47  // Set default parameter values and validate the inputs.
48  Teuchos::ParameterList valid_parameters;
49  this->setDefaultValidParameters(valid_parameters);
50  valid_parameters.set(
51  "Model ID", "", "Closure model id associated with this equation set");
52  valid_parameters.set("Basis Order", 1, "Order of the basis");
53  valid_parameters.set("Integration Order", 2, "Order of the integration");
54  valid_parameters.set("Build Reaction Bateman Source",
55  false,
56  "Reaction boolean with Bateman term");
57  valid_parameters.set("Build Advection", false, "Advection boolean");
58  valid_parameters.set("Build Diffusion", false, "Diffusion boolean");
59  valid_parameters.set(
60  "Build Fission Source", false, "Fission source boolean");
61  valid_parameters.set("Build Reaction Transmutation Source",
62  false,
63  "Reaction boolean with Transmutation term");
64  valid_parameters.set("Number of Species", 1, "Number of species");
65 
66  params->validateParametersAndSetDefaults(valid_parameters);
67 
68  // Extract parameters.
69  const int basis_order = params->get<int>("Basis Order", 1);
70  const int integration_order
71  = params->get<int>("Integration Order", basis_order + 1);
72  const std::string model_id = params->get<std::string>("Model ID");
73  _build_bateman = params->get<bool>("Build Reaction Bateman Source", false);
74  _build_advection = params->get<bool>("Build Advection", false);
75  _build_diffusion = params->get<bool>("Build Diffusion", false);
76  _build_fission_source = params->get<bool>("Build Fission Source", false);
77  _build_transmutation
78  = params->get<bool>("Build Reaction Transmutation Source", false);
79  const int _num_species = params->get<int>("Number of Species", 1);
80 
81  // Initialize equation names and variable names for
82  // reaction-advection-diffusion equations
83  for (int d = 0; d < _num_species; ++d)
84  {
85  const std::string ds = std::to_string(d);
86  _equ_dof_rad_pair.insert(
87  {"reaction_advection_diffusion_equation_" + ds, "species_" + ds});
88  }
89 
90  // Functions to set dofs
91  auto set_dofs
92  = [&, this](const std::string& equ_name, const std::string& dof_name) {
93  const std::string residual_name = "RESIDUAL_" + equ_name;
94  const std::string scatter_name = "SCATTER_" + equ_name;
95  const std::string basis_type = "HGrad";
96  this->addDOF(dof_name,
97  basis_type,
98  basis_order,
99  integration_order,
100  residual_name,
101  scatter_name);
102  this->addDOFGrad(dof_name);
103  this->addDOFTimeDerivative(dof_name);
104  };
105 
106  // Setup degrees of freedom for reaction-advection equations.
107  for (const auto& [equ_name, dof_name] : _equ_dof_rad_pair)
108  {
109  set_dofs(equ_name, dof_name);
110  };
111 
112  // Add closure models and set-up DOFs
113  this->addClosureModel(model_id);
114  this->setupDOFs();
115 }
116 
117 //---------------------------------------------------------------------------//
118 template<class EvalType>
119 void RAD<EvalType>::buildAndRegisterEquationSetEvaluators(
120  PHX::FieldManager<panzer::Traits>& fm,
121  const panzer::FieldLibrary&,
122  const Teuchos::ParameterList&) const
123 {
124  // Integration data. The same rule and basis is used for all DOFs in this
125  // implementation so use the first one to get this data.
126  const auto it = _equ_dof_rad_pair.begin();
127  const auto ir = this->getIntRuleForDOF(it->second);
128  const auto basis = this->getBasisIRLayoutForDOF(it->second);
129 
130  // Add basis time residuals
131  auto add_basis_time_scalar_residual = [&, this](
132  const std::string& equ_name,
133  const std::string& residual_name,
134  const double& multiplier,
135  std::vector<std::string>& op_names) {
136  const std::string closure_model_residual = residual_name + "_"
137  + equ_name;
138  const std::string full_residual = "RESIDUAL_" + closure_model_residual;
139  auto op = Teuchos::rcp(
140  new panzer::Integrator_BasisTimesScalar<EvalType, panzer::Traits>(
141  panzer::EvaluatorStyle::EVALUATES,
142  full_residual,
143  closure_model_residual,
144  *basis,
145  *ir,
146  multiplier));
147  this->template registerEvaluator<EvalType>(fm, op);
148  op_names.push_back(full_residual);
149  };
150 
151  // Add grad-basis time residuals
152  auto add_grad_basis_time_residual = [&, this](
153  const std::string& equ_name,
154  const std::string& residual_name,
155  const double& multiplier,
156  std::vector<std::string>& op_names) {
157  const std::string closure_model_residual = residual_name + "_"
158  + equ_name;
159  const std::string full_residual = "RESIDUAL_" + closure_model_residual;
160  auto op = Teuchos::rcp(
161  new panzer::Integrator_GradBasisDotVector<EvalType, panzer::Traits>(
162  panzer::EvaluatorStyle::EVALUATES,
163  full_residual,
164  closure_model_residual,
165  *basis,
166  *ir,
167  multiplier));
168  this->template registerEvaluator<EvalType>(fm, op);
169  op_names.push_back(full_residual);
170  };
171 
172  // Build total residuals for reaction-advection equations
173  for (const auto& [equ_name, dof_name] : _equ_dof_rad_pair)
174  {
175  // Define local variables
176  std::vector<std::string> residual_operator_names;
177 
178  // Time derivative residual
179  add_basis_time_scalar_residual(
180  equ_name, "DQDT", 1.0, residual_operator_names);
181 
182  // Reaction term residual
183  if (_build_bateman || _build_transmutation)
184  {
185  add_basis_time_scalar_residual(
186  equ_name, "REACTION_TERM", -1.0, residual_operator_names);
187  }
188 
189  // Advection flux residual
190  if (_build_advection)
191  {
192  add_grad_basis_time_residual(
193  equ_name, "ADVECTION_FLUX", -1.0, residual_operator_names);
194  }
195 
196  // Diffusion flux residual
197  if (_build_diffusion)
198  {
199  add_grad_basis_time_residual(
200  equ_name, "DIFFUSION_FLUX", 1.0, residual_operator_names);
201  }
202 
203  // Fission source residual
204  if (_build_fission_source)
205  {
206  add_basis_time_scalar_residual(
207  equ_name, "FISSION_SOURCE", -1.0, residual_operator_names);
208  }
209 
210  // Build and register residuals
211  this->buildAndRegisterResidualSummationEvaluator(
212  fm, dof_name, residual_operator_names, "RESIDUAL_" + equ_name);
213  }
214 }
215 
216 //---------------------------------------------------------------------------//
217 
218 } // end namespace EquationSet
219 } // end namespace VertexCFD
220 
221 #endif // end VERTEXCFD_EQUATIONSET_RAD_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23