Snapshot optimized solver and audit diagnostics before numerical experiments

This commit is contained in:
2026-09-16 14:34:06 -04:00
parent 75cc638739
commit 80cc3d83d7
64 changed files with 11969 additions and 267 deletions

View File

@@ -439,10 +439,26 @@ TEST_CASE(
massOperator.Prepare({.targetMass = 1.0}, dependencies);
const std::uint64_t preparationCount = massOperator.GetPreparationCount();
CHECK(massOperator.GetJacobianRowPreparationCount() == 0);
const auto rhoDirection = gravityContext.GetDensityMap().gather(
mass_normalization_test_utils::make_density_direction(f, 0.67));
const auto uDirection = gravityContext.GetDisplacementMap().gather(
mass_normalization_test_utils::make_displacement_direction(f, -0.53));
auto checkRows = [&](std::uint64_t expectedBuilds) {
REQUIRE(massOperator.PrepareJacobianRows());
CHECK(massOperator.GetJacobianRowPreparationCount() == expectedBuilds);
mfem::Vector actual, reference;
massOperator.ApplyCompleteJacobianAction(rhoDirection, uDirection, actual);
massOperator.ApplyCompleteJacobianActionReference(rhoDirection, uDirection, reference);
CHECK(mass_normalization_test_utils::relative_error(actual(0), reference(0)) < 2.0e-11);
CHECK(massOperator.GetJacobianRowPreparationCount() == expectedBuilds);
};
checkRows(1);
const auto repeated = massOperator.Prepare({.targetMass = 1.0}, dependencies);
CHECK_FALSE(repeated.DidAnyWork());
CHECK(massOperator.GetPreparationCount() == preparationCount);
checkRows(1);
++gravityPotentialRevision;
mass_normalization_test_utils::prepare_gravity_context(
@@ -451,6 +467,7 @@ TEST_CASE(
const auto potentialOnly = massOperator.Prepare({.targetMass = 1.0}, dependencies);
CHECK_FALSE(potentialOnly.DidAnyWork());
checkRows(1);
const double residualBeforeTargetChange = mass_normalization_test_utils::residual_value(massOperator);
const double massBeforeTargetChange = massOperator.GetCurrentMass();
@@ -463,6 +480,7 @@ TEST_CASE(
CHECK_FALSE(targetOnly.refreshedGeometry);
CHECK_FALSE(targetOnly.refreshedDensity);
CHECK(massOperator.GetCurrentMass() == massBeforeTargetChange);
checkRows(1);
CHECK(
mass_normalization_test_utils::relative_error(
mass_normalization_test_utils::residual_value(massOperator) - residualBeforeTargetChange, -0.4
@@ -481,6 +499,8 @@ TEST_CASE(
CHECK(densityOnly.assembledResidual);
CHECK_FALSE(densityOnly.refreshedGeometry);
CHECK(massOperator.GetCurrentMass() != massBeforeDensityChange);
CHECK(massOperator.GetJacobianRowPreparationCount() == 1);
checkRows(2);
displacement = mass_normalization_test_utils::make_displacement_direction(f, 0.87);
++dependencies.displacement.revision;
@@ -492,6 +512,8 @@ TEST_CASE(
CHECK(geometryOnly.refreshedGeometry);
CHECK(geometryOnly.assembledResidual);
CHECK_FALSE(geometryOnly.refreshedDensity);
CHECK(massOperator.GetJacobianRowPreparationCount() == 2);
checkRows(3);
}
TEST_CASE(
@@ -587,6 +609,11 @@ TEST_CASE(
massOperator.ApplyDisplacementJacobianAction(reducedDisplacementDirection, displacementAction);
massOperator.ApplyCompleteJacobianAction(reducedDensityDirection, reducedDisplacementDirection, completeAction);
mfem::Vector preparedReference;
massOperator.ApplyCompleteJacobianActionReference(
reducedDensityDirection, reducedDisplacementDirection, preparedReference);
CHECK(mass_normalization_test_utils::relative_error(completeAction(0), preparedReference(0)) < 2.0e-11);
CHECK(
mass_normalization_test_utils::relative_error(completeAction(0), densityAction(0) + displacementAction(0)) <
2.0e-15