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

@@ -58,6 +58,12 @@ export namespace mean_field::operators {
[[nodiscard]] const field::FieldDofMap &GetPotentialMap() const noexcept;
[[nodiscard]] const field::FieldDofMap &GetDisplacementMap() const noexcept;
template <typename Visitor> void VisitMappedGeometryRules(Visitor &&visitor) const {
for (const ElementPAData &data : m_elements) {
visitor(data.element_id, *data.integration_rule);
}
}
void MultTranspose(
const mfem::Vector &potential,
mfem::Vector &action
@@ -80,6 +86,10 @@ export namespace mean_field::operators {
const mfem::IntegrationRule *integration_rule{nullptr};
// Rows are quadrature points; columns are element DOFs.
std::shared_ptr<const fem::ScalarReferenceTable> density_reference;
std::shared_ptr<const fem::ScalarReferenceTable> potential_reference;
std::shared_ptr<const fem::ScalarReferenceTable> displacement_reference;
// Non-VALUE map types retain their element-dependent physical basis.
mfem::DenseMatrix density_basis;
mfem::DenseMatrix potential_basis;
mfem::DenseMatrix inverse_element_jacobians;
@@ -87,6 +97,14 @@ export namespace mean_field::operators {
// Contains quadrature weight, mesh Jacobian, mapped Jacobian,
// and 4*pi*G.
mfem::Vector quadrature_data;
[[nodiscard]] const mfem::DenseMatrix &GetDensityBasis() const {
return density_reference ? density_reference->GetValues() : density_basis;
}
[[nodiscard]] const mfem::DenseMatrix &GetPotentialBasis() const {
return potential_reference ? potential_reference->GetValues() : potential_basis;
}
};
[[nodiscard]] GravitySourcePreparationResult TryPrepareImpl(
@@ -119,7 +137,6 @@ export namespace mean_field::operators {
mutable mfem::Vector m_element_displacement_variation;
mutable mfem::Vector m_quadrature_variation_action;
mutable mfem::Vector m_element_variation_action;
mutable mfem::DenseMatrix m_reference_displacement_dshape;
mutable mfem::DenseMatrix m_reference_displacement_jacobian;
mfem::Vector m_displacement_true;