Skip to content

max_mhd_level=0 default silently breaks pure-MHD runs #1294

Description

@nicolasaunai

Why

max_mhd_level defaults to 0 (check_max_mhd_level, pyphare/pharein/simulation.py:658-666), which makes sense for the Hybrid default case (model_options="HybridModel", no MHD levels at all). But nothing stops you from doing Simulation(model_options=["MHDModel"], ...) and leaving max_mhd_level untouched, and in that case things don't just behave oddly, they break silently.

In src/simulator/simulator.hpp:358:

multiphysInteg_->registerModel(0, maxMHDLevel_ - 1, mhdModel_);

With maxMHDLevel_ = 0 this is registerModel(0, -1, mhdModel_), an empty range, so no level gets the MHD model registered. The Hybrid-model registration branch right above it only runs when model_options includes "HybridModel", which it doesn't here. End result: a model_options=["MHDModel"] run with the default max_mhd_level ends up with literally no physics model attached to any level in the hierarchy.

What

Either:

  • error out at Simulation construction time if model_options=["MHDModel"] and max_mhd_level is left at 0, or
  • default max_mhd_level to max_nbr_levels when model_options is MHD-only, since that's what "every level is MHD" (the existing doc note for a pure MHD run) actually requires.

Ideas on how (optional)

In check_max_mhd_level (pyphare/pharein/simulation.py), make the default depend on model_options instead of being a flat 0:

def check_max_mhd_level(**kwargs):
    default = kwargs["max_nbr_levels"] if kwargs["model_options"] == ["MHDModel"] else 0
    max_mhd_level = kwargs.get("max_mhd_level", default)
    ...

(need to check ordering vs. check_model_options in checker, since model_options is currently validated after max_mhd_level)

Alternatives considered

No response

Additional context

Found while documenting max_mhd_level in the Simulation docstring.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions