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 __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 __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 __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 __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 __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 __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 __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 __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)
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)
def __init__(self, model, mxacts=0, nss=0, ntrib=0, ndiv=0, icalc=0, const=86400., ipakcb=0, dtype=None, stress_period_data=None, segment_data=None, extension='str', unitnumber=118, options=None, **kwargs): """ Package constructor. """ # Call parent init to set self.parent, extension, name and unit number Package.__init__(self, model, extension, 'STR', unitnumber) self.heading = '# STR for MODFLOW, generated by Flopy.' self.url = 'str.htm' self.mxacts = mxacts self.nss = nss self.icalc = icalc self.ntrib = ntrib self.ndiv = ndiv self.const = const if ipakcb != 0: self.ipakcb = 53 else: self.ipakcb = 0 # 0: no cell by cell terms are written # issue exception if ntrib is greater than 10 if ntrib > 10: raise Exception('ModflowStr error: ntrib must be less that 10: ' + 'specified value = {}'.format(ntrib)) if options is None: options = [] self.options = options # parameters are not supported self.npstr = 0 # determine dtype for dataset 6 if dtype is not None: self.dtype = dtype[0] self.dtype2 = dtype[1] else: auxnames = [] if len(options) > 0: auxnames = [] it = 0 while True: if 'aux' in options[it].lower(): aux_names.append(options[it + 1].lower()) it += 1 it += 1 if it > len(options): break if len(auxnames) < 1: auxnames = None d, d2 = self.get_empty(1, 1, aux_names=auxnames, structured=self.parent.structured) self.dtype = d.dtype self.dtype2 = d2.dtype # convert stress_period_data for datasets 6 and 8 to a recarray if necessary if stress_period_data is not None: for key, d in stress_period_data.items(): if isinstance(d, list): d = np.array(d) if isinstance(d, np.recarray): assert d.dtype == self.dtype, 'ModflowStr error: recarray dtype: ' + \ str(d.dtype) + ' does not match ' + \ 'self dtype: ' + str(self.dtype) elif isinstance(d, np.ndarray): d = np.core.records.fromarrays(d.transpose(), dtype=self.dtype) elif isinstance(d, int): if model.verbose: if d < 0: print( ' reusing str data from previous stress period' ) elif d == 0: print(' no str data for stress period {}'.format( key)) else: raise Exception( 'ModflowStr error: unsupported data type: ' + str(type(d)) + ' at kper ' + '{0:d}'.format(key)) # add stress_period_data to package self.stress_period_data = MfList(self, stress_period_data) # convert segment_data for datasets 9 and 10 to a recarray if necessary if segment_data is not None: for key, d in segment_data.items(): if isinstance(d, list): d = np.array(d) if isinstance(d, np.recarray): assert d.dtype == self.dtype2, 'ModflowStr error: recarray dtype: ' + \ str(d.dtype) + ' does not match ' + \ 'self dtype: ' + str(self.dtype2) elif isinstance(d, np.ndarray): d = np.core.records.fromarrays(d.transpose(), dtype=self.dtype2) elif isinstance(d, int): if model.verbose: if d < 0: print( ' reusing str segment data from previous stress period' ) elif d == 0: print( ' no str segment data for stress period {}'. format(key)) else: raise Exception( 'ModflowStr error: unsupported data type: ' + str(type(d)) + ' at kper ' + '{0:d}'.format(key)) # add stress_period_data to package self.segment_data = segment_data self.parent.add_package(self) return
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 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 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 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 Mt3dSsm(Package): """ MT3DMS Source and Sink Mixing Package Class. Parameters ---------- model : model object The model object (of type :class:`flopy.mt3d.mt.Mt3dms`) to which this package will be added. crch : array of floats CRCH is the concentration of recharge flux for a particular species. If the recharge flux is positive, it acts as a source whose concentration can be specified as desired. If the recharge flux is negative, it acts as a sink (discharge) whose concentration is always set equal to the concentration of groundwater at the cell where discharge occurs. Note that the location and flow rate of recharge/discharge are obtained from the flow model directly through the unformatted flow-transport link file. cevt : array of floats is the concentration of evapotranspiration flux for a particular species. Evapotranspiration is the only type of sink whose concentration may be specified externally. Note that the concentration of a sink cannot be greater than that of the aquifer at the sink cell. Thus, if the sink concentration is specified greater than that of the aquifer, it is automatically set equal to the concentration of the aquifer. Also note that the location and flow rate of evapotranspiration are obtained from the flow model directly through the unformatted flow-transport link file. stress_period_data : dictionary Keys in the dictionary are stress zero-based stress period numbers; values in the dictionary are recarrays of SSM boundaries. The dtype for the recarray can be obtained using ssm.dtype (after the ssm package has been created). The default dtype for the recarray is np.dtype([('k', np.int), ("i", np.int), ("j", np.int), ("css", np.float32), ("itype", np.int), ((cssms(n), np.float), n=1, ncomp)]) If there are more than one component species, then additional entries will be added to the dtype as indicated by cssm(n). Note that if the number of dictionary entries is less than the number of stress periods, then the last recarray of boundaries will apply until the end of the simulation. Full details of all options to specify stress_period_data can be found in the flopy3_multi-component_SSM ipython notebook in the Notebook subdirectory of the examples directory. css is the specified source concentration or mass-loading rate, depending on the value of ITYPE, in a single-species simulation, (For a multispecies simulation, CSS is not used, but a dummy value still needs to be entered here.) Note that for most types of sources, CSS is interpreted as the source concentration with the unit of mass per unit volume (ML-3), which, when multiplied by its corresponding flow rate (L3T-1) from the flow model, yields the mass-loading rate (MT-1) of the source. For a special type of sources (ITYPE = 15), CSS is taken directly as the mass-loading rate (MT-1) of the source so that no flow rate is required from the flow model. Furthermore, if the source is specified as a constant-concentration cell (itype = -1), the specified value of CSS is assigned directly as the concentration of the designated cell. If the designated cell is also associated with a sink/source term in the flow model, the flow rate is not used. itype is an integer indicating the type of the point source. An itype dictionary can be retrieved from the ssm object as itype = mt3d.Mt3dSsm.itype_dict() (CSSMS(n), n=1, NCOMP) defines the concentrations of a point source for multispecies simulation with NCOMP>1. In a multispecies simulation, it is necessary to define the concentrations of all species associated with a point source. As an example, if a chemical of a certain species is injected into a multispecies system, the concentration of that species is assigned a value greater than zero while the concentrations of all other species are assigned zero. CSSMS(n) can be entered in free format, separated by a comma or space between values. Several important notes on assigning concentration for the constant-concentration condition (ITYPE = -1) are listed below: The constant-concentration condition defined in this input file takes precedence to that defined in the Basic Transport Package input file. In a multiple stress period simulation, a constant-concentration cell, once defined, will remain a constant- concentration cell in the duration of the simulation, but its concentration value can be specified to vary in different stress periods. In a multispecies simulation, if it is only necessary to define different constant-concentration conditions for selected species at the same cell location, specify the desired concentrations for those species, and assign a negative value for all other species. The negative value is a flag used by MT3DMS to skip assigning the constant-concentration condition for the designated species. dtype : np.dtype dtype to use for the recarray of boundaries. If left as None (the default) then the dtype will be automatically constructed. extension : string Filename extension (default is 'ssm') unitnumber : int File unit number (default is 34). Attributes ---------- Methods ------- See Also -------- Notes ----- Examples -------- >>> import flopy >>> m = flopy.mt3d.Mt3dms() >>> itype = mt3d.Mt3dSsm.itype_dict() >>> ssm_data = {} >>> ssm_data[0] = [(4, 4, 4, 1.0, itype['GHB'], 1.0, 100.0)] >>> ssm_data[5] = [(4, 4, 4, 0.5, itype['GHB'], 0.5, 200.0)] >>> ssm = flopy.mt3d.Mt3dSsm(m, stress_period_data=ssm_data) """ unitnumber = 34 def __init__(self, model, crch=None, cevt=None, mxss=None, stress_period_data=None, dtype=None, extension='ssm', unitnumber=None, **kwargs): if unitnumber is None: unitnumber = self.unitnumber Package.__init__(self, model, extension, 'SSM', unitnumber) deprecated_kwargs = ['criv', 'cghb', 'cibd', 'cchd', 'cpbc', 'cwel'] for key in kwargs: if (key in deprecated_kwargs): warnings.warn("Deprecation Warning: Keyword argument '" + key + "' no longer supported. Use " + "'stress_period_data' instead.") # Set dimensions nrow = model.nrow ncol = model.ncol nlay = model.nlay ncomp = model.ncomp self.__SsmPackages = [] if self.parent.mf is not None: for i, label in enumerate(SsmLabels): self.__SsmPackages.append(SsmPackage(label, self.parent.mf.get_package(label), (i < 6))) # First 6 need T/F flag in file line 1 if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(ncomp) if stress_period_data is None: self.stress_period_data = None else: self.stress_period_data = MfList(self, model=model, data=stress_period_data) if mxss is None and self.parent.mf is None: warnings.warn('SSM Package: mxss is None and modflowmodel is ' + 'None. Cannot calculate max number of sources ' + 'and sinks. Estimating from stress_period_data. ') if mxss is None: # Need to calculate max number of sources and sinks self.mxss = 0 if self.stress_period_data is not None: self.mxss += np.sum(self.stress_period_data.data[0].itype == -1) self.mxss += np.sum(self.stress_period_data.data[0].itype == -15) if isinstance(self.parent.btn.icbund, np.ndarray): self.mxss += (self.parent.btn.icbund < 0).sum() for p in self.__SsmPackages: if ((p.label == 'BAS6') and (p.instance != None)): self.mxss += (p.instance.ibound.array < 0).sum() elif p.instance != None: self.mxss += p.instance.ncells() else: self.mxss = mxss # Note: list is used for multi-species, NOT for stress periods! if crch is not None: self.crch = [] t2d = Transient2d(model, (nrow, ncol), np.float32, crch, name='crch1', locat=self.unit_number[0]) self.crch.append(t2d) if ncomp > 1: for icomp in range(2, ncomp+1): val = 0.0 name = "crch" + str(icomp) if name in list(kwargs.keys()): val = kwargs.pop(name) else: print("SSM: setting crch for component " +\ str(icomp) + " to zero. kwarg name " +\ name) t2d = Transient2d(model, (nrow, ncol), np.float32, val, name=name, locat=self.unit_number[0]) self.crch.append(t2d) else: self.crch = None if cevt is not None: self.cevt = [] t2d = Transient2d(model, (nrow, ncol), np.float32, cevt, name='cevt1', locat=self.unit_number[0]) self.cevt.append(t2d) if ncomp > 1: for icomp in range(2, ncomp+1): val = 0.0 name = "cevt" + str(icomp) if name in list(kwargs.keys()): val = kwargs[name] kwargs.pop(name) else: print("SSM: setting cevt for component " +\ str(icomp) + " to zero, kwarg name " +\ name) t2d = Transient2d(model, (nrow, ncol), np.float32, val, name=name, locat=self.unit_number[0]) self.cevt.append(t2d) else: self.cevt = None if len(list(kwargs.keys())) > 0: raise Exception("SSM error: unrecognized kwargs: " + ' '.join(list(kwargs.keys()))) #Add self to parent and return self.parent.add_package(self) return def from_package(self, package, ncomp_aux_names): """ read the point source and sink info from a package ncomp_aux_names (list): the aux variable names in the package that are the component concentrations """ raise NotImplementedError() @staticmethod def itype_dict(): itype = {} itype["CHD"] = 1 itype["BAS6"] = 1 itype["PBC"] = 1 itype["WEL"] = 2 itype["DRN"] = 3 itype["RIV"] = 4 itype["GHB"] = 5 itype["MAS"] = 15 itype["CC"] = -1 return itype @staticmethod def get_default_dtype(ncomp=1): """ Construct a dtype for the recarray containing the list of sources and sinks """ type_list = [("k", np.int), ("i", np.int), ("j", np.int), ("css", np.float32), ("itype", np.int)] if ncomp > 1: for comp in range(1,ncomp+1): comp_name = "cssm({0:02d})".format(comp) type_list.append((comp_name, np.float32)) dtype = np.dtype(type_list) return dtype def write_file(self): """ Write the package file Returns ------- None """ # Open file for writing f_ssm = open(self.fn_path, 'w') for p in self.__SsmPackages: if p.needTFstr: f_ssm.write(p.TFstr) f_ssm.write(' F F F F\n') f_ssm.write('{:10d}\n'.format(self.mxss)) # Loop through each stress period and write ssm information nper = self.parent.nper for kper in range(nper): if f_ssm.closed == True: f_ssm = open(f_ssm.name,'a') # Distributed sources and sinks (Recharge and Evapotranspiration) if self.crch is not None: for c, t2d in enumerate(self.crch): incrch, file_entry = t2d.get_kper_entry(kper) if (c == 0): f_ssm.write('{:10d}\n'.format(incrch)) f_ssm.write(file_entry) if (self.cevt != None): for c, t2d in enumerate(self.cevt): incevt, file_entry = t2d.get_kper_entry(kper) if (c == 0): f_ssm.write('{:10d}\n'.format(incevt)) f_ssm.write(file_entry) # List of sources if self.stress_period_data is not None: self.stress_period_data.write_transient(f_ssm, single_per=kper) else: f_ssm.write('{}\n'.format(0)) f_ssm.close() return @staticmethod def load(f, model, nlay=None, nrow=None, ncol=None, nper=None, ncomp=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.mt3d.mt.Mt3dms`) 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 ------- ssm : Mt3dSsm object Mt3dSsm object. Examples -------- >>> import flopy >>> mt = flopy.mt3d.Mt3dms() >>> ssm = flopy.mt3d.Mt3dSsm.load('test.ssm', m) """ if model.verbose: sys.stdout.write('loading ssm package file...\n') # Open file, if necessary if not hasattr(f, 'read'): filename = f f = open(filename, 'r') # Set dimensions if necessary if nlay is None: nlay = model.nlay if nrow is None: nrow = model.nrow if ncol is None: ncol = model.ncol if nper is None: nper = model.nper if ncomp is None: ncomp = model.ncomp # dtype dtype = Mt3dSsm.get_default_dtype(ncomp) # Dataset 0 -- comment line while True: line = f.readline() if line[0] != '#': break # Item D1: Dummy input line - line already read above if model.verbose: print(' loading FWEL, FDRN, FRCH, FEVT, FRIV, FGHB, (FNEW(n), n=1,4)...') fwel = line[0:2] fdrn = line[4:6] frch = line[6:8] fevt = line[8:10] friv = line[10:12] fghb = line[12:14] fnew1 = line[14:16] fnew2 = line[16:18] fnew3 = line[18:20] fnew4 = line[20:22] if model.verbose: print(' FWEL {}'.format(fwel)) print(' FDRN {}'.format(fdrn)) print(' FRCH {}'.format(frch)) print(' FEVT {}'.format(fevt)) print(' FRIV {}'.format(friv)) print(' FGHB {}'.format(fghb)) print(' FNEW1 {}'.format(fnew1)) print(' FNEW2 {}'.format(fnew2)) print(' FNEW3 {}'.format(fnew3)) print(' FNEW4 {}'.format(fnew4)) # Item D2: MXSS, ISSGOUT mxss = None if model.verbose: print(' loading MXSS, ISSGOUT...') line = f.readline() mxss = int(line[0:10]) try: issgout = int(line[10:20]) except: issgout = 0 if model.verbose: print(' MXSS {}'.format(mxss)) print(' ISSGOUT {}'.format(issgout)) crch = None if 't' in frch.lower(): crch = {0:0} cevt = None if 't' in fevt.lower(): cevt = {0:0} stress_period_data = {} for iper in range(nper): if model.verbose: print(" loading ssm for kper {0:5d}".format(iper + 1)) # Item D3: INCRCH incrch = -1 if 't' in frch.lower(): if model.verbose: print(' loading INCRCH...') line = f.readline() incrch = int(line[0:10]) # Item D4: CRCH if incrch >= 0: if model.verbose: print(' loading CRCH...') t = Util2d.load(f, model, (nrow, ncol), np.float32, 'crch', ext_unit_dict) crch[iper] = t # Item D5: INCEVT incevt = -1 if 't' in fevt.lower(): if model.verbose: print(' loading INCEVT...') line = f.readline() incevt = int(line[0:10]) # Item D6: CEVT if incevt >= 0: if model.verbose: print(' loading CEVT...') t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cevt', ext_unit_dict) cevt[iper] = t # Item D7: NSS if model.verbose: print(' loading NSS...') line = f.readline() nss = int(line[0:10]) # Item D8: KSS, ISS, JSS, CSS, ITYPE, (CSSMS(n),n=1,NCOMP) if model.verbose: print(' loading KSS, ISS, JSS, CSS, ITYPE, (CSSMS(n),n=1,NCOMP)...') current = 0 if nss > 0: current = np.empty((nss), dtype=dtype) for ibnd in range(nss): line = f.readline() t = [] for ivar in range(5): istart = ivar * 10 istop = istart + 10 t.append(line[istart:istop]) ncssms = len(current.dtype.names) - 5 if ncssms > 0: tt = line[istop:].strip().split() for ivar in range(ncssms): t.append(tt[ivar]) current[ibnd] = tuple(t[:len(current.dtype.names)]) # convert indices to zero-based current['k'] -= 1 current['i'] -= 1 current['j'] -= 1 current = current.view(np.recarray) stress_period_data[iper] = current # Construct and return ssm package ssm = Mt3dSsm(model, crch=crch, cevt=cevt, mxss=mxss, stress_period_data=stress_period_data) return ssm
def __init__(self, model, crch=None, cevt=None, mxss=None, stress_period_data=None, dtype=None, extension='ssm', unitnumber=None, **kwargs): if unitnumber is None: unitnumber = self.unitnumber Package.__init__(self, model, extension, 'SSM', unitnumber) deprecated_kwargs = ['criv', 'cghb', 'cibd', 'cchd', 'cpbc', 'cwel'] for key in kwargs: if (key in deprecated_kwargs): warnings.warn("Deprecation Warning: Keyword argument '" + key + "' no longer supported. Use " + "'stress_period_data' instead.") # Set dimensions nrow = model.nrow ncol = model.ncol nlay = model.nlay ncomp = model.ncomp self.__SsmPackages = [] if self.parent.mf is not None: for i, label in enumerate(SsmLabels): self.__SsmPackages.append(SsmPackage(label, self.parent.mf.get_package(label), (i < 6))) # First 6 need T/F flag in file line 1 if dtype is not None: self.dtype = dtype else: self.dtype = self.get_default_dtype(ncomp) if stress_period_data is None: self.stress_period_data = None else: self.stress_period_data = MfList(self, model=model, data=stress_period_data) if mxss is None and self.parent.mf is None: warnings.warn('SSM Package: mxss is None and modflowmodel is ' + 'None. Cannot calculate max number of sources ' + 'and sinks. Estimating from stress_period_data. ') if mxss is None: # Need to calculate max number of sources and sinks self.mxss = 0 if self.stress_period_data is not None: self.mxss += np.sum(self.stress_period_data.data[0].itype == -1) self.mxss += np.sum(self.stress_period_data.data[0].itype == -15) if isinstance(self.parent.btn.icbund, np.ndarray): self.mxss += (self.parent.btn.icbund < 0).sum() for p in self.__SsmPackages: if ((p.label == 'BAS6') and (p.instance != None)): self.mxss += (p.instance.ibound.array < 0).sum() elif p.instance != None: self.mxss += p.instance.ncells() else: self.mxss = mxss # Note: list is used for multi-species, NOT for stress periods! if crch is not None: self.crch = [] t2d = Transient2d(model, (nrow, ncol), np.float32, crch, name='crch1', locat=self.unit_number[0]) self.crch.append(t2d) if ncomp > 1: for icomp in range(2, ncomp+1): val = 0.0 name = "crch" + str(icomp) if name in list(kwargs.keys()): val = kwargs.pop(name) else: print("SSM: setting crch for component " +\ str(icomp) + " to zero. kwarg name " +\ name) t2d = Transient2d(model, (nrow, ncol), np.float32, val, name=name, locat=self.unit_number[0]) self.crch.append(t2d) else: self.crch = None if cevt is not None: self.cevt = [] t2d = Transient2d(model, (nrow, ncol), np.float32, cevt, name='cevt1', locat=self.unit_number[0]) self.cevt.append(t2d) if ncomp > 1: for icomp in range(2, ncomp+1): val = 0.0 name = "cevt" + str(icomp) if name in list(kwargs.keys()): val = kwargs[name] kwargs.pop(name) else: print("SSM: setting cevt for component " +\ str(icomp) + " to zero, kwarg name " +\ name) t2d = Transient2d(model, (nrow, ncol), np.float32, val, name=name, locat=self.unit_number[0]) self.cevt.append(t2d) else: self.cevt = None if len(list(kwargs.keys())) > 0: raise Exception("SSM error: unrecognized kwargs: " + ' '.join(list(kwargs.keys()))) #Add self to parent and return self.parent.add_package(self) return
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 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 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 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 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)