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:
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "mfem/fem/intrules.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature::backend::mfem {
|
||||
template <typename IntegratorT>
|
||||
concept HasReferenceSetIntegrationRule = requires (IntegratorT &integrator, const ::mfem::IntegrationRule &integration_rule) {
|
||||
integrator.SetIntegrationRule(integration_rule);
|
||||
};
|
||||
|
||||
template <typename IntegratorT>
|
||||
concept HasPointerSetIntegrationRule = requires (IntegratorT &integrator, const ::mfem::IntegrationRule &integration_rule) {
|
||||
integrator.SetIntRule(&integration_rule);
|
||||
};
|
||||
|
||||
template <typename IntegratorT>
|
||||
concept HasSetIntRule = requires (IntegratorT &integrator, const ::mfem::IntegrationRule &integration_rule) {
|
||||
integrator.SetIntRule(integration_rule);
|
||||
};
|
||||
|
||||
template <typename IntegratorT>
|
||||
concept ConfigurableIntegrator = HasReferenceSetIntegrationRule<IntegratorT> ||
|
||||
HasPointerSetIntegrationRule<IntegratorT> ||
|
||||
HasSetIntRule<IntegratorT>;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "mfem/fem/intrules.hpp"
|
||||
|
||||
#include "serif/discretization/quadrature/backend/mfem/concepts.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature::backend::mfem {
|
||||
template <ConfigurableIntegrator IntegratorT>
|
||||
void set_integration_rule(IntegratorT &integrator, const ::mfem::IntegrationRule &integration_rule) {
|
||||
if constexpr (HasReferenceSetIntegrationRule<IntegratorT>) {
|
||||
integrator.SetIntegrationRule(integration_rule);
|
||||
} else if constexpr (HasPointerSetIntegrationRule<IntegratorT>) {
|
||||
integrator.SetIntegrationRule(&integration_rule);
|
||||
} else {
|
||||
integrator.SetIntRule(&integration_rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
#include <span>
|
||||
|
||||
#include "mfem/fem/geom.hpp"
|
||||
#include "mfem/fem/intrules.hpp"
|
||||
|
||||
#include "serif/discretization/blocks/traits.hpp"
|
||||
#include "serif/discretization/quadrature/rules.hpp"
|
||||
|
||||
#include "serif/discretization/quadrature/backend/order.hpp"
|
||||
|
||||
#include "serif/discretization/domain/concepts.hpp"
|
||||
#include "serif/discretization/quadrature/policy.hpp"
|
||||
#include "serif/discretization/quadrature/query.hpp"
|
||||
|
||||
#include "serif/discretization/quadrature/backend/mfem/concepts.hpp"
|
||||
#include "serif/discretization/quadrature/backend/mfem/mfem_static_order.hpp"
|
||||
|
||||
// We may want to consider renaming this file to runtime to stick to convention. The reason
|
||||
// I did not initially is that this is more specific than pure runtime projection of compile
|
||||
// time invariants (which is what most of the other files named runtime.hpp do). Something to think
|
||||
// about
|
||||
|
||||
// Note also that you will see ::mfem throughout. This is an important syntax to use here since MFEM's
|
||||
// code lives in the mfem namespace; however, we also have code living in an mfem namespace.
|
||||
// Outside of translation units that include using namespace serif::discretization::quadrature::backend
|
||||
// and outside of the serif::discretization::quadrature::backend::mfem namespace itself these two things
|
||||
// do not conflict. However, in those two cases there is a degeneracy the compiler cannot
|
||||
// resolve between mfem:: and mfem:: (see what I did there?) Using ::mfem explicitly tells the compiler
|
||||
// that we are looking from the root of the namespace tree not the current namespace. This is important to avoid ambiguity and compiler errors.
|
||||
|
||||
namespace serif::discretization::quadrature::backend::mfem {
|
||||
struct MFEMQuadratureContext final {
|
||||
QuadratureRole role = QuadratureRole::discretization;
|
||||
|
||||
::mfem::Geometry::Type geometry = ::mfem::Geometry::INVALID;
|
||||
int geometry_weight_order = 0;
|
||||
|
||||
std::span<const int> dynamic_orders{};
|
||||
domain::DomainOrSet domain = domain::AllDomains{};
|
||||
|
||||
MappingKind mapping = MappingKind::none;
|
||||
};
|
||||
|
||||
struct MFEMRule final {
|
||||
Resolution resolution;
|
||||
|
||||
const ::mfem::IntegrationRule *integration_rule = nullptr;
|
||||
};
|
||||
|
||||
class MFEMResolver final {
|
||||
public:
|
||||
explicit MFEMResolver (Policy policy) noexcept : m_policy(std::move(policy)) {} // Do we actually want to use move rvalue semantics here?
|
||||
|
||||
template <forms::Form FormT>
|
||||
[[nodiscard]] MFEMRule resolve(const MFEMQuadratureContext& context) const {
|
||||
if (context.geometry_weight_order < 0) {
|
||||
utils::errors::serif_error<std::invalid_argument, utils::errors::SERiFErrorCode::INVALID_QUADRATURE_ORDER>("MFEM geometry weight order must be non-negative. Received an order of {}", context.geometry_weight_order);
|
||||
}
|
||||
|
||||
const int dynamic_order = sum_dynamic_orders(context.dynamic_orders);
|
||||
const int base_order = mfem_form_static_order<FormT> + dynamic_order + context.geometry_weight_order;
|
||||
|
||||
const Query query {
|
||||
.form = forms::form_descriptor<FormT>,
|
||||
.role = context.role,
|
||||
.domain = context.domain,
|
||||
.mapping = context.mapping,
|
||||
.base_order = base_order
|
||||
};
|
||||
|
||||
const Resolution resolution = m_policy.resolve(query);
|
||||
|
||||
const ::mfem::IntegrationRule &integration_rule = ::mfem::IntRules.Get(context.geometry, resolution.order);
|
||||
return MFEMRule{.resolution = resolution, .integration_rule = &integration_rule};
|
||||
}
|
||||
|
||||
template <forms::Form FormT, ConfigurableIntegrator IntegratorT>
|
||||
Resolution configure(IntegratorT &integrator, const MFEMQuadratureContext& context) const {
|
||||
const MFEMRule rule = resolve<FormT>(context);
|
||||
set_integration_rule(integrator, *rule.integration_rule);
|
||||
return rule.resolution;
|
||||
}
|
||||
|
||||
private:
|
||||
Policy m_policy;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "serif/discretization/blocks/concepts.hpp"
|
||||
#include "serif/discretization/forms/operands.hpp"
|
||||
#include "serif/utils/types/type_list.hpp"
|
||||
#include "serif/discretization/quadrature/backend/order.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature::backend::mfem {
|
||||
template <typename OperandListT>
|
||||
struct MFEMOperandListOrder;
|
||||
|
||||
template <forms::IsOperand... OperandTs>
|
||||
struct MFEMOperandListOrder<utils::types::TypeList<OperandTs...>> final {
|
||||
static constexpr int value = (resolve_operand_order<OperandTs>() + ... + 0);
|
||||
};
|
||||
|
||||
template <forms::Form FormT>
|
||||
inline constexpr int mfem_form_static_order = MFEMOperandListOrder<typename FormT::operand_types>::value;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "serif/discretization/functional_space/space.hpp"
|
||||
#include "serif/discretization/blocks/concepts.hpp"
|
||||
#include "serif/discretization/forms/operands.hpp"
|
||||
#include "serif/utils/error/errors.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature::backend::mfem {
|
||||
template <typename FunctionalSpaceT>
|
||||
struct DiscreteFunctionalSpaceTraits;
|
||||
|
||||
template <auto SpaceV, auto OrderV, auto RankV>
|
||||
struct DiscreteFunctionalSpaceTraits<functional_space::DiscreteFunctionalSpace<SpaceV, OrderV, RankV>> final {
|
||||
static constexpr auto space = SpaceV;
|
||||
static constexpr auto order = static_cast<int>(OrderV);
|
||||
static constexpr std::size_t rank = static_cast<std::size_t>(RankV);
|
||||
};
|
||||
|
||||
template <blocks::HasFunctionalSpace TermT>
|
||||
using FunctionalSpaceTraits = DiscreteFunctionalSpaceTraits<typename TermT::FunctionalSpace>;
|
||||
|
||||
template <forms::IsOperand OperandT>
|
||||
[[nodiscard]] consteval int resolve_operand_order() noexcept {
|
||||
using Operand = std::remove_cvref_t<OperandT>;
|
||||
using Term = Operand::term_type;
|
||||
using Operation = Operand::operation_type;
|
||||
|
||||
if constexpr (!blocks::HasFunctionalSpace<Term>) {
|
||||
static_assert(std::same_as<forms::Operation, forms::Operation::Value>, "Non-Spatial terms only support the value operation at the moment.");
|
||||
return 0;
|
||||
} else {
|
||||
using Space = FunctionalSpaceTraits<Term>;
|
||||
|
||||
constexpr auto family = Space::space.family;
|
||||
constexpr int order = Space::order;
|
||||
|
||||
if constexpr (std::same_as<Operation, forms::Operation::Value>) {
|
||||
if constexpr (family == functional_space::Family::hdiv) {
|
||||
return order + 1;
|
||||
} else {
|
||||
return order;
|
||||
}
|
||||
} else if constexpr (std::same_as<Operation, forms::Operation::Gradient>) {
|
||||
static_assert(family == functional_space::Family::h1, "Only H1 spaces support the gradient operation at the moment.");
|
||||
|
||||
return order > 0 ? order - 1 : 0;
|
||||
} else if constexpr (std::same_as<Operation, forms::Operation::Divergence>) {
|
||||
static_assert(family == functional_space::Family::hdiv, "Only H(div) spaces support the divergence operation at the moment.");
|
||||
|
||||
return order;
|
||||
} else if constexpr (std::same_as<Operation, forms::Operation::Curl>) {
|
||||
static_assert(family == functional_space::Family::hcurl, "Only H(curl) spaces support the curl operation at the moment.");
|
||||
|
||||
return order > 0 ? order - 1 : 0;
|
||||
} else if constexpr (std::same_as<Operation, forms::Operation::NormalTrace>) {
|
||||
static_assert(family == functional_space::Family::hdiv, "Only H(div) spaces support the normal trace operation at the moment.");
|
||||
|
||||
return order;
|
||||
} else {
|
||||
static_assert(false, "Unsupported operation type. This indicates that an operation was used which is not currently registered in the operand configuration system. If you are a developer and you are seeing this error, please register your operation in the resolve_operand_order function in discretization/quadrature/detail.hpp. If you are a user and you are seeing this error, please report it to the SERiF developers.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] inline int sum_dynamic_orders(const std::span<const int> dynamic_orders) {
|
||||
int total = 0;
|
||||
for (const int order : dynamic_orders) {
|
||||
if (order < 0) {
|
||||
utils::errors::serif_error<std::invalid_argument, utils::errors::SERiFErrorCode::INVALID_QUADRATURE_ORDER>("Dynamic quadrature order cannot be negative. Received {}.", order);
|
||||
}
|
||||
|
||||
total += order;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
20
src/include/serif/discretization/quadrature/policy.hpp
Normal file
20
src/include/serif/discretization/quadrature/policy.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "serif/discretization/quadrature/query.hpp"
|
||||
#include "serif/discretization/quadrature/rules.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature {
|
||||
class Policy final {
|
||||
public:
|
||||
explicit Policy(RuleSet ruleSet);
|
||||
|
||||
[[nodiscard]] Resolution resolve(const Query &query) const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] static int compute_base_order(const Query &query);
|
||||
[[nodiscard]] const RuleControl &get_role_control(QuadratureRole role) const;
|
||||
|
||||
private:
|
||||
RuleSet m_ruleSet;
|
||||
};
|
||||
}
|
||||
74
src/include/serif/discretization/quadrature/query.hpp
Normal file
74
src/include/serif/discretization/quadrature/query.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
#include "serif/discretization/quadrature/rules.hpp"
|
||||
#include "serif/discretization/domain/physical_domains.hpp"
|
||||
#include "serif/discretization/forms/form_traits.hpp"
|
||||
#include "serif/discretization/forms/runtime.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature {
|
||||
struct Query final {
|
||||
forms::FormDescriptor form;
|
||||
|
||||
QuadratureRole role = QuadratureRole::discretization;
|
||||
domain::DomainOrSet domain = domain::AllDomains{};
|
||||
MappingKind mapping = MappingKind::none;
|
||||
|
||||
int trial_order = 0;
|
||||
int test_order = 0;
|
||||
int coefficient_order = 0;
|
||||
int geometry_weight_order = 0;
|
||||
int trial_order_reduction = 0;
|
||||
int test_order_reduction = 0;
|
||||
|
||||
std::optional<int> base_order;
|
||||
};
|
||||
|
||||
template <forms::Form FormT>
|
||||
[[nodiscard]] constexpr Query make_query(
|
||||
const QuadratureRole role,
|
||||
const domain::DomainOrSet domain,
|
||||
const MappingKind mapping,
|
||||
const int trialOrder,
|
||||
const int testOrder,
|
||||
const int coefficientOrder,
|
||||
const int geometryWeightOrder,
|
||||
const std::optional<int> baseOrder = std::nullopt
|
||||
) noexcept {
|
||||
return Query{
|
||||
.form = forms::form_descriptor<FormT>,
|
||||
.role = role,
|
||||
.domain = domain,
|
||||
.mapping = mapping,
|
||||
.trial_order = trialOrder,
|
||||
.test_order = testOrder,
|
||||
.coefficient_order = coefficientOrder,
|
||||
.geometry_weight_order = geometryWeightOrder,
|
||||
.trial_order_reduction = forms::FormTraits<FormT>::trial_order_reduction,
|
||||
.test_order_reduction = forms::FormTraits<FormT>::test_order_reduction,
|
||||
.base_order = baseOrder
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::Query> : std::formatter<std::string> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::Query& q, FormatContext& ctx) const {
|
||||
return std::formatter<std::string>::format(std::format("Query(form={}, role={}, domain={}, mapping={}, trial_order={}, test_order={}, coefficient_order={}, geometry_weight_order={}, trial_order_reduction={}, test_order_reduction={}, base_order={})",
|
||||
q.form,
|
||||
q.role,
|
||||
q.domain,
|
||||
q.mapping,
|
||||
q.trial_order,
|
||||
q.test_order,
|
||||
q.coefficient_order,
|
||||
q.geometry_weight_order,
|
||||
q.trial_order_reduction,
|
||||
q.test_order_reduction,
|
||||
(q.base_order.has_value() ? std::to_string(q.base_order.value()) : "nullopt")
|
||||
), ctx);
|
||||
}
|
||||
};
|
||||
342
src/include/serif/discretization/quadrature/rules.hpp
Normal file
342
src/include/serif/discretization/quadrature/rules.hpp
Normal file
@@ -0,0 +1,342 @@
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <format>
|
||||
#include <utility>
|
||||
|
||||
#include "serif/discretization/forms/runtime.hpp"
|
||||
|
||||
namespace serif::discretization::quadrature {
|
||||
enum class QuadratureRole {
|
||||
discretization,
|
||||
preconditioner,
|
||||
diagnostic,
|
||||
projection
|
||||
};
|
||||
|
||||
enum class MappingKind {
|
||||
none,
|
||||
affine,
|
||||
general,
|
||||
kelvin
|
||||
};
|
||||
|
||||
enum class Mode {
|
||||
fast,
|
||||
production,
|
||||
reference,
|
||||
convergence
|
||||
};
|
||||
|
||||
struct RuleControl {
|
||||
std::optional<int> fixed_order;
|
||||
int boost = 0;
|
||||
};
|
||||
|
||||
struct FormRule final {
|
||||
forms::FormDescriptor form;
|
||||
RuleControl control;
|
||||
};
|
||||
|
||||
class RuleSet {
|
||||
public:
|
||||
template <forms::Form FormT>
|
||||
void set_form_control(
|
||||
const RuleControl control
|
||||
) {
|
||||
set_form_control(forms::form_descriptor<FormT>, control);
|
||||
}
|
||||
|
||||
void set_form_control(
|
||||
const forms::FormDescriptor &form,
|
||||
const RuleControl control
|
||||
) {
|
||||
for (auto &[formDescriptor, ruleControl] : m_formRules) {
|
||||
if (formDescriptor == form) {
|
||||
ruleControl = control;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_formRules.push_back(FormRule{.form = form, .control = control});
|
||||
}
|
||||
|
||||
[[nodiscard]] const RuleControl *find_form_control(
|
||||
const forms::FormDescriptor &form
|
||||
) const noexcept {
|
||||
for (const auto &[formDescriptor, ruleControl] : m_formRules) {
|
||||
if (formDescriptor == form) {
|
||||
return &ruleControl;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void set_role_control(
|
||||
const QuadratureRole role,
|
||||
const RuleControl control
|
||||
) noexcept {
|
||||
switch (role) {
|
||||
case QuadratureRole::discretization:
|
||||
m_discretizationControl = control;
|
||||
break;
|
||||
|
||||
case QuadratureRole::preconditioner:
|
||||
m_preconditionerControl = control;
|
||||
break;
|
||||
|
||||
case QuadratureRole::diagnostic:
|
||||
m_diagnosticControl = control;
|
||||
break;
|
||||
|
||||
case QuadratureRole::projection:
|
||||
m_projectionControl = control;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] const RuleControl &role_control(
|
||||
const QuadratureRole role
|
||||
) const noexcept {
|
||||
switch (role) {
|
||||
case QuadratureRole::discretization:
|
||||
return m_discretizationControl;
|
||||
|
||||
case QuadratureRole::preconditioner:
|
||||
return m_preconditionerControl;
|
||||
|
||||
case QuadratureRole::diagnostic:
|
||||
return m_diagnosticControl;
|
||||
|
||||
case QuadratureRole::projection:
|
||||
return m_projectionControl;
|
||||
}
|
||||
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
void set_fallback_control(
|
||||
const RuleControl control
|
||||
) noexcept {
|
||||
m_fallbackControl = control;
|
||||
}
|
||||
|
||||
[[nodiscard]] const RuleControl &fallback_control() const noexcept {
|
||||
return m_fallbackControl;
|
||||
}
|
||||
|
||||
auto begin() {
|
||||
return m_formRules.begin();
|
||||
}
|
||||
|
||||
auto end() {
|
||||
return m_formRules.end();
|
||||
}
|
||||
|
||||
auto begin() const {
|
||||
return m_formRules.begin();
|
||||
}
|
||||
|
||||
auto end() const {
|
||||
return m_formRules.end();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<FormRule> m_formRules;
|
||||
|
||||
RuleControl m_discretizationControl;
|
||||
RuleControl m_preconditionerControl;
|
||||
RuleControl m_diagnosticControl;
|
||||
RuleControl m_projectionControl;
|
||||
|
||||
RuleControl m_fallbackControl;
|
||||
};
|
||||
|
||||
struct RoleControls {
|
||||
RuleControl discretization;
|
||||
RuleControl preconditioner;
|
||||
RuleControl diagnostic;
|
||||
RuleControl projection;
|
||||
};
|
||||
|
||||
|
||||
struct Resolution {
|
||||
int base_order;
|
||||
int boost;
|
||||
int order;
|
||||
bool used_fixed_order;
|
||||
};
|
||||
|
||||
struct QuadratureTermOptions {
|
||||
std::optional<int> fixed_order;
|
||||
int additional_boost = 0;
|
||||
};
|
||||
|
||||
struct QuadratureManifestOptions {
|
||||
bool enabled = false;
|
||||
bool include_repeated_queries = false;
|
||||
std::optional<std::string> output_file;
|
||||
};
|
||||
|
||||
struct QuadratureValidationOptions {
|
||||
bool require_explicit_base_order = false;
|
||||
bool require_explicit_mfem_rule = false;
|
||||
bool reject_negative_boosts = true;
|
||||
bool report_unused_overrides = true;
|
||||
};
|
||||
|
||||
struct QuadratureRoleOptions {
|
||||
QuadratureTermOptions discretization;
|
||||
QuadratureTermOptions preconditioner;
|
||||
QuadratureTermOptions diagnostic;
|
||||
QuadratureTermOptions projection;
|
||||
};
|
||||
|
||||
struct QuadratureOptions {
|
||||
Mode mode = Mode::production;
|
||||
int global_boost = 0;
|
||||
std::optional<int> fallback_fixed_order;
|
||||
|
||||
QuadratureTermOptions gravity_hdiv_mass;
|
||||
QuadratureTermOptions gravity_divergence;
|
||||
QuadratureTermOptions gravity_source;
|
||||
QuadratureTermOptions gravity_force;
|
||||
QuadratureTermOptions gravity_boundary;
|
||||
QuadratureTermOptions centrifugal;
|
||||
QuadratureTermOptions density_projection;
|
||||
QuadratureTermOptions eos_closure;
|
||||
QuadratureTermOptions hydrostatic_equilibrium;
|
||||
QuadratureTermOptions isobaric_surface;
|
||||
QuadratureTermOptions mesh_extension;
|
||||
QuadratureTermOptions mass_conservation;
|
||||
QuadratureTermOptions mass_normalization;
|
||||
QuadratureTermOptions center_of_mass;
|
||||
QuadratureTermOptions quadrupole;
|
||||
QuadratureTermOptions gravitational_energy;
|
||||
QuadratureTermOptions pressure_integral;
|
||||
QuadratureTermOptions pressure_force;
|
||||
QuadratureTermOptions virial;
|
||||
QuadratureTermOptions error_norm;
|
||||
|
||||
QuadratureRoleOptions roles;
|
||||
|
||||
std::vector<int> convergence_boosts = {0, 2, 4};
|
||||
QuadratureManifestOptions manifest;
|
||||
QuadratureValidationOptions validation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::QuadratureRole> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::QuadratureRole& role, FormatContext& ctx) const {
|
||||
std::string_view roleStr;
|
||||
switch (role) {
|
||||
case serif::discretization::quadrature::QuadratureRole::preconditioner:
|
||||
roleStr = "preconditioner";
|
||||
break;
|
||||
case serif::discretization::quadrature::QuadratureRole::diagnostic:
|
||||
roleStr = "diagnostic";
|
||||
break;
|
||||
case serif::discretization::quadrature::QuadratureRole::projection:
|
||||
roleStr = "projection";
|
||||
break;
|
||||
default:
|
||||
roleStr = "unknown";
|
||||
break;
|
||||
}
|
||||
return std::formatter<std::string_view>::format(roleStr, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::MappingKind> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::MappingKind& mk, FormatContext& ctx) const {
|
||||
std::string_view mappingKindStr;
|
||||
switch (mk) {
|
||||
case serif::discretization::quadrature::MappingKind::none:
|
||||
mappingKindStr = "none";
|
||||
break;
|
||||
case serif::discretization::quadrature::MappingKind::affine:
|
||||
mappingKindStr = "affine";
|
||||
break;
|
||||
case serif::discretization::quadrature::MappingKind::general:
|
||||
mappingKindStr = "general";
|
||||
break;
|
||||
case serif::discretization::quadrature::MappingKind::kelvin:
|
||||
mappingKindStr = "kelvin";
|
||||
break;
|
||||
default:
|
||||
mappingKindStr = "unknown";
|
||||
break;
|
||||
}
|
||||
return std::formatter<std::string_view>::format(mappingKindStr, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::Mode> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::Mode& mode, FormatContext& ctx) const {
|
||||
std::string_view modeStr;
|
||||
switch (mode) {
|
||||
case serif::discretization::quadrature::Mode::fast:
|
||||
modeStr = "fast";
|
||||
break;
|
||||
case serif::discretization::quadrature::Mode::production:
|
||||
modeStr = "production";
|
||||
break;
|
||||
case serif::discretization::quadrature::Mode::reference:
|
||||
modeStr = "reference";
|
||||
break;
|
||||
case serif::discretization::quadrature::Mode::convergence:
|
||||
modeStr = "convergence";
|
||||
break;
|
||||
default:
|
||||
modeStr = "unknown";
|
||||
break;
|
||||
}
|
||||
return std::formatter<std::string_view>::format(modeStr, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::RuleControl> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::RuleControl& rc, FormatContext& ctx) const {
|
||||
return std::formatter<std::string_view>::format(
|
||||
std::format("RuleControl(fixed_order={}, boost={})", rc.fixed_order.has_value() ? std::to_string(rc.fixed_order.value()) : "none", rc.boost),
|
||||
ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::FormRule> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::FormRule& fr, FormatContext& ctx) const {
|
||||
return std::formatter<std::string_view>::format(
|
||||
std::format("FormRule(form={}, control={})", fr.form, fr.control),
|
||||
ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<serif::discretization::quadrature::RuleSet> : std::formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const serif::discretization::quadrature::RuleSet& rs, FormatContext& ctx) const {
|
||||
std::string rulesStr;
|
||||
for (const auto& rule : rs) {
|
||||
if (!rulesStr.empty()) {
|
||||
rulesStr += ", ";
|
||||
}
|
||||
rulesStr += std::format("{}", rule);
|
||||
}
|
||||
return std::formatter<std::string_view>::format(
|
||||
std::format("RuleSet(formRules=[{}])", rulesStr),
|
||||
ctx);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user