def test_CSTR_steadystate(): dict1 = { 'Tank': { 'pollutant': 0, 'method': 'CSTR', 'parameters': { 'k': -0.2, 'n': 1.0, 'c0': 10.0 } } } conc2 = [] vol = [] flow = [] with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim: Tank = Nodes(sim)["Tank"] for index, step in enumerate(sim): v = Tank.volume vol.append(v) q = Tank.total_inflow flow.append(q) with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim: CS = WaterQuality(sim, dict1) Tank = Nodes(sim)["Tank"] for index, step in enumerate(sim): CS.updateWQState_CSTR(index) c = Tank.pollut_quality conc2.append(c['P1']) C_steadystate = dict1['Tank']['parameters']['c0'] / ( (1 - (dict1['Tank']['parameters']['k'] * (np.mean(vol) / np.mean(flow))))**dict1['Tank']['parameters']['n']) error = (C_steadystate - conc2[-1]) / C_steadystate assert error <= 0.03
def test_CSTR_load(): dict1 = { 'Tank': { 'pollutant': 0, 'method': 'CSTR', 'parameters': { 'k': -0.2, 'n': 1.0, 'c0': 10.0 } } } conc = [] conc1 = [] flow = [] flow1 = [] with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim: CS = WaterQuality(sim, dict1) Tank = Nodes(sim)["Tank"] Valve = Links(sim)["Valve"] for index, step in enumerate(sim): CS.updateWQState_CSTR(index) c = Tank.pollut_quality conc.append(c['P1']) c1 = Valve.pollut_quality conc1.append(c1['P1']) flow.append(sim._model.getNodeResult("Tank", 0)) flow1.append(sim._model.getLinkResult("Valve", 0)) load = [a * b for a, b in zip(conc, flow)] cum_load = np.cumsum(load) load1 = [a * b for a, b in zip(conc1, flow1)] cum_load1 = np.cumsum(load1) error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1] print(error) assert error <= 0.03