def __init__(self, par): cmf.set_parallel_threads(1) # run the model self.project = cmf.project() self.cell = self.project.NewCell(x=0, y=0, z=238.628, area=1000, with_surfacewater=True) c = self.cell r_curve = cmf.VanGenuchtenMualem(Ksat=10**par.pKsat, phi=par.porosity, alpha=par.alpha, n=par.n) # Make the layer boundaries and create soil layers lthickness = [.01] * 5 + [0.025] * 6 + [0.05] * 6 + [0.1] * 5 ldepth = np.cumsum(lthickness) # Create soil layers and pick the new soil layers if they are inside of the evaluation depth's for d in ldepth: c.add_layer(d, r_curve) # Use a Richards model c.install_connection(cmf.Richards) # Use shuttleworth wallace self.ET = c.install_connection(cmf.ShuttleworthWallace) c.saturated_depth = 0.5 self.gw = self.project.NewOutlet('groundwater', x=0, y=0, z=.9) cmf.Richards(c.layers[-1], self.gw) self.gw.potential = c.z - 0.5 #IMPORTANT self.gw.is_source = True self.gwhead = cmf.timeseries.from_scalar(c.z - 0.5) self.solver = cmf.CVodeIntegrator(self.project, 1e-9)
def connect_matrix(self): """ Creates matrix percolation (MatrixInfiltration is created automatically) """ self.c.surfacewater.remove_connection(self.c.layers[0]) mx_infiltration = cmf.MatrixInfiltration(self.c.layers[0], self.c.surfacewater) mx_percolation = [] for left, right in zip(self.c.layers[:-1], self.c.layers[1:]): mx_percolation.append(cmf.Richards(left, right)) return mx_infiltration, mx_percolation
def simple1D(): from matplotlib import pyplot as plt import cmf from datetime import datetime, timedelta project = cmf.project() # Add one cell at position (0,0,0), Area=1000m2 cell = project.NewCell(0, 0, 0, 1000, with_surfacewater=True) # Create a retention curve r_curve = cmf.VanGenuchtenMualem(Ksat=1, phi=0.5, alpha=0.01, n=2.0) # Add ten layers of 10cm thickness for i in range(10): depth = (i + 1) * 0.1 cell.add_layer(depth, r_curve) # Connect layers with Richards perc. # this can be shorten as cell.install_connection(cmf.Richards) # Create solver solver = cmf.CVodeIntegrator(project, 1e-6) solver.t = cmf.Time(1, 1, 2011) # Create groundwater boundary (uncomment to use it) # Create the boundary condition gw = project.NewOutlet('groundwater', x=0, y=0, z=-1.1) # Set the potential gw.potential = -2 # Connect the lowest layer to the groundwater using Richards percolation gw_flux=cmf.Richards(cell.layers[-1],gw) # Set inital conditions # Set all layers to a potential of -2 m cell.saturated_depth = 2. # 100 mm water in the surface water storage cell.surfacewater.depth = 0.1 # The run time loop, run for 72 hours # Save potential and soil moisture for each layer potential = [cell.layers.potential] moisture = [cell.layers.theta] for t in solver.run(solver.t, solver.t + timedelta(days=7), timedelta(hours=1)): potential.append(cell.layers.potential) moisture.append(cell.layers.theta) """ # Plot results plt.subplot(211) plt.plot(moisture) plt.ylabel(r'Soil moisture $\theta [m^3/m^3]$') plt.xlabel(r'$time [h]$') plt.grid() plt.subplot(212) plt.plot(potential) plt.ylabel(r'Water head $\Psi_{tot} [m]$') plt.xlabel(r'$time [h]$') plt.grid() plt.show() """ print(cell.vegetation)
# Create a cell at position (0,0,0) with 1000m2 size (making conversion from m3 to mm trivial) c = p.NewCell(0, 0, 0, 1000) # Customize cell # Create layers for d in [0.05, 0.1, 0.2, 0.3, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]: c.add_layer(d, soiltype(d)) # Set the head of each layer at 2 m below ground c.saturated_depth = 5. # Create a surfacewater storage c.surfacewater_as_storage() # use Richards connection for lup, ldown in zip(c.layers[:-1], c.layers[1:]): cmf.Richards(lup, ldown) # Use matrix infiltration as connection between surface water and first layer c.install_connection(cmf.MatrixInfiltration) # Create a snow storage and use a simple Temperature index model as a connection between snow and surfacewater c.install_connection(cmf.SimpleTindexSnowMelt) # Use Penman-Monteith for ET c.install_connection(cmf.ShuttleworthWallace) c.vegetation.stomatal_resistance = 200 # Make an outlet (Groundwater as a boundary condition) groundwater = p.NewOutlet('outlet', 0, 0, -4.4) # Connect last layer with the groundwater, using Richards equation cmf.Richards(c.layers[-1], groundwater) # load meteorological data load_meteo(p) # Make solver solver = cmf.CVodeIntegrator(p, 1e-9)
# Create a single cell c with a surfacewater storage, which references 3 solute storages c = p.NewCell(0, 0, 0, 1000, with_surfacewater=True) # Create 50 layers with 2cm thickness for i in range(50): # Add a layer. Each layer will reference 3 solute storages l = c.add_layer((i + 1) * 0.02, cmf.VanGenuchtenMualem()) # Add a 10% decay per day for Tracer z l.Solute(Z).decay = 0.25 # Use Richards equation c.install_connection(cmf.Richards) # Use a constant rainfall of 50 mm c.set_rainfall(100.) # Make a groundwater boundary condition gw = p.NewOutlet('gw', 0, 0, -1.5) cmf.Richards(c.layers[-1], gw) # Template for the water solver #wsolver = cmf.CVodeIntegrator(1e-9) # Template for the solute solver #ssolver = cmf.ImplicitEuler(1e-9) # Creating the SWI, the storage objects of the project are internally assigned to the correct solver #solver = cmf.SoluteWaterIntegrator(p.solutes, wsolver,ssolver,p) solver = cmf.CVodeIntegrator(p, 1e-9) c.saturated_depth = 1.5 c.layers[0].conc(X, 1.) c.layers[15].conc(Y, 1.) c.layers[0].conc(Z, 1.) # Save wetness and concentration of all layers conc = []
def _run(self, alpha=None, n=None, porosity=None, ksat=None): #return alpha,n,porosity,ksat ''' Runs the model instance Input: Parameter set (in this case VAN-Genuchten Parameter alpha,n,porosity,ksat) Output: Simulated values on given observation days ''' #Check if given parameter set is in realistic boundaries if alpha<self.bound[0][0] or alpha>self.bound[0][1] or ksat<self.bound[1][0] \ or ksat>self.bound[1][1] or n<self.bound[2][0] or n>self.bound[2][1] or \ porosity<self.bound[3][0] or porosity>self.bound[3][1]: print('The following combination was ignored') text = 'n= ' + str(n) print(text) text = 'alpha=' + str(alpha) print(text) text = 'ksat= ' + str(ksat) print(text) text = 'porosity= ' + str(porosity) print(text) print('##############################') return self.observations * -np.inf else: project = cmf.project() cell = project.NewCell(x=0, y=0, z=0, area=1000, with_surfacewater=True) text = 'n= ' + str(n) print(text) text = 'alpha=' + str(alpha) print(text) text = 'ksat= ' + str(ksat) print(text) text = 'porosity= ' + str(porosity) print(text) print('##############################') r_curve = cmf.VanGenuchtenMualem(Ksat=ksat, phi=porosity, alpha=alpha, n=n) layers = 5 ldepth = .01 for i in range(layers): depth = (i + 1) * ldepth cell.add_layer(depth, r_curve) cell.install_connection(cmf.Richards) cell.install_connection(cmf.ShuttleworthWallace) cell.saturated_depth = .5 solver = cmf.CVodeIntegrator(project, 1e-6) self._load_meteo(project) gw = project.NewOutlet('groundwater', x=0, y=0, z=.9) #layers*ldepth) cmf.Richards(cell.layers[-1], gw) gw.potential = -.5 #IMPORTANT gw.is_source = True solver.t = self.datastart Evalstep, evallist = 0, [] rundays = (self.dataend - self.datastart).days for t in solver.run(solver.t, solver.t + timedelta(days=rundays), timedelta(hours=1)): if self.gw_array['Date'].__contains__(t) == True: Gw_Index = np.where(self.gw_array['Date'] == t) gw.potential = self.gw_array[self.piezometer][Gw_Index] print(gw.potential ) #TO DO: CHECK IF SOMETHING HAPPENS HERE!!!! if t > self.analysestart: if Evalstep != len(self.eval_dates ) and t == self.eval_dates[Evalstep]: evallist.append(cell.layers.wetness[0] * cell.layers.porosity[0] * 100) Evalstep += 1 return evallist