VertexCFD  0.0-dev
VertexCFD_SolidElectricPotentialClosureModelFactory_impl.hpp
1 #ifndef VERTEXCFD_SOLIDELECTRICPOTENTIALCLOSUREMODELFACTORY_IMPL_HPP
2 #define VERTEXCFD_SOLIDELECTRICPOTENTIALCLOSUREMODELFACTORY_IMPL_HPP
3 
4 #include "induction_less_mhd_solver/closure_models/VertexCFD_Closure_SolidElectricConductivity.hpp"
5 #include "induction_less_mhd_solver/closure_models/VertexCFD_Closure_SolidElectricPotentialDiffusionFlux.hpp"
6 #include "induction_less_mhd_solver/closure_models/VertexCFD_Closure_SolidElectricPotentialErrorNorms.hpp"
7 #include "induction_less_mhd_solver/closure_models/VertexCFD_Closure_SolidElectricPotentialExactSolution.hpp"
8 #include "induction_less_mhd_solver/closure_models/VertexCFD_SolidElectricPotentialClosureModelFactory.hpp"
9 
10 #include "closure_models/VertexCFD_Closure_ConstantScalarField.hpp"
11 
12 #include <vector>
13 
14 namespace VertexCFD
15 {
16 namespace ClosureModel
17 {
18 
19 //---------------------------------------------------------------------------//
20 template<class EvalType, int NumSpaceDim>
21 Teuchos::RCP<std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>>
23  const std::string& model_id,
24  const Teuchos::ParameterList& model_params,
25  const panzer::FieldLayoutLibrary&,
26  const Teuchos::RCP<panzer::IntegrationRule>& ir,
27  const Teuchos::ParameterList& ,
28  const Teuchos::ParameterList& ,
29  const Teuchos::RCP<panzer::GlobalData>& ,
30  PHX::FieldManager<panzer::Traits>&) const
31 {
32  auto evaluators = Teuchos::rcp(
33  new std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>);
34 
35  if (!model_params.isSublist(model_id))
36  {
37  throw std::runtime_error("SolidElectricPotential closure model id "
38  + model_id + "not in list.");
39  }
40 
41  constexpr int num_space_dim = NumSpaceDim;
42 
43  // Get closure model list for 'model_id'
44  const Teuchos::ParameterList& closure_model_list
45  = model_params.sublist(model_id);
46 
47  // Check for closure model factory type. If not `SolidElectricPotential`
48  // return empty evaluator
49  const std::string factory_type
50  = closure_model_list.isType<std::string>("Closure Factory Type")
51  ? closure_model_list.get<std::string>("Closure Factory Type")
52  : "None";
53 
54  if (factory_type != "SolidElectricPotential")
55  return evaluators;
56 
57  // Adding default closure models to solve MHD equation
58  const std::string default_closure_models
59  = "SolidElectricPotentialDiffusionFlux,\n";
60 
61  // SolidElectricPotential flux
62  {
63  auto eval_conduction = Teuchos::rcp(
65  *ir));
66  evaluators->push_back(eval_conduction);
67  }
68 
69  // Check for required sublist
70  std::vector<std::string> needed_cm = {"Material Properties"};
71  for (std::string cm : needed_cm)
72  {
73  if (!closure_model_list.isSublist(cm))
74  {
75  throw std::runtime_error(
76  "\n\nERROR: the required sublist '" + cm
77  + "' could not be found in the closure model list '" + model_id
78  + "'\n\n");
79  }
80  }
81 
82  // Loop over closure models
83  for (const auto& closure_model : closure_model_list)
84  {
85  bool found_model = false;
86 
87  const auto closure_name = closure_model.first;
88  if (closure_name == "Closure Factory Type")
89  continue;
90 
91  // Get closure parameters for current closure model
92  const auto& closure_params
93  = Teuchos::getValue<Teuchos::ParameterList>(closure_model.second);
94 
95  if (closure_params.isType<std::string>("Type"))
96  {
97  const auto closure_type = closure_params.get<std::string>("Type");
98 
99  // Check if 'closure_type' is a default closure model
100  if (default_closure_models.find(closure_type) != std::string::npos)
101  {
102  std::string msg = "\n\nSolidElectricPotential closure model/type '" + closure_name + "'/'" + closure_type
103  + "' found in model id '" + model_id + "' is a default closure model and should not be added to the input file.\n";
104  msg += "The list of default closure models for the conduction equation is:\n";
105  msg += default_closure_models;
106  throw std::runtime_error(msg);
107  }
108 
109  // Electric conductivity
110  if (closure_type == "SolidElectricConductivity")
111  {
112  auto eval = Teuchos::rcp(
114  *ir, closure_params));
115  evaluators->push_back(eval);
116  found_model = true;
117  }
118 
119  // Error norms
120  if (closure_type == "SolidElectricPotentialErrorNorms")
121  {
122  auto eval = Teuchos::rcp(
124  panzer::Traits,
125  num_space_dim>(*ir));
126  evaluators->push_back(eval);
127  found_model = true;
128  }
129 
130  // Exact solution
131  if (closure_type == "SolidElectricPotentialExactSolution")
132  {
133  auto eval = Teuchos::rcp(
135  panzer::Traits,
136  num_space_dim>(
137  *ir, closure_params));
138  evaluators->push_back(eval);
139  found_model = true;
140  }
141 
142  // Time step size: this is only needed when solving for the
143  // induction-less equation in a solid region without any other
144  // physics.
145  if (closure_type == "SolidElectricTimeStepSize")
146  {
147  auto eval = Teuchos::rcp(
149  *ir, "local_dt", 10e10));
150  evaluators->push_back(eval);
151  found_model = true;
152  }
153 
154  // Error message if closure model not found
155  if (!found_model)
156  {
157  std::string msg
158  = "\n\nSolidElectricPotential closure model/type "
159  + closure_name + "/" + closure_type
160  + " failed to build in model id " + model_id + ".\n";
161  msg += "The conduction closure models available in Vertex-CFD are:\n";
162  msg += "SolidElectricConductivity,\n";
163  msg += "SolidElectricPotentialErrorNorms,\n";
164  msg += "SolidElectricPotentialExactSolution,\n";
165  msg += "SolidElectricTimeStepSize,\n";
166  msg += "\n";
167 
168  throw std::runtime_error(msg);
169  }
170  }
171  }
172 
173  return evaluators;
174 }
175 
176 //---------------------------------------------------------------------------//
177 
178 } // end namespace ClosureModel
179 } // end namespace VertexCFD
180 
181 #endif // end VERTEXCFD_SOLIDELECTRICPOTENTIALCLOSUREMODELFACTORY_IMPL_HPP
VertexCFD::ClosureModel::SolidElectricConductivity
Definition: VertexCFD_Closure_SolidElectricConductivity.hpp:27
VertexCFD::ClosureModel::SolidElectricPotentialDiffusionFlux
Definition: VertexCFD_Closure_SolidElectricPotentialDiffusionFlux.hpp:28
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::ClosureModel::SolidElectricPotentialFactory::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_SolidElectricPotentialClosureModelFactory_impl.hpp:22
VertexCFD::ClosureModel::SolidElectricPotentialErrorNorms
Definition: VertexCFD_Closure_SolidElectricPotentialErrorNorms.hpp:27
VertexCFD::ClosureModel::ConstantScalarField
Definition: VertexCFD_Closure_ConstantScalarField.hpp:26
VertexCFD::ClosureModel::SolidElectricPotentialExactSolution
Definition: VertexCFD_Closure_SolidElectricPotentialExactSolution.hpp:27