VertexCFD  0.0-dev
VertexCFD_SolidFullInductionClosureModelFactory_impl.hpp
1 #ifndef VERTEXCFD_SOLIDFULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
2 #define VERTEXCFD_SOLIDFULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
3 
4 #include "closure_models/VertexCFD_Closure_ConstantScalarField.hpp"
5 #include "closure_models/VertexCFD_Closure_ElementLength.hpp"
6 #include "closure_models/VertexCFD_Closure_ExternalMagneticField.hpp"
7 #include "closure_models/VertexCFD_Closure_VectorFieldDivergence.hpp"
8 
9 #include "incompressible_solver/closure_models/VertexCFD_Closure_IncompressibleVariableTimeDerivative.hpp"
10 
11 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionConstantSource.hpp"
12 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionResistiveFlux.hpp"
13 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_MagneticCorrectionDampingSource.hpp"
14 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_SolidFullInductionConvectiveFlux.hpp"
15 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_SolidFullInductionLocalTimeStepSize.hpp"
16 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_TotalMagneticField.hpp"
17 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_TotalMagneticFieldGradient.hpp"
18 
19 #include "full_induction_mhd_solver/mhd_properties/VertexCFD_FullInductionMHDProperties.hpp"
20 
21 #include <Panzer_String_Utilities.hpp>
22 
23 #include <string>
24 #include <vector>
25 
26 namespace VertexCFD
27 {
28 namespace ClosureModel
29 {
30 //---------------------------------------------------------------------------//
31 template<class EvalType, int NumSpaceDim>
32 Teuchos::RCP<std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>>
34  const std::string& model_id,
35  const Teuchos::ParameterList& model_params,
36  const panzer::FieldLayoutLibrary&,
37  const Teuchos::RCP<panzer::IntegrationRule>& ir,
38  const Teuchos::ParameterList& ,
39  const Teuchos::ParameterList& user_params,
40  const Teuchos::RCP<panzer::GlobalData>& ,
41  PHX::FieldManager<panzer::Traits>&) const
42 {
43  auto evaluators = Teuchos::rcp(
44  new std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>);
45 
46  if (!model_params.isSublist(model_id))
47  {
48  throw std::runtime_error("Solid Full Induction closure model id "
49  + model_id + "not in list.");
50  }
51 
52  constexpr int num_space_dim = NumSpaceDim;
53 
54  // Get closure model list for 'model_id'
55  const Teuchos::ParameterList& closure_model_list
56  = model_params.sublist(model_id);
57 
58  // Check for closure model factory type. If not `SolidFullInduction`
59  // return empty evaluator
60  const std::string factory_type
61  = closure_model_list.isType<std::string>("Closure Factory Type")
62  ? closure_model_list.get<std::string>("Closure Factory Type")
63  : "None";
64 
65  if (factory_type != "Solid Full Induction")
66  return evaluators;
67 
68  // Properties used by full induction MHD closure models
69  const auto full_induction_params
70  = closure_model_list.sublist("Full Induction MHD Properties");
72  full_induction_params);
73  const bool build_magn_corr = mhd_props.buildMagnCorr();
74 
75  // Get the list of default-included closure models
76  // Note: not all default closures are including, as determined by
77  // other input options (e.g. InductionResistiveFlux)
78  const std::string default_closure_models
79  = "ElementLength,\n"
80  "ExternalMagneticField,\n"
81  "FullInductionTimeDerivative,\n"
82  "Resistivity,\n"
83  "InductionResistiveFlux,\n"
84  "SolidFullInductionConvectiveFlux,\n"
85  "SolidFullInductionLocalTimeStepSize,\n"
86  "TotalMagneticField,\n"
87  "TotalMagneticFieldGradient,\n";
88 
89  // Element length
90  {
91  auto eval
92  = Teuchos::rcp(new ElementLength<EvalType, panzer::Traits>(*ir));
93  evaluators->push_back(eval);
94  }
95 
96  // SolidFullInductionLocalTimeStepSize closure
97  {
98  if (build_magn_corr)
99  {
100  auto eval = Teuchos::rcp(
102  *ir, mhd_props));
103  evaluators->push_back(eval);
104  }
105  else
106  {
107  auto eval = Teuchos::rcp(
109  *ir, "local_dt", 1e6));
110  evaluators->push_back(eval);
111  }
112  }
113 
114  // Induction time derivative closures
115  {
116  std::vector<Teuchos::ParameterList> mhd_names_list_vct;
117  for (int dim = 0; dim < num_space_dim; ++dim)
118  {
119  Teuchos::ParameterList ind_names_list;
120  ind_names_list.set(
121  "Field Name", "induced_magnetic_field_" + std::to_string(dim));
122  ind_names_list.set("Equation Name",
123  "induction_" + std::to_string(dim));
124  mhd_names_list_vct.push_back(ind_names_list);
125  }
126  if (build_magn_corr)
127  {
128  Teuchos::ParameterList magn_corr_names_list;
129  magn_corr_names_list.set("Field Name", "scalar_magnetic_potential");
130  magn_corr_names_list.set("Equation Name",
131  "magnetic_correction_potential");
132  mhd_names_list_vct.push_back(magn_corr_names_list);
133  }
134  for (auto& mhd_names_list : mhd_names_list_vct)
135  {
136  auto eval_time = Teuchos::rcp(
138  *ir, mhd_names_list));
139  evaluators->push_back(eval_time);
140  }
141  }
142 
143  // ExternalMagneticField closure, req'd for total
144  {
145  auto eval
147  *ir, user_params));
148  evaluators->push_back(eval);
149  }
150 
151  // TotalMagneticField closure
152  {
153  auto eval = Teuchos::rcp(
155  *ir));
156  evaluators->push_back(eval);
157  }
158 
159  // SolidFullInductionConvectiveFlux closure
160  // Required only when using divergence cleaning
161  if (build_magn_corr)
162  {
163  auto eval
164  = Teuchos::rcp(new SolidFullInductionConvectiveFlux<EvalType,
165  panzer::Traits,
166  num_space_dim>(
167  *ir, mhd_props));
168  evaluators->push_back(eval);
169  }
170 
171  // Closures required for resistive flux
172  if (mhd_props.buildResistiveFlux())
173  {
174  // TotalMagneticFieldGradient closure
175  {
176  auto eval = Teuchos::rcp(
177  new TotalMagneticFieldGradient<EvalType,
178  panzer::Traits,
179  num_space_dim>(*ir));
180  evaluators->push_back(eval);
181  }
182 
183  // Resistivity
184  {
185  if (mhd_props.variableResistivity())
186  {
187  throw std::runtime_error(
188  "No closure models currently exist to evaluate variable "
189  "resistivity. Use a constant resistivity only.");
190  }
191  else
192  {
193  auto eval = Teuchos::rcp(
195  *ir, "resistivity", mhd_props.resistivity()));
196  evaluators->push_back(eval);
197  }
198  }
199 
200  // Resistive Flux
201  {
202  auto eval = Teuchos::rcp(
204  *ir, mhd_props));
205  evaluators->push_back(eval);
206  }
207  }
208 
209  // Loop over closure models
210  for (const auto& closure_model : closure_model_list)
211  {
212  bool found_model = false;
213 
214  // skip non-closure entries
215  const auto closure_name = closure_model.first;
216  if (closure_name == "Closure Factory Type"
217  || closure_name == "Full Induction MHD Properties")
218  continue;
219 
220  // Get closure parameters for current closure model
221  const auto& closure_params
222  = Teuchos::getValue<Teuchos::ParameterList>(closure_model.second);
223 
224  if (closure_params.isType<std::string>("Type"))
225  {
226  const auto closure_type = closure_params.get<std::string>("Type");
227 
228  // Check if 'closure_type' is a default closure model
229  if (default_closure_models.find(closure_type) != std::string::npos)
230  {
231  const std::string msg = "\n\nSolidFullInduction closure model/type '"
232  + closure_name + "'/'" + closure_type
233  + "' found in model id '" + model_id
234  + "' is a default closure model and should "
235  "not be added to the input file.\n"
236  "The list of default closure models for "
237  "the solid full induction equations is:\n"
238  + default_closure_models;
239  throw std::runtime_error(msg);
240  }
241 
242  if (closure_type == "ConstantMaterialProperties")
243  {
244  // Density
245  auto eval_rho = Teuchos::rcp(
247  *ir,
248  "solid_density",
249  closure_params.get<double>("Density Value")));
250  evaluators->push_back(eval_rho);
251  found_model = true;
252  }
253 
254  if (closure_type == "InductionConstantSource")
255  {
256  auto eval = Teuchos::rcp(
258  *ir, closure_params));
259  evaluators->push_back(eval);
260  found_model = true;
261  }
262 
263  if (closure_type == "MagneticCorrectionDampingSource")
264  {
265  auto eval = Teuchos::rcp(
267  *ir, mhd_props));
268  evaluators->push_back(eval);
269  found_model = true;
270  }
271 
272  if (std::string::npos != closure_type.find("VectorFieldDivergence"))
273  {
274  const auto field_names
275  = closure_params.get<std::string>("Field Names");
276  std::vector<std::string> tokens;
277  panzer::StringTokenizer(tokens, field_names, ",", true);
278  for (auto& field : tokens)
279  {
280  auto eval = Teuchos::rcp(
281  new VectorFieldDivergence<EvalType,
282  panzer::Traits,
283  num_space_dim>(
284  *ir, field, closure_type));
285  evaluators->push_back(eval);
286  }
287  found_model = true;
288  }
289 
290  // Error message if closure model not found
291  if (!found_model)
292  {
293  const std::string msg
294  = "\n\nSolidFullInduction closure model/type "
295  + closure_name + "/" + closure_type
296  + " failed to build in model id " + model_id + ".\n"
297  "Solid full induction closure models available in Vertex-CFD are:\n"
298  "ConstantMaterialProperties\n"
299  "InductionConstantSource,\n"
300  "MagneticCorrectionDampingSource,\n"
301  "(Abs)VectorFieldDivergence\n"
302  "\n";
303  throw std::runtime_error(msg);
304  }
305  }
306  }
307 
308  return evaluators;
309 }
310 
311 //---------------------------------------------------------------------------//
312 
313 } // end namespace ClosureModel
314 } // end namespace VertexCFD
315 
316 #endif // end VERTEXCFD_SOLIDFULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::ClosureModel::VectorFieldDivergence
Definition: VertexCFD_Closure_VectorFieldDivergence.hpp:26
VertexCFD::MHDProperties::FullInductionMHDProperties
Definition: VertexCFD_FullInductionMHDProperties.hpp:17
VertexCFD::ClosureModel::IncompressibleVariableTimeDerivative
Definition: VertexCFD_Closure_IncompressibleVariableTimeDerivative.hpp:24
VertexCFD::ClosureModel::TotalMagneticField
Definition: VertexCFD_Closure_TotalMagneticField.hpp:28
VertexCFD::ClosureModel::SolidFullInductionConvectiveFlux
Definition: VertexCFD_Closure_SolidFullInductionConvectiveFlux.hpp:31
VertexCFD::ClosureModel::MagneticCorrectionDampingSource
Definition: VertexCFD_Closure_MagneticCorrectionDampingSource.hpp:27
VertexCFD::ClosureModel::ExternalMagneticField
Definition: VertexCFD_Closure_ExternalMagneticField.hpp:26
VertexCFD::ClosureModel::SolidFullInductionFactory::buildClosureModels
Teuchos::RCP< std::vector< Teuchos::RCP< PHX::Evaluator< panzer::Traits > > > > buildClosureModels(const std::string &model_id, const Teuchos::ParameterList &model_params, const panzer::FieldLayoutLibrary &fl, const Teuchos::RCP< panzer::IntegrationRule > &ir, const Teuchos::ParameterList &default_params, const Teuchos::ParameterList &user_params, const Teuchos::RCP< panzer::GlobalData > &global_data, PHX::FieldManager< panzer::Traits > &fm) const override
Definition: VertexCFD_SolidFullInductionClosureModelFactory_impl.hpp:33
VertexCFD::ClosureModel::InductionResistiveFlux
Definition: VertexCFD_Closure_InductionResistiveFlux.hpp:30
VertexCFD::ClosureModel::InductionConstantSource
Definition: VertexCFD_Closure_InductionConstantSource.hpp:26
VertexCFD::ClosureModel::ConstantScalarField
Definition: VertexCFD_Closure_ConstantScalarField.hpp:26
VertexCFD::ClosureModel::TotalMagneticFieldGradient
Definition: VertexCFD_Closure_TotalMagneticFieldGradient.hpp:29
VertexCFD::ClosureModel::ElementLength
Definition: VertexCFD_Closure_ElementLength.hpp:24
VertexCFD::ClosureModel::SolidFullInductionLocalTimeStepSize
Definition: VertexCFD_Closure_SolidFullInductionLocalTimeStepSize.hpp:33