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

@@ -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);
}
}