From bbf4c2fdadfef43b4b7053eb5bba15c087240879 Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Mon, 9 Nov 2026 12:30:52 -0800 Subject: [PATCH] Fixes #113. Adding `sigma`, `epsilon`, or `mu` (or the LLG `mag_Ms_*`, `mag_alpha_*`, `mag_exchange_*`, `mag_anisotropy_*` fields) to `fields_to_plot` segfaults when `algo.em_solver_medium` is not `macroscopic`. The crash happens in `FullDiagnostics::InitializeFieldFunctors`, where `MacroscopicProperties` returns null MultiFab pointers because the material properties were never initialized. `Diagnostics::BaseReadParameters` already has asserts meant to catch this with a clear message. They never fire because they check `m_varnames`, which is still empty at that point. It only gets filled from `m_varnames_fields` later in the same function. The seven checks now look at `m_varnames_fields` instead of `m_varnames`, matching the existing check for `G` just above them. - With `algo.em_solver_medium = vacuum` and `sigma` in `fields_to_plot`: before, a segfault; after, the run stops with `sigma in plotfiles only works with algo.em_solver_medium=macroscopic`. - With `algo.em_solver_medium = macroscopic`: `sigma`, `epsilon`, and `mu` are still written correctly, with and without LLG and when restarting from a checkpoint. --- Source/Diagnostics/Diagnostics.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index 55ab056fd..ce4031508 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -108,7 +108,7 @@ Diagnostics::BaseReadParameters () } // sigma can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "sigma")) + if (utils::algorithms::is_in(m_varnames_fields, "sigma")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, @@ -116,7 +116,7 @@ Diagnostics::BaseReadParameters () } // epsilon can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "epsilon")) + if (utils::algorithms::is_in(m_varnames_fields, "epsilon")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, @@ -124,7 +124,7 @@ Diagnostics::BaseReadParameters () } // mu can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "mu")) + if (utils::algorithms::is_in(m_varnames_fields, "mu")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, @@ -133,21 +133,21 @@ Diagnostics::BaseReadParameters () #ifdef WARPX_MAG_LLG // mag_Ms can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "mag_Ms_xface") || utils::algorithms::is_in(m_varnames, "mag_Ms_yface") || utils::algorithms::is_in(m_varnames, "mag_Ms_zface")) + if (utils::algorithms::is_in(m_varnames_fields, "mag_Ms_xface") || utils::algorithms::is_in(m_varnames_fields, "mag_Ms_yface") || utils::algorithms::is_in(m_varnames_fields, "mag_Ms_zface")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, "mag_Ms in plotfiles only works with algo.em_solver_medium=macroscopic"); } // mag_alpha can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "mag_alpha_xface") || utils::algorithms::is_in(m_varnames, "mag_alpha_yface") || utils::algorithms::is_in(m_varnames, "mag_alpha_zface")) + if (utils::algorithms::is_in(m_varnames_fields, "mag_alpha_xface") || utils::algorithms::is_in(m_varnames_fields, "mag_alpha_yface") || utils::algorithms::is_in(m_varnames_fields, "mag_alpha_zface")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, "mag_alpha in plotfiles only works with algo.em_solver_medium=macroscopic"); } // mag_exchange can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "mag_exchange_xface") || utils::algorithms::is_in(m_varnames, "mag_exchange_yface") || utils::algorithms::is_in(m_varnames, "mag_exchange_zface")) + if (utils::algorithms::is_in(m_varnames_fields, "mag_exchange_xface") || utils::algorithms::is_in(m_varnames_fields, "mag_exchange_yface") || utils::algorithms::is_in(m_varnames_fields, "mag_exchange_zface")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic, @@ -159,7 +159,7 @@ Diagnostics::BaseReadParameters () } } // mag_anisotropy can be written to file only if WarpX::em_solver_medium == MediumForEM::Macroscopic - if (utils::algorithms::is_in(m_varnames, "mag_anisotropy_xface") || utils::algorithms::is_in(m_varnames, "mag_anisotropy_yface") || utils::algorithms::is_in(m_varnames, "mag_anisotropy_zface")) + if (utils::algorithms::is_in(m_varnames_fields, "mag_anisotropy_xface") || utils::algorithms::is_in(m_varnames_fields, "mag_anisotropy_yface") || utils::algorithms::is_in(m_varnames_fields, "mag_anisotropy_zface")) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::em_solver_medium == MediumForEM::Macroscopic,