mf6rtm.io package

Submodules

mf6rtm.io.externalio module

externalio to write outputs and to write and read phreeqcrm inputs from layered txt files.

class mf6rtm.io.externalio.Regenerator(wd='.', phinp='phinp.dat', yamlfile='mf6rtm.yaml', dllfile='libmf6.dll')

Bases: object

A class to regenerate a Mup3d object from a script file.

add_m0_to_config()

Add the loaded array data to the config dictionary.

Reads the external files first if they have not been loaded yet.

Returns:

The configuration dictionary with m0 arrays added per phase.

Return type:

dict

generate_equilibrium_phases_blocks()

Generate per-cell EQUILIBRIUM_PHASES blocks from the config.

Returns:

One EQUILIBRIUM_PHASES block string per grid cell.

Return type:

list of str

generate_exchange_phases_blocks()

Generate per-cell EXCHANGE blocks from the config.

Returns:

One EXCHANGE block string per grid cell.

Return type:

list of str

generate_kinetic_phases_blocks()

Generate per-cell KINETICS blocks from the config.

Returns:

One KINETICS block string per grid cell.

Return type:

list of str

generate_new_script()

Generate a new _phinp.dat script from the source phinp and the config.

The source is parsed into PHREEQC keyword blocks and bucketed by category, then reassembled in an order that respects PHREEQC semantics:

DEFINITION blocks (KNOBS, RATES, PHASES, *_SPECIES, …) at the top -> SOLUTION blocks (verbatim) -> preserved reaction blocks (SURFACE/GAS_PHASE/SOLID_SOLUTIONS, verbatim) -> per-cell phase blocks regenerated from the config m0 files -> OUTPUT blocks (SELECTED_OUTPUT/USER_PUNCH/PRINT, verbatim, exactly once)

Source EQUILIBRIUM_PHASES/KINETICS/EXCHANGE blocks are dropped because they are rebuilt per cell from the config.

read_external_files()

Read the external phase files required for regeneration.

Returns:

Loaded arrays organized by phase key and name, reshaped to the grid dimensions; also stored on self.file_data.

Return type:

dict

read_phinp()

Read the PHREEQC input script from disk.

Returns:

Lines of the phinp file in the working directory.

Return type:

list of str

classmethod regenerate_from_external_files(wd='.', phinpfile='phinp.dat', yamlfile='mf6rtm.yaml', dllfile='libmf6.dll', prefix='_')

Regenerate the PHREEQC script and YAML from external files.

Parameters:
  • wd (str, optional) – Working directory. Default is ".".

  • phinpfile (str, optional) – Name of the source phinp file. Default is "phinp.dat".

  • yamlfile (str, optional) – Name of the PhreeqcRM YAML file. Default is "mf6rtm.yaml".

  • dllfile (str, optional) – Name of the MODFLOW 6 shared library. Default is "libmf6.dll".

  • prefix (str, optional) – Prefix for the regenerated output files. Default is "_".

Returns:

The instance after writing the regenerated script and YAML.

Return type:

Regenerator

update_yaml(filename='_mf6rtm.yaml')

Update the YAML file with the regenerated script and initial conditions.

Parameters:

filename (str, optional) – Name of the YAML file to write. Default is "_mf6rtm.yaml".

Returns:

The flattened initial-condition array written to PhreeqcRM.

Return type:

numpy.ndarray

validate_external_files()

Validate the existence of external files required for regeneration.

write_new_script(filename='_phinp.dat')

Write the regenerated script to a file.

Parameters:

filename (str, optional) – Name of the output script file. Default is "_phinp.dat".

Returns:

Full path to the written script file.

Return type:

str

class mf6rtm.io.externalio.SelectedOutput(mf6rtm, sout_fname='sout.csv', output_format='csv')

Bases: object

Collects and writes PhreeqcRM selected output for a run.

Reads the PhreeqcRM selected-output block each reactive time step and writes it (with cell ids and saturation) to CSV or HDF5, and optionally exports machine-learning feature arrays.

Parameters:
  • mf6rtm (Mf6RTM) – The parent reactive transport instance, providing the MF6 and PhreeqcRM interfaces.

  • sout_fname (str) – Output filename. Default is "sout.csv". A .h5/.hdf5 extension switches the format to HDF5.

  • output_format (str) – Output format. Default is "csv". HDF5 requires PyTables.

write_ml_arrays(conc_array, iter, add_var_names=None, fname='_features.csv')

Write total transported component concentrations in mol/L (+ optional vars in mol/L) to CSV for Machine Learning arrays.

Parameters:
  • conc_array (array-like) – Main concentrations (ncomps x nxyz).

  • add_var_names (list of str, optional) – Extra PHREEQC variables to include.

  • fname (str) – Output filename (relative to model wd).

Return type:

None

Module contents

Main io module to write and read model files