VertexCFD  0.0-dev
VertexCFD_FullInductionClosureModelFactory_impl.hpp
1 #ifndef VERTEXCFD_FULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
2 #define VERTEXCFD_FULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
3 
4 #include "closure_models/VertexCFD_Closure_ConstantScalarField.hpp"
5 #include "closure_models/VertexCFD_Closure_ExternalMagneticField.hpp"
6 #include "closure_models/VertexCFD_Closure_VectorFieldDivergence.hpp"
7 
8 #include "incompressible_solver/closure_models/VertexCFD_Closure_IncompressibleVariableTimeDerivative.hpp"
9 
10 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_DivergenceCleaningSource.hpp"
11 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_FullInductionLocalTimeStepSize.hpp"
12 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_FullInductionModelErrorNorms.hpp"
13 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_GodunovPowellSource.hpp"
14 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionConstantSource.hpp"
15 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionConvectiveFlux.hpp"
16 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionConvectiveMomentumFlux.hpp"
17 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_InductionResistiveFlux.hpp"
18 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_MHDVortexProblemExact.hpp"
19 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_MagneticCorrectionDampingSource.hpp"
20 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_MagneticPressure.hpp"
21 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_TotalMagneticField.hpp"
22 #include "full_induction_mhd_solver/closure_models/VertexCFD_Closure_TotalMagneticFieldGradient.hpp"
23 #include "full_induction_mhd_solver/mhd_properties/VertexCFD_FullInductionMHDProperties.hpp"
24 
25 #include <Panzer_String_Utilities.hpp>
26 
27 namespace VertexCFD
28 {
29 namespace ClosureModel
30 {
31 //---------------------------------------------------------------------------//
32 template<class EvalType, int NumSpaceDim>
33 Teuchos::RCP<std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>>
35  const std::string& model_id,
36  const Teuchos::ParameterList& model_params,
37  const panzer::FieldLayoutLibrary&,
38  const Teuchos::RCP<panzer::IntegrationRule>& ir,
39  const Teuchos::ParameterList& ,
40  const Teuchos::ParameterList& user_params,
41  const Teuchos::RCP<panzer::GlobalData>& ,
42  PHX::FieldManager<panzer::Traits>&) const
43 {
44  auto evaluators = Teuchos::rcp(
45  new std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>);
46 
47  if (!model_params.isSublist(model_id))
48  {
49  throw std::runtime_error("Full Induction closure model id " + model_id
50  + "not in list.");
51  }
52 
53  // Get closure model list for 'model_id'
54  const Teuchos::ParameterList& closure_model_list
55  = model_params.sublist(model_id);
56 
57  // Check for closure model factory type and return empty evaluators if it
58  // is not "Full Induction MHD"
59  const std::string factory_type
60  = closure_model_list.isType<std::string>("Closure Factory Type")
61  ? closure_model_list.get<std::string>("Closure Factory Type")
62  : "None";
63 
64  if (factory_type != "Full Induction MHD")
65  return evaluators;
66 
67  // Properties used by full induction MHD closure models
68  const auto full_induction_params
69  = closure_model_list.sublist("Full Induction MHD Properties");
71  full_induction_params);
72  const bool build_magn_corr = mhd_props.buildMagnCorr();
73 
74  // Loop over closure models
75  for (const auto& closure_model : closure_model_list)
76  {
77  bool found_model = false;
78 
79  const auto closure_name = closure_model.first;
80  if (closure_name == "Closure Factory Type"
81  || closure_name == "Full Induction MHD Properties"
82  || closure_name == "Fluid Properties")
83  continue;
84 
85  // Get closure parameters for current closure model
86  const auto& closure_params
87  = Teuchos::getValue<Teuchos::ParameterList>(closure_model.second);
88 
89  if (!closure_params.isType<std::string>("Type"))
90  continue;
91 
92  const auto closure_type = closure_params.get<std::string>("Type");
93 
94  // Closure models
95  if (closure_type == "InductionConvectiveFlux")
96  {
97  // Induction and magnetic correction equation fluxes
98  auto ind_eval = Teuchos::rcp(
100  *ir, mhd_props));
101  evaluators->push_back(ind_eval);
102 
103  // Momentum equation fluxes
104  auto mtm_eval = Teuchos::rcp(
105  new InductionConvectiveMomentumFlux<EvalType,
106  panzer::Traits,
107  num_space_dim>(*ir,
108  mhd_props));
109  evaluators->push_back(mtm_eval);
110 
111  found_model = true;
112  }
113 
114  if (closure_type == "InductionResistiveFlux")
115  {
116  auto eval = Teuchos::rcp(
118  *ir, mhd_props));
119  evaluators->push_back(eval);
120  found_model = true;
121  }
122 
123  if (closure_type == "MagneticPressure")
124  {
125  auto eval = Teuchos::rcp(
126  new MagneticPressure<EvalType, panzer::Traits>(*ir, mhd_props));
127  evaluators->push_back(eval);
128  found_model = true;
129  }
130 
131  if (closure_type == "FullInductionTimeDerivative")
132  {
133  std::vector<Teuchos::ParameterList> mhd_names_list_vct;
134  for (int dim = 0; dim < num_space_dim; ++dim)
135  {
136  Teuchos::ParameterList ind_names_list;
137  ind_names_list.set(
138  "Field Name",
139  "induced_magnetic_field_" + std::to_string(dim));
140  ind_names_list.set("Equation Name",
141  "induction_" + std::to_string(dim));
142  mhd_names_list_vct.push_back(ind_names_list);
143  }
144  if (build_magn_corr)
145  {
146  Teuchos::ParameterList magn_corr_names_list;
147  magn_corr_names_list.set("Field Name",
148  "scalar_magnetic_potential");
149  magn_corr_names_list.set("Equation Name",
150  "magnetic_correction_potential");
151  mhd_names_list_vct.push_back(magn_corr_names_list);
152  }
153  for (auto& mhd_names_list : mhd_names_list_vct)
154  {
155  auto eval_time = Teuchos::rcp(
157  panzer::Traits>(
158  *ir, mhd_names_list));
159  evaluators->push_back(eval_time);
160  }
161  found_model = true;
162  }
163 
164  if (closure_type == "TotalMagneticField")
165  {
166  auto eval = Teuchos::rcp(
168  *ir));
169  evaluators->push_back(eval);
170  auto eval_grad = Teuchos::rcp(
171  new TotalMagneticFieldGradient<EvalType,
172  panzer::Traits,
173  num_space_dim>(*ir));
174  evaluators->push_back(eval_grad);
175  found_model = true;
176  }
177 
178  if (closure_type == "MHDVortexProblemExact")
179  {
180  auto eval = Teuchos::rcp(
182  *ir, closure_params));
183  evaluators->push_back(eval);
184  found_model = true;
185  }
186 
187  if (closure_type == "FullInductionModelErrorNorm")
188  {
189  auto eval = Teuchos::rcp(
190  new FullInductionModelErrorNorms<EvalType,
191  panzer::Traits,
192  NumSpaceDim>(*ir));
193  evaluators->push_back(eval);
194  found_model = true;
195  }
196 
197  if (closure_type == "DivergenceCleaningSource")
198  {
199  auto eval = Teuchos::rcp(
201  *ir));
202  evaluators->push_back(eval);
203  found_model = true;
204  }
205 
206  if (closure_type == "GodunovPowellSource")
207  {
208  auto eval = Teuchos::rcp(
210  *ir, mhd_props));
211  evaluators->push_back(eval);
212  found_model = true;
213  }
214 
215  if (closure_type == "MagneticCorrectionDampingSource")
216  {
217  auto eval = Teuchos::rcp(
219  *ir, mhd_props));
220  evaluators->push_back(eval);
221  found_model = true;
222  }
223 
224  if (closure_type == "FullInductionLocalTimeStepSize")
225  {
226  auto eval = Teuchos::rcp(
227  new FullInductionLocalTimeStepSize<EvalType,
228  panzer::Traits,
229  NumSpaceDim>(*ir, mhd_props));
230  evaluators->push_back(eval);
231  found_model = true;
232  }
233 
234  if (closure_type == "Resistivity")
235  {
236  if (mhd_props.variableResistivity())
237  {
238  throw std::runtime_error(
239  "No closure models currently exist to evaluate variable "
240  "resistivity. Use a constant resistivity only.");
241  }
242  else
243  {
244  auto eval = Teuchos::rcp(
246  *ir, "resistivity", mhd_props.resistivity()));
247  evaluators->push_back(eval);
248  found_model = true;
249  }
250  }
251 
252  if (closure_type == "InductionConstantSource")
253  {
254  auto eval = Teuchos::rcp(
256  *ir, closure_params));
257  evaluators->push_back(eval);
258  found_model = true;
259  }
260 
261  if (closure_type == "ExternalMagneticField")
262  {
263  auto eval = Teuchos::rcp(
265  *ir, user_params));
266  evaluators->push_back(eval);
267  found_model = true;
268  }
269 
270  if (std::string::npos != closure_type.find("VectorFieldDivergence"))
271  {
272  const auto field_names
273  = closure_params.get<std::string>("Field Names");
274  std::vector<std::string> tokens;
275  panzer::StringTokenizer(tokens, field_names, ",", true);
276  for (auto& field : tokens)
277  {
278  if (std::string::npos != field.find("total_magnetic_field"))
279  {
280  throw std::runtime_error(
281  "The layout of \"total_magnetic_field\" is "
282  "incompatible with the current implementation of "
283  "\"VectorFieldDivergence\", and should not be "
284  "included in the list of field names for this closure "
285  "model. The field \"divergence_total_magnetic_field\" "
286  "is evaluated within the "
287  "\"TotalMagneticFieldGradient\" closure model.");
288  }
289 
290  auto eval = Teuchos::rcp(
292  *ir, field, closure_type));
293  evaluators->push_back(eval);
294  }
295  found_model = true;
296  }
297 
298  if (!found_model)
299  {
300  const std::string msg = "\n\nFull Induction MHD closure model/type "
301  + closure_name + "/" + closure_type
302  + " failed to build in model id " + model_id
303  + ".\n"
304  "The conduction closure models available in Vertex-CFD are:\n"
305  + availableClosureModels();
306  throw std::runtime_error(msg);
307  }
308  }
309 
310  return evaluators;
311 }
312 
313 //---------------------------------------------------------------------------//
314 
315 } // end namespace ClosureModel
316 } // end namespace VertexCFD
317 
318 #endif // end VERTEXCFD_FULLINDUCTIONCLOSUREMODELFACTORY_IMPL_HPP
VertexCFD::ClosureModel::DivergenceCleaningSource
Definition: VertexCFD_Closure_DivergenceCleaningSource.hpp:25
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::MagneticCorrectionDampingSource
Definition: VertexCFD_Closure_MagneticCorrectionDampingSource.hpp:27
VertexCFD::ClosureModel::GodunovPowellSource
Definition: VertexCFD_Closure_GodunovPowellSource.hpp:28
VertexCFD::ClosureModel::FullInductionFactory::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_FullInductionClosureModelFactory_impl.hpp:34
VertexCFD::ClosureModel::ExternalMagneticField
Definition: VertexCFD_Closure_ExternalMagneticField.hpp:26
VertexCFD::ClosureModel::InductionResistiveFlux
Definition: VertexCFD_Closure_InductionResistiveFlux.hpp:30
VertexCFD::ClosureModel::InductionConvectiveMomentumFlux
Definition: VertexCFD_Closure_InductionConvectiveMomentumFlux.hpp:31
VertexCFD::ClosureModel::InductionConstantSource
Definition: VertexCFD_Closure_InductionConstantSource.hpp:26
VertexCFD::ClosureModel::ConstantScalarField
Definition: VertexCFD_Closure_ConstantScalarField.hpp:26
VertexCFD::ClosureModel::FullInductionLocalTimeStepSize
Definition: VertexCFD_Closure_FullInductionLocalTimeStepSize.hpp:33
VertexCFD::ClosureModel::FullInductionModelErrorNorms
Definition: VertexCFD_Closure_FullInductionModelErrorNorms.hpp:27
VertexCFD::ClosureModel::InductionConvectiveFlux
Definition: VertexCFD_Closure_InductionConvectiveFlux.hpp:30
VertexCFD::ClosureModel::MagneticPressure
Definition: VertexCFD_Closure_MagneticPressure.hpp:30
VertexCFD::ClosureModel::TotalMagneticFieldGradient
Definition: VertexCFD_Closure_TotalMagneticFieldGradient.hpp:29
VertexCFD::ClosureModel::MHDVortexProblemExact
Definition: VertexCFD_Closure_MHDVortexProblemExact.hpp:26