def _define_fluxes(self): """ Defines process description for fluxes, meteorological forcing and boundary conditions (outlets). Returns ------- None. """ # meteorology self.rainfall_stations.add('', 0.0, (0, 0, 0)) self.use_nearest_rainfall() self.ET = [] # cell to cell flux cmf.connect_cells_with_flux(self, cmf.Richards_lateral) cmf.connect_cells_with_flux(self, cmf.DiffusiveSurfaceRunoff) # define outlets # outlet Darcy flow self.outlet = self.NewOutlet('out', -self.length / self.ncell, 0, 0-self.gradient*self.length/self.ncell) # outflow surface runoff self.outlet_s = self.NewOutlet('out_s', -self.length / self.ncell, 0, 0+self.depth-self.gradient*self.length/self.ncell) for li in self[0].layers: cmf.Darcy(li, self.outlet, self.width) cmf.DiffusiveSurfaceRunoff(self[0].surfacewater, self.outlet_s, self.width)
def __init__(self, subsurface_lateral_connection, surface_lateral_connection=None, layercount=0): """ Creates the cmf project :param subsurface_lateral_connection: Type of lateral subsurface connection, eg. cmf.Darcy :param surface_lateral_connection: Type of lateral surface flux connection, eg. cmf.KinematicSurfaceRunoff or None :param layercount: Number of layers in the subsurface :return: """ p = cmf.project() shp = Shapefile('data/vollnkirchner_bach_cells.shp') # Create cells self.outlet_cells = [] for feature in shp: # Create a cell for each feature in the shape file c = cmf.geometry.create_cell(p, feature.shape, feature.HEIGHT, feature.OID, with_surfacewater=False) # If it is an outlet feature, add cell to the list of outletcells if feature.LANDUSE_CU.startswith('outlet'): self.outlet_cells.append(c) else: # If it is a normal upload cell, add layers self.build_cell(c, layercount) # Build topology cmf.geometry.mesh_project(p, verbose=True) # Connect cells with fluxes cmf.connect_cells_with_flux(p, subsurface_lateral_connection) if surface_lateral_connection: cmf.connect_cells_with_flux(p, surface_lateral_connection) # Connect outlets with neighbor cells for o_cell in self.outlet_cells: self.connect_outlet_cell(o_cell, subsurface_lateral_connection, surface_lateral_connection) # Load driver data load_meteo(p) self.project = p self.solver = cmf.CVodeIntegrator(p, 1e-9) self.solver.t = p.meteo_stations[0].T.begin
def install_flux_connections(cmf_project: cmf.project, cell_properties: dict) -> cmf.project: cmf.connect_cells_with_flux(cmf_project, cmf.DarcyKinematic) logger.info('Installed Darcy kinematic for all cells in project.') if cell_properties['runoff_method'] == 'kinematic': cmf.connect_cells_with_flux(cmf_project, cmf.KinematicSurfaceRunoff) logger.info('Installed kinematic surface run-off') elif cell_properties['runoff_method'] == 'diffusive': cmf.DiffusiveSurfaceRunoff.set_linear_slope(1e-8) cmf.connect_cells_with_flux(cmf_project, cmf.DiffusiveSurfaceRunoff) logger.info('Installed diffusive surface run-off. Slope set to 1e-8.') return cmf_project
def configure_cells(self, cmf_project: cmf.project, cell_properties_dict: dict): """Configure the cells""" # Helper functions def install_connections(cell_, evapotranspiration_method): # Install connections cell_.install_connection(cmf.Richards) cell_.install_connection(cmf.GreenAmptInfiltration) if evapotranspiration_method == 'penman_monteith': # Install Penman & Monteith method to calculate evapotranspiration_potential cell_.install_connection(cmf.PenmanMonteithET) elif evapotranspiration_method == 'shuttleworth_wallace': # Install Shuttleworth-Wallace method to calculate evapotranspiration cell_.install_connection(cmf.ShuttleworthWallace) return True def retention_curve(r_curve_: dict): """ Converts a dict of retention curve parameters into a CMF van Genuchten-Mualem retention curve. :param r_curve_: dict :return: CMF retention curve """ curve = cmf.VanGenuchtenMualem(r_curve_['K_sat'], r_curve_['phi'], r_curve_['alpha'], r_curve_['n'], r_curve_['m']) curve.l = r_curve_['l'] return curve # Convert retention curve parameters into CMF retention curve r_curve = retention_curve(cell_properties_dict['retention_curve']) for cell_index in cell_properties_dict['face_indices']: cell = cmf_project.cells[int(float(cell_index))] # Add layers for i in range(0, len(cell_properties_dict['layers'])): cell.add_layer(float(cell_properties_dict['layers'][i]), r_curve) install_connections(cell, cell_properties_dict['et_method']) self.set_vegetation_properties( cell, cell_properties_dict['vegetation_properties']) if cell_properties_dict['manning']: cell.surfacewater.set_nManning( float(cell_properties_dict['manning'])) if cell_properties_dict['puddle_depth']: cell.surfacewater.puddledepth = cell_properties_dict[ 'puddle_depth'] # Set initial saturation cell.saturated_depth = cell_properties_dict['saturated_depth'] # Connect fluxes cmf.connect_cells_with_flux(cmf_project, cmf.Darcy) cmf.connect_cells_with_flux(cmf_project, cmf.KinematicSurfaceRunoff) return True
#if i and j: #c.topology.AddNeighbor(cells[i,j-1],length*.5) for c in p: c.surfacewater_as_storage() # 1mm puddle depth c.surfacewater.puddledepth = 0.001 #np.random.uniform(0.0,0.001) #c.surfacewater.depth = 0.002 # Asphalt c.surfacewater.nManning = 0.015 c.add_layer(0.1, cmf.VanGenuchtenMualem(Ksat=0.005)) c.install_connection(cmf.GreenAmptInfiltration) cmf.DiffusiveSurfaceRunoff.set_linear_slope(1e-8) cmf.connect_cells_with_flux(p, cmf.DiffusiveSurfaceRunoff) outlet = p.NewOutlet('outlet',-length,0,-slope*length) #for j in range(size[1]): # for i in range(size[0]): # is_border = i in [0,size[0]-1] or j in [0, size[1]-1] # if is_border: # cmf.waterbalance_connection(cells[i,j].surfacewater,outlet) cmf.DiffusiveSurfaceRunoff(cells[0,0].surfacewater, outlet,length) def setrain(rainfall): for c in p: c.set_rainfall(rainfall) # cells[size[0]//2,size[1]//2].set_rainfall(rainfall*20) solver = cmf.CVodeIntegrator(p,1e-9) setrain(10.*24.)
# Customize cells for c in p: for d in [0.05,0.1,0.2,0.3,0.5,0.75,1.0,1.3,1.7,2.]: c.add_layer(d, soiltype(d)) c.saturated_depth=5. c.surfacewater_as_storage() # use Richards connection c.install_connection(cmf.Richards) c.install_connection(cmf.MatrixInfiltration) c.install_connection(cmf.CanopyOverflow) c.install_connection(cmf.SimpleTindexSnowMelt) c.install_connection(cmf.PenmanMonteithET) # This connects the layers of all adjacent cells laterally cmf.connect_cells_with_flux(p,cmf.DarcyKinematic) cmf.connect_cells_with_flux(p,cmf.KinematicSurfaceRunoff) # Make an outlet (ditch, 30cm deep) outlet=p.NewOutlet('outlet',-celllength, 0, -.3) # Connect outlet to soil p[0].connect_soil_with_node(outlet,cmf.DarcyKinematic,10.0,5.0) # Connect outlet to surfacewater (overbank flow) cmf.KinematicSurfaceRunoff(p[0].surfacewater, outlet, 10.0, 5.0) load_meteo(p) # Make solver solver=cmf.CVodeIntegrator(p,1e-6) solver.t=cmf.Time(1,1,1990)
import cmf from cmf.geos_shapereader import Shapefile as cmf_shape p = cmf.project() r_curve = cmf.VanGenuchtenMualem() # Load cell polygons from file path = r'C:\Users\Christian\Desktop\Livestock\shapefiles\shape_mesh.shp' polygons = cmf_shape(path) # create cell mesh from polygons cells = p.cells_from_polygons(polygons) for c in p.cells: # Add ten layers for i in range(10): c.AddLayer((i + 1) * 0.1, r_curve) cmf.Richards.use_for_cell(c) c.surfacewater_as_storage() # subsurface flow cmf.connect_cells_with_flux(p, cmf.Richards_lateral) # surface runoff cmf.connect_cells_with_flux(p, cmf.Manning_Kinematic)
# Customize cells for c in p: for d in [0.05,0.1,0.2,0.3,0.5,0.75,1.0,1.3,1.7,2.]: c.add_layer(d, soiltype(d)) c.saturated_depth=5. c.surfacewater_as_storage() # use Richards connection c.install_connection(cmf.Richards) c.install_connection(cmf.MatrixInfiltration) c.install_connection(cmf.CanopyOverflow) c.install_connection(cmf.SimpleTindexSnowMelt) c.install_connection(cmf.PenmanMonteithET) # This connects the layers of all adjacent cells laterally cmf.connect_cells_with_flux(p,cmf.Richards_lateral) cmf.connect_cells_with_flux(p,cmf.KinematicSurfaceRunoff) # Make an outlet (ditch, 30cm deep) outlet=p.NewOutlet('outlet',-celllength, 0, -.3) # Connect outlet to soil p[0].connect_soil_with_node(outlet,cmf.Richards_lateral,10.0,5.0) # Connect outlet to surfacewater (overbank flow) cmf.KinematicSurfaceRunoff(p[0].surfacewater, outlet, 10.0, 5.0) load_meteo(p) # Make solver solver=cmf.CVodeIntegrator(p,1e-6) solver.t=cmf.Time(1,1,1990)