flopy.mf6.mfmodel module

class MFModel(simulation, model_type='gwf6', modelname='model', model_nam_file=None, version='mf6', exe_name='mf6.exe', add_to_simulation=True, structure=None, model_rel_path='.', verbose=False, **kwargs)[source]

Bases: flopy.mf6.mfbase.PackageContainer, flopy.mbase.ModelInterface

MODFLOW-6 model base class. Represents a single model in a simulation.

Parameters:
  • simulation_data (MFSimulationData) – Simulation data object of the simulation this model will belong to
  • structure (MFModelStructure) – Structure of this type of model
  • modelname (str) – Name of the model
  • model_nam_file (str) – Relative path to the model name file from model working folder
  • version (str) – Version of modflow
  • exe_name (str) – Model executable name
  • model_ws (str) – Model working folder path
  • disfile (str) – Relative path to dis file from model working folder
  • grid_type (str) – Type of grid the model will use (structured, unstructured, vertices)
  • verbose (bool) – Verbose setting for model operations (default False)
name

Name of the model

Type:str
exe_name

Model executable name

Type:str
packages

Dictionary of model packages

Type:OrderedDict(MFPackage)
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:

success

Return type:

bool

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow.load('model.nam')
>>> m.check()
exename

MODFLOW executable name

export(f, **kwargs)[source]

Method to export a model to a shapefile or netcdf file

Parameters:
  • f (str) – File name (“.nc” for netcdf or “.shp” for shapefile) or dictionary of ….
  • **kwargs (keyword arguments) –
    modelgrid: flopy.discretization.Grid
    User supplied modelgrid object which will supercede the built in modelgrid object
    epsg : int
    EPSG projection code
    prj : str
    The prj file name

    if fmt is set to ‘vtk’, parameters of vtk.export_model

get_grid_type()[source]

Return the type of grid used by model ‘model_name’ in simulation containing simulation data ‘simulation_data’.

Returns:grid type
Return type:DiscretizationType
get_ims_package()[source]

Get the IMS package associated with this model.

Returns:IMS package
Return type:ModflowIms
get_steadystate_list()[source]

Returns a list of stress periods that are steady state.

Returns:steady state list
Return type:list
hdry

Dry cell value

hnoflo

No-flow cell value

is_valid()[source]

Checks the validity of the model and all of its packages

Returns:valid
Return type:bool
laycbd

Quasi-3D confining bed. Not supported in MODFLOW-6.

Returns:None
Return type:None
laytyp

Layering type

classmethod load_base(simulation, structure, modelname='NewModel', model_nam_file='modflowtest.nam', mtype='gwf', version='mf6', exe_name='mf6.exe', strict=True, model_rel_path='.', load_only=None)[source]

Class method that loads an existing model.

Parameters:
  • simulation (MFSimulation) – simulation object that this model is a part of
  • simulation_data (MFSimulationData) – simulation data object
  • structure (MFModelStructure) – structure of this type of model
  • model_name (str) – name of the model
  • model_nam_file (str) – relative path to the model name file from model working folder
  • version (str) – version of modflow
  • exe_name (str) – model executable name
  • model_ws (str) – model working folder relative to simulation working folder
  • strict (bool) – strict mode when loading files
  • model_rel_path (str) – relative path of model folder to simulation folder
  • 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’, ‘my_well_package_1’]
Returns:

model

Return type:

MFModel

Examples

load_package(ftype, fname, pname, strict, ref_path, dict_package_name=None, parent_package=None)[source]

Loads a package from a file. This method is used internally by FloPy and is not intended for the end user.

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

Examples

model_ws

Model file path.

modeldiscrit

Basic model spatial discretization information. This is used internally prior to model spatial discretization information being fully loaded.

Returns:model grid – FloPy object containing basic spatial discretization information for the model.
Return type:Grid subclass
modelgrid

Model spatial discretization information.

Returns:model grid – FloPy object containing spatial discretization information for the model.
Return type:Grid subclass
modeltime

Model time discretization information.

Returns:modeltime – FloPy object containing time discretization information for the simulation.
Return type:ModelTime
namefile

Model namefile object.

nper

Number of stress periods.

Returns:nper – Number of stress periods in the simulation.
Return type:int
output
packagelist

List of model packages.

plot(SelPackList=None, **kwargs)[source]

Plot 2-D, 3-D, transient 2-D, and stress period list (MfList) model input data from a model instance

Parameters:
  • model – Flopy model instance
  • SelPackList – (list) list of package names to plot, if none all packages will be plotted
  • **kwargs

    dict 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 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:

list

Empty list is returned if filename_base is not None. Otherwise a list of matplotlib.pyplot.axis are returned.

Return type:

axes

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

Registers a package with the model. This method is used internally by FloPy and is not intended for use by the end user.

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, package structure

Return type:

tuple, MFPackageStructure

remove_package(package_name)[source]

Removes package and all child packages from the model. package_name can be the package’s name, type, or package object to be removed from the model.

Parameters:package_name (str) – Package name, package type, or package object to be removed from the model.
rename_all_packages(name)[source]

Renames all package files in the model.

Parameters:name (str) – Prefix of package names. Packages files will be named <name>.<package ext>.
set_all_data_external(check_data=True, external_data_folder=None)[source]

Sets the model’s list and array data to be stored externally.

Parameters:
  • check_data (bool) – Determines if data error checking is enabled during this process.
  • 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_all_data_internal(check_data=True)[source]

Sets the model’s list and array data to be stored externally.

Parameters:check_data (bool) – Determines if data error checking is enabled during this process.
set_model_relative_path(model_ws)[source]

Sets the file path to the model folder relative to the simulation folder and updates all model file paths, placing them in the model folder.

Parameters:model_ws (str) – Model working folder relative to simulation working folder
solver_tols

Returns the solver inner hclose and rclose values.

Returns:inner_hclose, rclose
Return type:float, float
verbose

Verbose setting for model operations (True/False)

version

Version of MODFLOW

write(ext_file_action=<ExtFileAction.copy_relative_paths: 3>)[source]

Writes out model’s package 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.