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:
2026-09-19 07:35:57 -04:00
parent 7b4f30d945
commit c44584c1e7
75 changed files with 8936 additions and 172 deletions

View File

@@ -1 +1,65 @@
#pragma once
#pragma once
#include "serif/discretization/blocks/fields.hpp"
namespace serif::discretization::blocks {
template <typename FieldCandidate>
concept Field = std::derived_from<FieldCandidate, field>;
template <typename T>
concept Term = std::derived_from<std::remove_cvref_t<T>, term_base> && // a term must derive from term_base
requires {typename std::remove_cvref_t<T>::field_type;} && // a term must have a field_type member
Field<typename std::remove_cvref_t<T>::field_type>; // That field type member must be a valid field
template <typename T>
concept HasFunctionalSpace =
Term<T> &&
requires {
typename std::remove_cvref_t<T>::FunctionalSpace;
};
template <typename T>
concept HasSupport =
Term<T> &&
requires {
typename std::remove_cvref_t<T>::Support;
};
template <typename T>
concept HasQuantity =
Term<T> &&
requires {
typename std::remove_cvref_t<T>::Quantity;
};
template <typename T>
concept HasValueBlock =
Term<T> &&
requires {
typename std::remove_cvref_t<T>::value;
};
template <typename T>
concept HasResidualBlock =
Term<T> &&
requires {
typename std::remove_cvref_t<T>::residual;
};
template <typename T>
concept SpatialTerm =
Term<T> &&
HasFunctionalSpace<T> &&
HasSupport<T>;
template <typename T>
concept PhysicalSpatialTerm =
SpatialTerm<T> &&
HasQuantity<T>;
template <typename T>
struct IsSpatialTerm : std::bool_constant<SpatialTerm<T>> {};
template <typename T>
struct IsPhysicalSpatialTerm : std::bool_constant<PhysicalSpatialTerm<T>> {};
}

View File

