def case_solver(self, nx, ny, xnum, flux): meshsim = mesh2d.unimesh(nx, ny) bcper = {'type': 'per'} bclist = {tag: bcper for tag in meshsim.list_of_bctags()} model = euler.euler2d() rhs = modeldisc.fvm2d(model, meshsim, num=xnum, numflux=flux, bclist=bclist) solver = integ.rk3ssp(meshsim, rhs) def fuv(x, y): return euler.datavector(0. * x + .4, 0. * x + .2) def fp(x, y): # gamma = 1.4 return 0. * x + 1. def frho(x, y): return 1.4 * (1 + .2 * np.exp(-((x - .5)**2 + (y - .5)**2) / (.1)**2)) xc, yc = meshsim.centers() finit = rhs.fdata_fromprim([frho(xc, yc), fuv(xc, yc), fp(xc, yc)]) # rho, (u,v), p return solver, finit
def case_solver(self, nx, ny, xnum, flux, bcL, bcR): meshsim = mesh2d.unimesh(nx, ny) bcsym = {'type': 'sym'} bclist = {'top': bcsym, 'bottom': bcsym, 'left': bcL, 'right': bcR} model = euler.euler2d() rhs = modeldisc.fvm2d(model, meshsim, num=xnum, numflux=flux, bclist=bclist) solver = integ.rk3ssp(meshsim, rhs) finit = rhs.fdata_fromprim([1., [0.8, 0.], 1.]) # rho, (u,v), p return solver, finit
def test_shocktube_sodsup(flux): model = euler.model() sod = solR.Sod_supersonic(model) # sol.Sod_supersonic(model) # bcL = { 'type': 'dirichlet', 'prim': sod.bcL() } bcR = { 'type': 'dirichlet', 'prim': sod.bcR() } xnum = muscl(minmod) # rhs = modeldisc.fvm(model, meshref, xnum, numflux=flux, bcL=bcL, bcR=bcR) solver = integ.rk3ssp(meshref, rhs) # computation # endtime = 2. cfl = 1. finit = sod.fdata(meshref) fsol = solver.solve(finit, cfl, [endtime]) fref = sod.fdata(meshref, endtime) # for name in ['density', 'pressure', 'mach']: error = np.sqrt(np.sum((fsol[-1].phydata(name)-fref.phydata(name))**2))/np.sum(np.abs(fref.phydata(name))) assert error < 5.e-3
def test_nozzle(NPR): def S(x): # section law, throat is at x=5 return 1. - .5 * np.exp(-.5 * (x - 5.)**2) model = euler.nozzle(sectionlaw=S) meshsim = mesh.unimesh(ncell=50, length=10.) nozz = solN.nozzle(model, S(meshsim.centers()), NPR=NPR) fref = nozz.fdata(meshsim) # BC bcL = {'type': 'insub', 'ptot': NPR, 'rttot': 1.} bcR = {'type': 'outsub', 'p': 1.} # rhs = modeldisc.fvm(model, meshsim, muscl(vanleer), bcL=bcL, bcR=bcR) solver = integ.rk3ssp(meshsim, rhs) # computation endtime = 100. cfl = .8 finit = rhs.fdata_fromprim([1., 0.1, 1.]) # rho, u, p fsol = solver.solve(finit, cfl, [endtime]) # error error = np.sqrt( np.sum((fsol[-1].phydata('mach') - fref.phydata('mach'))**2)) / np.sum( np.abs(fref.phydata('mach'))) assert error < 5.e-2
import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc #import flowdyn.solution.euler_riemann as sol nx = 50 meshsim = unimesh(ncell=nx, length=10.) model = euler.model() bcL = {'type': 'insub', 'ptot': 1.4, 'rttot': 1.} bcR = {'type': 'outsub', 'p': 1.} rhs = modeldisc.fvm(model, meshsim, muscl(minmod), bcL=bcL, bcR=bcR) solver1 = tnum.rk3ssp(meshsim, rhs) solver2 = tnum.gear(meshsim, rhs) # computation # endtime = 100. cfl1 = .8 cfl2 = 20. finit = rhs.fdata_fromprim([1., 0.1, 1.]) # rho, u, p fsol1 = solver1.solve(finit, cfl1, [endtime]) solver1.show_perf() fsol2 = solver2.solve(finit, cfl2, [endtime]) solver2.show_perf()
import flowdyn.solution.euler_riemann as sol meshsim = unimesh(ncell=200, length=10., x0=-4.) meshref = unimesh(ncell=1000, length=10., x0=-4.) model1 = euler.model() model2 = euler.model() sod = sol.Sod_subsonic(model1) # sol.Sod_supersonic(model1) # bcL = { 'type': 'dirichlet', 'prim': sod.bcL() } bcR = { 'type': 'dirichlet', 'prim': sod.bcR() } xnum1 = muscl(minmod) # xnum2 = muscl(vanalbada) # rhs1 = modeldisc.fvm(model1, meshsim, xnum1, numflux='hlle', bcL=bcL, bcR=bcR) solver1 = tnum.rk3ssp(meshsim, rhs1) rhs2 = modeldisc.fvm(model2, meshsim, xnum2, numflux='hlle', bcL=bcL, bcR=bcR) solver2 = tnum.rk3ssp(meshsim, rhs2) # computation # endtime = 2.8 # 2.8 for subsonic, 2.8 for supersonic cfl = 1. finit = sod.fdata(meshsim) fsol1 = solver1.solve(finit, cfl, [endtime]) solver1.show_perf() fsol2 = solver2.solve(finit, cfl, [endtime]) solver2.show_perf()
#meshsim = mesh.unimesh(ncell=200, length=10., x0=-4.) #meshref = mesh.unimesh(ncell=1000, length=10., x0=-4.) @pytest.mark.parametrize("case, endtime", [(solR.Sod_subsonic, 2.8), (solR.Sod_supersonic, 2.)]) def test_shocktube(case, endtime): meshsim = mesh.unimesh(ncell=200, length=10., x0=-4.) model = euler.euler1d() sod = case(model) # sol.Sod_supersonic(model) # bcL = {'type': 'dirichlet', 'prim': sod.bcL()} bcR = {'type': 'dirichlet', 'prim': sod.bcR()} xnum = muscl(minmod) # rhs = modeldisc.fvm(model, meshsim, xnum, numflux='hllc', bcL=bcL, bcR=bcR) solver = integ.rk3ssp(meshsim, rhs) # computation # cfl = 1. finit = sod.fdata(meshsim) fsol = solver.solve(finit, cfl, [endtime]) fref = sod.fdata(meshsim, endtime) # for name in ['density', 'pressure', 'mach']: error = np.sqrt( np.sum((fsol[-1].phydata(name) - fref.phydata(name))**2)) / np.sum( np.abs(fref.phydata(name))) assert error < 1.e-2 @pytest.mark.no_cover
bcR = {'type': 'outsub', 'p': 1.} rhs = modeldisc.fvm(model, meshsim, muscl(vanleer), bcL=bcL, bcR=bcR) monitors = { 'residual': { 'name': 'pipo', 'frequency': 1 }, 'data_average': { 'data': 'mach', 'name': 'Mach average', 'frequency': 1 } } solver = tnum.rk3ssp(meshsim, rhs, monitors=monitors) # computation # endtime = 100. cfl = .8 finit = rhs.fdata_fromprim([1., 0.1, 1.]) # rho, u, p pr = cProfile.Profile() pr.enable() fsol = solver.solve(finit, cfl, [endtime]) pr.disable() solver.show_perf() s = io.StringIO()
bcper = {'type': 'per'} bcsym = {'type': 'sym'} xnum = xn.extrapol2dk(k=1. / 3.) #xnum=xn.extrapol2d1() rhs = modeldisc.fvm2d(model, meshsim, num=xnum, numflux='hlle', bclist={ 'left': bcper, 'right': bcper, 'top': bcper, 'bottom': bcper }) solver = tn.rk3ssp(meshsim, rhs) # computation # endtime = 20. cfl = 1. # initial functions def fuv(x, y): r = np.sqrt((x - lx / 2)**2 + (y - ly / 2)**2) return euler.datavector( 0.5 - b / (2 * np.pi) * np.exp(0.5 * (1 - r**2)) * (y - ly / 2), 0.5 + b / (2 * np.pi) * np.exp(0.5 * (1 - r**2)) * (x - lx / 2))
def S(x): # section law, throat is at x=5 return 1 + (AsAc - 1.0) * (1.0 - np.exp(-0.5 * (x - 2.0)**2)) model = euler.nozzle(gamma=gam, sectionlaw=S) nozz = sol.nozzle(model, S(meshsim.centers()), NPR=NPRsup) finit = nozz.fdata(meshsim) print(NPRsup, AsAc, Msup, Msub) # solver / numerical model bcL = {"type": "insub_cbc", "ptot": NPRsup, "rttot": 1.0} bcR = {"type": bctype, "p": 1.} rhs = modeldisc.fvm(model, meshsim, muscl(vanleer), bcL=bcL, bcR=bcR) solver = rk3ssp(meshsim, rhs) #finit = rhs.fdata_fromprim([1.4, Msub, 1.]) cfl = 0.8 monitors = {"residual": {"frequency": 1}} fsol = solver.solve(finit, cfl, stop={"maxit": nit_super}, monitors=monitors) fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(14, 4)) monitors["residual"]["output"].semilogplot_it(ax=ax1) fsol[-1].plot('mach', style='-', axes=ax2) fsol[-1].plot('ptot', style='-', axes=ax3) finit.plot('mach', style='--', axes=ax2) finit.plot('ptot', style='--', axes=ax3) fig.show() # if verbose: solver.show_perf()
uR = uL._rankinehugoniot_from_ushock(ushock=0.) # bcL = { 'type': 'dirichlet', 'prim': [uL.rho, uL.u, uL.p] } bcR = { 'type': 'dirichlet', 'prim': [uR.rho, uR.u, uR.p] } def initdata(x, uL, uR): rho = uL.rho + (uR.rho-uL.rho)*(x>0.) u = uL.u + (uR.u-uL.u)*(x>0.) p = uL.p + (uR.p-uL.p)*(x>0.) return [rho, u, p] xnum1 = muscl(minmod) # xnum2 = muscl(vanalbada) # rhs1 = modeldisc.fvm(model1, meshsim, xnum1, numflux='rusanov', bcL=bcL, bcR=bcR) solver1 = rk3ssp(meshsim, rhs1) rhs2 = modeldisc.fvm(model2, meshsim, xnum1, numflux='hlle', bcL=bcL, bcR=bcR) solver2 = rk3ssp(meshsim, rhs2) # computation # endtime = 2. # 2.8 for subsonic, 2.8 for supersonic cfl = 1. finit = rhs1.fdata_fromprim(initdata(meshsim.centers(), uL, uR)) fsol1 = solver1.solve(finit, cfl, [endtime]) solver1.show_perf() fsol2 = solver2.solve(finit, cfl, [endtime]) solver2.show_perf()