def test_jac(self): hL = 0.75 hR = 0.25 xi = 0.5 N = 8 t = np.linspace(0, 0.1, 4) x = np.linspace(0, 1., N) x_domain = Domain("x", value=x, unit="m", description="x1 coordinate") m = ShallowWater(x_domain=x_domain, scheme=SchemeM1FDMEnum.CENTRAL_N2, scheme_hrs=SchemeM1FDMEnum.CENTRAL_N2, flux_delimiter=FluxDelimiterEnum.SMART2) v0 = np.zeros(N) m.variables["v"].set_ic(v0, "m/s") h0 = np.zeros(N) h0 = np.where(x < xi, hL, h0) h0 = np.where(x >= xi, hR, h0) m.variables["h"].set_ic(h0, "m") y0 = m.variables.get_ic_array() ou1, ou2 = m.jacobian(0, y0, np.zeros_like(y0), 1.0, None) self.assertTrue(True)
def test_1(self, plot=True): N = 200 t = np.linspace(0, 20, 10) x = np.linspace(0, 500., N) Pi = 1200000 Pf = 1000000 qi = 21 qf = 20 x_domain = Domain("x", value=x, unit="m", description="x1 coordinate") m = SinglePhaseFlow( x_domain=x_domain, flux_delimiter=FluxDelimiterEnum.SMART2, ) m.parameters["D"].set(4, "in") m.parameters['g'].set(9.81, "m/s**2") m.parameters['epw'].set(46, "um") m.parameters['mu'].set(0.001, "Pa*s") m.parameters['rho'].set(1000, "kg/m**3") m.parameters['drhodP'].set(5e-7, "kg/m**3/Pa") m.parameters['z'].set(np.zeros_like(x), "m") m.parameters['q_lb'].set(value_span=qi * np.array([1, 1, 1.01, 1.01]), value_unit="kg/s", time_unit="s", time_span=np.array([0, 1, 3, 10000])) m.parameters['P_ub'].set(value_span=Pf * np.array([1, 1, 1, 1]), value_unit="Pa", time_unit="s", time_span=np.array([0, 1, 3, 10000])) q0 = np.linspace(qi, qf, N) m.variables["q"].set_ic(value=q0, unit="kg/s") P0 = np.linspace(Pi, Pf, N) m.variables["P"].set_ic(value=P0, unit="Pa") y0 = m.variables.get_ic_array() t0, y0, yp0 = DasslSolver.run(m, None, y0, display=True, rtol=1e-3, atol=1e-6) t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-6) if plot: m.plot_result(t, y) else: self.assertAlmostEqual(y[-1, 0], qi)
def test_1(self, plot=True): N = 20 t = np.linspace(0, 0.5, 4) x1 = np.linspace(-1, 1., N) x2 = np.linspace(-1, 1., N) x1_domain = Domain("x1", value=x1, unit="m", description="x1 coordinate") x2_domain = Domain("x2", value=x2, unit="m", description="x2 coordinate") m = Burgers2D( x1_domain=x1_domain, x2_domain=x2_domain, flux_delimiter=FluxDelimiterEnum.SMART2, scheme=SchemeM1FDMEnum.CENTRAL_N2, scheme_hrs=SchemeM1FDMEnum.CENTRAL_N6, ) m.parameters["visc"].set(0.001, "m**2/s") X1, X2 = np.meshgrid(x1, x2, indexing="ij") u0 = np.zeros_like(X1) u0[(X1 + 0.2)**2 + (X2 + 0.2)**2 <= 0.4] = 1.0 m.variables["u"].set_ic(u0, "m/s") y0 = m.variables.get_ic_array() t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-6, user_jacobian=True) if plot: m.plot_result(t, y) else: self.assertAlmostEqual(y[-1, 0], u0[0, 0])
def test_1(self, plot=True): # TODO - Does not converge for N > 200 N = 100 t = np.linspace(0, 0.8, 110) tresp = np.linspace(0, 0.8, 4) x = np.linspace(0, 1., N) u0 = np.sin(2 * 3.1415 * x) + np.sin(3.1415 * x) / 2 deltax = x[1] - x[0] vmax = np.max(u0) Cmax = 1 deltatmax = Cmax * deltax / vmax m = Burgers( x_domain=Domain("x", x, "m"), flux_delimiter=FluxDelimiterEnum.SMART2, scheme=SchemeM1FDMEnum.CENTRAL_N2, scheme_hrs=SchemeM1FDMEnum.CENTRAL_N6, ) m.parameters["visc"].set(0.001, "m**2/s") m.parameters["lb"].set(None, "m/s") m.parameters["ub"].set(None, "m/s") #m.jacobian = None m.variables["u"].set_ic(u0, "m/s") y0 = m.variables.get_ic_array() t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-6, user_jacobian=True) fresp = interp1d(t, y, axis=0) yresp = fresp(tresp) if plot: m.plot_result(tresp, yresp) else: self.assertAlmostEqual(y[-1, 0], u0[0])
def test_2(self, plot=False): N = 1000 #t = np.linspace(0, 0.6, 600) t = np.linspace(0, 0.6, 4) vL = 1.0 vR = 0.5 xi = 0.2 x = np.linspace(0, 1., N) deltax = x[1] - x[0] vmax = vL Cmax = 1 deltatmax = Cmax * deltax / vmax m = Burgers(x_domain=Domain("x", x, "m"), flux_delimiter=FluxDelimiterEnum.SMART2) m.parameters["visc"].set(0.001, "m**2/s") m.parameters["lb"].set(vL, "m/s") m.parameters["ub"].set(vR, "m/s") u0 = np.zeros(N) u0 = np.where(x < xi, vL, u0) u0 = np.where(x >= xi, vR, u0) m.variables["u"].set_ic(u0, "m/s") y0 = m.variables.get_ic_array() t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-6, user_jacobian=True) if plot: m.plot_result(t, y) else: self.assertAlmostEqual(y[-1, 0], u0[0])
def test_1(self, plot=True): # TODO - This is not working hL = 0.75 hR = 0.25 xi = 0.5 N = 100 t = np.linspace(0, 0.1, 4) x = np.linspace(0, 1., N) x_domain = Domain("x", value=x, unit="m", description="x1 coordinate") m = ShallowWater(x_domain=x_domain, scheme=SchemeM1FDMEnum.CENTRAL_N2, scheme_hrs=SchemeM1FDMEnum.CENTRAL_N6, flux_delimiter=FluxDelimiterEnum.SMART2) v0 = np.zeros(N) m.variables["v"].set_ic(v0, "m/s") h0 = np.zeros(N) h0 = np.where(x < xi, hL, h0) h0 = np.where(x >= xi, hR, h0) m.variables["h"].set_ic(h0, "m") y0 = m.variables.get_ic_array() t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-3, user_jacobian=True) if plot: m.plot_result(t, y) else: self.assertAlmostEqual(y[-1, 0], v0[0])
def test_1(self, plot=True): N = 25 t = np.linspace(0, 100, 11) x = np.linspace(0, 100., N) Pr = 1e5 alphaLi = 0.46 Pi = 520000 / Pr Pf = 500000 / Pr qLi = 11 qGi = 0.5 x_domain = Domain("x", value=x, unit="m", description="x1 coordinate") m = TwoPhaseFlow( x_domain=x_domain, flux_delimiter=FluxDelimiterEnum.MINMOD2, ) m.parameters['Pr'].set(Pr, "Pa") m.parameters['D'].set(8, "in") m.parameters['epw'].set(46, "um") m.parameters['g'].set(9.81, "m/s**2") m.parameters['rhoL'].set(1000, "kg/m**3") m.parameters['muL'].set(0.001, "Pa*s") m.parameters['drhoLdP'].set(5e-7, "kg/m**3/Pa") m.parameters['rhoG'].set(1, "kg/m**3") m.parameters['muG'].set(0.00001, "Pa*s") m.parameters['drhoGdP'].set(5e-4, "kg/m**3/Pa") m.parameters['tetha'].set(np.zeros_like(x), "") m.parameters['qL_lb'].set(value_span=qLi * np.array([1, 1, 1.1, 1.1]), value_unit="kg/s", time_unit="s", time_span=np.array([0, 20, 60, 10000])) m.parameters['qG_lb'].set(value_span=qGi * np.array([1, 1, 1., 1.]), value_unit="kg/s", time_unit="s", time_span=np.array([0, 2, 3, 10000])) m.parameters['P_ub'].set(value_span=Pf * Pr * np.array([1, 1, 1, 1]), value_unit="Pa", time_unit="s", time_span=np.array([0, 1, 3, 10000])) qL0 = np.linspace(qLi, qLi, N) m.variables["qL"].set_ic(value=qL0, unit="kg/s") qG0 = np.linspace(qGi, qGi, N) m.variables["qG"].set_ic(value=qG0, unit="kg/s") alphaL0 = np.linspace(alphaLi, alphaLi, N) m.variables["alphaL"].set_ic(value=alphaL0, unit="") P0 = np.linspace(Pi, Pf, N) m.variables["P"].set_ic(value=P0, unit="Pa/Pa") y0 = m.variables.get_ic_array() out = m.jacobian(0, y0, np.zeros_like(y0), 1.0, None) t0, y0, yp0 = DasslSolver.run(m, None, y0, display=True, rtol=1e-3, atol=1e-6) t, y, yp = DasslSolver.run(m, t, y0, display=True, rtol=1e-3, atol=1e-6, user_jacobian=True) if plot: m.plot_result(t, y) else: self.assertAlmostEqual(y[-1, 0], qLi)