1 #ifndef VERTEXCFD_COMPUTE_ERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_COMPUTE_ERRORNORMS_IMPL_HPP
4 #include <Panzer_ResponseEvaluatorFactory_Functional.hpp>
6 #include <Teuchos_DefaultMpiComm.hpp>
13 namespace ComputeErrorNorms
16 template<
class Scalar>
17 ErrorNorms<Scalar>::ErrorNorms(
18 const Teuchos::RCP<panzer_stk::STK_Interface>& mesh,
19 const Teuchos::RCP<
const panzer::LinearObjFactory<panzer::Traits>>& lof,
20 const Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits>>& response_library,
21 const std::vector<Teuchos::RCP<panzer::PhysicsBlock>>& physics_blocks,
22 const panzer::ClosureModelFactory_TemplateManager<panzer::Traits>& cm_factory,
23 const Teuchos::ParameterList& closure_params,
24 const Teuchos::ParameterList& user_params,
25 const Teuchos::RCP<panzer::EquationSetFactory>& eq_set_factory,
27 const int integration_order)
29 , _response_library(response_library)
30 , _physics_blocks(physics_blocks)
31 , _cm_factory(cm_factory)
32 , _closure_params(closure_params)
33 , _user_params(user_params)
34 , _eq_set_factory(eq_set_factory)
41 bool build_ns_error_norms =
true;
42 bool build_temp_error_norms =
false;
43 bool build_inductionless_error_norms =
false;
44 bool build_rad_error_norms =
false;
45 bool build_fim_error_norms =
false;
46 bool build_lsvof_error_norms =
false;
47 for (
auto it = closure_params.begin(); it != closure_params.end(); ++it)
49 const std::string name = it->first;
50 if (closure_params.isSublist(name))
52 const auto p = closure_params.sublist(name);
54 if (p.isType<std::string>(
"Closure Factory Type"))
56 if (p.get<std::string>(
"Closure Factory Type")
57 ==
"Full Induction MHD")
59 build_fim_error_norms =
true;
61 else if (p.get<std::string>(
"Closure Factory Type")
62 ==
"SolidElectricPotential")
64 build_inductionless_error_norms =
true;
66 else if (p.get<std::string>(
"Closure Factory Type") ==
"LSVOF")
68 build_lsvof_error_norms =
true;
70 else if (p.get<std::string>(
"Closure Factory Type") ==
"RAD")
72 build_rad_error_norms =
true;
74 else if (p.get<std::string>(
"Closure Factory Type")
77 build_temp_error_norms =
true;
84 if (p.isSublist(
"Fluid Properties"))
86 if (p.sublist(
"Fluid Properties")
87 .isType<
bool>(
"Build Temperature Equation"))
89 build_temp_error_norms
90 = p.sublist(
"Fluid Properties")
91 .get<
bool>(
"Build Temperature Equation");
94 if (p.sublist(
"Fluid Properties")
95 .isType<
bool>(
"Build Inductionless MHD Equation"))
97 build_inductionless_error_norms
98 = p.sublist(
"Fluid Properties")
99 .get<
bool>(
"Build Inductionless MHD Equation");
106 if (build_rad_error_norms)
107 build_ns_error_norms =
false;
110 if (build_lsvof_error_norms)
112 for (
auto it = closure_params.begin(); it != closure_params.end(); ++it)
114 const std::string name = it->first;
115 if (closure_params.isSublist(name))
117 const auto p = closure_params.sublist(name);
118 if (p.isSublist(
"LSVOF_Properties"))
120 const Teuchos::ParameterList& lsvof_params
121 = p.sublist(
"LSVOF_Properties");
123 if (lsvof_params.isType<
bool>(
"Build LSVOF Navier-Stokes "
126 build_ns_error_norms = lsvof_params.get<
bool>(
127 "Build LSVOF Navier-Stokes Equations");
135 std::vector<std::string> eq_name;
136 _num_space_dim = mesh->getDimension();
139 if (build_rad_error_norms)
141 for (
auto it = closure_params.begin(); it != closure_params.end(); ++it)
143 const std::string name = it->first;
144 if (closure_params.isSublist(name))
146 const auto p = closure_params.sublist(name);
147 const auto rad_params = p.sublist(
"Model Parameters");
148 const int num_species
149 = rad_params.isType<
int>(
"Number of Species")
150 ? rad_params.get<
int>(
"Number of Species")
152 for (
int i = 0; i < num_species; ++i)
154 eq_name.push_back(
"reaction_advection_diffusion_equation_"
155 + std::to_string(i));
166 if (build_ns_error_norms)
168 eq_name.push_back(
"continuity");
172 if (build_temp_error_norms)
174 eq_name.push_back(
"energy");
178 if (build_inductionless_error_norms)
180 eq_name.push_back(
"electric_potential_equation");
184 if (build_fim_error_norms)
186 for (
int i = 0; i < _num_space_dim; ++i)
188 eq_name.push_back(
"induction_" + std::to_string(i));
193 if (build_ns_error_norms)
196 for (
int i = 0; i < _num_space_dim; ++i)
197 eq_name.push_back(
"momentum_" + std::to_string(i));
201 if (build_lsvof_error_norms)
203 for (
auto it = closure_params.begin(); it != closure_params.end(); ++it)
205 const std::string name = it->first;
206 if (closure_params.isSublist(name))
208 const auto p = closure_params.sublist(name);
209 if (p.isSublist(
"LSVOF_Properties"))
211 const Teuchos::ParameterList& lsvof_params
212 = p.sublist(
"LSVOF_Properties");
214 const std::string lsvof_model
215 = lsvof_params.get<std::string>(
"LSVOF Model");
218 = lsvof_params.get<
int>(
"Number of Phases");
220 if (lsvof_model ==
"VOF")
222 for (
int phase = 1; phase < num_phases; ++phase)
224 const Teuchos::ParameterList& phase_list
225 = lsvof_params.sublist(
226 "Phase " + std::to_string(phase));
228 const std::string phase_name
229 = phase_list.get<std::string>(
"Phase Name");
231 eq_name.push_back(
"alpha_" + phase_name);
240 std::vector<std::string> element_blocks;
241 mesh->getElementBlockNames(element_blocks);
243 panzer::FunctionalResponse_Builder<int, int> response_builder;
244 response_builder.comm = Teuchos::getRawMpiComm(*(mesh->getComm()));
245 response_builder.cubatureDegree = integration_order;
246 response_builder.requiresCellIntegral =
true;
249 auto add_dof_L1 = [&](
const std::string& dof) {
250 response_builder.quadPointField =
"L1_Error_" + dof;
251 _response_library->addResponse(
252 dof +
"_L1_error_norms", element_blocks, response_builder);
254 _L1_error_norms.emplace_back(dof);
258 auto add_dof_L2 = [&](
const std::string& dof) {
259 response_builder.quadPointField =
"L2_Error_" + dof;
260 _response_library->addResponse(
261 dof +
"_L2_error_norms", element_blocks, response_builder);
263 _L2_error_norms.emplace_back(dof);
267 for (
auto& element : eq_name)
274 _response_library->buildResponseEvaluators(
275 _physics_blocks, _cm_factory, _closure_params, _user_params);
279 template<
class Scalar>
280 void ErrorNorms<Scalar>::ComputeNorms(
281 const Teuchos::RCP<Tempus::SolutionState<Scalar>>& working_state)
284 auto x = working_state->getX();
287 panzer::AssemblyEngineInArgs in_args;
288 in_args.container_ = _lof->buildLinearObjContainer();
289 in_args.ghostedContainer_ = _lof->buildGhostedLinearObjContainer();
290 in_args.evaluate_transient_terms =
false;
291 in_args.time = working_state->getTime();
293 _lof->initializeGhostedContainer(panzer::LinearObjContainer::X,
294 *(in_args.ghostedContainer_));
297 = Teuchos::rcp_dynamic_cast<panzer::ThyraObjContainer<double>>(
299 thyra_container->set_x_th(
300 Teuchos::rcp_const_cast<Thyra::VectorBase<double>>(x));
303 for (
auto& dof : _L1_error_norms)
305 auto resp = _response_library->getResponse<panzer::Traits::Residual>(
306 dof.name +
"_L1_error_norms");
307 auto resp_func = Teuchos::rcp_dynamic_cast<
308 panzer::Response_Functional<panzer::Traits::Residual>>(resp);
309 auto resp_vec = Thyra::createMember(resp_func->getVectorSpace());
310 resp_func->setVector(resp_vec);
314 for (
auto& dof : _L2_error_norms)
316 auto resp = _response_library->getResponse<panzer::Traits::Residual>(
317 dof.name +
"_L2_error_norms");
318 auto resp_func = Teuchos::rcp_dynamic_cast<
319 panzer::Response_Functional<panzer::Traits::Residual>>(resp);
320 auto resp_vec = Thyra::createMember(resp_func->getVectorSpace());
321 resp_func->setVector(resp_vec);
324 _response_library->addResponsesToInArgs<panzer::Traits::Residual>(in_args);
325 _response_library->evaluate<panzer::Traits::Residual>(in_args);
328 for (
auto& dof : _L1_error_norms)
330 auto resp = _response_library->getResponse<panzer::Traits::Residual>(
331 dof.name +
"_L1_error_norms");
332 auto resp_func = Teuchos::rcp_dynamic_cast<
333 panzer::Response_Functional<panzer::Traits::Residual>>(resp);
334 dof.error_norm = (resp_func->value) / _volume;
338 for (
auto& dof : _L2_error_norms)
340 auto resp = _response_library->getResponse<panzer::Traits::Residual>(
341 dof.name +
"_L2_error_norms");
342 auto resp_func = Teuchos::rcp_dynamic_cast<
343 panzer::Response_Functional<panzer::Traits::Residual>>(resp);
344 dof.error_norm = std::sqrt(resp_func->value) / _volume;
353 #endif // end VERTEXCFD_COMPUTE_ERRORNORMS_IMPL_HPP