@@ -1,65 +1,130 @@
#pragma once
#include <string_view>
#include "base.hpp"
#include "serif/dimensions/dimensions.hpp"
#include "serif/discretization/blocks/base.hpp"
#include "serif/discretization/functional_space/space.hpp"
#include "serif/discretization/domain/concepts.hpp"
#include "serif/discretization/domain/physical_domains.hpp"
#include "serif/utils/types/type_list.hpp"
#include "serif/meta/names.hpp"
namespace serif::discretization::blocks {
struct field {};
struct term {};
struct term_base {};
template <typename FieldT>
struct term : term_base {
using field_type = FieldT;
};
struct density final : field {
struct mass final : term {
static constexpr std::string_view name = meta::type_name<density>();
struct mass final : term<density> { // Note the reading here is mass density (that is this is not in reference to the common FEM usage of mass as a term in a weak form)
static constexpr std::string_view name = meta::type_name<mass>();
using FunctionalSpace = functional_space::DiscreteFunctionalSpace<functional_space::L2, 2, 0>; // second order scalar L2 space
using Support = domain::StellarDomains;
using Quantity = dimensions::Density;
static constexpr std::string_view symbol = "ρ";
struct value final : value_block_base {};
struct residual final : residual_block_base {};
};
static inline constexpr mass mass_density_term{};
static inline constexpr mass mass_term{};
using Terms = utils::types::TypeList<mass>;
};
struct displacement final : field {
struct geometry final : term {
static constexpr std::string_view name = meta::type_name<displacement>();
struct vector final : term<displacement> { // Similarly this is the displacement vector
static constexpr std::string_view name = meta::type_name<vector>();
using FunctionalSpace = functional_space::DiscreteFunctionalSpace<functional_space::H1, 3, 1>; // third order vector H1 space
using Support = domain::AllDomains;
using Quantity = dimensions::Length;
static constexpr std::string_view symbol = "d";
struct value final : value_block_base {};
struct residual final : residual_block_base {};
};
static inline constexpr vector vector_term{};
static inline constexpr geometry geometry_term{};
using Terms = utils::types::TypeList<vector>;
};
struct surface_deformation final : field {
struct parameters final : term {
struct surface_deformation final : field { // Surface deformation is a more general field that the others, it is not pointwise defined over the domain. Use concepts to constrain this as a non spatial field.
static constexpr std::string_view name = meta::type_name<surface_deformation>();
struct coefficients final : term<surface_deformation> {
static constexpr std::string_view name = meta::type_name<coefficients>();
struct value final : value_block_base {};
};
struct shape_equilibrium final : term {
struct shape_equilibrium final : term<surface_deformation> {
static constexpr std::string_view name = meta::type_name<shape_equilibrium>();
struct residual final : residual_block_base {};
};
static inline constexpr parameters parameters_term{};
static inline constexpr coefficients coefficients_term{};
static inline constexpr shape_equilibrium shape_equilibrium_term{};
using Terms = utils::types::TypeList<coefficients, shape_equilibrium>;
};
struct gravity final : field {
struct gradient final : term {
static constexpr std::string_view name = meta::type_name<gravity>();
struct gradient final : term<gravity> {
static constexpr std::string_view name = meta::type_name<gradient>();
using FunctionalSpace = functional_space::DiscreteFunctionalSpace<functional_space::Hdiv, 2, 1>;
using Support = domain::AllDomains;
using Quantity = dimensions::Acceleration;
static constexpr std::string_view symbol = "∇φ";
struct value final : value_block_base {};
struct residual final : residual_block_base {};
};
struct potential final : term {
struct potential final : term<gravity> {
static constexpr std::string_view name = meta::type_name<potential>();
using FunctionalSpace = functional_space::DiscreteFunctionalSpace<functional_space::L2, 2, 0>;
using Support = domain::AllDomains;
using Quantity = dimensions::GravitationalPotential;
static constexpr std::string_view symbol = "φ";
struct value final : value_block_base {};
struct residual final : residual_block_base {};
};
static inline constexpr potential potential_term{};
static inline constexpr gradient gradient_term{};
using Terms = utils::types::TypeList<potential, gradient>;
};
struct enthalpy final : field {
struct specific final : term {
static constexpr std::string_view name = meta::type_name<enthalpy>();
struct specific final : term<enthalpy> {
static constexpr std::string_view name = meta::type_name<specific>();
using FunctionalSpace = functional_space::DiscreteFunctionalSpace<functional_space::H1, 3, 0>;
using Support = domain::StellarDomains;
using Quantity = dimensions::SpecificEnthalpy;
static constexpr std::string_view symbol = "h";
struct value final : value_block_base { };
struct residual final : residual_block_base { };
};
static inline constexpr specific specific_term{};
};
using Terms = utils::types::TypeList<specific>;
};
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include <string_view>
#include "serif/discretization/blocks/concepts.hpp"
namespace serif::discretization::blocks {
struct FieldDescriptor final {
std::string_view name;
[[nodiscard]] friend constexpr bool operator==(const FieldDescriptor&, const FieldDescriptor&) noexcept = default;
};
struct TermDescriptor final {
FieldDescriptor field;
std::string_view name;
[[nodiscard]] friend constexpr bool operator==(const TermDescriptor&, const TermDescriptor&) noexcept = default;
};
template <Field FieldT>
inline constexpr FieldDescriptor field_descriptor{.name = FieldT::name};
template <Term TermT>
inline constexpr TermDescriptor term_descriptor{
.field = field_descriptor<typename TermT::field_type>,
.name = TermT::name
};
}
template <>
struct std::formatter<serif::discretization::blocks::FieldDescriptor> : std::formatter<std::string_view> {
template <typename FormatContext>
auto format(const serif::discretization::blocks::FieldDescriptor& fd, FormatContext& ctx) const {
return std::formatter<std::string_view>::format(fd.name, ctx);
}
};
template <>
struct std::formatter<serif::discretization::blocks::TermDescriptor> : std::formatter<std::string> {
template <typename FormatContext>
auto format(const serif::discretization::blocks::TermDescriptor& td, FormatContext& ctx) const {
return std::formatter<std::string>::format(std::format("TermDescriptor(field={}, name={})", td.field, td.name), ctx);
}
};

View File

@@ -1 +1,32 @@
#pragma once
#pragma once
#include <type_traits>
#include "serif/discretization/blocks/concepts.hpp"
namespace serif::discretization::blocks {
template <Term TermT>
using FieldOf = std::remove_cvref_t<TermT>::field_type;
template <HasFunctionalSpace TermT>
using FunctionalSpaceOf = std::remove_cvref_t<TermT>::FunctionalSpace;
template <HasSupport TermT>
using SupportOf = std::remove_cvref_t<TermT>::Support;
template <HasQuantity TermT>
using QuantityOf = std::remove_cvref_t<TermT>::Quantity;
template <typename FieldT>
using TermsOf = FieldT::Terms;
template <SpatialTerm TermT>
struct SpatialTermTraits {
using FunctionalSpace = TermT::FunctionalSpace;
using Support = TermT::Support;
static constexpr auto family = FunctionalSpace::functionalSpace.family;
static constexpr int order = FunctionalSpace::order;
static constexpr std::size_t rank = FunctionalSpace::rank;
};
}