Integrate frozen negative density over polynomial root intervals

This commit is contained in:
2026-09-19 10:06:10 -04:00
parent 9c22934d52
commit d1a594808f
4 changed files with 517 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ import mean_field;
#include "reduced_surface_diagnostics.hpp"
#include "spherical_harmonic_surface_diagnostics.hpp"
#include "negative_density_diagnostics.hpp"
#include "negative_density_regions.hpp"
using namespace mean_field;
namespace {
@@ -47,6 +48,7 @@ struct Options {
bool weakShapeProbe = false, weakShapeFinal = false;
bool reducedSurfaceProbe = false, reducedSurfaceAlgebraCheck = false;
bool densityDiagnostic = false;
bool densityRegions = false;
int surfaceDegree = 4, surfaceMaximumOrder = -1;
std::string surfacePrescription = "nodal";
bool coupledTrialProbe = false, coupledSeedControl = false;
@@ -129,6 +131,10 @@ Options Parse(int argc, char **argv) {
o.reducedSurfaceAlgebraCheck = true;
else if (a == "--density-diagnostic")
o.densityDiagnostic = true;
else if (a == "--density-regions") {
o.densityDiagnostic = true;
o.densityRegions = true;
}
else if (a == "--density-snapshot")
o.densitySnapshot = v();
else if (a == "--surface-prescription")
@@ -682,7 +688,7 @@ int RunContext(Context &context, const Options &o, const Scales &scales) {
<< "\nschur_correction_sweeps=" << o.schurCorrectionSweeps << "\nschur_relaxation=" << o.schurRelaxation
<< "\ncompiler=" << __VERSION__ << "\ncompiled=" << __DATE__ << ' ' << __TIME__ << '\n';
if (o.densityDiagnostic) {
metadata << "density_diagnostic=1\ndensity_source="
metadata << "density_diagnostic=1\ndensity_region_integral=" << o.densityRegions << "\ndensity_source="
<< (o.densitySnapshot.empty() ? "lane_emden_seed" : o.densitySnapshot.string()) << '\n';
metadata.flush();
solver::detail::StellarEquilibriumContextDiagnostics::WithState(context, [&](auto &s, const fem::FEM &f) {
@@ -721,7 +727,10 @@ int RunContext(Context &context, const Options &o, const Scales &scales) {
adapter.scatter(closureResidual, closureFull);
SaveVector(o.output / "production_closure_residual_full.txt", closureFull);
SaveVector(o.output / "observed_density_coefficients.txt", physical.density);
experiment::plateau_diagnostics::RecordNegativeDensity(physical, o.n, scales.K, o.output);
if (o.densityRegions)
experiment::plateau_diagnostics::RecordDensityNegativeRegions(physical, o.n, scales.K, o.output);
else
experiment::plateau_diagnostics::RecordNegativeDensity(physical, o.n, scales.K, o.output);
if (!d::Identical(accepted, s.AcceptedPhysicalState()) || !d::Identical(normalized, s.acceptedNormalizedState) ||
!d::Identical(residual, s.acceptedNormalizedResidual))
throw std::runtime_error("Density diagnostic changed the accepted state.");