perf(allocations): reduced overall allocations by 95%, increaseed jacobian applicatin by 2x

This commit uses global pre allocated work space to dramatically reduce memory usage and allocation time
This commit is contained in:
2026-09-10 06:50:56 -04:00
parent b3c04d507a
commit 75cc638739
66 changed files with 207183 additions and 99552 deletions

View File

@@ -31,6 +31,16 @@ export namespace mean_field::mapping::compactification {
public:
virtual ~ExteriorDomainMap() = default;
/*
* Return true when, with the reference and compactification data held
* fixed, both outputs of Evaluate are affine functions of the
* displaced position and displacement Jacobian. This is the contract
* required by the exact determinant-polynomial geometry preflight.
*/
[[nodiscard]] virtual bool IsAffineInDisplacement() const noexcept {
return false;
}
[[nodiscard]] virtual MappingStatus Evaluate(
const ExteriorMapInput &input,
ExteriorMapResult &result

View File

@@ -12,6 +12,10 @@ export namespace mean_field::mapping::compactification {
public:
explicit KelvinCompactification(options::KelvinCompactificationOptions options);
[[nodiscard]] bool IsAffineInDisplacement() const noexcept override {
return true;
}
[[nodiscard]] MappingStatus Evaluate(
const ExteriorMapInput &input,
ExteriorMapResult &result
@@ -45,4 +49,4 @@ export namespace mean_field::mapping::compactification {
options::KelvinCompactificationOptions m_options;
};
} // namespace mean_field::mapping::compactification
} // namespace mean_field::mapping::compactification

View File

@@ -80,6 +80,7 @@ export namespace mean_field::mapping {
mfem::Vector m_shape;
mfem::DenseMatrix m_reference_dshape;
mfem::DenseMatrix m_mesh_dshape;
mfem::DenseMatrix m_reference_field_jacobian;
mfem::Vector m_field_value;
mfem::DenseMatrix m_field_jacobian;

View File

@@ -0,0 +1,42 @@
module;
#include <mfem.hpp>
#include <vector>
export module mean_field:mapping.prepared_cache;
import :mapping.types;
export namespace mean_field::mapping {
// Flat, owning storage for prepared volume contexts. Load into reusable
// workspaces: no MFEM buffers or pointer aliases are owned per quadrature
// point. The layout retains every public context field without recomputing
// inverses or changing the mapper's numerical contract.
class VolumeMappingCache {
public:
void SetSize(
int point_count,
int dimension
);
void Store(
int point,
const VolumeMappingContext &context
);
void Load(
int point,
VolumeMappingContext &context
) const;
void LoadInverseJacobian(
int point,
mfem::DenseMatrix &inverse
) const;
[[nodiscard]] int GetPointCount() const;
[[nodiscard]] int GetDimension() const;
private:
[[nodiscard]] const double *GetPointData(int point) const;
std::vector<double> m_data;
int m_point_count{0};
int m_dimension{0};
int m_point_stride{0};
};
} // namespace mean_field::mapping