示例#1
0
文件: t006_test.py 项目: inowas/flopy
def test_mflist_reference():
    import os
    import numpy as np
    import shapefile
    import flopy.modflow as fmf

    # model_ws = os.path.join('..', 'data', 'freyberg')
    # ml = fmf.Modflow.load('freyberg.nam', model_ws=model_ws)
    # make the model
    ml = fmf.Modflow()
    assert isinstance(ml, fmf.Modflow)
    perlen = np.arange(1, 20, 1)
    nstp = np.flipud(perlen) + 3
    tsmult = 1.2
    nlay = 10
    nrow, ncol = 50, 40
    botm = np.arange(0, -100, -10)
    hk = np.random.random((nrow, ncol))
    dis = fmf.ModflowDis(ml,
                         delr=100.0,
                         delc=100.0,
                         nrow=nrow,
                         ncol=ncol,
                         nlay=nlay,
                         nper=perlen.shape[0],
                         perlen=perlen,
                         nstp=nstp,
                         tsmult=tsmult,
                         top=10,
                         botm=botm,
                         steady=False)
    assert isinstance(dis, fmf.ModflowDis)
    lpf = fmf.ModflowLpf(ml, hk=hk, vka=10.0, laytyp=1)
    assert isinstance(lpf, fmf.ModflowLpf)
    pcg = fmf.ModflowPcg(ml)
    assert isinstance(pcg, fmf.ModflowPcg)
    oc = fmf.ModflowOc(ml)
    assert isinstance(oc, fmf.ModflowOc)
    ibound = np.ones((nrow, ncol))
    ibound[:, 0] = -1
    ibound[25:30, 30:39] = 0
    bas = fmf.ModflowBas(ml, strt=5.0, ibound=ibound)
    assert isinstance(bas, fmf.ModflowBas)
    rch = fmf.ModflowRch(ml, rech={0: 0.00001, 5: 0.0001, 6: 0.0})
    assert isinstance(rch, fmf.ModflowRch)
    wel_dict = {}
    wel_data = [[9, 25, 20, -200], [0, 0, 0, -400], [5, 20, 32, 500]]
    wel_dict[0] = wel_data
    wel_data2 = [[45, 20, 200], [9, 49, 39, 400], [5, 20, 32, 500]]
    wel_dict[10] = wel_data2
    wel = fmf.ModflowWel(ml, stress_period_data={0: wel_data})
    assert isinstance(wel, fmf.ModflowWel)
    ghb_dict = {0: [1, 10, 10, 400, 300]}
    ghb = fmf.ModflowGhb(ml, stress_period_data=ghb_dict)
    assert isinstance(ghb, fmf.ModflowGhb)

    test = os.path.join('temp', 'test3.shp')
    ml.export(test, kper=0)
    shp = shapefile.Reader(test)
    assert shp.numRecords == nrow * ncol
示例#2
0
文件: wncMF.py 项目: bbuzz31/ModSWMM
 def lpf(self):
     hk = self.df_mf.filter(like='KX').T.values.reshape(
         self.nlays, self.nrows, self.ncols)
     vk = self.df_mf.filter(like='KZ').T.values.reshape(
         self.nlays, self.nrows, self.ncols)
     lpf = flomf.ModflowLpf(self.mf,
                            laytyp=np.ones(self.nlays),
                            layavg=np.ones(self.nlays) * 2,
                            hk=hk,
                            vka=vk,
                            sy=self.params.get('sy', 0.25))
     return lpf
示例#3
0
#        [-1.,  1.,  1., ...,  1.,  1., -1.],
#        [-1., -1., -1., ..., -1., -1., -1.]]])

# set center cell in upper layer to constant head (-1)
ibound[0, Nhalf, Nhalf] = -1

# defining the start-values
# in the calculation only the -1 cells will be considered
#
# all values are set to h1
start = h1 * np.ones((N, N))
# and the center value is set to h2
start[Nhalf, Nhalf] = h2

# instantiate the modflow-basic package with iBound and startvalues
bas = mf.ModflowBas(ml, ibound=ibound, strt=start)

# set the aquifer properties with the lpf-package
lpf = mf.ModflowLpf(ml, hk=k)

# instantiation of the solver with default values
pcg = mf.ModflowPcg(ml)

# instantiation of the output control with default values
oc = mf.ModflowOc(ml)

rch = mf.ModflowRch(ml)

