policy.cpp stdexcept format print ../../../../include/serif/discretization/quadrature/policy.hpp serif/utils/warnings/warning.hpp serif/utils/error/errors.hpp serif serif::discretization serif::discretization::quadrature #include<stdexcept> #include<format> #include<print> #include"../../../../include/serif/discretization/quadrature/policy.hpp" #include"serif/utils/warnings/warning.hpp" #include"serif/utils/error/errors.hpp" namespaceserif::discretization::quadrature{ usingnamespaceserif::utils::warnings; usingnamespaceserif::utils::errors; Policy::Policy(RuleSetruleSet):m_ruleSet(std::move(ruleSet)){ } intPolicy::compute_base_order(constQuery&query){ if(query.base_order.has_value()){ if(*query.base_order<0){ serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadraturebase_ordermustbenon-negative.Received:{}.Thisislikelyaconfigurationerror",*query.base_order); } return*query.base_order; } if(query.trial_order<0||query.test_order<0||query.coefficient_order<0||query.geometry_weight_order<0){ serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadratureordersmustbenon-negative.Received:trial_order={},test_order={},coefficient_order={},geometry_weight_order={}.Thisislikelyaconfigurationerror",query.trial_order,query.test_order,query.coefficient_order,query.geometry_weight_order); } if(query.trial_order_reduction<0||query.test_order_reduction<0){ serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadratureorderreductionsmustbenon-negative.Received:trial_order_reduction={},test_order_reduction={}.Notethesearereductions,theyaresubtractedfromthecorrespondingorder.Youdonotneedtoincludeanegativesignwiththem.Thisislikelyaconfigurationerror",query.trial_order_reduction,query.test_order_reduction); } constintreduced_trial_order=query.trial_order-query.trial_order_reduction; constintreduced_test_order=query.test_order-query.test_order_reduction; if(reduced_trial_order<0){ serif_warning("Quadraturetrialorderreduction({})isgreaterthanthetrialorder({}).Clampingthisvalueto0",query.trial_order_reduction,query.trial_order); } if(reduced_test_order<0){ serif_warning("Quadraturetestorderreduction({})isgreaterthanthetestorder({}).Clampingthisvalueto0",query.test_order_reduction,query.test_order); } constinttrial_order=std::max(0,reduced_trial_order); constinttest_order=std::max(0,reduced_test_order); returntrial_order+test_order+query.coefficient_order+query.geometry_weight_order; } constRuleControl&Policy::get_role_control(QuadratureRolerole)const{ returnm_ruleSet.role_control(role); } ResolutionPolicy::resolve(constQuery&query)const{ constintbase_order=compute_base_order(query); constRuleControl*form_control=m_ruleSet.find_form_control(query.form); constRuleControl&role_control=get_role_control(query.role); constRuleControl&fallback_control=m_ruleSet.fallback_control(); std::optional<int>fixed_order; if(form_control!=nullptr&&form_control->fixed_order.has_value()){ fixed_order=form_control->fixed_order; }elseif(role_control.fixed_order.has_value()){ fixed_order=role_control.fixed_order; }elseif(fallback_control.fixed_order.has_value()){ fixed_order=fallback_control.fixed_order; } if(fixed_order.has_value()){ if(*fixed_order<0){ serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadraturefixed_ordermustbenon-negative.Received:{}.Thisislikelyaconfigurationerror",*fixed_order); } returnResolution{ .base_order=base_order, .boost=0, .order=*fixed_order, .used_fixed_order=true }; } intboost=fallback_control.boost+role_control.boost; if(form_control!=nullptr){ boost+=form_control->boost; } constintorder=base_order+boost; if(order<0){ serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadratureordermustbenon-negative.Received:{}.Realisticallythisshouldnotbeabletohappenandrepresentsalikelybuginthecode.PleasecontacttheSERiFdevelopers.",order); }; returnResolution{ .base_order=base_order, .boost=boost, .order=order, .used_fixed_order=false }; } }