flopy.mf6.modflow.mfsimulation module

mfsimulation module. contains the MFSimulation class.

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 MODFLOW6 simulation.

Parameters:
  • sim_name (string) – name of the simulation.
  • version (string) – MODFLOW version
  • exe_name (string) – relative path to MODFLOW executable from the simulation working folder
  • sim_ws (string) – path to simulation working folder
  • 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
  • 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
sim_name

name of the simulation

Type:string
_models

all models in the simulation

Type:OrderedDict
_exchange_files

all exchange packages in the simulation

Type:list
_ims_files

all ims packages in the simulation

Type:list
name_file

simulation name file

Type:MFPackage
_tdis_file

simulation tdis file

sim_package_list

list of all “simulation level” packages

load : (sim_name : string, version : string, exe_name : string,
sim_ws : string, strict : boolean, verbosity_level : VerbosityLevel) : MFSimulation

a class method that loads a simulation from files

write_simulation()[source]

writes the simulation to files

set_sim_path : (path : string)

set the file path to the root simulation folder and updates all model file paths

get_model : (model_name : string)
: [MFModel]

returns the models in the simulation with a given model name, name file name, or model type

add_model : (model : MFModel, sln_group : integer)

add model to the simulation

remove_model : (model_name : string)

remove model from the simulation

get_package : (type : string)

returns a simulation package based on package type

add_package : (package : MFPackage)

adds a simulation package to the simulation

remove_package : (package_name : string)

removes package from the simulation. package_name can be the package’s name, type, or package object to be removed from the model

is_valid : () : boolean

checks the validity of the solution and all of its models and packages

set_all_data_external : (check_data : boolean)

sets the simulation’s list and array data to be stored externally, check_data determines if data error checking is enabled during this process

Examples

>>> s = MFSimulation.load('my simulation', 'simulation.nam')
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:

Return type:

None

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow.load('model.nam')
>>> m.check()
delete_output_files()[source]

Delete simulation output files.

get_exchange_file(filename)[source]

Get a specified exchange file.

Parameters:filename (string) – name of exchange file to get
Returns:exchange package
Return type:MFPackage
get_gnc_file(filename)[source]

Get a specified gnc file.

Parameters:filename (string) – name of gnc file to get
Returns:gnc package
Return type:MFPackage
get_ims_package(key)[source]

Add a model to the simulation.

Parameters:key (str) – ims package key
Returns:ims_package
Return type:ModflowIms
get_model(model_name=None)[source]

Load an existing model.

Parameters:model_name (string) – name of model to get
Returns:model
Return type:MFModel
get_mvr_file(filename)[source]

Get a specified mover file.

Parameters:filename (string) – name of mover file to get
Returns:mover package
Return type:MFPackage
is_valid()[source]

Check all packages and models in the simulation to verify validity.

Returns:valid – simulation validity
Return type:boolean
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 (string) – name of the simulation.
  • version (string) – MODFLOW version
  • exe_name (string) – relative path to MODFLOW executable from the simulation working folder
  • sim_ws (string) – path to simulation working folder
  • strict (boolean) – 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 (string) – the file type
  • fname (string) – the name of the file containing the package input
  • pname (string) – the user-defined name for the package
  • strict (bool) – strict mode when loading the file
  • ref_path (string) – path to the file. uses local path if set to None
  • dict_package_name (string) – package name for dictionary lookup
  • parent_package (MFPackage) – parent package
model_dict

Return a dictionary of models.

Returns:model dict – dictionary of models
Return type:dict
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_base : str
    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_extension : str
    Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)
    mflay : int
    MODFLOW zero-based layer number to return. If None, then all layers will be included. (default is None)
    kper : int
    MODFLOW zero-based stress period number to return. (default is zero)
    key : str
    MfList dictionary key. (default is None)
Returns:

axes

Return type:

(list) matplotlib.pyplot.axes objects

register_exchange_file(package)[source]

