コード例 #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 pcg(self):
     pcg = flomf.ModflowPcg(self.mf,
                            mxiter=60,
                            iter1=20,
                            hclose=1,
                            rclose=1)
     return pcg
コード例 #3
0
ファイル: lake_example.py プロジェクト: awais307/modlfow
#        [-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 get_package(self, _mf):
     content = self.merge()
     return mf.ModflowPcg(
         _mf,
         **content
     )
コード例 #5
0
ファイル: InowasFlopy.py プロジェクト: inowas/pyprocessing
    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']
            )
コード例 #6
0
ファイル: base_2.py プロジェクト: awais307/modlfow
    (nrow, ncol)
)  # in the calculation only the -1 cells will be considered (all values can be set to 0)
bas = mf.ModflowBas(m, ibound=ibound, strt=strt)

# setting up recharge data and recharge package
recharge_data = 0.250  # recharge flux mm/year (default is 1.e-3)
nrchop = 1  # optional code (1: to top grid layer only; 2: to layer defined in irch 3: to highest active cell)
rch = mf.ModflowRch(m, nrchop=nrchop, rech=recharge_data)

# setting up the well package with stress periods
pumping_rate = -4e+10  # m^3 / year
lrcq = {0: [[0, 5, 6, 0.]], 1: [[0, 5, 6, -4e+10]]}
wel = mf.ModflowWel(m, stress_period_data=lrcq)

# instantiation of the solver with default values
pcg = mf.ModflowPcg(m)  # pre-conjugate gradient solver

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

timeStartWritingInput = datetime.now()
ml.write_input()
timeStartRunningModel = datetime.now()
ml.run_model()
timeEndRunningModel = datetime.now()
print "Time writing input: " + str(timeStartRunningModel -
                                   timeStartWritingInput)
print "Calculation Time: " + str(timeEndRunningModel - timeStartRunningModel)

if os.path.exists(workspace):
    shutil.rmtree(workspace)
コード例 #7
0
 well_LRCQ_list = create_LRCQ_list(
     well_obj_list,
     grid_obj)  # Set the settings of the wells for that timestep
 ssm_data = create_conc_list(well_obj_list, attrib='T_inj')
 '''Initialize MODFLOW Packages'''
 bas = mf.ModflowBas(ml, ibound=grid_obj.IBOUND,
                     strt=grid_obj.head)  # Basemodel Modflow
 wel = mf.ModflowWel(ml, stress_period_data=well_LRCQ_list)  # Put in Wells
 words = ['head', 'drawdown', 'budget', 'phead', 'pbudget']
 save_head_every = 1
 #oc = mf.ModflowOc(ml)                                                       # Output control package class --> moved (p3.7 iso p3.6)
 pcg = mf.ModflowPcg(
     ml,
     mxiter=200,
     iter1=200,
     npcond=
     1,  # Preconditioned Conjugate-Gradient Package  --> solves the finite differences equations
     hclose=0.001,
     rclose=0.001,
     relax=1.0,
     nbpol=0)
 ml.write_input()
 '''Initialize MT3DMS packages'''
 mt = mt3.Mt3dms(name,
                 'nam_mt3dms',
                 exe_name=swtexe_name,
                 modflowmodel=ml,
                 model_ws=dirs[0])
 adv = mt3.Mt3dAdv(
     mt,
     mixelm=0,
     percel=0.8,
コード例 #8
0
ファイル: flopy_swi2_ex5.py プロジェクト: Kirubaharan/flopy
# --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)
zeta = []
for kk in zip(get_stp, get_per):
    zeta.append(zobj.get_data(kstpkper=kk, text='      ZETASRF  1')[0])
zeta = np.array(zeta)
コード例 #9
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()
コード例 #10
0
ファイル: gw_tut.py プロジェクト: xzk0010/hydrology
                     botm=bot,
                     laycbd=0)

Nhalf = (N - 1) / 2
ibound = np.ones((Nlay, N, N))
ibound[:, 0, :] = -1
ibound[:, -1, :] = -1
ibound[:, :, 0] = -1
ibound[:, :, -1] = -1
ibound[0, Nhalf, Nhalf] = -1
start = h1 * np.ones((N, N))
start[Nhalf, Nhalf] = h2
bas = fmf.ModflowBas(ml, ibound=ibound, strt=start)
print "o"
lpf = fmf.ModflowLpf(ml, hk=k)
pcg = fmf.ModflowPcg(ml)
oc = fmf.ModflowOc(ml)
ml.write_input()
ml.run_model()

head_file = '/home/kiruba/PycharmProjects/area_of_curve/hydrology/hydrology/mf_files/lake_example.hds'
hds = fut.HeadFile(head_file)
h = hds.get_data(kstpkper=(1, 1))
print len(h)
x = y = np.linspace(0, L, N)
c = plt.contour(x, y, h[0], np.arange(90, 100.1, 0.2))
plt.clabel(c, fmt='%2.1f')
plt.axis('scaled')
plt.show()
c = plt.contour(x, y, h[-1], np.arange(90, 100.1, 0.2))
plt.clabel(c, fmt='%1.1f')
コード例 #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
ファイル: GGOR.py プロジェクト: jonathanqv/GGOR
                    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:
    raise Exception('MODFLOW did not terminate normally.')

#%% SHOWING RESULTS

#%% READ DATA FILES
HDS = bf.HeadFile(modelname + '.hds')
コード例 #13
0
#dictionary specifies that two wells (one in cell 1, 1,
#51 and one in cell 1, 1, 151), each with a rate of
#-1 m3/d, will be active for the first stress period.
#Because this is a steady-state model, there is only
#one stress period and therefore only one entry in the
#dictionary.

fpm.ModflowRch(model, rech=0.001)
lrcQ = {0: [[0, 0, 50, -1], [0, 0, 150, -1]]}
fpm.ModflowWel(model, stress_period_data=lrcQ)

#5. The preconditioned conjugate-gradient (PCG) solver,
#using the default settings, is specified to solve the
#model.

fpm.ModflowPcg(model)

#6. The frequency and type of output that MODFLOW
#writes to an output file is specified with the output
#control (OC) package. In this case, the budget is printed
#and heads are saved (the default), so no arguments are
#needed.

fpm.ModflowOc(model)

#7. Finally the MODFLOW input files are written (eight
#files for this model) and the model is run. This
#requires, of course, that MODFLOW is installed on
#your computer and FloPy can find the executable in
#your path.