Began working on mfem_resolver formatters

This commit is contained in:
2026-09-19 08:52:30 -04:00
parent c44584c1e7
commit f69fac8f1e
5 changed files with 59 additions and 6 deletions

View File

@@ -1,10 +1,11 @@
#pragma once
#include <span>
#include <format>
#include <unordered_map>
#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"
@@ -16,6 +17,8 @@
#include "serif/discretization/quadrature/backend/mfem/concepts.hpp"
#include "serif/discretization/quadrature/backend/mfem/mfem_static_order.hpp"
#include "serif/utils/format/strings.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
@@ -43,7 +46,7 @@ namespace serif::discretization::quadrature::backend::mfem {
};
struct MFEMRule final {
Resolution resolution;
Resolution resolution{};
const ::mfem::IntegrationRule *integration_rule = nullptr;
};
@@ -86,3 +89,32 @@ namespace serif::discretization::quadrature::backend::mfem {
Policy m_policy;
};
}
template <>
struct std::formatter<serif::discretization::quadrature::backend::mfem::MFEMQuadratureContext> : std::formatter<std::string> {
template <typename FormatContext>
auto format(const serif::discretization::quadrature::backend::mfem::MFEMQuadratureContext& mfem_context, FormatContext& fc) {
std::unordered_map<::mfem::Geometry::Type, std::string> MFEM_GEOM_TYPE_NAME_MAP {
{::mfem::Geometry::INVALID, "INVALID"},
{::mfem::Geometry::POINT, "POINT"},
{::mfem::Geometry::SEGMENT, "SEGMENT"},
{::mfem::Geometry::SQUARE, "SQUARE"},
{::mfem::Geometry::TETRAHEDRON, "TETRAHEDRON"},
{::mfem::Geometry::CUBE, "CUBE"},
{::mfem::Geometry::PRISM, "PRISM"},
{::mfem::Geometry::PYRAMID, "PYRAMID"},
{::mfem::Geometry::NUM_GEOMETRIES, std::format("NUM_GEOMETRIES={}", static_cast<int>(mfem::Geometry::NUM_GEOMETRIES))}
};
return std::formatter<std::string>::format(
std::format(
"MFEMQuadratureContext(form={}, geom_type={}, geom_weight_order={}, dynamic_orders={}, domains={}, mapping={})",
mfem_context.role,
MFEM_GEOM_TYPE_NAME_MAP.at(mfem_context.geometry),
mfem_context.geometry_weight_order,
serif::utils::misc::format::join(mfem_context.dynamic_orders, ", "),
mfem_context.domain,
mfem_context.mapping
), fc);
}
};

View File

@@ -71,7 +71,7 @@ namespace serif::utils::errors {
// Note if we move to C++26 we can replace this with a more standard and less convoluted
// formated static_assert.
sizeof(serif_error_printer<message, code>);
[[maybe_unused]] std::size_t error_kick = sizeof(serif_error_printer<message, code>);
}
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <string>
#include <string_view>
#include <span>
#include <format>
#include <type_traits>
namespace serif::utils::misc::format {
template <typename T>
std::string join(const std::span<T>& elements, std::string_view delimiter)
{
std::string out;
for (const auto& element : elements) {
out = std::format("{}{}{}", out, delimiter, element);
}
return out;
}
}

View File

@@ -3,6 +3,7 @@
#include <string_view>
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <unistd.h>
namespace serif::utils::misc::terminal {

View File

@@ -1,4 +1,5 @@
#include "serif/dimensions/runtime/concepts.hpp"
#include <cstdio>
int main() {
puts("Hello, world!\n");