perf(jacobian-action): major updates to jacobian action application by removing redudant quadrature work. ~5x increase in speed
This commit is contained in:
@@ -679,6 +679,93 @@ TEST_CASE(
|
||||
null_space::report_progress(communicator, "coupled reduced surface-mode probe complete; writing CSV output");
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"Fixed Central Density Phase Couples To The N3 Homology Tangent",
|
||||
"[null_space][homology][central_density][phase]"
|
||||
) {
|
||||
mean_field::utils::Args args = test_utils::setup_args();
|
||||
null_space::N3Equilibrium fixture(std::move(args));
|
||||
const MPI_Comm communicator = fixture.fem().mesh->GetComm();
|
||||
|
||||
const std::vector<GaugeMode> modes = make_gauge_modes(fixture);
|
||||
const auto homology = std::ranges::find_if(modes, [](const GaugeMode &mode) { return mode.family == "homology"; });
|
||||
REQUIRE(homology != modes.end());
|
||||
|
||||
const auto &layout = fixture.stellar_operator().GetLayout();
|
||||
const mfem::Vector enthalpy = null_space::const_value_view(fixture.state(), layout, null_space::enthalpyValue);
|
||||
const mfem::Vector enthalpyDirection =
|
||||
null_space::const_value_view(homology->direction, layout, null_space::enthalpyValue);
|
||||
|
||||
const mean_field::field::FieldDofMap enthalpyMap =
|
||||
mean_field::field::make_field_dof_map<mean_field::field::Enthalpy, null_space::DomainSchema>(
|
||||
*fixture.fem().enthalpyFes
|
||||
);
|
||||
mfem::Vector origin(fixture.fem().mesh->SpaceDimension());
|
||||
origin = 0.0;
|
||||
mean_field::field::FieldPointDofMap centerDof =
|
||||
mean_field::field::make_field_point_dof_map<mean_field::field::Enthalpy>(
|
||||
*fixture.fem().enthalpyFes, enthalpyMap, origin, 1.0e-12
|
||||
);
|
||||
|
||||
double localCentralEnthalpy = 0.0;
|
||||
for (const int reducedDof : centerDof.reduced_dofs()) {
|
||||
localCentralEnthalpy += enthalpy(reducedDof);
|
||||
}
|
||||
double centralEnthalpy = 0.0;
|
||||
MPI_Allreduce(&localCentralEnthalpy, ¢ralEnthalpy, 1, MPI_DOUBLE, MPI_SUM, communicator);
|
||||
REQUIRE(std::isfinite(centralEnthalpy));
|
||||
REQUIRE(centralEnthalpy > 0.0);
|
||||
|
||||
const auto &equationOfState = fixture.model().equationOfState();
|
||||
const mean_field::eos::DensityValue targetDensity = mean_field::eos::evaluate<mean_field::eos::quantity::Density>(
|
||||
equationOfState, mean_field::eos::SpecificEnthalpyValue{centralEnthalpy}
|
||||
);
|
||||
const mean_field::models::CompiledFixedCentralDensity compiled =
|
||||
mean_field::models::compileConstraint(mean_field::models::FixedCentralDensity{targetDensity}, equationOfState);
|
||||
mean_field::operators::PreparedCentralDensityConstraint phase(std::move(centerDof), communicator);
|
||||
phase.Prepare(compiled, enthalpy, 0.0, {.enthalpy = {.identity = 3251, .revision = 1}});
|
||||
|
||||
mfem::Vector enthalpyAction(enthalpy.Size());
|
||||
mfem::Vector phaseAction(1);
|
||||
enthalpyAction = 0.0;
|
||||
phaseAction = 0.0;
|
||||
phase.ApplyJacobian(
|
||||
{.enthalpyVariation = enthalpyDirection, .borderVariation = 0.0},
|
||||
{.enthalpyAction = enthalpyAction, .phaseAction = phaseAction}
|
||||
);
|
||||
|
||||
const double couplingScale = std::max(1.0, std::abs(compiled.targetEnthalpy().value()));
|
||||
const double enthalpyDirectionNorm = null_space::global_norm(enthalpyDirection, communicator);
|
||||
const double homologyDirectionNorm = null_space::global_norm(homology->direction, communicator);
|
||||
const double absolutePhaseCoupling = std::abs(phaseAction(0));
|
||||
INFO("Central enthalpy = " << centralEnthalpy);
|
||||
INFO("N3 homology phase coupling = " << phaseAction(0));
|
||||
REQUIRE(std::isfinite(phaseAction(0)));
|
||||
REQUIRE(enthalpyDirectionNorm > 0.0);
|
||||
REQUIRE(homologyDirectionNorm > 0.0);
|
||||
CHECK(absolutePhaseCoupling > 100.0 * std::numeric_limits<double>::epsilon() * couplingScale);
|
||||
|
||||
int rank = 0;
|
||||
MPI_Comm_rank(communicator, &rank);
|
||||
if (rank == 0) {
|
||||
experiment::record_experiment_result(
|
||||
"fixed_central_density_homology_coupling", "n3_homology",
|
||||
{{"mesh_file", test_utils::setup_args().mesh_file},
|
||||
{"local_state_dofs", std::to_string(fixture.stellar_operator().Width())}},
|
||||
{{"target_density", compiled.targetDensity().value()},
|
||||
{"target_enthalpy", compiled.targetEnthalpy().value()},
|
||||
{"central_enthalpy", centralEnthalpy},
|
||||
{"homology_phase_action", phaseAction(0)},
|
||||
{"absolute_phase_coupling", absolutePhaseCoupling},
|
||||
{"target_scaled_phase_coupling", absolutePhaseCoupling / couplingScale},
|
||||
{"enthalpy_direction_norm", enthalpyDirectionNorm},
|
||||
{"enthalpy_normalized_phase_coupling", absolutePhaseCoupling / enthalpyDirectionNorm},
|
||||
{"homology_direction_norm", homologyDirectionNorm},
|
||||
{"state_normalized_phase_coupling", absolutePhaseCoupling / homologyDirectionNorm}}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"N3 Homology Mass Cancellation At The Registered Polynomial Order",
|
||||
"[null_space][homology][mass_normalization][convergence][p_refinement]"
|
||||
|
||||
Reference in New Issue
Block a user