feat(preconditioner): major work on preconditioner system
first preconditioner MVP
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
module;
|
||||
#include "profile.h"
|
||||
#include <array>
|
||||
#include <mfem.hpp>
|
||||
|
||||
@@ -62,6 +63,8 @@ namespace mean_field::analysis {
|
||||
utils::DOMAINS domain,
|
||||
mapping::COORDINATE_SPACE coord_space
|
||||
) {
|
||||
MEAN_FIELD_PROFILE_SCOPE_WARMUP("analysis::domain_integrate_grid_function", 0);
|
||||
|
||||
mfem::LinearForm lf(fem.densityFes.get());
|
||||
mfem::GridFunctionCoefficient gf_c(&gf);
|
||||
double local_integral;
|
||||
@@ -107,11 +110,15 @@ namespace mean_field::analysis {
|
||||
const fem::FEM &fem,
|
||||
const mfem::GridFunction &rho
|
||||
) {
|
||||
const int dim = fem.mesh->Dimension();
|
||||
MEAN_FIELD_PROFILE_SCOPE_WARMUP("analysis::get_com", 0);
|
||||
|
||||
std::uint64_t mapping_evaluations = 0;
|
||||
const int dim = fem.mesh->Dimension();
|
||||
mapping::GridFunctionMappingEvaluator mapping_evaluator(
|
||||
*fem.domainMapperStateless, *fem.displacement, *fem.compactificationCoordinate
|
||||
);
|
||||
mfem::Vector local_com(dim);
|
||||
mapping::VolumeMappingContext mapping_context;
|
||||
local_com = 0.0;
|
||||
double local_mass = 0.0;
|
||||
|
||||
@@ -127,11 +134,11 @@ namespace mean_field::analysis {
|
||||
const mfem::IntegrationPoint &ip = ir.IntPoint(j);
|
||||
trans->SetIntPoint(&ip);
|
||||
|
||||
mapping::VolumeMappingContext mapping_context;
|
||||
MFEM_VERIFY(
|
||||
mapping_evaluator.EvaluateVolume(*trans, ip, mapping_context) == mapping::MappingStatus::valid,
|
||||
"Center-of-mass integration encountered an invalid mapping."
|
||||
);
|
||||
++mapping_evaluations;
|
||||
const double weight = mapping_context.quadrature.weight;
|
||||
double rho_val = rho.GetValue(i, ip);
|
||||
|
||||
@@ -146,13 +153,23 @@ namespace mean_field::analysis {
|
||||
}
|
||||
}
|
||||
|
||||
double global_mass = 0.0;
|
||||
MEAN_FIELD_PROFILE_COUNT("analysis::get_com mapping evaluations", mapping_evaluations);
|
||||
|
||||
mfem::Vector local_integrals(dim + 1);
|
||||
mfem::Vector global_integrals(dim + 1);
|
||||
local_integrals(0) = local_mass;
|
||||
for (int d = 0; d < dim; ++d) {
|
||||
local_integrals(d + 1) = local_com(d);
|
||||
}
|
||||
MPI_Allreduce(
|
||||
local_integrals.GetData(), global_integrals.GetData(), dim + 1, MPI_DOUBLE, MPI_SUM, fem.mesh->GetComm()
|
||||
);
|
||||
|
||||
const double global_mass = global_integrals(0);
|
||||
mfem::Vector global_com(dim);
|
||||
MPI_Comm comm = fem.mesh->GetComm();
|
||||
|
||||
MPI_Allreduce(&local_mass, &global_mass, 1, MPI_DOUBLE, MPI_SUM, comm);
|
||||
|
||||
MPI_Allreduce(local_com.GetData(), global_com.GetData(), dim, MPI_DOUBLE, MPI_SUM, comm);
|
||||
for (int d = 0; d < dim; ++d) {
|
||||
global_com(d) = global_integrals(d + 1);
|
||||
}
|
||||
|
||||
if (global_mass > 1e-18) {
|
||||
global_com /= global_mass;
|
||||
@@ -168,6 +185,8 @@ namespace mean_field::analysis {
|
||||
mfem::GridFunction &rho,
|
||||
const double target_mass
|
||||
) {
|
||||
MEAN_FIELD_PROFILE_SCOPE_WARMUP("analysis::conserve_mass", 0);
|
||||
|
||||
if (const double current_mass = domain_integrate_grid_function(fem, rho, utils::DOMAINS::STELLAR);
|
||||
current_mass > 1e-15)
|
||||
rho *= (target_mass / current_mass);
|
||||
@@ -177,6 +196,8 @@ namespace mean_field::analysis {
|
||||
const fem::FEM &fem,
|
||||
const mfem::GridFunction &rho
|
||||
) {
|
||||
MEAN_FIELD_PROFILE_SCOPE_WARMUP("analysis::get_moment_of_inertia", 0);
|
||||
|
||||
auto s2_func = [](const mfem::Vector &x) { return std::pow(x(0), 2) + std::pow(x(1), 2); };
|
||||
|
||||
std::unique_ptr<mfem::Coefficient> s2_coeff;
|
||||
@@ -227,6 +248,8 @@ namespace mean_field::analysis {
|
||||
const mapping::COORDINATE_SPACE coordinate_space,
|
||||
const utils::DOMAINS domain
|
||||
) {
|
||||
MEAN_FIELD_PROFILE_SCOPE_WARMUP("analysis::get_mesh_volume", 0);
|
||||
|
||||
mfem::ParMesh &mesh = *fem.mesh;
|
||||
const bool physical = (coordinate_space == mapping::COORDINATE_SPACE::PHYSICAL);
|
||||
|
||||
@@ -238,6 +261,7 @@ namespace mean_field::analysis {
|
||||
mapping::GridFunctionMappingEvaluator mapping_evaluator(
|
||||
*fem.domainMapperStateless, *fem.displacement, *fem.compactificationCoordinate
|
||||
);
|
||||
mapping::VolumeMappingContext mapping_context;
|
||||
|
||||
for (int e = 0; e < mesh.GetNE(); ++e) {
|
||||
const int attr = mesh.GetAttribute(e);
|
||||
@@ -259,12 +283,11 @@ namespace mean_field::analysis {
|
||||
double dV = ip.weight * T->Weight();
|
||||
|
||||
if (physical) {
|
||||
mapping::VolumeMappingContext context;
|
||||
MFEM_VERIFY(
|
||||
mapping_evaluator.EvaluateVolume(*T, ip, context) == mapping::MappingStatus::valid,
|
||||
mapping_evaluator.EvaluateVolume(*T, ip, mapping_context) == mapping::MappingStatus::valid,
|
||||
"Mesh-volume integration encountered an invalid mapping."
|
||||
);
|
||||
dV = context.quadrature.weight;
|
||||
dV = mapping_context.quadrature.weight;
|
||||
}
|
||||
|
||||
local_volume += dV;
|
||||
|
||||
Reference in New Issue
Block a user