class ModflowChd(Package): """ MODFLOW Constant Head Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. stress_period_data : list of boundaries, recarrays, or dictionary of boundaries. Each chd cell is defined through definition of layer (int), row (int), column (int), shead (float), ehead (float) shead is the head at the start of the stress period, and ehead is the head at the end of the stress period. The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ], 1: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ], ... kper: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of chds will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory. extension : string Filename extension (default is 'chd') unitnumber : int File unit number (default is 24). Attributes ---------- mxactc : int Maximum number of chds for all stress periods. This is calculated automatically by FloPy based on the information in stress_period_data. Methods ------- See Also -------- Notes ----- Parameters are supported in Flopy only when reading in existing models. Parameter values are converted to native values in Flopy and the connection to "parameters" is thus nonexistent. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcd = [[[2, 3, 4, 10., 10.1]]] #this chd will be applied to all >>> #stress periods >>> chd = flopy.modflow.ModflowChd(m, stress_period_data=lrcd) """ def __init__(self, model, stress_period_data=None, dtype=None, extension='chd', unitnumber=24, **kwargs): # Call ancestor's init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'CHD', unitnumber) self.url = 'chd.htm' self.heading = '# CHD for MODFLOW, generated by Flopy.' if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype( structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) self.np = 0 self.parent.add_package(self) def ncells(self): # Returns the maximum number of cells that have recharge (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_chd = open(self.fn_path, 'w') f_chd.write('{0:s}\n'.format(self.heading)) f_chd.write(' {0:9d}\n'.format(self.stress_period_data.mxact)) self.stress_period_data.write_transient(f_chd) f_chd.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfchd error adding record to list: " + str(e)) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that corresponds to dtype dtype = ModflowChd.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("shead", np.float32), ("ehead", np.float32)]) else: dtype = np.dtype([("node", np.int), ("shead", np.float32), ("ehead", np.float32)]) return dtype @staticmethod def load(f, model, nper=None, ext_unit_dict=None): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- chd : ModflowChd object ModflowChd object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> wel = flopy.modflow.ModflowChd.load('test.chd', m) """ if model.verbose: sys.stdout.write('loading chd package file...\n') return Package.load(model, ModflowChd, f, nper)
class ModflowRiv(Package): """ MODFLOW River Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, or recarray of boundaries, or dictionary of boundaries. Each river cell is defined through definition of layer (int), row (int), column (int), stage (float), cond (float), rbot (float). The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], 1: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], ... kper: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of rivers will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory. dtype : custom datatype of stress_period_data. (default is None) If None the default river datatype will be applied. naux : int number of auxiliary variables extension : string Filename extension (default is 'riv') unitnumber : int File unit number (default is 18). options : list of strings Package options. (default is None). Attributes ---------- mxactr : int Maximum number of river cells for a stress period. This is calculated automatically by FloPy based on the information in layer_row_column_data. Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcd = {} >>> lrcd[0] = [[2, 3, 4, 15.6, 1050., -4]] #this river boundary will be >>> #applied to all stress periods >>> riv = flopy.modflow.ModflowRiv(m, stress_period_data=lrcd) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, extension='riv', unitnumber=18, options=None, **kwargs): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'RIV', unitnumber) self.heading = '# RIV for MODFLOW, generated by Flopy.' self.url = 'riv.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.mxactr = 0 self.np = 0 if options is None: options = [] self.options = options if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) # self.stress_period_data = MfList(model, self.dtype, stress_period_data) self.stress_period_data = MfList(self, stress_period_data) self.parent.add_package(self) def check(self, f=None, verbose=True, level=1): """ Check package 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 ------- None Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow.load('model.nam') >>> m.riv.check() """ basechk = super(ModflowRiv, self).check(verbose=False) chk = check(self, f=f, verbose=verbose, level=level) chk.summary_array = basechk.summary_array for per in self.stress_period_data.data.keys(): if isinstance(self.stress_period_data.data[per], np.recarray): spd = self.stress_period_data.data[per] inds = (spd.k, spd.i, spd.j) if self.parent.structured else (spd.node) # check that river stage and bottom are above model cell bottoms # also checks for nan values botms = self.parent.dis.botm.array[inds] for elev in ['stage', 'rbot']: chk.stress_period_data_values(spd, spd[elev] < botms, col=elev, error_name='{} below cell bottom'.format(elev), error_type='Error') # check that river stage is above the rbot chk.stress_period_data_values(spd, spd['rbot'] > spd['stage'], col='stage', error_name='RIV stage below rbots', error_type='Error') chk.summarize() return chk @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recarray that correponds to dtype dtype = ModflowRiv.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) else: dtype = np.dtype([("node", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) return dtype def ncells(self): # Return the maximum number of cells that have river # (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self, check=True): """ Write the package file. Parameters ---------- check : boolean Check package data for common errors. (default True) Returns ------- None """ if check: # allows turning off package checks when writing files at model level self.check(f='{}.chk'.format(self.name[0]), verbose=self.parent.verbose, level=1) f_riv = open(self.fn_path, 'w') f_riv.write('{0}\n'.format(self.heading)) line = '{0:10d}{1:10d}'.format(self.stress_period_data.mxact, self.ipakcb) for opt in self.options: line += ' ' + str(opt) line += '\n' f_riv.write(line) self.stress_period_data.write_transient(f_riv) f_riv.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfriv error adding record to list: " + str(e)) @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. check : boolean Check package data for common errors. (default True) Returns ------- rch : ModflowRiv object ModflowRiv object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> riv = flopy.modflow.ModflowRiv.load('test.riv', m) """ if model.verbose: sys.stdout.write('loading riv package file...\n') return Package.load(model, ModflowRiv, f, nper, check=check)
class ModflowWel(Package): """ MODFLOW Well Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, or recarray of boundaries, or dictionary of boundaries Each well is defined through definition of layer (int), row (int), column (int), flux (float). The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ], 1: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ], ... kper: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of wells will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory options : list of strings Package options. (default is None). extension : string Filename extension (default is 'wel') unitnumber : int File unit number (default is 11). Attributes ---------- mxactw : int Maximum number of wells for a stress period. This is calculated automatically by FloPy based on the information in stress_period_data. Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcq = {0:[[2, 3, 4, -100.]], 1:[[2, 3, 4, -100.]]} >>> wel = flopy.modflow.ModflowWel(m, stress_period_data=lrcq) """ def __init__( self, model, ipakcb=0, stress_period_data=None, dtype=None, extension="wel", unitnumber=20, options=None ): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, "WEL", unitnumber) self.heading = "# Well file for MODFLOW, generated by Flopy." self.url = "wel.htm" if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.np = 0 if options is None: options = [] self.specify = False for idx, opt in enumerate(options): if "specify" in opt: t = opt.strip().split() self.specify = True self.phiramp = np.float(t[1]) self.phiramp_unit = np.int(t[2]) options.pop(idx) break self.options = options self.parent.add_package(self) if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) def ncells(self): # Returns the maximum number of cells that have a well # (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_wel = open(self.fn_path, "w") f_wel.write("%s\n" % self.heading) line = " {0:9d} {1:9d}".format(self.stress_period_data.mxact, self.ipakcb) for opt in self.options: line += " " + str(opt) line += "\n" f_wel.write(line) if self.specify and self.parent.version == "mfnwt": f_wel.write("SPECIFY {0:10.5g} {1:10d}\n".format(self.phiramp, self.phiramp_unit)) self.stress_period_data.write_transient(f_wel) f_wel.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfwel error adding record to list: " + str(e)) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("flux", np.float32)]) else: dtype = np.dtype([("node", np.int), ("flux", np.float32)]) return dtype @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that correponds to dtype dtype = ModflowWel.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0e10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- wel : ModflowWel object ModflowWel object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> wel = flopy.modflow.ModflowWel.load('test.wel', m) """ if model.verbose: sys.stdout.write("loading wel package file...\n") return Package.load(model, ModflowWel, f, nper, check=check)
class ModflowGhb(Package): """ MODFLOW General-Head Boundary Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, recarray of boundaries or, dictionary of boundaries. Each ghb cell is defined through definition of layer(int), row(int), column(int), stage(float), conductance(float) The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], 1: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], ... kper: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ] } Note that if no values are specified for a certain stress period, then the list of boundaries for the previous stress period for which values were defined is used. Full details of all options to specify stress_period_data can be found in the flopy3boundaries Notebook in the basic subdirectory of the examples directory dtype : dtype definition if data type is different from default options : list of strings Package options. (default is None). extension : string Filename extension (default is 'ghb') unitnumber : int File unit number (default is 23). Attributes ---------- Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> ml = flopy.modflow.Modflow() >>> lrcsc = {0:[2, 3, 4, 10., 100.]} #this ghb will be applied to all >>> #stress periods >>> ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=lrcsc) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, no_print=False, options=None, extension='ghb', unitnumber=23): """ Package constructor. """ Package.__init__(self, model, extension, 'GHB', unitnumber) self.heading = '# GHB for MODFLOW, generated by Flopy.' self.url = 'ghb.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.no_print = no_print self.np = 0 if options is None: options = [] if self.no_print: options.append('NOPRINT') self.options = options self.parent.add_package(self) if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) def ncells(self): """ Returns the maximum number of cells that have a ghb cell (developped for MT3DMS SSM package) """ return self.stress_period_data.mxact def write_file(self, check=True): """ Write the package file. Parameters ---------- check : boolean Check package data for common errors. (default True) Returns ------- None """ if check: # allows turning off package checks when writing files at model level self.check(f='{}.chk'.format(self.name[0]), verbose=self.parent.verbose, level=1) f_ghb = open(self.fn_path, 'w') f_ghb.write('{}\n'.format(self.heading)) f_ghb.write('{:10d}{:10d}'.format(self.stress_period_data.mxact, self.ipakcb)) for option in self.options: f_ghb.write(' {}'.format(option)) f_ghb.write('\n') self.stress_period_data.write_transient(f_ghb) f_ghb.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfghb error adding record to list: " + str(e)) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that correponds to dtype dtype = ModflowGhb.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("bhead", np.float32), ("cond", np.float32)]) else: dtype = np.dtype([("node", np.int), ("bhead", np.float32), ("cond", np.float32)]) return dtype @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. check : boolean Check package data for common errors. (default True) Returns ------- ghb : ModflowGhb object ModflowGhb object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> ghb = flopy.modflow.ModflowGhb.load('test.ghb', m) """ if model.verbose: sys.stdout.write('loading ghb package file...\n') return Package.load(model, ModflowGhb, f, nper, check=check)
class ModflowDrn(Package): """ MODFLOW Drain Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries or recarray of boundaries or dictionary of boundaries Each drain cell is defined through definition of layer(int), row(int), column(int), elevation(float), conductance(float) The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of stress_period_data = {0: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], 1: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], ... kper: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ] } Note that if no values are specified for a certain stress period, then the list of boundaries for the previous stress period for which values were defined is used. Full details of all options to specify stress_period_data can be found in the flopy3boundaries Notebook in the basic subdirectory of the examples directory dtype : dtype definition if data type is different from default options : list of strings Package options. (default is None). extension : string Filename extension (default is 'drn') unitnumber : int File unit number (default is 21). Attributes ---------- Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> ml = flopy.modflow.Modflow() >>> lrcec = {0:[2, 3, 4, 10., 100.]} #this drain will be applied to all >>> #stress periods >>> drn = flopy.modflow.ModflowDrn(ml, stress_period_data=lrcec) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, extension='drn', unitnumber=21, options=None, **kwargs): """ Package constructor """ Package.__init__(self, model, extension, 'DRN', unitnumber) # Call ancestor's init to set self.parent, extension, name and unit number self.heading = '# DRN for MODFLOW, generated by Flopy.' self.url = 'drn.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.np = 0 if options is None: options = [] self.options = options if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) self.parent.add_package(self) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("elev", np.float32), ("cond", np.float32)]) else: dtype = np.dtype([("node", np.int), ("elev", np.float32), ("cond", np.float32)]) return dtype def ncells(self): # Returns the maximum number of cells that have drains (developed for MT3DMS SSM package) # print 'Function must be implemented properly for drn package' return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_drn = open(self.fn_path, 'w') f_drn.write('{0}\n'.format(self.heading)) # f_drn.write('%10i%10i\n' % (self.mxactd, self.idrncb)) line = '{0:10d}{1:10d}'.format(self.stress_period_data.mxact, self.ipakcb) for opt in self.options: line += ' ' + str(opt) line += '\n' f_drn.write(line) self.stress_period_data.write_transient(f_drn) f_drn.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfdrn error adding record to list: " + str(e)) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that correponds to dtype dtype = ModflowDrn.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def load(f, model, nper=None, ext_unit_dict=None): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- drn : ModflowDrn object ModflowDrn object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> drn = flopy.modflow.ModflowDrn.load('test.drn', m) """ if model.verbose: sys.stdout.write('loading drn package file...\n') return Package.load(model, ModflowDrn, f, nper)
class ModflowChd(Package): """ MODFLOW Constant Head Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. stress_period_data : list of boundaries, recarrays, or dictionary of boundaries. Each chd cell is defined through definition of layer (int), row (int), column (int), shead (float), ehead (float) shead is the head at the start of the stress period, and ehead is the head at the end of the stress period. The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ], 1: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ], ... kper: [ [lay, row, col, shead, ehead], [lay, row, col, shead, ehead], [lay, row, col, shead, ehead] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of chds will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory. extension : string Filename extension (default is 'chd') unitnumber : int File unit number (default is 24). Attributes ---------- mxactc : int Maximum number of chds for all stress periods. This is calculated automatically by FloPy based on the information in stress_period_data. Methods ------- See Also -------- Notes ----- Parameters are supported in Flopy only when reading in existing models. Parameter values are converted to native values in Flopy and the connection to "parameters" is thus nonexistent. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcd = {0:[[2, 3, 4, 10., 10.1]]} #this chd will be applied to all >>> #stress periods >>> chd = flopy.modflow.ModflowChd(m, stress_period_data=lrcd) """ def __init__(self, model, stress_period_data=None, dtype=None, options=None, extension='chd', unitnumber=24, **kwargs): # Call ancestor's init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'CHD', unitnumber) self.url = 'chd.htm' self.heading = '# CHD for MODFLOW, generated by Flopy.' if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) self.np = 0 if options is None: options = [] self.options = options self.parent.add_package(self) def ncells(self): # Returns the maximum number of cells that have recharge (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_chd = open(self.fn_path, 'w') f_chd.write('{0:s}\n'.format(self.heading)) f_chd.write(' {0:9d}'.format(self.stress_period_data.mxact)) for option in self.options: f_chd.write(' {}'.format(option)) f_chd.write('\n') self.stress_period_data.write_transient(f_chd) f_chd.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfchd error adding record to list: " + str(e)) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that corresponds to dtype dtype = ModflowChd.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("shead", np.float32), ("ehead", np.float32)]) else: dtype = np.dtype([("node", np.int), ("shead", np.float32), ("ehead", np.float32)]) return dtype @staticmethod def load(f, model, nper=None, ext_unit_dict=None): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- chd : ModflowChd object ModflowChd object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> wel = flopy.modflow.ModflowChd.load('test.chd', m) """ if model.verbose: sys.stdout.write('loading chd package file...\n') return Package.load(model, ModflowChd, f, nper)
class ModflowRiv(Package): """ MODFLOW River Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, or recarray of boundaries, or dictionary of boundaries. Each river cell is defined through definition of layer (int), row (int), column (int), stage (float), cond (float), rbot (float). The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], 1: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], ... kper: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of rivers will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory. options : list of strings Package options. (default is None). naux : int number of auxiliary variables extension : string Filename extension (default is 'riv') unitnumber : int File unit number (default is 18). Attributes ---------- mxactr : int Maximum number of river cells for a stress period. This is calculated automatically by FloPy based on the information in layer_row_column_data. Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcd = {} >>> lrcd[0] = [[2, 3, 4, 15.6, 1050., -4]] #this river boundary will be >>> #applied to all stress periods >>> riv = flopy.modflow.ModflowRiv(m, stress_period_data=lrcd) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, extension='riv', unitnumber=18, options=None, **kwargs): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'RIV', unitnumber) self.heading = '# RIV for MODFLOW, generated by Flopy.' self.url = 'riv.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.mxactr = 0 self.np = 0 if options is None: options = [] self.options = options if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype( structured=self.parent.structured) # self.stress_period_data = MfList(model, self.dtype, stress_period_data) self.stress_period_data = MfList(self, stress_period_data) self.parent.add_package(self) def check(self, f=None, verbose=True, level=1): """ Check package 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 ------- None Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow.load('model.nam') >>> m.riv.check() """ basechk = super(ModflowRiv, self).check(verbose=False) chk = check(self, f=f, verbose=verbose, level=level) chk.summary_array = basechk.summary_array for per in self.stress_period_data.data.keys(): if isinstance(self.stress_period_data.data[per], np.recarray): spd = self.stress_period_data.data[per] inds = (spd.k, spd.i, spd.j) if self.parent.structured else (spd.node) # check that river stage and bottom are above model cell bottoms # also checks for nan values botms = self.parent.dis.botm.array[inds] for elev in ['stage', 'rbot']: chk.stress_period_data_values( spd, spd[elev] < botms, col=elev, error_name='{} below cell bottom'.format(elev), error_type='Error') # check that river stage is above the rbot chk.stress_period_data_values( spd, spd['rbot'] > spd['stage'], col='stage', error_name='RIV stage below rbots', error_type='Error') chk.summarize() return chk @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recarray that correponds to dtype dtype = ModflowRiv.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) else: dtype = np.dtype([("node", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) return dtype def ncells(self): # Return the maximum number of cells that have river # (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self, check=True): """ Write the package file. Parameters ---------- check : boolean Check package data for common errors. (default True) Returns ------- None """ if check: # allows turning off package checks when writing files at model level self.check(f='{}.chk'.format(self.name[0]), verbose=self.parent.verbose, level=1) f_riv = open(self.fn_path, 'w') f_riv.write('{0}\n'.format(self.heading)) line = '{0:10d}{1:10d}'.format(self.stress_period_data.mxact, self.ipakcb) for opt in self.options: line += ' ' + str(opt) line += '\n' f_riv.write(line) self.stress_period_data.write_transient(f_riv) f_riv.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfriv error adding record to list: " + str(e)) @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. check : boolean Check package data for common errors. (default True) Returns ------- rch : ModflowRiv object ModflowRiv object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> riv = flopy.modflow.ModflowRiv.load('test.riv', m) """ if model.verbose: sys.stdout.write('loading riv package file...\n') return Package.load(model, ModflowRiv, f, nper, check=check)
class ModflowRiv(Package): """ MODFLOW River Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries or recarray of boundaries or dictionary of boundaries Each river cell is defined through definition of layer (int), row (int), column (int), stage (float), cond (float), rbot (float). The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of stress_period_data = {0: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], 1: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ], ... kper: [ [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot], [lay, row, col, stage, cond, rbot] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of rivers will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory. options : list of strings Package options. (default is None). naux : int number of auxiliary variables extension : string Filename extension (default is 'riv') unitnumber : int File unit number (default is 18). Attributes ---------- mxactr : int Maximum number of river cells for a stress period. This is calculated automatically by FloPy based on the information in layer_row_column_data. Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcd = {} >>> lrcd[0] = [[2, 3, 4, 15.6, 1050., -4]] #this river boundary will be >>> #applied to all stress periods >>> riv = flopy.modflow.ModflowRiv(m, stress_period_data=lrcd) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, extension='riv', unitnumber=18, options=None, **kwargs): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'RIV', unitnumber) self.heading = '# RIV for MODFLOW, generated by Flopy.' self.url = 'riv.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.mxactr = 0 self.np = 0 if options is None: options = [] self.options = options if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(structured=self.parent.structured) # self.stress_period_data = MfList(model, self.dtype, stress_period_data) self.stress_period_data = MfList(self, stress_period_data) self.parent.add_package(self) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recarray that correponds to dtype dtype = ModflowRiv.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) else: dtype = np.dtype([("node", np.int), ("stage", np.float32), ("cond", np.float32), ("rbot", np.float32)]) return dtype def ncells(self): # Return the maximum number of cells that have river # (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_riv = open(self.fn_path, 'w') f_riv.write('{0}\n'.format(self.heading)) line = '{0:10d}{1:10d}'.format(self.stress_period_data.mxact, self.ipakcb) for opt in self.options: line += ' ' + str(opt) line += '\n' f_riv.write(line) self.stress_period_data.write_transient(f_riv) f_riv.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfriv error adding record to list: " + str(e)) @staticmethod def load(f, model, nper=None, ext_unit_dict=None): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- rch : ModflowRiv object ModflowRiv object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> riv = flopy.modflow.ModflowRiv.load('test.riv', m) """ if model.verbose: sys.stdout.write('loading riv package file...\n') return Package.load(model, ModflowRiv, f, nper)
class ModflowGhb(Package): """ MODFLOW General-Head Boundary Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, recarray of boundaries or, dictionary of boundaries. Each ghb cell is defined through definition of layer(int), row(int), column(int), stage(float), conductance(float) The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], 1: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ], ... kper: [ [lay, row, col, stage, cond], [lay, row, col, stage, cond], [lay, row, col, stage, cond], ] } Note that if no values are specified for a certain stress period, then the list of boundaries for the previous stress period for which values were defined is used. Full details of all options to specify stress_period_data can be found in the flopy3boundaries Notebook in the basic subdirectory of the examples directory dtype : dtype definition if data type is different from default options : list of strings Package options. (default is None). extension : string Filename extension (default is 'ghb') unitnumber : int File unit number (default is 23). Attributes ---------- Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> ml = flopy.modflow.Modflow() >>> lrcsc = {0:[2, 3, 4, 10., 100.]} #this ghb will be applied to all >>> #stress periods >>> ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=lrcsc) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, no_print=False, options=None, extension='ghb', unitnumber=23): """ Package constructor. """ Package.__init__(self, model, extension, 'GHB', unitnumber) self.heading = '# GHB for MODFLOW, generated by Flopy.' self.url = 'ghb.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.no_print = no_print self.np = 0 if options is None: options = [] if self.no_print: options.append('NOPRINT') self.options = options self.parent.add_package(self) if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype( structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) def ncells(self): """ Returns the maximum number of cells that have a ghb cell (developped for MT3DMS SSM package) """ return self.stress_period_data.mxact def write_file(self, check=True): """ Write the package file. Parameters ---------- check : boolean Check package data for common errors. (default True) Returns ------- None """ if check: # allows turning off package checks when writing files at model level self.check(f='{}.chk'.format(self.name[0]), verbose=self.parent.verbose, level=1) f_ghb = open(self.fn_path, 'w') f_ghb.write('{}\n'.format(self.heading)) f_ghb.write('{:10d}{:10d}'.format(self.stress_period_data.mxact, self.ipakcb)) for option in self.options: f_ghb.write(' {}'.format(option)) f_ghb.write('\n') self.stress_period_data.write_transient(f_ghb) f_ghb.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfghb error adding record to list: " + str(e)) @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): # get an empty recaray that correponds to dtype dtype = ModflowGhb.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("bhead", np.float32), ("cond", np.float32)]) else: dtype = np.dtype([("node", np.int), ("bhead", np.float32), ("cond", np.float32)]) return dtype @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. check : boolean Check package data for common errors. (default True) Returns ------- ghb : ModflowGhb object ModflowGhb object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> ghb = flopy.modflow.ModflowGhb.load('test.ghb', m) """ if model.verbose: sys.stdout.write('loading ghb package file...\n') return Package.load(model, ModflowGhb, f, nper, check=check)
class ModflowWel(Package): """ MODFLOW Well Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. ipakcb : int A flag that is used to determine if cell-by-cell budget data should be saved. If ipakcb is non-zero cell-by-cell budget data will be saved. (default is 0). stress_period_data : list of boundaries, or recarray of boundaries, or dictionary of boundaries Each well is defined through definition of layer (int), row (int), column (int), flux (float). The simplest form is a dictionary with a lists of boundaries for each stress period, where each list of boundaries itself is a list of boundaries. Indices of the dictionary are the numbers of the stress period. This gives the form of:: stress_period_data = {0: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ], 1: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ], ... kper: [ [lay, row, col, flux], [lay, row, col, flux], [lay, row, col, flux] ] } Note that if the number of lists is smaller than the number of stress periods, then the last list of wells will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3 boundaries Notebook in the basic subdirectory of the examples directory options : list of strings Package options. (default is None). extension : string Filename extension (default is 'wel') unitnumber : int File unit number (default is 11). Attributes ---------- mxactw : int Maximum number of wells for a stress period. This is calculated automatically by FloPy based on the information in stress_period_data. Methods ------- See Also -------- Notes ----- Parameters are not supported in FloPy. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> lrcq = {0:[[2, 3, 4, -100.]], 1:[[2, 3, 4, -100.]]} >>> wel = flopy.modflow.ModflowWel(m, stress_period_data=lrcq) """ def __init__(self, model, ipakcb=0, stress_period_data=None, dtype=None, extension='wel', unitnumber=20, options=None): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'WEL', unitnumber) self.heading = '# Well file for MODFLOW, generated by Flopy.' self.url = 'wel.htm' if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written self.np = 0 if options is None: options = [] self.specify = False for idx, opt in enumerate(options): if 'specify' in opt: t = opt.strip().split() self.specify = True self.phiramp = np.float(t[1]) self.phiramp_unit = np.int(t[2]) options.pop(idx) break self.options = options self.parent.add_package(self) if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype( structured=self.parent.structured) self.stress_period_data = MfList(self, stress_period_data) def ncells(self): # Returns the maximum number of cells that have a well # (developed for MT3DMS SSM package) return self.stress_period_data.mxact def write_file(self): """ Write the package file. Returns ------- None """ f_wel = open(self.fn_path, 'w') f_wel.write('%s\n' % self.heading) line = (' {0:9d} {1:9d}'.format(self.stress_period_data.mxact, self.ipakcb)) for opt in self.options: line += ' ' + str(opt) line += '\n' f_wel.write(line) if self.specify and self.parent.version == 'mfnwt': f_wel.write('SPECIFY {0:10.5g} {1:10d}\n'.format( self.phiramp, self.phiramp_unit)) self.stress_period_data.write_transient(f_wel) f_wel.close() def add_record(self, kper, index, values): try: self.stress_period_data.add_record(kper, index, values) except Exception as e: raise Exception("mfwel error adding record to list: " + str(e)) @staticmethod def get_default_dtype(structured=True): if structured: dtype = np.dtype([("k", np.int), ("i", np.int), ("j", np.int), ("flux", np.float32)]) else: dtype = np.dtype([("node", np.int), ("flux", np.float32)]) return dtype @staticmethod def get_empty(ncells=0, aux_names=None, structured=True): #get an empty recaray that correponds to dtype dtype = ModflowWel.get_default_dtype(structured=structured) if aux_names is not None: dtype = Package.add_to_dtype(dtype, aux_names, np.float32) d = np.zeros((ncells, len(dtype)), dtype=dtype) d[:, :] = -1.0E+10 return np.core.records.fromarrays(d.transpose(), dtype=dtype) @staticmethod def load(f, model, nper=None, ext_unit_dict=None, check=True): """ Load an existing package. Parameters ---------- f : filename or file handle File to load. model : model object The model object (of type :class:`flopy.modflow.mf.Modflow`) to which this package will be added. nper : int The number of stress periods. If nper is None, then nper will be obtained from the model object. (default is None). ext_unit_dict : dictionary, optional If the arrays in the file are specified using EXTERNAL, or older style array control records, then `f` should be a file handle. In this case ext_unit_dict is required, which can be constructed using the function :class:`flopy.utils.mfreadnam.parsenamefile`. Returns ------- wel : ModflowWel object ModflowWel object. Examples -------- >>> import flopy >>> m = flopy.modflow.Modflow() >>> wel = flopy.modflow.ModflowWel.load('test.wel', m) """ if model.verbose: sys.stdout.write('loading wel package file...\n') return Package.load(model, ModflowWel, f, nper, check=check)