flopy.mf6.modflow.mfsimulation module
- class MFSimulation(sim_name='sim', version='mf6', exe_name: str | PathLike = 'mf6', sim_ws: str | PathLike = '.', verbosity_level=1, continue_=None, nocheck=None, memory_print_option=None, write_headers=True, lazy_io=False)[source]
Bases:
PackageContainer
Entry point into any MODFLOW simulation.
MFSimulation is used to load, build, and/or save a MODFLOW 6 simulation. A MFSimulation object must be created before creating any of the MODFLOW 6 model objects.
- Parameters:
sim_name (str) – Name of the simulation.
version (str) – Version of MODFLOW 6 executable
exe_name (str) – Path to MODFLOW 6 executable
sim_ws (str) – Path to MODFLOW 6 simulation working folder. This is the folder containing the simulation name file.
verbosity_level (int) – Verbosity level of standard output from 0 to 2. When 0 is specified no standard output is written. When 1 is specified standard error/warning messages with some informational messages are written. When 2 is specified full error/warning/informational messages are written (this is ideal for debugging).
continue (bool) – Sets the continue option in the simulation name file. The continue option is a keyword flag to indicate that the simulation should continue even if one or more solutions do not converge.
nocheck (bool) – Sets the nocheck option in the simulation name file. The nocheck option is a keyword flag to indicate that the model input check routines should not be called prior to each time step. Checks are performed by default.
memory_print_option (str) – Sets memory_print_option in the simulation name file. Memory_print_option is a flag that controls printing of detailed memory manager usage to the end of the simulation list file. NONE means do not print detailed information. SUMMARY means print only the total memory for each simulation component. ALL means print information for each variable stored in the memory manager. NONE is default if memory_print_option is not specified.
write_headers (bool) – When true flopy writes a header to each package file indicating that it was created by flopy.
lazy_io (bool) – When true flopy only reads external data when the data is requested and only writes external data if the data has changed. This option automatically overrides the verify_data and auto_set_sizes, turning both off.
Examples
>>> s = MFSimulation.load('my simulation', 'simulation.nam')
- check(f: str | PathLike | None = None, verbose=True, level=1)[source]
Check model data for common errors.
- Parameters:
f (str or PathLike, optional) – String defining file name or file handle for summary file of check method output. If str or pathlike, a file handle is created. If None, the method does not write results to a summary file. (default is None)
verbose (bool) – Boolean flag used to determine if check method results are written to the screen
level (int) – Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed.
- Returns:
check list – Python list containing simulation check results
- Return type:
Examples
>>> import flopy >>> m = flopy.modflow.Modflow.load('model.nam') >>> m.check()
- property exchange_files
Return list of exchange files associated with this simulation.
- Returns:
list
- Return type:
list of exchange names
- get_model(model_name=None)[source]
Returns the models in the simulation with a given model name, name file name, or model type.
- is_valid()[source]
Checks the validity of the solution and all of its models and packages. Returns true if the solution is valid, false if it is not.
- Returns:
valid – Whether this is a valid simulation
- Return type:
- classmethod load(sim_name='modflowsim', version='mf6', exe_name: str | PathLike = 'mf6', sim_ws: str | PathLike = '.', strict=True, verbosity_level=1, load_only=None, verify_data=False, write_headers=True, lazy_io=False)[source]
Load an existing model.
- Parameters:
sim_name (str) – Name of the simulation.
version (str) – MODFLOW version
exe_name (str or PathLike) – Path to MODFLOW executable (relative to the simulation workspace or absolute)
sim_ws (str or PathLike) – Path to simulation workspace
strict (bool) – Strict enforcement of file formatting
verbosity_level (int) –
- Verbosity level of standard output
0: No standard output 1: Standard error/warning messages with some informational
messages
- 2: Verbose mode with full error/warning/informational
messages. This is ideal for debugging.
load_only (list) – List of package abbreviations or package names corresponding to packages that flopy will load. default is None, which loads all packages. the discretization packages will load regardless of this setting. subpackages, like time series and observations, will also load regardless of this setting. example list: [‘ic’, ‘maw’, ‘npf’, ‘oc’, ‘ims’, ‘gwf6-gwf6’]
verify_data (bool) – Verify data when it is loaded. this can slow down loading
write_headers (bool) – When true flopy writes a header to each package file indicating that it was created by flopy
lazy_io (bool) – When true flopy only reads external data when the data is requested and only writes external data if the data has changed. This option automatically overrides the verify_data and auto_set_sizes, turning both off.
- Returns:
sim
- Return type:
MFSimulation object
Examples
>>> s = flopy.mf6.mfsimulation.load('my simulation')
- load_package(ftype, fname: str | PathLike, pname, strict, ref_path: str | PathLike, dict_package_name=None, parent_package=None)[source]
Load a package from a file.
- Parameters:
ftype (str) – the file type
fname (str or PathLike) – the path of the file containing the package input
pname (str) – the user-defined name for the package
strict (bool) – strict mode when loading the file
ref_path (str) – path to the file. uses local path if set to None
dict_package_name (str) – package name for dictionary lookup
parent_package (MFPackage) – parent package
- property model_dict
Return a dictionary of models associated with this simulation.
- Returns:
model dict – dictionary of models
- Return type:
- property model_names
Return a list of model names associated with this simulation.
- Returns:
list
- Return type:
list of model names
- plot(model_list: str | List[str] | None = None, SelPackList=None, **kwargs)[source]
Plot simulation or models.
Method to plot a whole simulation or a series of models that are part of a simulation.
- Parameters:
model_list (list, optional) – List of model names to plot, if none all models will be plotted
SelPackList (list, optional) – List of package names to plot, if none all packages will be plotted
kwargs –
- filename_basestr
Base file name that will be used to automatically generate file names for output image files. Plots will be exported as image files if file_name_base is not None. (default is None)
- file_extensionstr
Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)
- mflayint
MODFLOW zero-based layer number to return. If None, then all layers will be included. (default is None)
- kperint
MODFLOW zero-based stress period number to return. (default is zero)
- keystr
MFList dictionary key. (default is None)
- Returns:
axes – matplotlib.pyplot.axes objects
- Return type:
(list)
- register_exchange_file(package)[source]
Register an exchange package file with the simulation. This is a call-back method made from the package and should not be called directly.
- Parameters:
package (MFPackage) – Exchange package object to register
- register_model(model, model_type, model_name, model_namefile)[source]
Add a model to the simulation. This is a call-back method made from the package and should not be called directly.
- Parameters:
- Returns:
model_structure_object
- Return type:
- register_package(package, add_to_package_list=True, set_package_name=True, set_package_filename=True)[source]
Register a package file with the simulation. This is a call-back method made from the package and should not be called directly.
- Parameters:
- Returns:
(path
- Return type:
tuple, package structure : MFPackageStructure)
- register_solution_package(solution_file: MFPackage, model_list: str | List[str])[source]
Register a solution package with the simulation.
- Parameters
- solution_fileMFPackage
solution package to register
- model_listlist of strings
list of models using the solution package to be registered
- remove_exchange_file(package)[source]
Removes the exchange file “package”. This is for internal flopy library use only.
- Parameters:
package (MFPackage) – Exchange package to be removed
- remove_model(model_name)[source]
Remove model with name model_name from the simulation
- Parameters:
model_name (str) – Model name to remove from simulation
- remove_package(package_name)[source]
Removes package from the simulation. package_name can be the package’s name, type, or package object to be removed from the model.
- Parameters:
package_name (str) – Name of package to be removed
- rename_all_packages(name)[source]
Rename all packages with name as prefix.
- Parameters:
name (str) – Prefix of package names
- rename_model_namefile(model, new_namefile)[source]
Rename a model’s namefile. For internal flopy library use only.
- run_simulation(silent=None, pause=False, report=False, normal_msg='normal termination', use_async=False, cargs=None)[source]
Run the simulation.
- Parameters:
silent (bool) – Run in silent mode
pause (bool) – Pause at end of run
report (bool) – Save stdout lines to a list (buff)
normal_msg (str or list) – Normal termination message used to determine if the run terminated normally. More than one message can be provided using a list. (default is ‘normal termination’)
use_async (bool) – Asynchronously read model stdout and report with timestamps. good for models that take long time to run. not good for models that run really fast
cargs (str or list of strings) – Additional command line arguments to pass to the executable. default is None
- Returns:
success (bool)
buff (list of lines of stdout)
- set_all_data_external(check_data=True, external_data_folder=None)[source]
Sets the simulation’s list and array data to be stored externally.
- Parameters:
check_data (bool) – Determines if data error checking is enabled during this process. Data error checking can be slow on large datasets.
external_data_folder (str or PathLike) – Path relative to the simulation path or model relative path (see use_model_relative_path parameter), where external data will be stored
- set_sim_path(path: str | PathLike)[source]
Return a list of output data keys.
- Parameters:
path (str) – Relative or absolute path to simulation root folder.
- property sim_package_list
List of all “simulation level” packages
- update_package_filename(package, new_name)[source]
Updates internal arrays to be consistent with a new file name. This is for internal flopy library use only.
- write_simulation(ext_file_action=ExtFileAction.copy_relative_paths, silent=False)[source]
Write the simulation to files.
- Parameters
- ext_file_actionExtFileAction
Defines what to do with external files when the simulation path has changed. Defaults to copy_relative_paths which copies only files with relative paths, leaving files defined by absolute paths fixed.
- silentbool
Writes out the simulation in silent mode (verbosity_level = 0)
- class MFSimulationData(path: str | PathLike, mfsim)[source]
Bases:
object
Class containing MODFLOW simulation data and file formatting data. Use MFSimulationData to set simulation-wide settings which include data formatting and file location settings.
- Parameters:
path (str) – path on disk to the simulation
- max_columns_of_data
Maximum columns of data before line wraps. For structured grids this is set to ncol by default. For all other grids the default is 20.
- Type:
- wrap_multidim_arrays
Whether to wrap line for multi-dimensional arrays at the end of a row/column/layer
- Type:
- write_headers
When true flopy writes a header to each package file indicating that it was created by flopy
- Type:
- sci_note_upper_thres
Numbers greater than this threshold are written in scientific notation
- Type:
- sci_note_lower_thres
Numbers less than this threshold are written in scientific notation
- Type:
- mfpath
File path location information for the simulation
- Type:
- mfdata
Custom dictionary containing all model data for the simulation
- Type:
- property float_characters
Gets max characters used in floating point numbers.
- property float_precision
Gets precision of floating point numbers.
- property lazy_io
- property max_columns_of_data
- class SimulationDict(path=None)[source]
Bases:
dict
Class containing custom dictionary for MODFLOW simulations. Dictionary contains model data. Dictionary keys are “paths” to the data that include the model and package containing the data.
Behaves as an dict with some additional features described below.
- Parameters:
path (MFFileMgmt) – Object containing path information for the simulation