Exemplo n.º 1
0
 def upw(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)
     # calibration base = 3.76022E+00; best = 2.87323E+00
     hk[0] *= (.75 * self.params.get('hk_factor', 1))
     hk[1] *= (2   * self.params.get('hk_factor', 1))
     vk    *= (4   * self.params.get('vk_factor', 1))
     upw = flomf.ModflowUpw(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 upw
Exemplo n.º 2
0
def main():
    '''
    This is the main function.
    '''

    # Package all the required file paths into the Paths object
    mfPaths = Paths()

    # Package all the required framework specifications into the mfFrame object
    mfFrame = Frame(Paths=mfPaths, dx_dy=dx_dy)

    if build_from_gis:

        # Build the model framework ASCII files from the GIS layers. Note that this
        # requires a GDAL installation.  If you don't want to get into that you
        # can skip this step and simply build the model from the ASCII files that I've
        # already created.
        mfFrame.build_frame(Paths=mfPaths)
    # ---------------------------------------------
    # ---------------------------------------------
    # Now use Flopy to build the MODFLOW model packages
    # ---------------------------------------------
    # ---------------------------------------------

    start_dir = os.getcwd()
    os.chdir(mfPaths.modflow_dir
             )  # This is simplest if done inside the MODFLOW directory

    # Initialize a Flopy model object. This is the base class around which the model
    # packages are built.
    Modflow = mf.Modflow(mfFrame.model_name,
                         external_path='./',
                         version=mfPaths.mf_version)

    # The .oc ('output control') package specifies how the model output is written.
    # This model includes a single steady state stress period. Save the
    # distribution of heads as well as the flow budget/mass balance to binaries.
    # These can be plotted or converted to rasters (the current version of the script
    # doesn't do any post-processing.)
    oc = mf.ModflowOc(Modflow,
                      stress_period_data={
                          (0, 0): ['SAVE HEAD', 'SAVE BUDGET']
                      })

    # The .dis and .bas packages define the model framework. I've already defined
    # the framework attributes using the mfFrame object and simply pass those
    # attributes to the constructor.
    dis = mf.ModflowDis(Modflow,mfFrame.nlay,mfFrame.nrow,mfFrame.ncol,\
                         delr=mfFrame.delr,delc=mfFrame.delc,\
                         top=mfFrame.top,botm=mfFrame.bottom)

    bas = mf.ModflowBas(Modflow,
                        ibound=mfFrame.ibound,
                        strt=mfFrame.top,
                        hnoflo=mfFrame.hnoflo)

    # The .upw package describes the system properties (e.g., transmissivity/conductivity).
    # For this model I simply give it a constant hydraulic conductivity field. This model
    # converges but I have no idea how physically realistic it is. If you would
    # like to make it more physically realistic (e.g., try to fit head or discharge
    # data) you would need to estimate the hydraulic conductivity field via
    # calibration/inverse modeling
    hk = np.ones(np.shape(mfFrame.ibound))
    upw = mf.ModflowUpw(Modflow, laytyp=mfFrame.laytyp, hk=hk, ipakcb=53)

    # The .nwt package defines the solver specs. Just use the defaults.
    nwt = mf.ModflowNwt(Modflow)

    # RECHARGE INPUTS TO THE SYSTEM
    # -----------------------------
    # The .rch packages specifies recharge/precipitation inputs to the water table.
    # Remember that I have already generated an array from the GIS layer and attached
    # it to the mfFrame object.
    rch = mf.ModflowRch(Modflow, nrchop=3, rech={0: mfFrame.rch}, ipakcb=53)

    # BASEFLOW DISCHARGE FROM THE SYSTEM
    # ----------------------------------
    # The .drn package is one method of simulating the discharge of groundwater as
    # base-flow in streams in rivers.  Define every landsurface cell as a drain
    # in order to allow the discharge network to emerge from topography.
    drn_stages = mfFrame.top
    drn_stages[mfFrame.ibound.squeeze() <= 0] = np.nan
    drn_input = build_drain_input(mfFrame=mfFrame, stages=drn_stages)

    drn = mf.ModflowDrn(Modflow, stress_period_data=drn_input, ipakcb=53)

    # Now write the files.  Flopy can also run the model if you tell it where the
    # binary is, but if I understood your method correctly you will be invoking something
    # from hydroshare. For convenience I am writing a windows .bat file that
    # can be used to run the model.
    Modflow.write_input()
    os.chdir(start_dir)

    with open(mfPaths.mf_bat_file, 'w') as fout:
        fout.write('%s %s' % (binary_path, os.path.basename(mfPaths.nam_file)))

    folder = mfPaths.scratch_dir
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)

    folder = mfPaths.model_frame_dir
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)

    folder = mfPaths.data_dir
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)

    return
Exemplo n.º 3
0
 def get_package(self, _mf):
     content = self.merge()
     return mf.ModflowUpw(_mf, **content)
Exemplo n.º 4
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()