Working on more domain mapper translation

This commit is contained in:
2026-09-22 05:30:55 -04:00
parent ce5809bca9
commit 9e0e1f5c18
4 changed files with 82 additions and 5 deletions

View File

@@ -118,8 +118,8 @@ namespace serif::mapping {
struct DMGeometryCache {
bool enabled{true};
const mfem::Mesh* mesh{nullptr};
int32_t sequence{-1};
int32_t nodesSequence{-1};
long sequence{-1}; // We explicitly use the non explicltiy sized versions here since that what MFEM uses fort these members. Alternative we could use a int64_t and verify that on the compiled system that is the same as a long
long nodesSequence{-1};
std::unordered_map<std::tuple<int, double, double, double>, DMFixedMeshGeometry> points;
uint64_t hits{0};
uint64_t misses{0};

View File

@@ -11,6 +11,7 @@
#include "serif/mapping/compactification/kelvin.hpp"
#include "serif/mapping/context.hpp"
#include "serif/mapping/data.hpp"
#include "serif/mapping/variation.hpp"
#include "serif/utils/user_options/mapping/domain_mapper.hpp"
@@ -25,9 +26,10 @@ namespace serif::mapping {
DomainMapper(const DomainMapper&) = delete;
DomainMapper& operator=(const DomainMapper&) = delete;
~DomainMapper();
DomainMapper(DomainMapper&&) = delete;
DomainMapper& operator=(DomainMapper&&) = delete;
~DomainMapper() = default;
DomainMapper(DomainMapper&&) = default;
DomainMapper& operator=(DomainMapper&&) = default;
void set_geometry_cache_enabled(bool enabled) const;
[[nodiscard]] bool is_geometry_cache_enabled() const noexcept;

View File

@@ -0,0 +1,74 @@
#include "serif/mapping/domain_mapper.hpp"
#include "serif/utils/error/errors.hpp"
#include <array>
namespace serif::mapping {
using namespace serif::utils::errors;
void DomainMapper::set_geometry_cache_enabled(const bool enabled) const {
m_geometryCache->enabled = enabled;
}
bool DomainMapper::is_geometry_cache_enabled() const noexcept {
return m_geometryCache->enabled;
}
void DomainMapper::clear_geometry_cache() const {
auto &cache = *m_geometryCache;
cache.points.clear();
cache.mesh = nullptr;
cache.sequence = cache.nodesSequence = -1;
cache.hits = cache.misses = 0;
}
DMGeometryCacheStatistics DomainMapper::get_geometry_cache_statistics() const {
const auto& cache = *m_geometryCache;
return {.hits = cache.hits, .misses = cache.misses, .points = cache.points.size()};
}
const DMFixedMeshGeometry* DomainMapper::get_fixed_mesh_geometry(
mfem::ElementTransformation& transformation,
const mfem::IntegrationPoint& ip
) const {
transformation.SetIntPoint(&ip);
auto &cache = *m_geometryCache;
const auto *mesh = transformation.mesh;
auto should_return_null = [&]() -> bool {
const bool is_cache_disabled = !cache.enabled;
const bool is_mesh_null = mesh == nullptr;
const bool is_not_element = transformation.ElementType == mfem::ElementTransformation::ELEMENT;
const bool is_element_no_lt_0 = transformation.ElementNo < 0;
const bool is_element_no_gt_NE = transformation.ElementNo >= mesh->GetNE();
const bool is_dim_invalid = transformation.GetSpaceDim() != m_options.dimension;
return (is_cache_disabled || is_mesh_null || is_not_element || is_element_no_lt_0 || is_element_no_gt_NE || is_dim_invalid);
};
if (should_return_null()) {
return nullptr;
}
const std::array<double, 3> coordinates{ip.x, m_options.dimension > 1 ? ip.y : 0.0, m_options.dimension > 2 ? ip.z: 0.0};
for (const double coordinate : coordinates) {
if (!std::isfinite(coordinate)) {
return nullptr;
}
}
if (cache.mesh != mesh || cache.sequence != mesh->GetSequence() || cache.nodesSequence != mesh->GetNodesSequence()) {
cache.points.clear();
cache.mesh = mesh;
cache.sequence = mesh->GetSequence();
cache.nodesSequence = mesh->GetNodesSequence();
}
const auto key = std::tuple{transformation.ElementNo, coordinates[0], coordinates[1], coordinates[2]};
const auto found = cache.points.find(key);
}
}

View File

@@ -7,6 +7,7 @@ serif_sources = files(
'lib/serif/eos/models/polytropic.cpp',
'lib/serif/mapping/compactification/kelvin.cpp',
'lib/serif/mapping/data.cpp',
'lib/serif/mapping/domain_mapper.cpp',
)
serif_lib = library(