feat(libmeanfield): centrifugal + pressure

This commit is contained in:
2026-08-04 14:24:55 -04:00
parent 9bc4f2758a
commit dc912fd15e
115 changed files with 260058 additions and 163261 deletions

View File

@@ -11,7 +11,7 @@ namespace mean_field::utils {
mfem::Vector &x_ref
) {
const int dim = fem.mesh->Dimension();
x_ref = x_phys_target;
x_ref = x_phys_target;
mfem::Array<int> init_elem;
mfem::Array<mfem::IntegrationPoint> init_ip;
@@ -29,8 +29,10 @@ namespace mean_field::utils {
mfem::Array<mfem::IntegrationPoint> origin_ip;
fem.mesh->FindPoints(P_origin, origin_elem, origin_ip, false);
if (origin_elem.Size() > 0 && origin_elem[0] >= 0 && !fem.mapping->IsIdentity()) {
mfem::ElementTransformation *T0 = fem.mesh->GetElementTransformation(origin_elem[0]);
if (origin_elem.Size() > 0 && origin_elem[0] >= 0 &&
fem.mapping->HasDisplacementField()) {
mfem::ElementTransformation *T0 =
fem.mesh->GetElementTransformation(origin_elem[0]);
T0->SetIntPoint(&origin_ip[0]);
mfem::DenseMatrix J0(dim, dim), J0_inv(dim, dim);
@@ -81,7 +83,8 @@ namespace mean_field::utils {
if (elem_ids.Size() == 0 || elem_ids[0] < 0) {
find_failures++;
if (find_failures > 10) return false;
if (find_failures > 10)
return false;
double norm = x_ref.Norml2();
if (norm > 1e-15) {
@@ -92,10 +95,11 @@ namespace mean_field::utils {
continue;
}
int elemID = elem_ids[0];
int elemID = elem_ids[0];
const mfem::IntegrationPoint &ip = ips[0];
mfem::ElementTransformation *T = fem.mesh->GetElementTransformation(elemID);
mfem::ElementTransformation *T =
fem.mesh->GetElementTransformation(elemID);
T->SetIntPoint(&ip);
mfem::Vector current_x_phys(dim);
@@ -135,7 +139,8 @@ namespace mean_field::utils {
x_ref = x_ref_candidate;
} else {
find_failures++;
if (find_failures > 10) return false;
if (find_failures > 10)
return false;
if (double norm = x_ref.Norml2(); norm > 1e-15) {
x_ref *= 0.5 * RADIUS / norm;
} else {
@@ -155,7 +160,8 @@ namespace mean_field::utils {
const mapping::COORDINATE_SPACE rspace
) {
mfem::Vector x_search;
if (vspace == mapping::COORDINATE_SPACE::PHYSICAL && fem.has_mapping()) {
if (vspace == mapping::COORDINATE_SPACE::PHYSICAL &&
fem.has_mapping()) {
GetReferencePoint(fem, x, x_search);
} else {
x_search = x;
@@ -171,18 +177,22 @@ namespace mean_field::utils {
double local_val = 0.0;
if (elem_ids.Size() > 0 && elem_ids[0] >= 0) {
const double val = u.GetValue(elem_ids[0], ips[0]);
if (rspace == mapping::COORDINATE_SPACE::PHYSICAL && !fem.has_mapping()) {
MFEM_ABORT("Physical evaluation mode requested but no mapping provided. Check domain bounds and mapping setup.");
if (rspace == mapping::COORDINATE_SPACE::PHYSICAL &&
!fem.has_mapping()) {
MFEM_ABORT(
"Physical evaluation mode requested but no mapping "
"provided. Check "
"domain bounds and mapping setup."
);
}
local_val = val;
}
double global_val = 0.0;
MPI_Allreduce(&local_val, &global_val, 1, MPI_DOUBLE, MPI_MAX, fem.H1_fes->GetComm());
MPI_Allreduce(
&local_val, &global_val, 1, MPI_DOUBLE, MPI_MAX, fem.mesh->GetComm()
);
return global_val;
}
}
} // namespace mean_field::utils

View File

@@ -1,6 +1,6 @@
module;
#include <mfem.hpp>
#include <expected>
#include <mfem.hpp>
module mean_field;
import :boundary.contexts;
@@ -10,18 +10,22 @@ namespace mean_field::utils {
DOMAINS lhs,
DOMAINS rhs
) {
return static_cast<DOMAINS>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
return static_cast<DOMAINS>(
static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs)
);
}
DOMAINS operator&(
DOMAINS lhs,
DOMAINS rhs
) {
return static_cast<DOMAINS>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
return static_cast<DOMAINS>(
static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs)
);
}
void populate_element_mask(
const mfem::Mesh* mesh,
const mfem::Mesh *mesh,
const DOMAINS domain,
mfem::Array<int> &mask
) {
@@ -33,7 +37,8 @@ namespace mean_field::utils {
mask[0] = 1;
}
if ((domain & DOMAINS::ENVELOPE) == DOMAINS::ENVELOPE && max_attr >= 2) {
if ((domain & DOMAINS::ENVELOPE) == DOMAINS::ENVELOPE &&
max_attr >= 2) {
mask[1] = 1;
}
@@ -59,7 +64,8 @@ namespace mean_field::utils {
for (int j = 0; j < dofs.Size(); j++) {
int index = dofs[j];
if (index < 0) index = -1 - index;
if (index < 0)
index = -1 - index;
vdof_marker[index] = 1;
}
}
@@ -68,23 +74,28 @@ namespace mean_field::utils {
fes->MarkerToList(vdof_marker, ess_tdof);
}
std::expected<boundary::Bounds, boundary::BoundsError> discover_bounds(
std::expected<
boundary::Bounds,
boundary::BoundsError>
discover_bounds(
const mfem::Mesh *mesh,
const int vacuum_attr
) {
double local_min_r = std::numeric_limits<double>::max();
double local_max_r = -std::numeric_limits<double>::max();
bool found_vacuum = false;
bool found_vacuum = false;
for (int i = 0; i < mesh->GetNE(); ++i) {
if (mesh->GetAttribute(i) == vacuum_attr) {
found_vacuum = true;
mfem::Array<int> vertices;
mesh->GetElementVertices(i, vertices);
for (const int v: vertices) {
for (const int v : vertices) {
const double *coords = mesh->GetVertex(v);
double r = std::sqrt(coords[0] * coords[0] + coords[1] * coords[1] + coords[2] * coords[2]);
double r = std::sqrt(
coords[0] * coords[0] + coords[1] * coords[1] +
coords[2] * coords[2]
);
local_min_r = std::min(local_min_r, r);
local_max_r = std::max(local_max_r, r);
}
@@ -93,16 +104,22 @@ namespace mean_field::utils {
double global_min_r, global_max_r;
int global_found_vacuum;
int l_found = found_vacuum ? 1 : 0;
int l_found = found_vacuum ? 1 : 0;
MPI_Comm comm = MPI_COMM_WORLD;
if (const auto *pmesh = dynamic_cast<const mfem::ParMesh *>(mesh)) {
comm = pmesh->GetComm();
}
MPI_Allreduce(&local_min_r, &global_min_r, 1, MPI_DOUBLE, MPI_MIN, comm);
MPI_Allreduce(&local_max_r, &global_max_r, 1, MPI_DOUBLE, MPI_MAX, comm);
MPI_Allreduce(&l_found, &global_found_vacuum, 1, MPI_INT, MPI_MAX, comm);
MPI_Allreduce(
&local_min_r, &global_min_r, 1, MPI_DOUBLE, MPI_MIN, comm
);
MPI_Allreduce(
&local_max_r, &global_max_r, 1, MPI_DOUBLE, MPI_MAX, comm
);
MPI_Allreduce(
&l_found, &global_found_vacuum, 1, MPI_INT, MPI_MAX, comm
);
if (global_found_vacuum) {
return boundary::Bounds(global_min_r, global_max_r);
@@ -110,15 +127,11 @@ namespace mean_field::utils {
return std::unexpected(boundary::BoundsError::CANNOT_FIND_VACUUM);
}
int get_mesh_order(
const mfem::Mesh &mesh
) {
int get_mesh_order(const mfem::Mesh &mesh) {
if (mesh.GetNodes() != nullptr) {
return mesh.GetNodes()->FESpace()->GetMaxElementOrder();
}
return 1;
}
}
} // namespace mean_field::utils