Files
MeanField_SERiF/src/include/serif/discretization/quadrature/backend/order.hpp

81 lines
3.8 KiB
C++
Raw Normal View History

#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;
}
}