class Test_limiter_conv(): mesh100 = mesh.unimesh(ncell=100, length=1.) mesh50 = mesh.unimesh(ncell=50, length=1.) mymodel = conv.model(1.) # periodic wave def init_sinperk(self, mesh, k): return np.sin(2 * k * np.pi / mesh.length * mesh.centers()) def test_0_tvd(self, limiter): slope = limiter(-2., 1.) # tvd: 0 if opposite signs assert slope == 0. slope = limiter(3., 3.) # consistency assert slope == 3. slope = limiter(1., 10.) # tvd: max is double of smallest assert slope <= 2. def test_muscl_limiters(self, limiter): curmesh = self.mesh50 endtime = 5 cfl = .8 # extrapol1(), extrapol2()=extrapolk(1), centered=extrapolk(-1), extrapol3=extrapolk(1./3.) xnum = muscl(limiter) finit = field.fdata(self.mymodel, curmesh, [self.init_sinperk(curmesh, k=4)]) rhs = modeldisc.fvm(self.mymodel, curmesh, xnum) solver = rk3ssp(curmesh, rhs) fsol = solver.solve(finit, cfl, [endtime]) assert not fsol[-1].isnan() avg, var = fsol[-1].stats('q') #varref = { } assert avg == pytest.approx(0., abs=1.e-12)
class integration_data(): curmesh = mesh.unimesh(ncell=50, length=1.) convmodel = conv.model(convcoef=1.) def init_sinperk(self, mesh, k): return np.sin(2 * k * np.pi / mesh.length * mesh.centers())
class monitor_data(): mesh50 = mesh.unimesh(ncell=50, length=1.) convmodel = conv.model(convcoef=1.) eulermodel = euler.model() xsch = xnum.extrapol3() def init_sinperk(self, mesh, k): return np.sin(2 * k * np.pi / mesh.length * mesh.centers())
def test_mesh_uni(): lmesh = mesh.unimesh(ncell=50, length=1.) endtime = 5 cfl = 1. # extrapol1(), extrapol2()=extrapolk(1), centered=extrapolk(-1), extrapol3=extrapolk(1./3.) xnum = extrapol3() # explicit, rk2, rk3ssp, rk4, implicit, trapezoidal=cranknicolson tnum = rk3ssp finit = field.fdata(mymodel, lmesh, [init_sinperk(lmesh, k=2)]) rhs = modeldisc.fvm(mymodel, lmesh, xnum) solver = tnum(lmesh, rhs) fsol = solver.solve(finit, cfl, [endtime]) assert not fsol[-1].isnan()
def test_sym_flux(flux): endtime = 1. cfl = 0.6 xnum = muscl(minmod) tnum = integ.rk3ssp meshsim = mesh.unimesh(ncell=100, length=1.) xc = meshsim.centers() bcL = { 'type': 'sym'} bcR = { 'type': 'sym'} model = shw.shallowwater1d() model10 = shw.shallowwater1d(g=10.) rhs = modeldisc.fvm(model, meshsim, xnum, numflux=flux, bcL=bcL, bcR=bcR) finit = rhs.fdata(model.prim2cons(waterdrop(xc, .01))) # rho, u, p solver = tnum(meshsim, rhs) fsol = solver.solve(finit, cfl, [endtime]) assert not fsol[-1].isnan() avg, var = fsol[-1].stats('height') assert avg == pytest.approx(0.098232, rel=1.e-4) assert var >= 6.5e-6
class Test_fdataclass_vec(): model = euler.model() mesh1d = mesh.unimesh(ncell=100, length=10.) mesh2d = mesh2d.mesh2d(60, 50, 20., 10.) def fn(self, x): return np.exp(-np.square(x) / 2) * np.sin(5 * x) @pytest.mark.mpl_image_compare def test_plotdata_vec(self): f = field.fdata(self.model, self.mesh1d, [1., self.fn(self.mesh1d.centers() - 5.), 5.]) fig, ax = plt.subplots(1, 1) f.plot('mach', axes=ax, style='r-') return fig @pytest.mark.mpl_image_compare def test_plot2dcontour(self): xc, yc = self.mesh2d.centers() f = field.fdata(self.model, self.mesh2d, [ 1., euler.datavector(0., 0.), self.fn(np.sqrt(np.square(xc - 8) + np.square(yc - 4))) ]) fig, ax = plt.subplots(1, 1) f.contour('pressure', axes=ax, style='r-') return fig @pytest.mark.mpl_image_compare def test_plot2dcontourf(self): xc, yc = self.mesh2d.centers() f = field.fdata(self.model, self.mesh2d, [ 1., euler.datavector(0., 0.), self.fn(np.sqrt(np.square(xc - 8) + np.square(yc - 4))) ]) fig, ax = plt.subplots(1, 1) f.contourf('pressure', axes=ax, style='r-') return fig
def test_shocktube_sodsup_th(flux): meshref = mesh.unimesh(ncell=1000, length=10., x0=-4.) 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
class Test_fdataclass_scalar(): convmodel = conv.model(convcoef=1.) curmesh = mesh.unimesh(ncell=50, length=1.) def test_init_empty(self): f = field.fdata(self.convmodel, self.curmesh, []) assert f.time == 0. # default value assert f.it == -1 # default value assert f.data == [] f.set_time(10.) assert f.time == 10. def test_reset(self): f = field.fdata(self.convmodel, self.curmesh, []) f.set_time(10.) f.reset(t=5.) assert f.time == 5. assert f.it == -1 # default value f.reset(it=20) assert f.time == 0. # default value assert f.it == 20 def test_init_expand(self): f = field.fdata(self.convmodel, self.curmesh, [1.]) assert f.time == 0. # default value assert np.size(f.data[0]) == self.curmesh.ncell assert np.average(f.data[0]) == 1. @pytest.mark.mpl_image_compare def test_plotdata_sca(self): def fn(x): return np.exp(-2 * np.square(x - .5)) * np.sin(20 * (x - .5)) f = field.fdata(self.convmodel, self.curmesh, [fn(self.curmesh.centers())]) fig, ax = plt.subplots(1, 1) f.plot('q') return fig
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
class Test_fieldlistclass(): convmodel = conv.model(convcoef=1.) curmesh = mesh.unimesh(ncell=50, length=1.) def test_append_scalararray(self): flist = field.fieldlist() f1 = field.fdata(self.convmodel, self.curmesh, [1.]) flist.append(f1) f2 = f1.copy() f2.set_time(10.) flist.append(f2) assert len(flist) == 2 assert flist[0].time == 0. assert flist[-1].time == 10. assert flist.time_array() == [0., 10.] def test_extend_scalararray(self): flist = field.fieldlist() f1 = field.fdata(self.convmodel, self.curmesh, [1.]) flist.append(f1) f2 = f1.copy() f2.set_time(10.) flist.append(f2) newlist = field.fieldlist() f3 = f2.copy() newlist.append(f3) f3.set_time(20.) newlist.append(f2) flist.extend(newlist) f2.reset(t=100., it=5) assert len(flist) == 4 # f1, f2, f3, f2 assert flist.time_array() == [0., 100., 20., 100.] assert flist.it_array() == [-1, 5, -1, 5] @pytest.mark.mpl_image_compare def test_flist_plotxtcontour(self): def fn(x, t): return np.exp(-2 * np.square(x - .5 + .2 * np.sin(10 * t))) times = np.linspace(0., 5., 11, endpoint=True) flist = field.fieldlist() for t in times: f = field.fdata(self.convmodel, self.curmesh, [fn(self.curmesh.centers(), t)]) f.set_time(t) flist.append(f) fig, ax = plt.subplots(1, 1) flist.xtcontour('q') return fig @pytest.mark.mpl_image_compare def test_flist_plotxtcontourf(self): def fn(x, t): return np.exp(-2 * np.square(x - .5 + .2 * np.sin(10 * t))) times = np.linspace(0., 5., 11, endpoint=True) flist = field.fieldlist() for t in times: f = field.fdata(self.convmodel, self.curmesh, [fn(self.curmesh.centers(), t)]) f.set_time(t) flist.append(f) fig, ax = plt.subplots(1, 1) flist.xtcontourf('q') return fig
from flowdyn.xnum import * import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc import flowdyn.solution.euler_nozzle as sol NPR = 1.1 def S(x): # section law, throat is at x=5 return 1. - .5 * np.exp(-.5 * (x - 5.)**2) model = euler.nozzle(gamma=1.35, sectionlaw=S) meshsim = mesh.unimesh(ncell=200, length=10.) meshref = mesh.unimesh(ncell=1000, length=10.) nozz = sol.nozzle(model, S(meshref.centers()), NPR=NPR) fref = nozz.fdata(meshref) bcL = {'type': 'insub', 'ptot': NPR, 'rttot': 1.} bcR = {'type': 'outsub', 'p': 1.} rhs = modeldisc.fvm(model, meshsim, muscl(vanleer), bcL=bcL, bcR=bcR) monitors = { 'residual': { 'name': 'pipo', 'frequency': 1 },
# -*- coding: utf-8 -*- """ test integration methods """ import numpy as np import matplotlib.pyplot as plt import flowdyn.mesh as mesh import flowdyn.xnum as xnum import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc n = 500 h = 1. / n meshsim = mesh.unimesh(ncell=n, length=1.) #meshref = unimesh(ncell=1000, length=1.) model = euler.model() musclrus = {'num': xnum.muscl(xnum.vanalbada), 'numflux': 'rusanov'} musclhllc = {'num': xnum.muscl(xnum.vanalbada), 'numflux': 'hllc'} ctr2 = {'num': xnum.extrapol1(), 'numflux': 'centered'} ctr4 = {'num': xnum.extrapol3(), 'numflux': 'centered'} # computation # gam = 1.4 M0 = 0.5 a0 = 1.
import flowdyn.modelphy.euler as euler import flowdyn.solution.euler_riemann as solR import flowdyn.solution.euler_nozzle as solN import flowdyn.modeldisc as modeldisc import flowdyn.field as field from flowdyn.xnum import * import flowdyn.integration as integ #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']:
# -*- coding: utf-8 -*- """ test integration methods """ import matplotlib.pyplot as plt import numpy as np from flowdyn.mesh import unimesh from flowdyn.xnum import * import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc import flowdyn.solution.euler_riemann as sol meshsim = unimesh(ncell=200, length=1.) meshref = unimesh(ncell=1000, length=1.) model = euler.model() bcL = {'type': 'outsup'} bcR = {'type': 'sym'} xnum = muscl(vanalbada) flux = 'hllc' #xnum = extrapol1() ; flux = 'centered' rhs = modeldisc.fvm(model, meshsim, numflux=flux, num=xnum, bcL=bcL, bcR=bcR) solver = tnum.rk3ssp(meshsim, rhs) # computation #
import numpy as np import flowdyn.mesh as mesh import flowdyn.modelphy.burgers as burgers import flowdyn.modeldisc as modeldisc import flowdyn.field as field from flowdyn.xnum import * import flowdyn.integration as integ mesh100 = mesh.unimesh(ncell=100, length=5.) mesh50 = mesh.unimesh(ncell=50, length=5.) mymodel = burgers.model() def init_step(mesh, ul, ur): step = np.zeros(len(mesh.centers())) xr = 1.0 x = mesh.centers() for i in range(len(x)): if x[i] < xr: step[i] = ul elif xr <= x[i] <= 2.0: step[i] = 3.0-x[i] elif x[i] > 2.0: step[i] = ur return step def init_sin(mesh): k = 2 # nombre d'onde omega = k*np.pi/mesh.length return .2+np.sin(omega*mesh.centers())
# -*- coding: utf-8 -*- """ test integration methods """ #import cProfile import matplotlib.pyplot as plt import numpy as np from flowdyn.mesh import unimesh from flowdyn.xnum import * import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc meshsim = unimesh(ncell=200, length=1.) #meshref = unimesh(ncell=1000, length=1.) model = euler.model() bcL = {'type': 'sym'} # not physical but can work bcR = {'type': 'sym'} # for wall xnum = muscl(vanalbada) flux = 'hllc' #xnum = extrapol1() ; flux = 'centered' rhs = modeldisc.fvm(model, meshsim, numflux=flux, num=xnum, bcL=bcL, bcR=bcR) solver = tnum.lsrk26bb(meshsim, rhs) # computation #
# import flowdyn.mesh as mesh import flowdyn.modelphy.shallowwater as shw import flowdyn.modeldisc as modeldisc #import flowdyn.field as field import flowdyn.xnum as xnum import flowdyn.integration as tnum plt.rcParams[ "animation.html"] = "jshtml" # for matplotlib 2.1 and above, uses JavaScript ncell = 300 # Définition de la mesh ntime = 50 # number of intermediate snapshots, only 1 is recommended endtime = 1. tsave = np.linspace(0, endtime, num=ntime + 1) length = 3. mesh = mesh.unimesh(ncell, length) model = shw.shallowwater1d(g=10.) cfl = 1 # schéma linéaire: extrapol1(), extrapol2()=extrapolk(1), centered=extrapolk(-1), extrapol3=extrapol(1./3.) # schéma avec limitation non linéaire: muscl(LIMITER) avec LIMITER = minmod, vanalbada, vanleer, superbee xmeth, xmethstr = xnum.extrapol3(), 'extrapol3' # explicit, rk2, rk3ssp, rk4, implicit, trapezoidal=cranknicolson tmeth, tmethstr = tnum.rk3ssp, 'rk3ssp' # Numerical Flux : 'centered', 'rusanov', or 'HLL' are availaible. # Centered flux is easily shown to be unconditionnaly unstable numflux = 'hll'
#import cProfile from matplotlib.pyplot import figure, ylabel, grid, show import numpy as np from flowdyn.mesh import unimesh #from flowdyn.field import * from flowdyn.xnum import * 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.
class euler_w_mesh(): mesh100 = mesh.unimesh(ncell=100, length=1.) mesh50 = mesh.unimesh(ncell=50, length=1.) mesh20 = mesh.unimesh(ncell=20, length=1.)
gam = 1.4 bctype = "outsub_rh" ncell = 100 nit_super = 1000 nit_tot = 10000 # expected Mach number at exit when supersonic ; defines As/Ac ratio Msup = 1.8 AsAc = mf.Sigma_Mach(Msup, gam) Msub = mf.MachSub_Sigma(AsAc, gam) NPRsup = Is.PtPs_Mach(Msup, gam) NPRsub = Is.PtPs_Mach(Msub, gam) res = {} meshsim = mesh.unimesh(ncell=ncell, length=10.0) 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)
""" test integration methods """ #import cProfile import matplotlib.pyplot as plt import numpy as np from flowdyn.mesh import unimesh from flowdyn.xnum import * import flowdyn.integration as tnum import flowdyn.modelphy.euler as euler import flowdyn.modeldisc as modeldisc 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)
class Test_Burgers(): mesh100 = mesh.unimesh(ncell=100, length=5.) mesh50 = mesh.unimesh(ncell=50, length=5.) mymodel = burgers.model() def init_step(self, mesh, ul, ur): step = np.zeros(len(mesh.centers())) xr = 1.0 x = mesh.centers() for i in range(len(x)): if x[i] < xr: step[i] = ul elif xr <= x[i] <= 2.0: step[i] = 3.0-x[i] elif x[i] > 2.0: step[i] = ur return step def init_sin(self, mesh): k = 2 # nombre d'onde omega = k*np.pi/mesh.length return .2+np.sin(omega*mesh.centers()) def test_compression_prop(self): endtime = 2. cfl = 0.5 xnum = muscl(minmod) tnum = integ.rk3ssp thismesh = self.mesh100 thisprim = [self.init_step(thismesh, 2, .5)] thiscons = field.fdata(self.mymodel, thismesh, thisprim) bcL = { 'type': 'dirichlet', 'prim': thisprim[0] } bcR = { 'type': 'dirichlet', 'prim': thisprim[-1] } rhs = modeldisc.fvm(self.mymodel, thismesh, xnum, bcL=bcL, bcR=bcR) solver = tnum(thismesh, rhs) fsol = solver.solve(thiscons, cfl, [endtime]) assert not fsol[-1].isnan() def test_compression_centered(self): endtime = 2. cfl = .5 xnum = muscl(minmod) tnum = integ.rk3ssp thismesh = self.mesh100 thisprim = [self.init_step(thismesh, 2, -1.)] thiscons = field.fdata(self.mymodel, thismesh, thisprim) bcL = { 'type': 'dirichlet', 'prim': thisprim[0] } bcR = { 'type': 'dirichlet', 'prim': thisprim[-1] } rhs = modeldisc.fvm(self.mymodel, thismesh, xnum, bcL=bcL, bcR=bcR) solver = tnum(thismesh, rhs) fsol = solver.solve(thiscons, cfl, [endtime]) assert not fsol[-1].isnan() def test_expansion(self): endtime = 2. cfl = 0.5 xnum = muscl(minmod) tnum = integ.rk3ssp thismesh = self.mesh100 thisprim = [self.init_step(thismesh, 1., 2.)] thiscons = field.fdata(self.mymodel, thismesh, thisprim) bcL = { 'type': 'dirichlet', 'prim': thisprim[0] } bcR = { 'type': 'dirichlet', 'prim': thisprim[-1] } rhs = modeldisc.fvm(self.mymodel, thismesh, xnum, bcL=bcL, bcR=bcR) solver = tnum(thismesh, rhs) fsol = solver.solve(thiscons, cfl, [endtime]) assert not fsol[-1].isnan() def test_sin_bcper(self): endtime = 2. cfl = 0.5 xnum = muscl(minmod) tnum = integ.rk3ssp thismesh = self.mesh100 thisprim = [ self.init_sin(thismesh) ] thiscons = field.fdata(self.mymodel, thismesh, thisprim) bcL = { 'type': 'per' } bcR = { 'type': 'per' } rhs = modeldisc.fvm(self.mymodel, thismesh, xnum, bcL=bcL, bcR=bcR) solver = tnum(thismesh, rhs) fsol = solver.solve(thiscons, cfl, [endtime]) assert not fsol[-1].isnan()
# -*- coding: utf-8 -*- """ test integration methods """ import time from pylab import * import flowdyn.mesh as mesh import flowdyn.model as model from flowdyn.field import * from flowdyn.xnum import * from flowdyn.integration import * mesh200 = mesh.unimesh(ncell=200, length=1.) mesh100 = mesh.unimesh(ncell=100, length=1.) mesh50 = mesh.unimesh(ncell=50, length=1.) endtime = .8 # final physical time of simulation ntime = 1 # number of intermediate snapshots tsave = linspace(0, endtime, num=ntime + 1) mymodel = model.convmodel(1.) # sinus packet def init_sinpack(mesh): return sin(2 * 2 * pi / mesh.length * mesh.centers()) * ( 1 + sign(-(mesh.centers() / mesh.length - .25) * (mesh.centers() / mesh.length - .75))) / 2
test integration methods """ import time #import numpy as np #import matplotlib as mp from pylab import * #from math import * import flowdyn.mesh as mesh import flowdyn.model as model from flowdyn.field import * from flowdyn.xnum import * from flowdyn.integration import * mesh400 = mesh.unimesh(ncell=400, length=1.) mesh200 = mesh.unimesh(ncell=200, length=1.) mesh100 = mesh.unimesh(ncell=100, length=1.) mgmesh = mesh.refinedmesh(ncell=100, length=1., ratio=3.) endtime = 20 # final physical time of simulation ntime = 1 # number of intermediate snapshots tsave = linspace(0, endtime, num=ntime + 1) mymodel = model.convmodel(1.) # TODO : make init method for scafield # sinus packet def init_sinpack(mesh): return sin(2 * 2 * pi / mesh.length * mesh.centers()) * (
test integration methods """ import time #import numpy as np #import matplotlib as mp from pylab import * #from math import * import flowdyn.mesh as mesh import flowdyn.model as model from flowdyn.field import * from flowdyn.xnum import * from flowdyn.integration import * mesh100 = mesh.unimesh(ncell=100, length=1.) mgmesh = mesh.refinedmesh(ncell=100, length=1., ratio=2.) mymodel = model.convmodel(1.) # TODO : make init method for scafield # sinus packet def init_sinpack(mesh): return sin(2 * 2 * pi / mesh.length * mesh.centers()) * ( 1 + sign(-(mesh.centers() / mesh.length - .25) * (mesh.centers() / mesh.length - .75))) / 2 # periodic wave def init_sinper(mesh, k):
import numpy as np import flowdyn.mesh as mesh import flowdyn.modelphy.convection as conv import flowdyn.modeldisc as modeldisc import flowdyn.field as field import flowdyn.xnum as xnum import flowdyn.integration as tnum curmesh = mesh.unimesh(ncell=50, length=1.) convmodel = conv.model(convcoef=1.) def init_sinperk(mesh, k): return np.sin(2*k*np.pi/mesh.length*mesh.centers()) xsch = xnum.extrapol3() tottime = 10. breaktime = 5. cfl = .5 finit = field.fdata(convmodel, curmesh, [ init_sinperk(curmesh, k=4) ] ) rhs = modeldisc.fvm(convmodel, curmesh, xsch) solver = tnum.rk4(curmesh, rhs) nsol = 10+1 # every second tsave = np.linspace(0, tottime, nsol, endpoint=True) # stop_directive = { 'tottime': breaktime } fsol0 = solver.solve(finit, cfl, tsave, stop=stop_directive) assert len(fsol0) < nsol # end before expected by tsave assert not fsol0[-1].isnan() assert fsol0[-1].time == breaktime