ml.write_input()
ml.run_model()
示例#4
0
    def create_package(self, name, content):
        if name == 'mf':
            model_ws = os.path.realpath(os.path.join(self._data_folder, self._model_id, content['model_ws']))
            if not os.path.exists(model_ws):
                os.makedirs(model_ws)

            self._mf = mf.Modflow(
                modelname=content['modelname'],
                exe_name=content['exe_name'],
                version=content['version'],
                model_ws=model_ws
            )
        if name == 'dis':
            mf.ModflowDis(
                self._mf,
                nlay=content['nlay'],
                nrow=content['nrow'],
                ncol=content['ncol'],
                nper=content['nper'],
                delr=content['delr'],
                delc=content['delc'],
                laycbd=content['laycbd'],
                top=content['top'],
                botm=content['botm'],
                perlen=content['perlen'],
                nstp=content['nstp'],
                tsmult=content['tsmult'],
                steady=content['steady'],
                itmuni=content['itmuni'],
                lenuni=content['lenuni'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                xul=content['xul'],
                yul=content['yul'],
                rotation=content['rotation'],
                proj4_str=content['proj4_str'],
                start_datetime=content['start_datetime']
            )
        if name == 'bas':
            mf.ModflowBas(
                self._mf,
                ibound=content['ibound'],
                strt=content['strt'],
                ifrefm=content['ifrefm'],
                ixsec=content['ixsec'],
                ichflg=content['ichflg'],
                stoper=content['stoper'],
                hnoflo=content['hnoflo'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'lpf':
            mf.ModflowLpf(
                self._mf,
                laytyp=content['laytyp'],
                layavg=content['layavg'],
                chani=content['chani'],
                layvka=content['layvka'],
                laywet=content['laywet'],
                ipakcb=content['ipakcb'],
                hdry=content['hdry'],
                iwdflg=content['iwdflg'],
                wetfct=content['wetfct'],
                iwetit=content['iwetit'],
                ihdwet=content['ihdwet'],
                hk=content['hk'],
                hani=content['hani'],
                vka=content['vka'],
                ss=content['ss'],
                sy=content['sy'],
                vkcb=content['vkcb'],
                wetdry=content['wetdry'],
                storagecoefficient=content['storagecoefficient'],
                constantcv=content['constantcv'],
                thickstrt=content['thickstrt'],
                nocvcorrection=content['nocvcorrection'],
                novfc=content['novfc'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'pcg':
            mf.ModflowPcg(
                self._mf,
                mxiter=content['mxiter'],
                iter1=content['iter1'],
                npcond=content['npcond'],
                hclose=content['hclose'],
                rclose=content['rclose'],
                relax=content['relax'],
                nbpol=content['nbpol'],
                iprpcg=content['iprpcg'],
                mutpcg=content['mutpcg'],
                damp=content['damp'],
                dampt=content['dampt'],
                ihcofadd=content['ihcofadd'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'oc':
            mf.ModflowOc(
                self._mf,
                ihedfm=content['ihedfm'],
                iddnfm=content['iddnfm'],
                chedfm=content['chedfm'],
                cddnfm=content['cddnfm'],
                cboufm=content['cboufm'],
                compact=content['compact'],
                stress_period_data=self.get_stress_period_data(content['stress_period_data']),
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'risdlkfjlv':
            mf.ModflowRiv(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                options=content['options'],
                naux=content['naux']
            )
        if name == 'wel':
            mf.ModflowWel(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                options=content['options']
            )
        if name == 'rch':
            mf.ModflowRch(
                self._mf,
                ipakcb=content['ipakcb'],
                nrchop=content['nrchop'],
                rech=content['rech'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'chd':
            mf.ModflowChd(
                self._mf,
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                options=content['options'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )

        if name == 'ghb':
            mf.ModflowGhb(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                options=content['options'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
示例#5
0
# ssm data
itype = mt3.Mt3dSsm.itype_dict()
ssm_data = {0: [0, 0, 0, 35., itype['BAS6']]}

#print sconcp
#mt3d print times
timprs = (np.arange(5) + 1) * 2000.
nprs = len(timprs)
# MODFLOW files
ml = []
ml = mf.Modflow(modelname, version='mf2005', exe_name=swtexe_name, model_ws=dirs[1])
discret = mf.ModflowDis(ml, nrow=swt_nrow, ncol=swt_ncol, nlay=swt_nlay,
                        delr=swt_delr, delc=swt_delc, laycbd=0, top=swt_top, botm=swt_botm,
                        nper=nper, perlen=perlen, nstp=1, steady=False)
bas = mf.ModflowBas(ml, ibound=swt_ibound, strt=0.05)
lpf = mf.ModflowLpf(ml, hk=2.0, vka=2.0, ss=0.0, sy=0.0, laytyp=0, layavg=0)
oc = mf.ModflowOc88(ml, save_head_every=1, item2=[[0, 1, 0, 0]])
pcg = mf.ModflowPcg(ml)
ml.write_input()
# Create the basic MT3DMS model structure
mt = mt3.Mt3dms(modelname, 'nam_mt3dms', modflowmodel=ml, 
                model_ws=dirs[1])  # Coupled to modflow model 'mf'
adv = mt3.Mt3dAdv(mt, mixelm=-1,  #-1 is TVD
                  percel=0.05,
                  nadvfd=0,  #0 or 1 is upstream; 2 is central in space
                  #particle based methods
                  nplane=4,
                  mxpart=1e7,
                  itrack=2,
                  dceps=1e-4,
                  npl=16,
示例#6
0
for idx in range(49, 200, 50):
    key = (0, idx)
    ocdict[key] = ['save head', 'save budget']
    key = (0, idx+1)  
    ocdict[key] = []  


# create flopy modflow object
ml = mf.Modflow(modelname, version='mf2005', exe_name=exe_name)
# create flopy modflow package objects
discret = mf.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol,
                        delr=delr, delc=delc,
                        top=0, botm=[-40.0],
                        perlen=400, nstp=200)
bas = mf.ModflowBas(ml, ibound=ibound, strt=0.0)
lpf = mf.ModflowLpf(ml, hk=2., vka=2.0, vkcb=0, laytyp=0, layavg=0)
wel = mf.ModflowWel(ml, stress_period_data={0:[(0, 0, 0, 1)]})
swi = mf.ModflowSwi2(ml, npln=1, istrat=1, toeslope=0.2, tipslope=0.2, nu=[0, 0.025],
                     zeta=z, ssz=0.2, isource=isource, nsolver=1)
oc = mf.ModflowOc(ml, stress_period_data=ocdict)
pcg = mf.ModflowPcg(ml)
# create model files
ml.write_input()
# run the model
m = ml.run_model(silent=False)
# read model heads
headfile = '{}.hds'.format(modelname)
hdobj = fu.HeadFile(headfile)
head = hdobj.get_alldata()
head = np.array(head)
# read model zeta
示例#7
0
 def get_package(self, _mf):
     content = self.merge()
     return mf.ModflowLpf(_mf, **content)
示例#8
0
                        ncol=int(grid_obj.ncol),
                        nlay=grid_obj.nlay,
                        delr=grid_obj.delr,
                        delc=grid_obj.delc,
                        laycbd=0.,
                        top=grid_obj.top,
                        botm=grid_obj.botm,
                        nper=nper,
                        perlen=perlen,
                        nstp=nstp,
                        steady=steady)

lpf = mf.ModflowLpf(ml,
                    hk=grid_obj.HK,
                    vka=grid_obj.VK,
                    ss=grid_obj.ss,
                    ipakcb=53,
                    sy=0.15,
                    laytyp=laytyp,
                    layavg=0.)
#%%============================================================================
''' [C] Iterate the model'''
start_time = time.time()
for period in range(rl):
    if OutsideAirBound == 1:
        grid_obj.temp[0, :, :] = grid_obj.SurfaceT[
            period]  # sets temperature at surface level according to time of year

    if well_obj_list:  # Create well and temperature lists following Modflow/MT3DMS format. Each timestep, flows and infiltration temp are assigned to the wells
        for i in well_obj_list:
            i.Q = i.flow[period]
        if temp_assigned == True:
示例#9
0
            if savehead == True:
                twords.append('head')
            savewords.append(twords)
solver2params = {'mxiter': 100, 'iter1': 20, 'npcond': 1, 'zclose': 1.0e-6, 'rclose': 3e-3, 'relax': 1.0,
                 'nbpol': 2, 'damp': 1.0, 'dampt': 1.0}

# --create model file and run model
modelname = 'swi2ex5'
mf_name = 'mf2005'
if not skipRuns:
    ml = mf.Modflow(modelname, version='mf2005', exe_name=mf_name, model_ws=dirs[0])
    discret = mf.ModflowDis(ml, nrow=nrow, ncol=ncol, nlay=nlay, delr=delr, delc=delc,
                            top=0, botm=bot, laycbd=0, nper=nper,
                            perlen=perlen, nstp=nstp, steady=steady)
    bas = mf.ModflowBas(ml, ibound=ibound, strt=ihead)
    lpf = mf.ModflowLpf(ml, hk=kh, vka=kv, ss=ss, sy=ssz, vkcb=0, laytyp=0, layavg=1)
    wel = mf.ModflowWel(ml, stress_period_data=well_data)
    swi = mf.ModflowSwi2(ml, npln=1, istrat=1, toeslope=0.025, tipslope=0.025, nu=[0, 0.025], \
                         zeta=z, ssz=ssz, isource=isource, nsolver=2, solver2params=solver2params)
    oc = mf.ModflowOc(ml, words=savewords)
    pcg = mf.ModflowPcg(ml, hclose=1.0e-6, rclose=3.0e-3, mxiter=100, iter1=50)
    # --write the modflow files
    ml.write_input()
    m = ml.run_model(silent=False)

# --read model zeta
get_stp = [364, 729, 1094, 1459, 364, 729, 1094, 1459]
get_per = [0, 0, 0, 0, 1, 1, 1, 1]
nswi_times = len(get_per)
zetafile = os.path.join(dirs[0], '{}.zta'.format(modelname))
zobj = fu.CellBudgetFile(zetafile)
示例#10
0
    def run_experiment(self, experiment):
        '''
        Method for running an instantiated model structure. 
        
        This method should always be implemented.
        
        :param case: keyword arguments for running the model. The case is a 
                     dict with the names of the uncertainties as key, and
                     the values to which to set these uncertainties. 
        '''

        #NetLogo agent attributes to be passed to Python well objects
        #when new wells are created in NetLogo
        nl_read_sys_attribs = ['who', 'xcor', 'ycor']
        nl_read_well_attribs = [
            'who', 'xcor', 'ycor', 'IsCold', 'z0', 'FilterLength', 'T_inj', 'Q'
        ]

        #NetLogo agent attributes to be updated by the Python objects after each period
        nl_update_well_attribs = ['T_modflow', 'H_modflow']
        nl_update_globals = ['ztop', 'Laquifer']

        self.netlogo.command('setup')

        for key, value in experiment.items():
            if key in self.NetLogo_uncertainties:
                try:
                    self.netlogo.command(self.command_format.format(
                        key, value))
                except jpype.JavaException as e:
                    warning('Variable {0} throws exception: {}'.format(
                        (key, str(e))))
                logging.debug(self.netlogo.report(str(key)))
            if key in self.SEAWAT_uncertainties:
                setattr(self, key, value)

        #Set policy parameters if present
        if self.policy:
            for key, value in self.policy.items():
                if (key in self.NetLogo_uncertainties and key != 'name'):
                    self.netlogo.command(self.command_format.format(
                        key, value))
                elif key in self.SEAWAT_uncertainties:
                    setattr(self, key, value)
            logging.info('Policy parameters set successfully')

        #Update NetLogo globals from input parameters
        for var in nl_update_globals:
            self.netlogo.command(
                self.command_format.format(var, getattr(self, var)))

        #Run the NetLogo setup routine, creating the agents
        #Create lists of Python objects based on the NetLogo agents
        self.netlogo.command('init-agents')
        sys_obj_list = update_runtime_objectlist(self.netlogo, [],
                                                 nl_read_sys_attribs,
                                                 breed='system',
                                                 objclass=PySystem)
        well_obj_list, newgrid_flag = update_runtime_objectlist(
            self.netlogo, [],
            nl_read_well_attribs,
            breed='well',
            objclass=PyWell)

        #Assign values for uncertain NetLogo parameters
        logging.info('NetLogo parameters set successfully')

        #self.netlogo.command('init-agents')

        #Calculate geohydrological parameters linked to variable inputs
        rho_b = self.rho_solid * (1 - self.PEFF)
        kT_b = self.kT_s * (1 - self.PEFF) + self.kT_f * self.PEFF
        dmcoef = kT_b / (self.PEFF * self.rho_f * self.Cp_f) * 24 * 3600
        trpt = self.al * self.trp_mult
        trpv = trpt

        #Initialize PyGrid object
        itype = mt3.Mt3dSsm.itype_dict()
        grid_obj = PyGrid()
        grid_obj.make_grid(well_obj_list,
                           dmin=self.dmin,
                           dmax=self.dmax,
                           dz=self.dz,
                           ztop=self.ztop,
                           zbot=self.zbot,
                           nstep=self.nstep,
                           grid_extents=self.grid_extents)

        #Initial arrays for grid values (temperature, head) - for this case, assumes no groundwater flow
        #and uniform temperature
        grid_obj.ncol = len(grid_obj.XGR) - 1
        grid_obj.delr = np.diff(grid_obj.XGR)
        grid_obj.nrow = len(grid_obj.YGR) - 1
        grid_obj.delc = -np.diff(grid_obj.YGR)

        grid_obj.top = self.ztop * np.ones([grid_obj.nrow, grid_obj.ncol])
        botm_range = np.arange(self.zbot, self.ztop, self.dz)[::-1]
        botm_2d = np.ones([grid_obj.nrow, grid_obj.ncol])
        grid_obj.botm = botm_2d * botm_range[:, None, None]
        grid_obj.nlay = len(botm_range)

        grid_obj.IBOUND, grid_obj.ICBUND = boundaries(
            grid_obj)  #Create grid boundaries

        #Initial arrays for grid values (temperature, head)
        init_grid = np.ones((grid_obj.nlay, grid_obj.nrow, grid_obj.ncol))
        grid_obj.temp = 10. * init_grid

        grid_obj.HK = self.HK * init_grid
        grid_obj.VK = self.VK * init_grid

        #Set initial heads according to groundwater flow (based on mfLab Utrecht model)
        y_array = np.array([(grid_obj.YGR[:-1] - np.mean(grid_obj.YGR[:-1])) *
                            self.PEFF * -self.gwflow_y / 365 / self.HK])
        y_tile = np.array([np.tile(y_array.T, (1, grid_obj.ncol))])
        x_array = (grid_obj.XGR[:-1] - np.mean(
            grid_obj.XGR[:-1])) * self.PEFF * -self.gwflow_x / 365 / self.HK
        y_tile += x_array
        grid_obj.head = np.tile(y_tile, (grid_obj.nlay, 1, 1))

        #Set times at which to read SEAWAT output for each simulation period
        timprs = np.array([self.perlen])
        nprs = len(timprs)
        logging.info('SEAWAT parameters set successfully')

        #Iterate the coupled model
        for period in range(self.run_length):

            #Set up the text output from NetLogo
            commands = []
            self.fns = {}
            for outcome in self.outcomes:
                #if outcome.time:
                name = outcome.name
                fn = r'{0}{3}{1}{2}'.format(self._working_directory, name,
                                            '.txt', os.sep)
                self.fns[name] = fn
                fn = '"{}"'.format(fn)
                fn = fn.replace(os.sep, '/')

                if self.netlogo.report('is-agentset? {}'.format(name)):
                    #If name is name of an agentset, we
                    #assume that we should count the total number of agents
                    nc = r'{2} {0} {3} {4} {1}'.format(fn, name, 'file-open',
                                                       'file-write', 'count')
                else:
                    #It is not an agentset, so assume that it is
                    #a reporter / global variable
                    nc = r'{2} {0} {3} {1}'.format(fn, name, 'file-open',
                                                   'file-write')
                commands.append(nc)

            c_out = ' '.join(commands)
            self.netlogo.command(c_out)

            logging.info(' -- Simulating period {0} of {1}'.format(
                period, self.run_length))
            #Run the NetLogo model for one tick
            self.netlogo.command('go')
            logging.debug('NetLogo step completed')

            #Create placeholder well list - required for MODFLOW WEL package if no wells active in NetLogo
            well_LRCQ_list = {}
            well_LRCQ_list[0] = [[0, 0, 0, 0]]
            ssm_data = {}
            ssm_data[0] = [[0, 0, 0, 0, itype['WEL']]]

            #Check the well agents which are active in NetLogo, and update the Python objects if required
            #The newgrid_flag indicates whether or not the grid should be recalculated to account for changes
            #in the list of active wells
            if well_obj_list:
                well_obj_list, newgrid_flag = update_runtime_objectlist(
                    self.netlogo, well_obj_list, nl_read_well_attribs)

            if well_obj_list and newgrid_flag:
                #If the list of active wells has changed and if there are active wells, create a new grid object
                newgrid_obj = PyGrid()
                newgrid_obj.make_grid(well_obj_list,
                                      dmin=self.dmin,
                                      dmax=self.dmax,
                                      dz=self.dz,
                                      ztop=self.ztop,
                                      zbot=self.zbot,
                                      nstep=self.nstep,
                                      grid_extents=self.grid_extents)
                #Interpolate the temperature and head arrays to match the new grid
                newgrid_obj.temp = grid_interpolate(grid_obj.temp[0, :, :],
                                                    grid_obj, newgrid_obj)
                newgrid_obj.head = grid_interpolate(grid_obj.head[0, :, :],
                                                    grid_obj, newgrid_obj)
                #Use the new simulation grid
                grid_obj = newgrid_obj

            logging.debug('Python update completed')

            if well_obj_list:
                for i in well_obj_list:
                    #Read well flows from NetLogo and locate each well in the simulation grid
                    i.Q = read_NetLogo_attrib(self.netlogo, 'Q', i.who)
                    i.calc_LRC(grid_obj)
                #Create well and temperature lists following MODFLOW/MT3DMS format
                well_LRCQ_list = create_LRCQ_list(well_obj_list, grid_obj)
                ssm_data = create_conc_list(well_obj_list)

            #Initialize MODFLOW packages using FloPy
            #ml = mf.Modflow(self.name, version='mf2005', exe_name=self.swtexe_name, model_ws=self.dirs[0])
            swtm = swt.Seawat(self.name,
                              exe_name=self.swtexe_name,
                              model_ws=self.dirs[0])
            discret = mf.ModflowDis(swtm,
                                    nrow=grid_obj.nrow,
                                    ncol=grid_obj.ncol,
                                    nlay=grid_obj.nlay,
                                    delr=grid_obj.delr,
                                    delc=grid_obj.delc,
                                    laycbd=0,
                                    top=self.ztop,
                                    botm=self.zbot,
                                    nper=self.nper,
                                    perlen=self.perlen,
                                    nstp=self.nstp,
                                    steady=self.steady)

            bas = mf.ModflowBas(swtm,
                                ibound=grid_obj.IBOUND,
                                strt=grid_obj.head)
            lpf = mf.ModflowLpf(swtm,
                                hk=self.HK,
                                vka=self.VK,
                                ss=0.0,
                                sy=0.0,
                                laytyp=0,
                                layavg=0)

            wel = mf.ModflowWel(swtm, stress_period_data=well_LRCQ_list)

            words = ['head', 'drawdown', 'budget', 'phead', 'pbudget']
            save_head_every = 1
            oc = mf.ModflowOc(swtm)
            pcg = mf.ModflowPcg(swtm,
                                mxiter=200,
                                iter1=200,
                                npcond=1,
                                hclose=0.001,
                                rclose=0.001,
                                relax=1.0,
                                nbpol=0)
            #ml.write_input()

            #Initialize MT3DMS packages
            #mt = mt3.Mt3dms(self.name, 'nam_mt3dms', modflowmodel=ml, model_ws=self.dirs[0])
            adv = mt3.Mt3dAdv(
                swtm,
                mixelm=0,  #-1 is TVD
                percel=1,
                nadvfd=1,
                #Particle based methods
                nplane=0,
                mxpart=250000,
                itrack=3,
                dceps=1e-4,
                npl=5,
                nph=8,
                npmin=1,
                npmax=16)
            btn = mt3.Mt3dBtn(swtm,
                              cinact=-100.,
                              icbund=grid_obj.ICBUND,
                              prsity=self.PEFF,
                              sconc=[grid_obj.temp][0],
                              ifmtcn=-1,
                              chkmas=False,
                              nprobs=0,
                              nprmas=1,
                              dt0=0.0,
                              ttsmult=1.5,
                              ttsmax=20000.,
                              ncomp=1,
                              nprs=nprs,
                              timprs=timprs,
                              mxstrn=9999)
            dsp = mt3.Mt3dDsp(swtm,
                              al=self.al,
                              trpt=trpt,
                              trpv=trpv,
                              dmcoef=dmcoef)
            rct = mt3.Mt3dRct(swtm, isothm=0, ireact=0, igetsc=0, rhob=rho_b)
            gcg = mt3.Mt3dGcg(swtm,
                              mxiter=50,
                              iter1=50,
                              isolve=1,
                              cclose=1e-3,
                              iprgcg=0)
            ssm = mt3.Mt3dSsm(swtm, stress_period_data=ssm_data)
            #mt.write_input()

            #Initialize SEAWAT packages
            # mswtf = swt.Seawat(self.name, 'nam_swt', modflowmodel=ml, mt3dmsmodel=mt,
            #                    model_ws=self.dirs[0])
            swtm.write_input()

            #Run SEAWAT
            #m = mswtf.run_model(silent=True)
            m = swtm.run_model(silent=True)
            logging.debug('SEAWAT step completed')

            #Copy Modflow/MT3DMS output to new files
            shutil.copyfile(
                os.path.join(self.dirs[0], self.name + '.hds'),
                os.path.join(self.dirs[0], self.name + str(period) + '.hds'))
            shutil.copyfile(
                os.path.join(self.dirs[0], 'MT3D001.UCN'),
                os.path.join(self.dirs[0], self.name + str(period) + '.UCN'))

            #Create head file object and read head array for next simulation period
            h_obj = bf.HeadFile(
                os.path.join(self.dirs[0], self.name + str(period) + '.hds'))
            grid_obj.head = h_obj.get_data(totim=self.perlen)

            #Create concentration file object and read temperature array for next simulation period
            t_obj = bf.UcnFile(
                os.path.join(self.dirs[0], self.name + str(period) + '.UCN'))
            grid_obj.temp = t_obj.get_data(totim=self.perlen)

            logging.debug('Output processed')

            if well_obj_list:
                for i in well_obj_list:
                    #Update each active Python well object with the temperature and head at its grid location
                    i.T_modflow = grid_obj.temp[i.L[0], i.R, i.C]
                    i.H_modflow = grid_obj.head[i.L[0], i.R, i.C]
                #Update the NetLogo agents from the corresponding Python objects
                write_NetLogo_attriblist(self.netlogo, well_obj_list,
                                         nl_update_well_attribs)

            #As an example of data exchange, we can calculate the fraction of the simulated grid in which
            #the temperature change is significant, and send this value to a NetLogo global variable
            use = subsurface_use(grid_obj, grid_obj.temp)

            write_NetLogo_global(self.netlogo, 'SubsurfaceUse', use)

            logging.debug('NetLogo update completed')

            h_obj.file.close()
            t_obj.file.close()

        self.netlogo.command('file-close-all')
        self._handle_outcomes()
示例#11
0
def calculate_model(z1_hk, z2_hk, z3_hk):
    # Z1_hk = 15  # 3<Z1_hk<15
    # Z2_hk = 15  # 3<Z2_hk<15
    # Z3_hk = 3  # 3<Z3_hk<15

    hobs = [
        [0, 20, 10, 69.52],
        [0, 40, 10, 71.44],
        [0, 60, 10, 72.99],
        [0, 80, 10, 73.86],
        [0, 20, 45, 58.73],
        [0, 40, 45, 50.57],
        [0, 60, 45, 54.31],
        [0, 80, 45, 58.06],
        [0, 20, 80, 56.31],
        [0, 40, 80, 52.32],
        [0, 60, 80, 46.35],
        [0, 80, 80, 29.01],
        [0, 20, 100, 57.24],
        [0, 40, 100, 54.24],
        [0, 60, 100, 39.48],
        [0, 80, 100, 48.47],
    ]

    model_path = os.path.join('_model')

    if os.path.exists(model_path):
        shutil.rmtree(model_path)

    modelname = 'parEstMod'

    version = 'mf2005'
    exe_name = 'mf2005'
    if platform.system() == 'Windows':
        exe_name = 'mf2005.exe'

    ml = mf.Modflow(modelname=modelname,
                    exe_name=exe_name,
                    version=version,
                    model_ws=model_path)

    nlay = 1
    nrow = 90
    ncol = 120

    area_width_y = 9000
    area_width_x = 12000

    delc = area_width_x / ncol
    delr = area_width_y / nrow

    nper = 1

    top = 100
    botm = 0

    dis = mf.ModflowDis(ml,
                        nlay=nlay,
                        nrow=nrow,
                        ncol=ncol,
                        delr=delr,
                        delc=delc,
                        top=top,
                        botm=botm,
                        nper=nper,
                        steady=True)

    ibound = 1
    strt = 100
    bas = mf.ModflowBas(ml, ibound=ibound, strt=strt)

    mask_arr = np.zeros((nlay, nrow, ncol))
    mask_arr[:, :, 0] = 80
    mask_arr[:, :, -1] = 60

    ghb_spd = {0: []}
    for layer_id in range(nlay):
        for row_id in range(nrow):
            for col_id in range(ncol):
                if mask_arr[layer_id][row_id][col_id] > 0:
                    ghb_spd[0].append([
                        layer_id, row_id, col_id,
                        mask_arr[layer_id][row_id][col_id], 200
                    ])

    ghb = mf.ModflowGhb(ml, stress_period_data=ghb_spd)

    rch = 0.0002
    rech = {}
    rech[0] = rch
    rch = mf.ModflowRch(ml, rech=rech, nrchop=3)

    welSp = {}
    welSp[0] = [
        [0, 20, 20, -20000],
        [0, 40, 40, -20000],
        [0, 60, 60, -20000],
        [0, 80, 80, -20000],
        [0, 60, 100, -20000],
    ]

    wel = mf.ModflowWel(ml, stress_period_data=welSp)

    hk = np.zeros((nlay, nrow, ncol))
    hk[:, :, 0:40] = z1_hk
    hk[:, :, 40:80] = z2_hk
    hk[:, :, 80:120] = z3_hk

    lpf = mf.ModflowLpf(ml, hk=hk, layavg=0, layvka=0, sy=0.3, ipakcb=53)

    pcg = mf.ModflowPcg(ml, rclose=1e-1)
    oc = mf.ModflowOc(ml)

    ml.write_input()
    ml.run_model(silent=True)
    hds = fu.HeadFile(os.path.join(model_path, modelname + '.hds'))
    times = hds.get_times()

    response = []

    for hob in hobs:
        observed = hob[3]
        calculated = hds.get_data(totim=times[-1])[hob[0]][hob[1]][hob[2]]
        response.append(observed - calculated)

    return json.dumps(response)
示例#12
0
    discret = mf.ModflowDis(ml,
                            nlay=nlay,
                            nrow=nrow,
                            ncol=ncol,
                            laycbd=0,
                            delr=delr,
                            delc=delc,
                            top=botm[0],
                            botm=botm[1:],
                            nper=nper,
                            perlen=perlen,
                            nstp=nstp,
                            steady=steady)
    bas = mf.ModflowBas(ml, ibound=ibound, strt=ihead)
    lpf = mf.ModflowLpf(ml, laytyp=laytyp, hk=hk, vka=vka)
    wel = mf.ModflowWel(ml, stress_period_data=base_well_data)
    ghb = mf.ModflowGhb(ml, stress_period_data=ghb_data)
    rch = mf.ModflowRch(ml, rech=rch_data)
    swi = mf.ModflowSwi2(ml,
                         nsrf=1,
                         istrat=1,
                         toeslope=toeslope,
                         tipslope=tipslope,
                         nu=nu,
                         zeta=z,
                         ssz=ssz,
                         isource=iso,
                         nsolver=1,
                         adaptive=adaptive,
                         nadptmx=nadptmx,
示例#13
0
文件: GGOR.py 项目: jonathanqv/GGOR
dis = fm.ModflowDis(mf,
                    Nlay,
                    Ny,
                    Nx,
                    delr=dx,
                    delc=dy,
                    top=zTop,
                    botm=zBot,
                    laycbd=LAYCBD,
                    nper=NPER,
                    perlen=PERLEN,
                    nstp=NSTP,
                    steady=STEADY)
bas = fm.ModflowBas(mf, ibound=IBOUND, strt=STRTHD)
lpf = fm.ModflowLpf(mf, hk=HK, vka=VKA, sy=SY, ss=SS, laytyp=LAYTYP, vkcb=VKCB)
ghb = fm.ModflowGhb(mf, stress_period_data=GHB)
wel = fm.ModflowWel(mf, stress_period_data=WEL)
rch = fm.ModflowRch(mf, nrchop=3, rech=RECH)
evt = fm.ModflowEvt(mf, nevtop=3, evtr=EVTR)
oc = fm.ModflowOc(mf, stress_period_data=OC, compact=True)
pcg = fm.ModflowPcg(mf)

#%% Write the model input files and running MODFLOW
mf.write_input()

success, mfoutput = mf.run_model(silent=False, pause=False)

print('Running success = {}'.format(success))

if not success:
示例#14
0
文件: GGOR.py 项目: jonathanqv/GGOR
                    gr.nx,
                    delr=gr.dx,
                    delc=gr.dy,
                    top=gr.Ztop[0],
                    botm=gr.Zbot,
                    laycbd=gr.LAYCBD,
                    nper=NPER,
                    perlen=PERLEN,
                    nstp=NSTP,
                    steady=STEADY)
bas = fm.ModflowBas(mf, ibound=IBOUND, strt=STRTHD)
lpf = fm.ModflowLpf(mf,
                    hk=HK,
                    vka=VKA,
                    chani=[1.e-20, 1.e-20],
                    sy=SY,
                    ss=SS,
                    laytyp=LAYTYP,
                    vkcb=VKCB,
                    ipakcb=53)
ghb = fm.ModflowGhb(mf, stress_period_data=GHB, ipakcb=53)
riv = fm.ModflowRiv(mf, stress_period_data=RIV, ipakcb=53)
drn = fm.ModflowDrn(mf, stress_period_data=DRN, ipakcb=53)
wel = fm.ModflowWel(mf, stress_period_data=SEEP, ipakcb=53)
rch = fm.ModflowRch(mf, nrchop=3, rech=RECH, ipakcb=53)
evt = fm.ModflowEvt(mf, nevtop=3, evtr=EVTR, ipakcb=53)
oc = fm.ModflowOc(mf, stress_period_data=OC, compact=True)
#pcg = fm.ModflowPcg(mf, mxiter=200, iter1=200, hclose=0.001, rclose=0.001)
sms = fm.ModflowSms(mf)  #, mxiter=200, iter1=200, hclose=0.001, rclose=0.001)

#%% Write the model input files and run MODFLOW
ibound = np.ones((1, 201))
ibound[0, 0] = ibound[0, -1] = -1
fpm.ModflowBas(model, ibound=ibound, strt=20)

#The hydraulic properties of the aquifer are specified
#with the layer properties flow (LPF) package (alternatively,
#the block centered flow (BCF) package may be
#used). Only the hydraulic conductivity of the aquifer
#and the layer type (laytyp) need to be specified. The
#latter is set to 1, which means that MODFLOW will
#calculate the saturated thickness differently depending
#on whether or not the head is above the top of the
#aquifer.

fpm.ModflowLpf(model, hk=10, laytyp=1)

#4. Aquifer recharge is simulated with the Recharge
#package (RCH) and the extraction of water at the two
#ditches is simulated with the Well package (WEL); the
#length of each ditch normal to the plane of flow is equal
#to 1m (delc = 1). The latter requires specification
#of the layer, row, column, and injection rate of the
#well for each stress period. The layers, rows, columns,
#and the stress period are numbered (consistent with
#Python's zero-based numbering convention) starting at
#0. The required data are stored in a Python dictionary
#(lrcQ in the code below), which is used in FloPy to
#store data that can vary by stress period. The lrcQ
#dictionary specifies that two wells (one in cell 1, 1,
#51 and one in cell 1, 1, 151), each with a rate of
示例#16
0
# what version of modflow to use?
modflow_v = 'mfnwt'  # 'mfnwt' or 'mf2005'

# where is your MODFLOW executable?
if (modflow_v == 'mf2005'):
    if platform.system() == 'Windows':
        path2mf = 'C:/Users/Sam/Dropbox/Work/Models/MODFLOW/MF2005.1_12/bin/mf2005.exe'
    else:
        path2mf = modflow_v
elif (modflow_v == 'mfnwt'):
    if platform.system() == 'Windows':
        path2mf = 'C:/Users/Sam/Dropbox/Work/Models/MODFLOW/MODFLOW-NWT_1.1.4/bin/MODFLOW-NWT.exe'
    else:
        path2mf = modflow_v

# set up super simple model
ml = mf.Modflow(modelname="testmodel", exe_name=path2mf, version=modflow_v)
dis = mf.ModflowDis(ml)
bas = mf.ModflowBas(ml)
oc = mf.ModflowOc(ml)

# choose solver package depending on modflow version
if (modflow_v == 'mf2005'):
    lpf = mf.ModflowLpf(ml)
    pcg = mf.ModflowPcg(ml)
elif (modflow_v == 'mfnwt'):
    upw = mf.ModflowUpw(ml)
    nwt = mf.ModflowNwt(ml)

ml.write_input()
ml.run_model()