mf6rtm package

Subpackages

Subpackages:

Module contents

The MF6RTM (Modflow 6 Reactive Transport Model) package is a Python package for reactive transport modeling via the MODFLOW 6 and PhreeqcRM APIs.

class mf6rtm.Mf6API(wd, dll)

Bases: ModflowApi

MODFLOW 6 API wrapper driving the flow and transport solve.

Extends modflowapi.ModflowApi to load the coupled simulation and run the per-timestep GWF/GWT solve loop that Mf6RTM alternates with the PhreeqcRM reaction step.

Parameters:
  • wd (os.PathLike) – Working directory containing the MODFLOW 6 simulation.

  • dll (os.PathLike) – Path to the MODFLOW 6 shared library (libmf6).

property grid_type: str

Return the grid type of the MODFLOW 6 model.

class mf6rtm.Mf6RTM(wd, mf6api, phreeqcbmi, output_format=None)

Bases: object

Reactive transport loop coupling MODFLOW 6 and PhreeqcRM.

Drives the sequential non-iterative (SNIA) operator-splitting loop: each time step MODFLOW 6 solves flow and conservative transport, the resulting concentrations are handed to PhreeqcRM to solve chemistry, and the reacted concentrations are written back to the transport models.

Instances are normally created via prep_to_run() and run with solve() rather than constructed directly. See __init__ for the full list of parameters and attributes.

get_saturation_from_mf6()

Get the cell saturation array from MODFLOW 6.

Reads the saturation for the transport models and stores it on the PhreeqcRM interface (sat_now).

Returns:

Saturation values for the grid; identical across all components.

Return type:

dict[Any, ndarray]

get_time_units_from_mf6()

Get the simulation time units from MODFLOW 6.

Returns:

The MODFLOW 6 TDIS time units (e.g. "days").

Return type:

str

is_reactive_tstep()

Check whether the current timestep should be reactive.

Returns:

True if the current timestep should be reactive, based on the run configuration; False otherwise.

Return type:

bool

print_warning_user_active()

Print a warning if reaction timing is set to ‘user’.

set_emulator_output_add_variables()

Add emulator target and feature variables to the output.

Updates selected_output with variables defined in the configuration. Defaults to empty lists if not provided.

selected_output.target_var

Target variables for emulator training.

Type:

list of str

selected_output.feat_var

Feature variables for emulator training.

Type:

list of str

Return type:

None

set_emulator_training()

Configure emulator training output.

Reads emulator_training_data from the configuration. If enabled, sets up emulator output variables; otherwise disables training data.

ml_output

Whether emulator training data output is enabled.

Type:

bool

Return type:

None

set_kiter()

Increment and return the coupling iteration counter.

Initializes kiter to 0 on the first call, then increments it on each subsequent call.

Returns:

The current iteration counter.

Return type:

int

set_min_concentration(min_concentration)

Set the floor value for non-charge concentrations passed to PhreeqcRM.

Parameters:

min_concentration (float | None) – Any non-charge concentration below this value will be replaced with this value before calling SetConcentrations. Use a small positive number (e.g. 1e-30) to avoid PHREEQC divide-by-zero errors. Pass None to disable filtering entirely.

Return type:

None

set_time_conversion()

Set the time conversion factor from the MODFLOW 6 time units.

Return type:

None

solve()

Run the coupled MODFLOW 6 / PhreeqcRM time-stepping loop.

Returns:

True if the run finished and both interfaces were finalized successfully.

Return type:

bool

class mf6rtm.PhreeqcBMI(yaml='mf6rtm.yaml')

Bases: BMIPhreeqcRM

Basic Model Interface wrapper around PhreeqcRM.

Extends phreeqcrm.BMIPhreeqcRM with helpers used by Mf6RTM to run the geochemical reaction step: scalar setters, selected-output handling and per-timestep solution updates.

Parameters:

yaml (str, optional) – Path to the PhreeqcRM YAML configuration file used to initialize the chemistry. Default is "mf6rtm.yaml".

get_grid_to_map()

Get the PhreeqcRM grid-to-map mapping.

Returns:

The grid-to-map mapping returned by GetGridToMap.

Return type:

array-like

set_scalar(var_name, value)

Set a scalar PhreeqcRM BMI variable.

Parameters:
  • var_name (str) – Name of the BMI variable to set.

  • value (Any) – Scalar value to assign; cast to the variable’s declared dtype.

Raises:

ValueError – If var_name does not refer to a scalar (dimension != 1).

mf6rtm.run_cmd(cwd=None)

Console entrypoint compatibility wrapper.

When used as a console script the entrypoint calls mf6rtm:run_cmd with no arguments. Allow cwd to be optional and default to the current working directory.

Return type:

None

mf6rtm.solve(wd, reactive=None, nthread=1, libname=None, output_format=None, **mf6rtm_kwargs)

Prepare the coupled interfaces and run the reactive transport solve.

Parameters:
  • wd (PathLike) – Model working directory.

  • reactive (bool | None) – If given, override the reactive mode taken from the configuration. When it differs from the configured value the mode is switched (and selected output is left to MODFLOW 6 for conservative runs). Default is None.

  • nthread (int) – Number of threads for PhreeqcRM. Default is 1.

  • libname (Path | None) – Path to the MODFLOW 6 shared library. Default is None.

  • output_format (str) – Selected-output format (e.g. "csv" or "hdf5"). Default is None.

  • **mf6rtm_kwargs – Additional attributes to set on the Mf6RTM instance before solving; each key must be an existing attribute.

Returns:

True if the simulation finished successfully.

Return type:

bool

Raises:

AttributeError – If a keyword in mf6rtm_kwargs is not an attribute of Mf6RTM.