feat(quadrature): quadrature system brought over
Ported and dramatically cleaned up the quadrature system. This includes centralizing all field definitions
This commit is contained in:
103
src/lib/serif/discretization/quadrature/policy.cpp
Normal file
103
src/lib/serif/discretization/quadrature/policy.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#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"
|
||||
|
||||
namespace serif::discretization::quadrature {
|
||||
using namespace serif::utils::warnings;
|
||||
using namespace serif::utils::errors;
|
||||
|
||||
Policy::Policy(RuleSet ruleSet) : m_ruleSet(std::move(ruleSet)) {
|
||||
|
||||
}
|
||||
|
||||
int Policy::compute_base_order(const Query &query) {
|
||||
if (query.base_order.has_value()) {
|
||||
if (*query.base_order < 0) {
|
||||
serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadrature base_order must be non-negative. Received: {}. This is likely a configuration error", *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>("Quadrature orders must be non-negative. Received: trial_order={}, test_order={}, coefficient_order={}, geometry_weight_order={}. This is likely a configuration error", 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>("Quadrature order reductions must be non-negative. Received: trial_order_reduction={}, test_order_reduction={}. Note these are reductions, they are subtracted from the corresponding order. You do not need to include a negative sign with them. This is likely a configuration error", query.trial_order_reduction, query.test_order_reduction);
|
||||
}
|
||||
|
||||
const int reduced_trial_order = query.trial_order - query.trial_order_reduction;
|
||||
const int reduced_test_order = query.test_order - query.test_order_reduction;
|
||||
|
||||
if (reduced_trial_order < 0) {
|
||||
serif_warning("Quadrature trial order reduction ({}) is greater than the trial order ({}). Clamping this value to 0", query.trial_order_reduction, query.trial_order);
|
||||
}
|
||||
if (reduced_test_order < 0) {
|
||||
serif_warning("Quadrature test order reduction ({}) is greater than the test order ({}). Clamping this value to 0", query.test_order_reduction, query.test_order);
|
||||
}
|
||||
|
||||
const int trial_order = std::max(0, reduced_trial_order);
|
||||
const int test_order = std::max(0, reduced_test_order);
|
||||
|
||||
return trial_order + test_order + query.coefficient_order + query.geometry_weight_order;
|
||||
}
|
||||
|
||||
const RuleControl &Policy::get_role_control(QuadratureRole role) const {
|
||||
return m_ruleSet.role_control(role);
|
||||
}
|
||||
|
||||
Resolution Policy::resolve(const Query &query) const {
|
||||
const int base_order = compute_base_order(query);
|
||||
const RuleControl *form_control = m_ruleSet.find_form_control(query.form);
|
||||
const RuleControl &role_control = get_role_control(query.role);
|
||||
const RuleControl &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;
|
||||
} else if (role_control.fixed_order.has_value()) {
|
||||
fixed_order = role_control.fixed_order;
|
||||
} else if (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>("Quadrature fixed_order must be non-negative. Received: {}. This is likely a configuration error", *fixed_order);
|
||||
}
|
||||
|
||||
return Resolution{
|
||||
.base_order = base_order,
|
||||
.boost = 0,
|
||||
.order = *fixed_order,
|
||||
.used_fixed_order = true
|
||||
};
|
||||
}
|
||||
|
||||
int boost = fallback_control.boost + role_control.boost;
|
||||
|
||||
if (form_control != nullptr) {
|
||||
boost += form_control->boost;
|
||||
}
|
||||
|
||||
const int order = base_order + boost;
|
||||
|
||||
if (order < 0) {
|
||||
serif_error<std::invalid_argument, SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Quadrature order must be non-negative. Received: {}. Realistically this should not be able to happen and represents a likely bug in the code. Please contact the SERiF developers.", order);
|
||||
};
|
||||
|
||||
return Resolution{
|
||||
.base_order = base_order,
|
||||
.boost = boost,
|
||||
.order = order,
|
||||
.used_fixed_order = false
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user