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:
@@ -60,6 +60,67 @@ TEST_CASE(
|
||||
CHECK(preparedOperator.GetPreparationCount() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"Prepared Mapped Gravity Source Reuses Tables Across Preparation Modes And Rejection",
|
||||
tags::gravity_prepared_unit &tags::geometry
|
||||
) {
|
||||
auto args = test_utils::setup_args();
|
||||
fem::FEM f = fem::setup_fem(args.mesh_file, args, 0);
|
||||
REQUIRE(f.okay());
|
||||
|
||||
operators::PreparedMappedGravitySourceOperator operation(f, *f.domainMapperStateless);
|
||||
const mfem::Vector densityTrue = prepared_test::make_deterministic_vector(f.densityFes->GetTrueVSize(), 0.41);
|
||||
const mfem::Vector density = operation.GetDensityMap().gather(densityTrue);
|
||||
const mfem::Vector displacementTrue = prepared_test::make_displacement(f, 0.4);
|
||||
const mfem::Vector displacement = operation.GetDisplacementMap().gather(displacementTrue);
|
||||
const mfem::Vector directionTrue = prepared_test::make_displacement(f, 0.7);
|
||||
const MPI_Comm communicator = f.mesh->GetComm();
|
||||
|
||||
operation.Prepare(displacement);
|
||||
mfem::Vector baselineAction;
|
||||
mfem::Vector baselineVariation;
|
||||
operation.Mult(density, baselineAction);
|
||||
operation.MultDisplacementVariationTrue(densityTrue, directionTrue, baselineVariation);
|
||||
|
||||
const mfem::Vector primalDisplacementTrue = prepared_test::make_displacement(f, 1.0);
|
||||
operation.PreparePrimal(operation.GetDisplacementMap().gather(primalDisplacementTrue));
|
||||
REQUIRE(operation.IsPrepared());
|
||||
CHECK_FALSE(operation.HasVariationData());
|
||||
mfem::Vector primalAction;
|
||||
mfem::Vector referenceActionTrue;
|
||||
operation.Mult(density, primalAction);
|
||||
operators::kernels::apply_mapped_source(
|
||||
f, *f.domainMapperStateless, densityTrue, primalDisplacementTrue, referenceActionTrue
|
||||
);
|
||||
CHECK_THAT(
|
||||
prepared_test::relative_error(
|
||||
primalAction, operation.GetPotentialMap().gather(referenceActionTrue), communicator
|
||||
),
|
||||
WithinAbs(0.0, 2.0e-11)
|
||||
);
|
||||
|
||||
operation.Prepare(displacement);
|
||||
REQUIRE(operation.HasVariationData());
|
||||
mfem::Vector repeatedAction;
|
||||
mfem::Vector repeatedVariation;
|
||||
operation.Mult(density, repeatedAction);
|
||||
operation.MultDisplacementVariationTrue(densityTrue, directionTrue, repeatedVariation);
|
||||
CHECK(prepared_test::relative_error(repeatedAction, baselineAction, communicator) < 2.0e-14);
|
||||
CHECK(prepared_test::relative_error(repeatedVariation, baselineVariation, communicator) < 2.0e-14);
|
||||
|
||||
const auto rejected = operation.TryPrepare(operation.GetDisplacementMap().gather(make_folding_displacement(f)));
|
||||
REQUIRE_FALSE(rejected.has_value());
|
||||
CHECK_FALSE(operation.IsPrepared());
|
||||
CHECK_FALSE(operation.HasVariationData());
|
||||
REQUIRE(operation.TryPrepare(displacement).has_value());
|
||||
REQUIRE(operation.HasVariationData());
|
||||
operation.Mult(density, repeatedAction);
|
||||
operation.MultDisplacementVariationTrue(densityTrue, directionTrue, repeatedVariation);
|
||||
CHECK(prepared_test::relative_error(repeatedAction, baselineAction, communicator) < 2.0e-14);
|
||||
CHECK(prepared_test::relative_error(repeatedVariation, baselineVariation, communicator) < 2.0e-14);
|
||||
CHECK(operation.GetPreparationCount() == 4);
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"Prepared Mapped Gravity Source Matches Stateless Kernel",
|
||||
tags::gravity_prepared
|
||||
|
||||
Reference in New Issue
Block a user