9#include <kernel/meshopt/rumpf_functionals/p1.hpp>
10#include <kernel/meshopt/rumpf_functionals/q1.hpp>
16#include <kernel/meshopt/hyperelasticity_functional.hpp>
17#include <kernel/meshopt/mesh_concentration_function.hpp>
19#include <control/meshopt/meshopt_control.hpp>
20#include <control/meshopt/dudv_functional_control.hpp>
21#include <control/meshopt/hyperelasticity_functional_control.hpp>
38 template<
typename,
typename,
typename,
typename,
typename>
class Functional_,
39 typename CellFunctional_
41 class SetCellFunctional
44 template<
typename DT_,
typename IT_,
typename Trafo_>
45 using Functional = Functional_<DT_, IT_, Trafo_, CellFunctional_, FEAT::Meshopt::RumpfTrafo<Trafo_, typename Trafo_::CoordType>>;
64 template<
typename DT_,
typename IT_>
88 template<
typename DomCtrl_>
89 static std::shared_ptr <Control::Meshopt::MeshoptControlBase<DomCtrl_>>
92 std::shared_ptr<Control::Meshopt::MeshoptControlBase<DomCtrl_>> result(
nullptr);
98 auto meshopt_section = meshopt_config->
query_section(section_key);
99 XASSERTM(meshopt_section !=
nullptr,
"Application config is missing the mandatory MeshOptimizer section!");
102 auto type_p = meshopt_section->query(
"type");
103 XASSERTM(type_p.second,
"MeshOptimizer section is missing the mandatory type!");
104 XASSERTM(type_p.first ==
"DuDv",
"Invalid type string!");
107 auto dirichlet_list_p = meshopt_section->query(
"dirichlet_boundaries");
108 std::deque<String> dirichlet_list = dirichlet_list_p.first.split_by_whitespaces();
111 auto slip_list_p = meshopt_section->query(
"slip_boundaries");
112 std::deque<String> slip_list = slip_list_p.first.split_by_whitespaces();
115 auto meshopt_lvl_p = meshopt_section->query(
"meshopt_lvl");
116 if(meshopt_lvl_p.second)
118 meshopt_lvl = std::stoi(meshopt_lvl_p.first);
121 auto config_section_p = meshopt_section->query(
"config_section");
122 XASSERTM(config_section_p.second,
"MeshOptimizer config section is missing config_section entry!");
124 auto dudv_config_section = meshopt_config->
query_section(config_section_p.first);
125 if(dudv_config_section ==
nullptr)
127 XABORTM(
"config_section "+config_section_p.first+
" not found!");
130 auto solver_p = dudv_config_section->query(
"solver_config");
131 XASSERTM(solver_p.second,
"DuDv config section is missing solver_config entry!");
133 bool fixed_reference_domain(
false);
134 auto fixed_reference_domain_p = dudv_config_section->query(
"fixed_reference_domain");
135 if(fixed_reference_domain_p.second)
137 fixed_reference_domain = (std::stoi(fixed_reference_domain_p.first) == 1);
141 result = std::make_shared<DuDvCtrl>(
142 dom_ctrl, meshopt_lvl,
143 dirichlet_list, slip_list, solver_p.first, *solver_config, fixed_reference_domain);
172 template<
typename DomCtrl_>
173 static std::shared_ptr <Control::Meshopt::MeshoptControlBase<DomCtrl_>>
177 typedef typename DomCtrl_::LevelType::TrafoType TrafoType;
179 std::shared_ptr<Control::Meshopt::MeshoptControlBase<DomCtrl_>> result(
nullptr);
192 auto meshopt_section = meshopt_config->
query_section(section_key);
193 XASSERTM(meshopt_section !=
nullptr,
"Application config is missing the mandatory MeshOptimizer section!");
196 auto type_p = meshopt_section->query(
"type");
197 XASSERTM(type_p.second,
"MeshOptimizer section is missing the mandatory type!");
198 XASSERTM(type_p.first ==
"Hyperelasticity",
"Invalid type!");
201 auto dirichlet_list_p = meshopt_section->query(
"dirichlet_boundaries");
202 std::deque<String> dirichlet_list = dirichlet_list_p.first.split_by_whitespaces();
205 auto slip_list_p = meshopt_section->query(
"slip_boundaries");
206 std::deque<String> slip_list = slip_list_p.first.split_by_whitespaces();
209 auto meshopt_lvl_p = meshopt_section->query(
"meshopt_lvl");
210 if(meshopt_lvl_p.second)
212 meshopt_lvl = std::stoi(meshopt_lvl_p.first);
216 auto config_section_p = meshopt_section->query(
"config_section");
217 if(!config_section_p.second)
219 XABORTM(
"config_section "+config_section_p.first+
" not found");
223 auto hyperelasticity_config_section = meshopt_config->
query_section(config_section_p.first);
226 auto fac_norm_p = hyperelasticity_config_section->
query(
"fac_norm");
227 if(!fac_norm_p.second)
229 XABORTM(
"config_section "+config_section_p.first+
" is missing fac_norm entry!");
231 fac_norm = DT_(std::stod(fac_norm_p.first));
234 auto fac_det_p = hyperelasticity_config_section->query(
"fac_det");
235 if(!fac_det_p.second)
237 XABORTM(
"config_section "+config_section_p.first+
" is missing fac_det entry!");
239 fac_det = DT_(std::stod(fac_det_p.first));
242 auto fac_cof_p = hyperelasticity_config_section->query(
"fac_cof");
243 if(!fac_cof_p.second)
245 XABORTM(
"config_section "+config_section_p.first+
" is missing fac_cof entry!");
247 fac_cof = DT_(std::stod(fac_cof_p.first));
250 auto fac_reg_p = hyperelasticity_config_section->query(
"fac_reg");
251 if(!fac_reg_p.second)
253 XABORTM(
"config_section "+config_section_p.first+
" is missing fac_reg entry!");
255 fac_reg = DT_(std::stod(fac_reg_p.first));
258 auto cell_functional_p = hyperelasticity_config_section->query(
"cell_functional");
259 if(!cell_functional_p.second)
261 XABORTM(
"config_section "+config_section_p.first+
" is missing cell_functional entry!");
266 auto exponent_det_p = hyperelasticity_config_section->query(
"exponent_det");
267 if(!exponent_det_p.second)
269 XABORTM(
"config_section "+config_section_p.first+
" is missing exponent_det entry!");
271 exponent_det = std::stoi(exponent_det_p.first);
274 if(cell_functional_p.first ==
"RumpfFunctional")
277 std::shared_ptr<CellFunctionalType> my_functional = std::make_shared<CellFunctionalType>
278 (fac_norm, fac_det, fac_cof, fac_reg, exponent_det);
281 (dom_ctrl, meshopt_lvl, hyperelasticity_config_section, meshopt_config, solver_config, my_functional,
282 dirichlet_list, slip_list);
296 XABORTM(
"Unhandled cell_functional "+cell_functional_p.first);
342 template<
typename DomCtrl_,
typename CellFunctional_>
343 static std::shared_ptr <Control::Meshopt::MeshoptControlBase<DomCtrl_>>
345 const int meshopt_lvl,
349 std::shared_ptr<CellFunctional_> my_functional,
350 const std::deque<String>& dirichlet_list,
const std::deque<String>& slip_list)
352 typedef typename DomCtrl_::LevelType::TrafoType TrafoType;
354 std::shared_ptr<Control::Meshopt::MeshoptControlBase<DomCtrl_>> result(
nullptr);
357 auto global_functional_p = hyperelasticity_config_section->
query(
"global_functional");
358 if(!global_functional_p.second)
360 XABORTM(
"Hyperelasticity config section is missing global_functional entry!");
366 auto scale_computation_p = hyperelasticity_config_section->
query(
"scale_computation");
367 if(scale_computation_p.second)
369 scale_computation << scale_computation_p.first;
373 auto align_mesh_p = hyperelasticity_config_section->
query(
"align_mesh");
374 if(align_mesh_p.second)
376 align_mesh = std::stoi(align_mesh_p.first);
380 auto solver_p = hyperelasticity_config_section->
query(
"solver_config");
383 XABORTM(
"Hyperelasticity config section is missing solver entry!");
386 if(global_functional_p.first ==
"HyperelasticityFunctional")
388 typedef typename FEAT::Meshopt::
389 HyperelasticityFunctional<DT_, IT_, TrafoType, CellFunctional_>::RefCellTrafo RefCellTrafo;
391 std::shared_ptr<FEAT::Meshopt::MeshConcentrationFunctionBase<TrafoType, RefCellTrafo>>
392 mesh_conc_func(
nullptr);
394 if( scale_computation == FEAT::Meshopt::ScaleComputation::current_concentration ||
395 scale_computation == FEAT::Meshopt::ScaleComputation::iter_concentration ||
398 auto conc_func_section_p = hyperelasticity_config_section->
query(
"conc_function");
399 XASSERTM(conc_func_section_p.second,
"conc_function missing!");
401 create(conc_func_section_p.first, meshopt_config);
406 SetCellFunctional<FEAT::Meshopt::HyperelasticityFunctional, CellFunctional_>::template Functional>>
407 (dom_ctrl, meshopt_lvl, dirichlet_list, slip_list, solver_p.first,
408 *solver_config, my_functional, scale_computation, mesh_conc_func, DT_(align_mesh));
412 XABORTM(
"Unknown global_functional "+global_functional_p.first);
438 template<
typename DomCtrl_>
439 static std::shared_ptr<Control::Meshopt::MeshoptControlBase<DomCtrl_>>
443 std::shared_ptr<Control::Meshopt::MeshoptControlBase<DomCtrl_>> result(
nullptr);
447 auto meshopt_section = meshopt_config->
query_section(section_key);
448 if(meshopt_section ==
nullptr)
450 XABORTM(
"Meshopt config is missing the ["+section_key+
"] section!");
455 auto type_p = meshopt_section->query(
"type");
458 XABORTM(
"MeshOptimizer section is missing the mandatory type!");
470 if(type ==
"Hyperelasticity")
475 if(result ==
nullptr)
477 XABORTM(
"MeshOptimizer section has unhandled type "+type);
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Control class for DuDvFunctionals.
Control class for HyperelasticityFunctionals.
Functionals for measuring and optimising mesh quality.
A class organizing a tree of key-value pairs.
PropertyMap * query_section(String sec_path)
Queries a section by its section path.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
String class implementation.
ScaleComputation
Enum class for different types of scale computations.
Factory for MeshoptControl objects.
static std::shared_ptr< Control::Meshopt::MeshoptControlBase< DomCtrl_ > > create_hyperelasticity_control(DomCtrl_ &dom_ctrl, const String §ion_key, PropertyMap *meshopt_config, PropertyMap *solver_config)
Creates a HyperelasticityFunctionalControl object.
static std::shared_ptr< Control::Meshopt::MeshoptControlBase< DomCtrl_ > > create_dudv_control(DomCtrl_ &dom_ctrl, const String §ion_key, PropertyMap *meshopt_config, PropertyMap *solver_config)
Creates a DuDvFunctionalControl object.
static std::shared_ptr< Control::Meshopt::MeshoptControlBase< DomCtrl_ > > create_meshopt_control(DomCtrl_ &dom_ctrl, const String §ion_key, PropertyMap *meshopt_config, PropertyMap *solver_config)
Creates a MeshoptControlBase object according to a PropertyMap.
static std::shared_ptr< Control::Meshopt::MeshoptControlBase< DomCtrl_ > > create_hyperelasticity_control_with_cell_functional(DomCtrl_ &dom_ctrl, const int meshopt_lvl, PropertyMap *hyperelasticity_config_section, PropertyMap *meshopt_config, PropertyMap *solver_config, std::shared_ptr< CellFunctional_ > my_functional, const std::deque< String > &dirichlet_list, const std::deque< String > &slip_list)
Creates a HyperelasticityFunctionalControl object.
static std::shared_ptr< MeshConcentrationFunctionBase< Trafo_, RefCellTrafo_ > > create(const String §ion_key, PropertyMap *config)
Creates a MeshConcentrationFunction according to a PropertyMap.