Register an exchange package file with the simulation.

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_file : MFPackage
ims package to register
model_list : list 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.

Parameters:
  • model (MFModel) – model object to add to simulation
  • sln_group (string) – solution group of model
Returns:

model_structure_object

Return type:

MFModelStructure

register_package(package, add_to_package_list=True, set_package_name=True, set_package_filename=True)[source]

Register a package file with the simulation.

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_model(model_name)[source]

Remove a model from the simulation.

Parameters:model_name (string) – model name to remove from simulation
remove_package(package_name)[source]

Remove a package.

Parameters:(str) (package_name) –
rename_all_packages(name)[source]

Rename all packages with name as prefix.

Parameters:(str) (name) –
run_simulation(silent=None, pause=False, report=False, normal_msg='normal termination', use_async=False, cargs=None)[source]

Run the simulation.

Parameters:
  • (bool) (report) – run in silent mode
  • (bool) – pause at end of run
  • (bool) – save stdout lines to a list (buff)
  • (str or list) (normal_msg) – 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 ((boolean)) – 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 : boolean buff : list of lines of stdout

Return type:

(success, buff)

set_all_data_external(check_data=True)[source]
set_sim_path(path)[source]

Return a list of output data keys.

Parameters:(bool) (print_keys) –
Returns:list
Return type:keys for requesting binary output
sim_package_list
write_simulation(ext_file_action=<ExtFileAction.copy_relative_paths: 3>, silent=False)[source]

Write the simulation to files.

Parameters
ext_file_action : ExtFileAction
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.
silent : bool
writes out the simulation in silent mode (verbosity_level = 0)
class MFSimulationData(path)[source]

Bases: object

Class containing MODFLOW simulation data and file formatting data.

Parameters:path (string) – path on disk to the simulation
indent_string

string used to define how much indent to use (file formatting)

Type:string
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

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:MFFileMgmt
model_dimensions

dictionary containing discretization information for each model

Type:OrderedDict
mfdata

custom dictionary containing all model data for the simulation

Type:SimulationDict
set_sci_note_lower_thres(value)[source]

Set threshold number.

Sets threshold number where any number smaller than threshold is represented in scientific notation.

Parameters:(float) (value) –
set_sci_note_upper_thres(value)[source]

Set threshold number.

Sets threshold number where any number larger than threshold is represented in scientific notation.

Parameters:(float) (value) –
class SimulationDict(path=None)[source]

Bases: collections.OrderedDict

Class containing custom dictionary for MODFLOW simulations.

Behaves as an OrderedDict with some additional features described below.

Parameters:path (MFFileMgmt) – object containing path information for the simulation
find_in_path : (key_path : string, key_leaf : string) : MFData, int

attempt to find key_leaf in a partial key path key_path

output_keys : (print_keys : boolean) : list

return a list of output data keys the dictionary supports for output data, print_keys allows those keys to be printed to output.

input_keys : ()

print all input data keys

observation_keys : ()

print observation keys

keys : ()

print all keys, input and output

plot : (key : string, **kwargs)

plot data with key ‘key’ using **kwargs for plot options

shapefile : (key : string, **kwargs)

create shapefile from data with key ‘key’ and with additional fields in **kwargs

rename_all_packages : (name : string)

rename all packages in the simulation and associated models

find_in_path(key_path, key_leaf)[source]

Attempt to find key_leaf in a partial key path key_path.

Parameters:
  • (string) (key_leaf) –
  • (string)
  • Returns – MFData: Data found at the path. int: Data index
input_keys()[source]

Return a list of input data keys.

Returns:input data keys
Return type:list
keys()[source]

Return a list of all keys.

Returns:all keys
Return type:list
observation_keys()[source]

Return a list of observation keys.

Returns:observation keys
Return type:list
output_keys(print_keys=True)[source]

Return a list of output data keys.

Parameters:
  • (bool) (print_keys) –
  • Returns – list: keys for requesting binary output