Пример #1
0
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())
Пример #2
0
 def test_rayleigh(self):
     endtime = 100.
     cfl = 1.2
     xnum = muscl(minmod)
     tnum = integ.rk4
     meshsim = self.mesh20
     modelrayleigh = euler.model(source=[None, None, lambda x, q: 2.])
     bcL = {'type': 'insub', 'ptot': 1.4, 'rttot': 1.}
     bcR = {'type': 'outsub', 'p': 1.}
     rhs = modeldisc.fvm(modelrayleigh, meshsim, xnum, bcL=bcL, bcR=bcR)
     finit = rhs.fdata_fromprim([1., 0., 1.])  # rho, u, p
     solver = tnum(meshsim, rhs)
     fsol = solver.solve(finit, cfl, [endtime])
     assert not fsol[-1].isnan()
     avg, var = fsol[-1].stats('rttot')
     assert avg == pytest.approx(1.6139, rel=1.e-4)
     assert var == pytest.approx(0.1242, rel=1.e-2)
Пример #3
0
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
Пример #4
0
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
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.

finit = rhs.fdata_fromprim([1., 0.1, 1.])  # rho, u, p
Пример #6
0
#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)

# computation
#
Пример #7
0
from pylab import *
import numpy as np 

from flowdyn.mesh  import *
from flowdyn.field import *
from flowdyn.xnum  import *
from flowdyn.integration import *
import flowdyn.modelphy.euler as euler
import flowdyn.modeldisc      as modeldisc
#import flowdyn.solution.euler_riemann as sol

nx = 50
length=10.
meshsim  = unimesh(ncell=nx,  length=length)

model = euler.model(source=[None, None, lambda x,q:.1])
bcL = { 'type': 'insub',  'ptot': 1.4, 'rttot': 1. }
bcR = { 'type': 'outsub', 'p': 1. }

rhs = modeldisc.fvm(model, meshsim, muscl(minmod), 
      bcL=bcL, bcR=bcR)
solver = rk2(meshsim, rhs)

# computation
#
endtime = 500.
cfl     = .5

finit = rhs.fdata_fromprim([ 1., 0., 1. ]) # rho, u, p

fsol = solver.solve(finit, cfl, [endtime])