feat(FieldDofMap): Completed FieldDofMap migration

also removed legacy BarotropicPolytrope implementation
This commit is contained in:
2026-08-29 08:56:36 -04:00
parent 177ae8b38a
commit 36adfa1174
104 changed files with 26967 additions and 26916 deletions

View File

@@ -9,6 +9,20 @@ import test_helpers;
using namespace mean_field;
namespace {
struct SerialMappingData {
explicit SerialMappingData(mfem::Mesh &mesh)
: compactification_fes(&mesh, &compactification_fec),
compactification_coordinate(&compactification_fes),
mapper(field_dof_test_utils::make_domain_mapper()) {
compactification_coordinate = 0.0;
}
mfem::H1_FECollection compactification_fec{1, 3};
mfem::FiniteElementSpace compactification_fes;
mfem::GridFunction compactification_coordinate;
mapping::DomainMapper mapper;
};
double compute_roche_surface_scale(
const double rotation_fraction,
const double sine_theta_squared
@@ -29,7 +43,7 @@ namespace {
TEST_CASE(
"Centrifugal Integrator Matches Manufactured Cartesian Load",
tags::unit &tags::solver &tags::integrator &tags::centrifugal
tags::rotation_integrator_unit
) {
constexpr int dim = 3;
constexpr double density = 1.7;
@@ -49,13 +63,15 @@ TEST_CASE(
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
SerialMappingData mapping_data(mesh);
mfem::Vector omega(dim);
omega = 0.0;
omega(2) = omega_value;
integrators::CentrifugalForceIntegrator integrator(domain_mapper, omega);
integrators::CentrifugalForceIntegrator integrator(
mapping_data.mapper, displacement, mapping_data.compactification_coordinate, omega
);
const mfem::FiniteElement *velocity_element = velocity_fes.GetFE(0);
const mfem::FiniteElement *density_element = density_fes.GetFE(0);
@@ -66,8 +82,7 @@ TEST_CASE(
quadrature::Policy policy(std::move(rule_set));
quadrature::RuleFactory quadrature_factory(std::move(policy));
const quadrature::MappingKind mapping_kind =
!domain_mapper.HasDisplacementField() ? quadrature::MappingKind::none : quadrature::MappingKind::general;
const quadrature::MappingKind mapping_kind = quadrature::MappingKind::general;
const int position_order = displacement_element->GetOrder();
quadrature_factory.configure_centrifugal(
@@ -127,7 +142,7 @@ TEST_CASE(
TEST_CASE(
"Centrifugal Integrator Jacobian Matches Residual Linearization",
tags::unit &tags::solver &tags::integrator &tags::centrifugal
tags::rotation_integrator_unit
) {
constexpr int dim = 3;
constexpr double step = 1.0e-6;
@@ -147,14 +162,16 @@ TEST_CASE(
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
SerialMappingData mapping_data(mesh);
mfem::Vector omega(dim);
omega(0) = 0.7;
omega(1) = -1.1;
omega(2) = 1.6;
integrators::CentrifugalForceIntegrator integrator(domain_mapper, omega);
integrators::CentrifugalForceIntegrator integrator(
mapping_data.mapper, displacement, mapping_data.compactification_coordinate, omega
);
const mfem::FiniteElement *velocity_element = velocity_fes.GetFE(0);
const mfem::FiniteElement *density_element = density_fes.GetFE(0);
@@ -165,8 +182,7 @@ TEST_CASE(
quadrature::Policy policy(std::move(rule_set));
quadrature::RuleFactory quadrature_factory(std::move(policy));
const quadrature::MappingKind mapping_kind =
!domain_mapper.HasDisplacementField() ? quadrature::MappingKind::none : quadrature::MappingKind::general;
const quadrature::MappingKind mapping_kind = quadrature::MappingKind::general;
const int position_order = displacement_element->GetOrder();
quadrature_factory.configure_centrifugal(
@@ -287,7 +303,7 @@ TEST_CASE(
TEST_CASE(
"Centrifugal Integrator Preserves Rotation Identities",
tags::unit &tags::solver &tags::integrator &tags::centrifugal
tags::rotation_integrator_unit
) {
constexpr int dim = 3;
constexpr double density = 1.4;
@@ -307,14 +323,16 @@ TEST_CASE(
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
SerialMappingData mapping_data(mesh);
mfem::Vector omega(dim);
omega(0) = 0.7;
omega(1) = -1.1;
omega(2) = 1.6;
integrators::CentrifugalForceIntegrator integrator(domain_mapper, omega);
integrators::CentrifugalForceIntegrator integrator(
mapping_data.mapper, displacement, mapping_data.compactification_coordinate, omega
);
const mfem::FiniteElement *velocity_element = velocity_fes.GetFE(0);
const mfem::FiniteElement *density_element = density_fes.GetFE(0);
@@ -325,8 +343,7 @@ TEST_CASE(
quadrature::Policy policy(std::move(rule_set));
quadrature::RuleFactory quadrature_factory(std::move(policy));
const quadrature::MappingKind mapping_kind =
!domain_mapper.HasDisplacementField() ? quadrature::MappingKind::none : quadrature::MappingKind::general;
const quadrature::MappingKind mapping_kind = quadrature::MappingKind::general;
const int position_order = displacement_element->GetOrder();
quadrature_factory.configure_centrifugal(
@@ -424,7 +441,7 @@ TEST_CASE(
TEST_CASE(
"Centrifugal Integrator Matches Rotational Virial On Roche Mappings",
tags::integration &tags::solver &tags::integrator &tags::centrifugal
tags::rotation_integrator_integration
) {
auto args = test_utils::setup_args();
fem::FEM f = fem::setup_fem(args.mesh_file, args, 0);
@@ -486,16 +503,20 @@ TEST_CASE(
mfem::VectorFunctionCoefficient displacement_coefficient(dim, rotation_displacement);
displacement.ProjectCoefficient(displacement_coefficient);
f.mapping->SetDisplacement(displacement);
*f.displacement = displacement;
mapping::GridFunctionMappingEvaluator mapping_evaluator(
*f.domainMapperStateless, *f.displacement, *f.compactificationCoordinate
);
mfem::Vector omega(dim);
omega = 0.0;
omega(2) = rotation_fraction;
integrators::CentrifugalForceIntegrator integrator(*f.mapping, omega);
integrators::CentrifugalForceIntegrator integrator(
*f.domainMapperStateless, *f.displacement, *f.compactificationCoordinate, omega
);
const quadrature::MappingKind mapping_kind =
!f.mapping->HasDisplacementField() ? quadrature::MappingKind::none : quadrature::MappingKind::general;
const quadrature::MappingKind mapping_kind = quadrature::MappingKind::general;
f.quadratureFactory->configure_centrifugal(
integrator, quadrature::QuadratureRole::discretization, representative_density_element,
representative_velocity_element, representative_transformation, position_order, utils::DOMAINS::STELLAR,
@@ -560,7 +581,7 @@ TEST_CASE(
for (int i = 0; i < velocity_dofs_count; ++i) {
const mfem::IntegrationPoint &node = velocity_nodes.IntPoint(i);
transformation->SetIntPoint(&node);
f.mapping->GetPhysicalPoint(*transformation, node, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, node, x_physical);
for (int d = 0; d < dim; ++d) {
position_test_dofs(i + d * velocity_dofs_count) = x_physical(d);
@@ -581,14 +602,14 @@ TEST_CASE(
const mfem::IntegrationPoint &integration_point = reference_rule.IntPoint(q);
transformation->SetIntPoint(&integration_point);
const double signed_map_determinant = f.mapping->ComputeDetJ(*transformation, integration_point);
const mapping::VolumeQuadratureContext context =
f.mapping->GetQuadratureContext(*transformation, integration_point);
mapping_evaluator.GetQuadratureContext(*transformation, integration_point);
const double signed_map_determinant = context.detJ;
local_minimum_map_determinant = std::min(local_minimum_map_determinant, signed_map_determinant);
local_maximum_map_determinant = std::max(local_maximum_map_determinant, signed_map_determinant);
f.mapping->GetPhysicalPoint(*transformation, integration_point, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, integration_point, x_physical);
velocity_element->CalcShape(integration_point, velocity_shape);
position_test_value = 0.0;
@@ -661,13 +682,13 @@ TEST_CASE(
CHECK_THAT(relative_position_error, Catch::Matchers::WithinAbs(0.0, position_tolerance));
}
f.mapping->ResetDisplacement();
*f.displacement = 0.0;
}
TEST_CASE(
"Centrifugal Virial Position Representation Is Consistent At The "
"Registered Order",
tags::integration &tags::solver &tags::integrator &tags::centrifugal
tags::rotation_integrator_integration
) {
constexpr int dim = 3;
constexpr double concentration = 4.0;
@@ -728,7 +749,10 @@ TEST_CASE(
mfem::VectorFunctionCoefficient displacement_coefficient(dim, rotation_displacement);
displacement.ProjectCoefficient(displacement_coefficient);
f.mapping->SetDisplacement(displacement);
*f.displacement = displacement;
mapping::GridFunctionMappingEvaluator mapping_evaluator(
*f.domainMapperStateless, *f.displacement, *f.compactificationCoordinate
);
mfem::Vector omega(dim);
omega = 0.0;
@@ -761,7 +785,7 @@ TEST_CASE(
for (int i = 0; i < velocity_dofs_count; ++i) {
const mfem::IntegrationPoint &node = velocity_nodes.IntPoint(i);
transformation->SetIntPoint(&node);
f.mapping->GetPhysicalPoint(*transformation, node, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, node, x_physical);
for (int d = 0; d < dim; ++d) {
position_test_dofs(i + d * velocity_dofs_count) = x_physical(d);
@@ -780,13 +804,13 @@ TEST_CASE(
const mfem::IntegrationPoint &integration_point = reference_rule.IntPoint(q);
transformation->SetIntPoint(&integration_point);
const double signed_map_determinant = f.mapping->ComputeDetJ(*transformation, integration_point);
const mapping::VolumeQuadratureContext context =
f.mapping->GetQuadratureContext(*transformation, integration_point);
mapping_evaluator.GetQuadratureContext(*transformation, integration_point);
const double signed_map_determinant = context.detJ;
local_minimum_determinant = std::min(local_minimum_determinant, signed_map_determinant);
f.mapping->GetPhysicalPoint(*transformation, integration_point, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, integration_point, x_physical);
velocity_element->CalcShape(integration_point, velocity_shape);
position_test_value = 0.0;
@@ -833,7 +857,7 @@ TEST_CASE(
minimum_determinants[rotation_index][order_index] = global_minimum_determinant;
}
f.mapping->ResetDisplacement();
*f.displacement = 0.0;
}
for (std::size_t rotation_index = 0; rotation_index < rotation_fractions.size(); ++rotation_index) {
@@ -853,7 +877,7 @@ TEST_CASE(
TEST_CASE(
"Centrifugal Virial Position Representation Converges Under H Refinement",
tags::integration &tags::solver &tags::integrator &tags::convergence &tags::h_refinement &tags::centrifugal
tags::rotation_integrator_convergence
) {
constexpr int dim = 3;
constexpr double concentration = 4.0;
@@ -916,7 +940,10 @@ TEST_CASE(
mfem::VectorFunctionCoefficient displacement_coefficient(dim, rotation_displacement);
displacement.ProjectCoefficient(displacement_coefficient);
f.mapping->SetDisplacement(displacement);
*f.displacement = displacement;
mapping::GridFunctionMappingEvaluator mapping_evaluator(
*f.domainMapperStateless, *f.displacement, *f.compactificationCoordinate
);
mfem::Vector omega(dim);
omega = 0.0;
@@ -949,7 +976,7 @@ TEST_CASE(
for (int i = 0; i < velocity_dofs_count; ++i) {
const mfem::IntegrationPoint &node = velocity_nodes.IntPoint(i);
transformation->SetIntPoint(&node);
f.mapping->GetPhysicalPoint(*transformation, node, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, node, x_physical);
for (int d = 0; d < dim; ++d) {
position_test_dofs(i + d * velocity_dofs_count) = x_physical(d);
@@ -968,13 +995,13 @@ TEST_CASE(
const mfem::IntegrationPoint &integration_point = reference_rule.IntPoint(q);
transformation->SetIntPoint(&integration_point);
const double signed_map_determinant = f.mapping->ComputeDetJ(*transformation, integration_point);
const mapping::VolumeQuadratureContext context =
f.mapping->GetQuadratureContext(*transformation, integration_point);
mapping_evaluator.GetQuadratureContext(*transformation, integration_point);
const double signed_map_determinant = context.detJ;
local_minimum_determinant = std::min(local_minimum_determinant, signed_map_determinant);
f.mapping->GetPhysicalPoint(*transformation, integration_point, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, integration_point, x_physical);
velocity_element->CalcShape(integration_point, velocity_shape);
position_test_value = 0.0;
@@ -1021,7 +1048,7 @@ TEST_CASE(
minimum_determinants[rotation_index][refinement_index] = global_minimum_determinant;
}
f.mapping->ResetDisplacement();
*f.displacement = 0.0;
}
for (std::size_t rotation_index = 0; rotation_index < rotation_fractions.size(); ++rotation_index) {

View File

@@ -10,7 +10,7 @@ using namespace mean_field;
TEST_CASE(
"Gravity Force Integrator Jacobian Matches Residual Linearization",
tags::unit &tags::solver &tags::integrator &tags::gravity
tags::gravity_integrator_unit
) {
constexpr int dim = 3;
constexpr double finite_difference_step = 1.0e-3;
@@ -31,21 +31,20 @@ TEST_CASE(
mfem::RT_FECollection gravity_gradient_fec(1, dim);
mfem::L2_FECollection gravity_potential_fec(1, dim);
mfem::H1_FECollection displacement_fec(2, dim);
mfem::H1_FECollection compactification_fec(1, dim);
mfem::FiniteElementSpace velocity_fes(&mesh, &velocity_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace density_fes(&mesh, &density_fec);
mfem::FiniteElementSpace gravity_gradient_fes(&mesh, &gravity_gradient_fec);
mfem::FiniteElementSpace gravity_potential_fes(&mesh, &gravity_potential_fec);
mfem::FiniteElementSpace displacement_fes(&mesh, &displacement_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace compactification_fes(&mesh, &compactification_fec);
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
INFO(std::format("Domain mapping is has displacement field: {}", domain_mapper.HasDisplacementField()));
INFO(std::format("Domain mapping is identity: {}", domain_mapper.CalcIsIdentity()));
REQUIRE(domain_mapper.CalcIsIdentity());
mfem::GridFunction compactification_coordinate(&compactification_fes);
compactification_coordinate = 0.0;
mapping::DomainMapper domain_mapper = field_dof_test_utils::make_domain_mapper();
const mfem::FiniteElement *velocity_element = velocity_fes.GetFE(0);
const mfem::FiniteElement *density_element = density_fes.GetFE(0);
@@ -130,7 +129,8 @@ TEST_CASE(
element_residual[displacement_block] = &displacement_residual;
integrators::GravityMomentumIntegrator integrator(
domain_mapper, integrators::GravityForceJacobianMode::field_coupled
domain_mapper, displacement, compactification_coordinate,
integrators::GravityForceJacobianMode::field_coupled
);
const int maximum_order = std::max(
@@ -268,7 +268,7 @@ TEST_CASE(
TEST_CASE(
"Gravity Force Integrator Matches Manufactured Cartesian Load",
tags::unit &tags::solver &tags::integrator &tags::gravity
tags::gravity_integrator_unit
) {
constexpr int dim = 3;
constexpr double tolerance = 1.0e-12;
@@ -286,18 +286,23 @@ TEST_CASE(
mfem::L2_FECollection density_fec(1, dim);
mfem::RT_FECollection gravity_gradient_fec(0, dim);
mfem::H1_FECollection displacement_fec(1, dim);
mfem::H1_FECollection compactification_fec(1, dim);
mfem::FiniteElementSpace velocity_fes(&mesh, &velocity_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace density_fes(&mesh, &density_fec);
mfem::FiniteElementSpace gravity_gradient_fes(&mesh, &gravity_gradient_fec);
mfem::FiniteElementSpace displacement_fes(&mesh, &displacement_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace compactification_fes(&mesh, &compactification_fec);
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mfem::GridFunction compactification_coordinate(&compactification_fes);
compactification_coordinate = 0.0;
mapping::DomainMapper domain_mapper = field_dof_test_utils::make_domain_mapper();
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
REQUIRE(domain_mapper.CalcIsIdentity());
mapping::GridFunctionMappingEvaluator mapping_evaluator(
domain_mapper, displacement, compactification_coordinate
);
auto reference_density = [](const mfem::Vector &x) { return 1.0 + x(0); };
@@ -376,7 +381,8 @@ TEST_CASE(
element_residual[displacement_block] = &displacement_residual;
integrators::GravityMomentumIntegrator integrator(
domain_mapper, integrators::GravityForceJacobianMode::field_coupled
domain_mapper, displacement, compactification_coordinate,
integrators::GravityForceJacobianMode::field_coupled
);
const mfem::IntegrationRule &integration_rule = mfem::IntRules.Get(velocity_element->GetGeomType(), 8);
@@ -395,7 +401,7 @@ TEST_CASE(
for (int i = 0; i < velocity_dofs_count; ++i) {
const mfem::IntegrationPoint &node = velocity_nodes.IntPoint(i);
transformation->SetIntPoint(&node);
domain_mapper.GetPhysicalPoint(*transformation, node, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, node, x_physical);
test_dofs(i + component * velocity_dofs_count) =
coordinate_weight < 0 ? 1.0 : x_physical(coordinate_weight);
}
@@ -433,7 +439,7 @@ TEST_CASE(
}
TEST_CASE(
"Gravity Force Integrator Preserves Gravity Identities",
tags::unit &tags::solver &tags::integrator &tags::gravity
tags::gravity_integrator_unit
) {
constexpr int dim = 3;
constexpr double density_value = 1.7;
@@ -454,18 +460,22 @@ TEST_CASE(
mfem::L2_FECollection density_fec(0, dim);
mfem::RT_FECollection gravity_gradient_fec(0, dim);
mfem::H1_FECollection displacement_fec(1, dim);
mfem::H1_FECollection compactification_fec(1, dim);
mfem::FiniteElementSpace velocity_fes(&mesh, &velocity_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace density_fes(&mesh, &density_fec);
mfem::FiniteElementSpace gravity_gradient_fes(&mesh, &gravity_gradient_fec);
mfem::FiniteElementSpace displacement_fes(&mesh, &displacement_fec, dim, mfem::Ordering::byVDIM);
mfem::FiniteElementSpace compactification_fes(&mesh, &compactification_fec);
mfem::GridFunction displacement(&displacement_fes);
displacement = 0.0;
mapping::DomainMapper domain_mapper(displacement, 1.0, 2.0);
REQUIRE(domain_mapper.HasDisplacementField());
mfem::GridFunction compactification_coordinate(&compactification_fes);
compactification_coordinate = 0.0;
mapping::DomainMapper domain_mapper = field_dof_test_utils::make_domain_mapper();
mapping::GridFunctionMappingEvaluator mapping_evaluator(
domain_mapper, displacement, compactification_coordinate
);
auto radial_gravity = [](const mfem::Vector &x, mfem::Vector &gravity) {
gravity.SetSize(3);
@@ -543,7 +553,8 @@ TEST_CASE(
element_residual[displacement_block] = &displacement_residual;
integrators::GravityMomentumIntegrator integrator(
domain_mapper, integrators::GravityForceJacobianMode::field_coupled
domain_mapper, displacement, compactification_coordinate,
integrators::GravityForceJacobianMode::field_coupled
);
const mfem::IntegrationRule &integration_rule = mfem::IntRules.Get(velocity_element->GetGeomType(), 8);
@@ -609,7 +620,7 @@ TEST_CASE(
for (int i = 0; i < velocity_dofs_count; ++i) {
const mfem::IntegrationPoint &node = velocity_nodes.IntPoint(i);
transformation->SetIntPoint(&node);
domain_mapper.GetPhysicalPoint(*transformation, node, x_physical);
mapping_evaluator.GetPhysicalPoint(*transformation, node, x_physical);
for (int component = 0; component < dim; ++component) {
centered_position(component) = x_physical(component) - 0.5;
@@ -714,4 +725,4 @@ TEST_CASE(
Catch::Matchers::WithinAbs(0.0, tolerance)
);
CHECK_THAT(zero_density_field_action.Norml2(), Catch::Matchers::WithinAbs(0.0, tolerance));
}
}