feat(field-support): added field support system, mid migration
currently the barotope and the pressure force operator are migrated to the new support system
This commit is contained in:
@@ -5,9 +5,7 @@ import mean_field;
|
||||
import test_helpers;
|
||||
|
||||
namespace prepared_hydrostatic_complete_test_utils {
|
||||
mean_field::operators::context::hydrostatic::
|
||||
HydrostaticEquilibriumDependencies
|
||||
make_dependencies() {
|
||||
mean_field::operators::context::hydrostatic::HydrostaticEquilibriumDependencies make_dependencies() {
|
||||
return {
|
||||
.discretization = {.identity = 503, .revision = 2},
|
||||
.enthalpy = {.identity = 509, .revision = 3},
|
||||
@@ -18,8 +16,7 @@ namespace prepared_hydrostatic_complete_test_utils {
|
||||
};
|
||||
}
|
||||
|
||||
mean_field::operators::context::hydrostatic::HydrostaticEquilibriumStateView
|
||||
make_state(
|
||||
mean_field::operators::context::hydrostatic::HydrostaticEquilibriumStateView make_state(
|
||||
const mfem::Vector &enthalpy,
|
||||
const mfem::Vector &gravityPotential,
|
||||
const mfem::Vector &displacement,
|
||||
@@ -54,11 +51,9 @@ namespace prepared_hydrostatic_complete_test_utils {
|
||||
const double firstPhase,
|
||||
const double secondPhase
|
||||
) {
|
||||
mfem::Vector direction =
|
||||
gravity_prepared_test_utils::make_displacement(f, firstPhase);
|
||||
mfem::Vector direction = gravity_prepared_test_utils::make_displacement(f, firstPhase);
|
||||
|
||||
const mfem::Vector secondField =
|
||||
gravity_prepared_test_utils::make_displacement(f, secondPhase);
|
||||
const mfem::Vector secondField = gravity_prepared_test_utils::make_displacement(f, secondPhase);
|
||||
|
||||
direction -= secondField;
|
||||
return direction;
|
||||
@@ -95,25 +90,21 @@ namespace prepared_hydrostatic_complete_test_utils {
|
||||
displacementPlus.Add(step, displacementVariation);
|
||||
displacementMinus.Add(-step, displacementVariation);
|
||||
|
||||
const double bernoulliConstantPlus =
|
||||
baseBernoulliConstant + step * bernoulliConstantVariation;
|
||||
const double bernoulliConstantPlus = baseBernoulliConstant + step * bernoulliConstantVariation;
|
||||
|
||||
const double bernoulliConstantMinus =
|
||||
baseBernoulliConstant - step * bernoulliConstantVariation;
|
||||
const double bernoulliConstantMinus = baseBernoulliConstant - step * bernoulliConstantVariation;
|
||||
|
||||
mfem::Vector residualPlus;
|
||||
mfem::Vector residualMinus;
|
||||
|
||||
mean_field::operators::kernels::apply_hydrostatic_equilibrium(
|
||||
f, *f.domainMapperStateless, rotation, enthalpyPlus,
|
||||
gravityPotentialPlus, displacementPlus, bernoulliConstantPlus,
|
||||
residualPlus
|
||||
f, *f.domainMapperStateless, rotation, enthalpyPlus, gravityPotentialPlus, displacementPlus,
|
||||
bernoulliConstantPlus, residualPlus
|
||||
);
|
||||
|
||||
mean_field::operators::kernels::apply_hydrostatic_equilibrium(
|
||||
f, *f.domainMapperStateless, rotation, enthalpyMinus,
|
||||
gravityPotentialMinus, displacementMinus, bernoulliConstantMinus,
|
||||
residualMinus
|
||||
f, *f.domainMapperStateless, rotation, enthalpyMinus, gravityPotentialMinus, displacementMinus,
|
||||
bernoulliConstantMinus, residualMinus
|
||||
);
|
||||
|
||||
difference = residualPlus;
|
||||
@@ -140,34 +131,25 @@ namespace prepared_hydrostatic_complete_test_utils {
|
||||
TEST_CASE(
|
||||
"Prepared Hydrostatic Complete Jacobian Matches Sum And Centered "
|
||||
"Differences",
|
||||
tags::barotrope &tags::hydro &tags::integration &tags::jacobian
|
||||
&tags::prepared &tags::self_consistency
|
||||
tags::barotrope &tags::hydro &tags::integration &tags::jacobian &tags::prepared &tags::self_consistency
|
||||
) {
|
||||
auto args = test_utils::setup_args();
|
||||
auto args = test_utils::setup_args();
|
||||
|
||||
mean_field::fem::FEM f =
|
||||
mean_field::fem::setup_fem(args.mesh_file, args, 0);
|
||||
mean_field::fem::FEM f = mean_field::fem::setup_fem(args.mesh_file, args, 0);
|
||||
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumOperator
|
||||
preparedOperator(f, *f.domainMapperStateless);
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumOperator preparedOperator(f, *f.domainMapperStateless);
|
||||
|
||||
const mfem::Vector enthalpy =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.enthalpyFes->GetTrueVSize(), 0.34
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.enthalpyFes->GetTrueVSize(), 0.34);
|
||||
|
||||
const mfem::Vector gravityPotential =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.gravityPotentialFes->GetTrueVSize(), 0.57
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.gravityPotentialFes->GetTrueVSize(), 0.57);
|
||||
|
||||
const mfem::Vector displacement =
|
||||
gravity_prepared_test_utils::make_displacement(f, 0.68);
|
||||
const mfem::Vector displacement = gravity_prepared_test_utils::make_displacement(f, 0.68);
|
||||
|
||||
constexpr double bernoulliConstant = 0.43;
|
||||
constexpr double bernoulliConstant = 0.43;
|
||||
|
||||
const mean_field::physics::RigidRotation rotation =
|
||||
prepared_hydrostatic_complete_test_utils::make_rotation();
|
||||
const mean_field::physics::RigidRotation rotation = prepared_hydrostatic_complete_test_utils::make_rotation();
|
||||
|
||||
preparedOperator.Prepare(
|
||||
prepared_hydrostatic_complete_test_utils::make_state(
|
||||
@@ -177,19 +159,13 @@ TEST_CASE(
|
||||
);
|
||||
|
||||
const mfem::Vector enthalpyVariation =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.enthalpyFes->GetTrueVSize(), 1.07
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.enthalpyFes->GetTrueVSize(), 1.07);
|
||||
|
||||
const mfem::Vector gravityPotentialVariation =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.gravityPotentialFes->GetTrueVSize(), 1.31
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.gravityPotentialFes->GetTrueVSize(), 1.31);
|
||||
|
||||
const mfem::Vector displacementVariation =
|
||||
prepared_hydrostatic_complete_test_utils::make_displacement_direction(
|
||||
f, 1.19, 0.38
|
||||
);
|
||||
prepared_hydrostatic_complete_test_utils::make_displacement_direction(f, 1.19, 0.38);
|
||||
|
||||
constexpr double bernoulliConstantVariation = -0.37;
|
||||
|
||||
@@ -199,25 +175,16 @@ TEST_CASE(
|
||||
mfem::Vector displacementAction;
|
||||
mfem::Vector completeAction;
|
||||
|
||||
preparedOperator.ApplyEnthalpyJacobianAction(
|
||||
enthalpyVariation, enthalpyAction
|
||||
);
|
||||
preparedOperator.ApplyEnthalpyJacobianAction(enthalpyVariation, enthalpyAction);
|
||||
|
||||
preparedOperator.ApplyGravityPotentialJacobianAction(
|
||||
gravityPotentialVariation, gravityPotentialAction
|
||||
);
|
||||
preparedOperator.ApplyGravityPotentialJacobianAction(gravityPotentialVariation, gravityPotentialAction);
|
||||
|
||||
preparedOperator.ApplyBernoulliConstantJacobianAction(
|
||||
bernoulliConstantVariation, bernoulliConstantAction
|
||||
);
|
||||
preparedOperator.ApplyBernoulliConstantJacobianAction(bernoulliConstantVariation, bernoulliConstantAction);
|
||||
|
||||
preparedOperator.ApplyDisplacementJacobianAction(
|
||||
displacementVariation, displacementAction
|
||||
);
|
||||
preparedOperator.ApplyDisplacementJacobianAction(displacementVariation, displacementAction);
|
||||
|
||||
preparedOperator.ApplyCompleteJacobianAction(
|
||||
enthalpyVariation, gravityPotentialVariation,
|
||||
bernoulliConstantVariation, displacementVariation, completeAction
|
||||
enthalpyVariation, gravityPotentialVariation, bernoulliConstantVariation, displacementVariation, completeAction
|
||||
);
|
||||
|
||||
mfem::Vector summedAction(enthalpyAction);
|
||||
@@ -230,27 +197,20 @@ TEST_CASE(
|
||||
mfem::Vector centeredDifference;
|
||||
|
||||
prepared_hydrostatic_complete_test_utils::centered_complete_difference(
|
||||
f, rotation, enthalpy, gravityPotential, displacement,
|
||||
bernoulliConstant, enthalpyVariation, gravityPotentialVariation,
|
||||
displacementVariation, bernoulliConstantVariation, finiteDifferenceStep,
|
||||
f, rotation, enthalpy, gravityPotential, displacement, bernoulliConstant, enthalpyVariation,
|
||||
gravityPotentialVariation, displacementVariation, bernoulliConstantVariation, finiteDifferenceStep,
|
||||
centeredDifference
|
||||
);
|
||||
|
||||
const double summationError = gravity_prepared_test_utils::relative_error(
|
||||
completeAction, summedAction, f.mesh->GetComm()
|
||||
);
|
||||
const double summationError =
|
||||
gravity_prepared_test_utils::relative_error(completeAction, summedAction, f.mesh->GetComm());
|
||||
|
||||
const double centeredDifferenceError =
|
||||
gravity_prepared_test_utils::relative_error(
|
||||
completeAction, centeredDifference, f.mesh->GetComm()
|
||||
);
|
||||
gravity_prepared_test_utils::relative_error(completeAction, centeredDifference, f.mesh->GetComm());
|
||||
|
||||
INFO("Complete-action summation error = " << summationError);
|
||||
|
||||
INFO(
|
||||
"Complete-action centered-difference error = "
|
||||
<< centeredDifferenceError
|
||||
);
|
||||
INFO("Complete-action centered-difference error = " << centeredDifferenceError);
|
||||
|
||||
CHECK(preparedOperator.GetCompleteJacobianStatistics().applications == 1);
|
||||
|
||||
@@ -261,29 +221,21 @@ TEST_CASE(
|
||||
TEST_CASE(
|
||||
"Prepared Hydrostatic MFEM Adapter Uses Four Block Layout And Reuses "
|
||||
"Preparation",
|
||||
tags::barotrope &tags::hydro &tags::integration &tags::jacobian
|
||||
&tags::mfem_operators &tags::prepared &tags::unit
|
||||
tags::barotrope &tags::hydro &tags::integration &tags::jacobian &tags::mfem_operators &tags::prepared &tags::unit
|
||||
) {
|
||||
auto args = test_utils::setup_args();
|
||||
auto args = test_utils::setup_args();
|
||||
|
||||
mean_field::fem::FEM f =
|
||||
mean_field::fem::setup_fem(args.mesh_file, args, 0);
|
||||
mean_field::fem::FEM f = mean_field::fem::setup_fem(args.mesh_file, args, 0);
|
||||
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumOperator
|
||||
preparedOperator(f, *f.domainMapperStateless);
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumOperator preparedOperator(f, *f.domainMapperStateless);
|
||||
|
||||
const mfem::Vector enthalpy =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.enthalpyFes->GetTrueVSize(), 0.41
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.enthalpyFes->GetTrueVSize(), 0.41);
|
||||
|
||||
const mfem::Vector gravityPotential =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.gravityPotentialFes->GetTrueVSize(), 0.63
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.gravityPotentialFes->GetTrueVSize(), 0.63);
|
||||
|
||||
const mfem::Vector displacement =
|
||||
gravity_prepared_test_utils::make_displacement(f, 0.74);
|
||||
const mfem::Vector displacement = gravity_prepared_test_utils::make_displacement(f, 0.74);
|
||||
|
||||
constexpr double bernoulliConstant = 0.38;
|
||||
|
||||
@@ -295,49 +247,31 @@ TEST_CASE(
|
||||
prepared_hydrostatic_complete_test_utils::make_rotation()
|
||||
);
|
||||
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumJacobianOperator
|
||||
adapter(f, preparedOperator);
|
||||
mean_field::operators::PreparedHydrostaticEquilibriumJacobianOperator adapter(f, preparedOperator);
|
||||
|
||||
const auto &layout = adapter.GetLayout();
|
||||
|
||||
CHECK(
|
||||
layout.Offset(
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::enthalpy
|
||||
) == 0
|
||||
);
|
||||
CHECK(layout.Offset(mean_field::operators::HydrostaticJacobianInputBlock::enthalpy) == 0);
|
||||
|
||||
CHECK(
|
||||
layout.Offset(
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::
|
||||
gravityPotential
|
||||
) == f.enthalpyFes->GetTrueVSize()
|
||||
layout.Offset(mean_field::operators::HydrostaticJacobianInputBlock::gravityPotential) ==
|
||||
f.enthalpyFes->GetTrueVSize()
|
||||
);
|
||||
|
||||
CHECK(
|
||||
layout.Size(
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::
|
||||
bernoulliConstant
|
||||
) == 1
|
||||
);
|
||||
CHECK(layout.Size(mean_field::operators::HydrostaticJacobianInputBlock::bernoulliConstant) == 1);
|
||||
|
||||
CHECK(adapter.Width() == layout.GetTotalSize());
|
||||
CHECK(adapter.Height() == layout.GetResidualSize());
|
||||
CHECK(adapter.Height() == f.enthalpyFes->GetTrueVSize());
|
||||
|
||||
const mfem::Vector enthalpyVariation =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.enthalpyFes->GetTrueVSize(), 1.12
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.enthalpyFes->GetTrueVSize(), 1.12);
|
||||
|
||||
const mfem::Vector gravityPotentialVariation =
|
||||
gravity_prepared_test_utils::make_deterministic_vector(
|
||||
f.gravityPotentialFes->GetTrueVSize(), 1.39
|
||||
);
|
||||
gravity_prepared_test_utils::make_deterministic_vector(f.gravityPotentialFes->GetTrueVSize(), 1.39);
|
||||
|
||||
const mfem::Vector displacementVariation =
|
||||
prepared_hydrostatic_complete_test_utils::make_displacement_direction(
|
||||
f, 1.28, 0.49
|
||||
);
|
||||
prepared_hydrostatic_complete_test_utils::make_displacement_direction(f, 1.28, 0.49);
|
||||
|
||||
constexpr double bernoulliConstantVariation = 0.29;
|
||||
|
||||
@@ -345,49 +279,39 @@ TEST_CASE(
|
||||
packedDirection = 0.0;
|
||||
|
||||
prepared_hydrostatic_complete_test_utils::set_block(
|
||||
packedDirection, layout,
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::enthalpy,
|
||||
enthalpyVariation
|
||||
packedDirection, layout, mean_field::operators::HydrostaticJacobianInputBlock::enthalpy, enthalpyVariation
|
||||
);
|
||||
|
||||
prepared_hydrostatic_complete_test_utils::set_block(
|
||||
packedDirection, layout,
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::gravityPotential,
|
||||
packedDirection, layout, mean_field::operators::HydrostaticJacobianInputBlock::gravityPotential,
|
||||
gravityPotentialVariation
|
||||
);
|
||||
|
||||
prepared_hydrostatic_complete_test_utils::set_block(
|
||||
packedDirection, layout,
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::displacement,
|
||||
packedDirection, layout, mean_field::operators::HydrostaticJacobianInputBlock::displacement,
|
||||
displacementVariation
|
||||
);
|
||||
|
||||
packedDirection(layout.Offset(
|
||||
mean_field::operators::HydrostaticJacobianInputBlock::bernoulliConstant
|
||||
)) = bernoulliConstantVariation;
|
||||
packedDirection(layout.Offset(mean_field::operators::HydrostaticJacobianInputBlock::bernoulliConstant)) =
|
||||
bernoulliConstantVariation;
|
||||
|
||||
mfem::Vector directAction;
|
||||
mfem::Vector adapterAction;
|
||||
|
||||
preparedOperator.ApplyCompleteJacobianAction(
|
||||
enthalpyVariation, gravityPotentialVariation,
|
||||
bernoulliConstantVariation, displacementVariation, directAction
|
||||
enthalpyVariation, gravityPotentialVariation, bernoulliConstantVariation, displacementVariation, directAction
|
||||
);
|
||||
|
||||
adapter.Mult(packedDirection, adapterAction);
|
||||
|
||||
const double adapterError = gravity_prepared_test_utils::relative_error(
|
||||
adapterAction, directAction, f.mesh->GetComm()
|
||||
);
|
||||
const double adapterError =
|
||||
gravity_prepared_test_utils::relative_error(adapterAction, directAction, f.mesh->GetComm());
|
||||
|
||||
const auto contextStatisticsBefore =
|
||||
preparedOperator.GetContextPreparationStatistics();
|
||||
const auto contextStatisticsBefore = preparedOperator.GetContextPreparationStatistics();
|
||||
|
||||
const auto algebraicStatisticsBefore =
|
||||
preparedOperator.GetAlgebraicJacobianStatistics();
|
||||
const auto algebraicStatisticsBefore = preparedOperator.GetAlgebraicJacobianStatistics();
|
||||
|
||||
const auto displacementStatisticsBefore =
|
||||
preparedOperator.GetDisplacementJacobianStatistics();
|
||||
const auto displacementStatisticsBefore = preparedOperator.GetDisplacementJacobianStatistics();
|
||||
|
||||
mfem::Vector secondPackedDirection(packedDirection);
|
||||
secondPackedDirection *= -0.61;
|
||||
@@ -399,18 +323,13 @@ TEST_CASE(
|
||||
expectedSecondAction *= -0.61;
|
||||
|
||||
const double adapterLinearityError =
|
||||
gravity_prepared_test_utils::relative_error(
|
||||
secondAdapterAction, expectedSecondAction, f.mesh->GetComm()
|
||||
);
|
||||
gravity_prepared_test_utils::relative_error(secondAdapterAction, expectedSecondAction, f.mesh->GetComm());
|
||||
|
||||
const auto &contextStatisticsAfter =
|
||||
preparedOperator.GetContextPreparationStatistics();
|
||||
const auto &contextStatisticsAfter = preparedOperator.GetContextPreparationStatistics();
|
||||
|
||||
const auto &algebraicStatisticsAfter =
|
||||
preparedOperator.GetAlgebraicJacobianStatistics();
|
||||
const auto &algebraicStatisticsAfter = preparedOperator.GetAlgebraicJacobianStatistics();
|
||||
|
||||
const auto &displacementStatisticsAfter =
|
||||
preparedOperator.GetDisplacementJacobianStatistics();
|
||||
const auto &displacementStatisticsAfter = preparedOperator.GetDisplacementJacobianStatistics();
|
||||
|
||||
INFO("MFEM adapter/direct-action error = " << adapterError);
|
||||
|
||||
@@ -422,15 +341,9 @@ TEST_CASE(
|
||||
|
||||
CHECK(contextStatisticsAfter == contextStatisticsBefore);
|
||||
|
||||
CHECK(
|
||||
algebraicStatisticsAfter.preparations ==
|
||||
algebraicStatisticsBefore.preparations
|
||||
);
|
||||
CHECK(algebraicStatisticsAfter.preparations == algebraicStatisticsBefore.preparations);
|
||||
|
||||
CHECK(
|
||||
displacementStatisticsAfter.preparations ==
|
||||
displacementStatisticsBefore.preparations
|
||||
);
|
||||
CHECK(displacementStatisticsAfter.preparations == displacementStatisticsBefore.preparations);
|
||||
|
||||
CHECK(preparedOperator.GetCompleteJacobianStatistics().applications == 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user