flopy.mf6.modflow.mfsimulation module¶
- class MFSimulation(sim_name='sim', version='mf6', exe_name='mf6.exe', sim_ws='.', verbosity_level=1, continue_=None, nocheck=None, memory_print_option=None, write_headers=True)[source]¶
Bases:
flopy.mf6.mfbase.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) – Relative path to MODFLOW 6 executable from the simulation working folder.
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.
Examples
>>> s = MFSimulation.load('my simulation', 'simulation.nam')
- sim_name¶
Name of the simulation
- Type
str
- check(f=None, verbose=True, level=1)[source]¶
Check model data for common errors.
- Parameters
f (str or file handle) – String defining file name or file handle for summary file of check method output. If a string is passed a file handle is created. If f is None, check 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
list
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_exchange_file(filename)[source]¶
Get a specified exchange file.
- Parameters
filename (str) – Name of exchange file to get
- Returns
exchange package
- Return type
- get_gnc_file(filename)[source]¶
Get a specified gnc file.
- Parameters
filename (str) – Name of gnc file to get
- Returns
gnc package
- Return type
- get_ims_package(key)[source]¶
Get the ims package with the specified key.
- Parameters
key (str) – ims package file name
- Returns
ims_package
- Return type
- get_model(model_name=None)[source]¶
Returns the models in the simulation with a given model name, name file name, or model type.
- Parameters
model_name (str) – Name of the model to get. Passing in None or an empty list will get the first model.
- Returns
model
- Return type
- get_mvr_file(filename)[source]¶
Get a specified mover file.
- Parameters
filename (str) – Name of mover file to get
- Returns
mover package
- Return type
- get_mvt_file(filename)[source]¶
Get a specified mvt file.
- Parameters
filename (str) – Name of mover transport file to get
- Returns
mover transport package
- Return 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
bool
- classmethod load(sim_name='modflowsim', version='mf6', exe_name='mf6.exe', sim_ws='.', strict=True, verbosity_level=1, load_only=None, verify_data=False, write_headers=True)[source]¶
Load an existing model.
- Parameters
sim_name (str) – Name of the simulation.
version (str) – MODFLOW version
exe_name (str) – Relative path to MODFLOW executable from the simulation working folder
sim_ws (str) – Path to simulation working folder
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
- Returns
sim
- Return type
MFSimulation object
Examples
>>> s = flopy.mf6.mfsimulation.load('my simulation')
- load_package(ftype, fname, pname, strict, ref_path, dict_package_name=None, parent_package=None)[source]¶
Load a package from a file.
- Parameters
ftype (str) – the file type
fname (str) – the name 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
dict
- property model_names¶
Return a list of model names associated with this simulation.
- Returns
list
- Return type
list of model names
- plot(model_list=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)) – List of model names to plot, if none all models will be plotted
SelPackList ((list)) – 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_ims_package(ims_file, model_list)[source]¶
Register an ims package with the simulation.
- Parameters
- ims_fileMFPackage
ims package to register
- model_listlist of strings
list of models using the ims package to be registered
- 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
model (MFModel) – Model object to add to simulation
sln_group (str) – Solution group of model
- 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
package (MFPackage) – Package to register
add_to_package_list (bool) – Add package to lookup list
set_package_name (bool) – Produce a package name for this package
set_package_filename (bool) – Produce a filename for this package
- Returns
(path
- Return type
tuple, package structure : MFPackageStructure)
- 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.
- Parameters
model (MFModel) – Model object whose namefile to rename
new_namefile (str) – Name of the new namefile
- 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 – Folder, 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)[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.
- Parameters
package (MFPackage) – Package with new name
new_name (str) – Package’s new name
- 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, 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
- indent_string¶
String used to define how much indent to use (file formatting)
- Type
str
- internal_formatting¶
List defining string to use for internal formatting
- Type
list
- external_formatting¶
List defining string to use for external formatting
- Type
list
- open_close_formatting¶
List defining string to use for open/close
- Type
list
- 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
int
- wrap_multidim_arrays¶
Whether to wrap line for multi-dimensional arrays at the end of a row/column/layer
- Type
bool
- float_precision¶
Number of decimal points to write for a floating point number
- Type
int
- float_characters¶
Number of characters a floating point number takes up
- Type
int
- write_headers¶
When true flopy writes a header to each package file indicating that it was created by flopy
- Type
bool
- sci_note_upper_thres¶
Numbers greater than this threshold are written in scientific notation
- Type
float
- sci_note_lower_thres¶
Numbers less than this threshold are written in scientific notation
- Type
float
- mfpath¶
File path location information for the simulation
- Type
- model_dimensions¶
Dictionary containing discretization information for each model
- Type
dict
- mfdata¶
Custom dictionary containing all model data for the simulation
- Type
- 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
- find_in_path(key_path, key_leaf)[source]¶
Attempt to find key_leaf in a partial key path key_path.
- Parameters
key_path (str) – partial path to the data
key_leaf (str) – name of the data
- Returns
Data (MFData,)
index (int)