def create_connections(self): # Route snow melt to surface cmf.SimpleTindexSnowMelt(self.cell.snow, self.cell.surfacewater, rate=7) # Infiltration cmf.SimpleInfiltration(self.soil, self.cell.surfacewater, W0=0.8) # Route infiltration / saturation excess to outlet cmf.WaterBalanceFlux(self.cell.surfacewater, self.outlet) # Parameterize soil water capacity self.soil.soil.porosity = 0.2 C = self.soil.get_capacity() # Parameterize water stress function self.cell.set_uptakestress(cmf.VolumeStress(0.2 * C, 0 * C)) cmf.TurcET(self.soil, self.cell.transpiration) # Route water from soil to gw cmf.PowerLawConnection(self.soil, self.gw, Q0=self.mm_to_m3(50), V0=0.5 * C, beta=4) # Route water from gw to outlet cmf.LinearStorageConnection(self.gw, self.outlet, residencetime=20, residual=0 * C)
def __init__(self, size, residence_time=1.0): """ Parameters ---------- size residence_time """ self.project = p = cmf.project() self.storages = [] self.outlet = p.NewOutlet('outlet', 0, 0, 0) for i in range(1, size+1): stor = p.NewStorage("S{}".format(i), i, 0, i) if self.storages: cmf.LinearStorageConnection(stor, self.storages[-1], residence_time / size) else: cmf.LinearStorageConnection(stor, self.outlet, residence_time / size) self.storages.append(stor)
def get_project(with_solute=False): if with_solute: p = cmf.project('X') X, = p.solutes else: p = cmf.project() X = None stores = [p.NewStorage('source{}'.format(i)) for i in range(10)] for l, r in zip(stores[:-1],stores[1:]): cmf.LinearStorageConnection(l, r, 1) stores[0].volume = 1 if with_solute: stores[0][X].source = 1 return p, stores, X
def test_Q_t(self): """ Tests if the linear storage connection behaves similar to the analytical solution """ p, w1, w2 = create_project_with_2_storages() q = cmf.LinearStorageConnection(w1, w2, 1) # Loop over several scales for residence time for res_t in 10**np.arange(-3, 3, 0.5): q.residencetime = res_t w1.volume = 1.0 w2.volume = 0.0 solver = cmf.CVodeIntegrator(p, 1e-9) solver.integrate_until(cmf.day) self.assertAlmostEqual( w1.volume, np.exp(-1 / res_t), 5, 'LinearStorage fails to reproduce analytical solution for t_r={:0.5g}' .format(res_t))
ws[X].set_adsorption(cmf.LinearAdsorption(1, 1)) # Tracer Y has a Freundlich isotherm xa/m=Kc^n, # with K = 1 and n=0.5 and sorbent mass m = 1 ws[Y].set_adsorption(cmf.FreundlichAdsorbtion(1., 1., 1.0)) # Tracer Y has a Langmuir isotherm xa/m=Kc/(1+Kc), # with K = 1 and sorbent mass m = 1 ws[Z].set_adsorption(cmf.LangmuirAdsorption(1., 1.)) # Now we put a constant clean water flux into the storage inflow = cmf.NeumannBoundary.create(ws) inflow.flux = 1.0 # 1 m3/day for s in p.solutes: inflow.concentration[s] = 0.0 # And an outlet, a linear storage term with a retention time of 1 day outlet = p.NewOutlet('out', 0, 0, 0) cmf.LinearStorageConnection(ws, outlet, 1.) # Create a solver solver = cmf.ExplicitEuler_fixed(p) # Rinse the storage for 1 week and get the outlet concentration at every hour # and the remaining tracer in the storage result = [[outlet.conc(t, s) for s in p.solutes] + [ws[s].state for s in p.solutes] for t in solver.run(solver.t, 2 * cmf.week, cmf.h)] # Plot result ] from pylab import * result = array(result) conc = result[:, :len(p.solutes)] load = result[:, len(p.solutes):]