Example #1
0
    def test_set_timestep(self):
        mesh = np.linspace(-0.05, 1.05, 12)
        d = fields.Domain(mesh)
        f = fields.UnsteadyField1D('x', d)
        f.set_timestep(0.1)

        assert f.dt == 0.1

        return
Example #2
0
    def test_set_timestep(self):
        mesh = np.linspace(-1.0, 1.0, 11)
        mesh = fields.Domain(xh=mesh)
        mesh.set_expansion(order=3)

        f = fields.UnsteadyField1D('q', mesh)
        f.set_timestep(0.1)

        assert f.dt == 0.1

        return
def burgers( nt, dt=0.001, nx = 203, nu=0.27, save_interval=5 ):

    ufunc = mth.BurgersWave1D()

    #set up problem
    L  = 2.*np.pi
    dx = L/(nx-1)
    t  = 0

    x  = np.linspace(-dx/2.0, L + dx/2.0, nx)
    x  = fields.Domain( x )
    u  = fields.UnsteadyField1D( 'u', x )
    u.set_boundary_condition( name='periodic' )
    u.set_timestep( dt )
    u.set_save_interval( nt=5 )

    #set initial solution
    u_0 = np.asarray([ufunc(t, x0, nu) for x0 in x.x_noghost])

    u.set_field( u_0 )

    print('cfl  =', max(u_0)*dt/dx)
    print('dif# =', nu*dt/(dx*dx))
    print('Pe   =', max(u_0)*dx/nu)

    fluxv = dfx.CDS2()
    fluxi = afx.UDS1()

    fluxi.set_variable( u )
    fluxi.set_advection_velocity( u )

    fluxv.set_variable( u )
    fluxv.set_diffusion_coefficient( nu )

    #--------------------------------------------------

    flux_inv = np.empty(nx+1)
    flux_vis = np.empty(nx+1)
    flux     = np.empty(nx+1)

    # timestepping
    for n in range(nt):

        # calculate inviscid and viscous fluxes across each face
        flux_vis = fluxv.apply()
        flux_inv = fluxi.apply()
        flux     = flux_inv + flux_vis

        dudt = -np.diff(flux)/dx
        du   = dudt*dt

        u.update( du )

    return u
Example #4
0
    def test_set_field(self):
        mesh = np.linspace(-0.05, 1.05, 12)
        d = fields.Domain(mesh)
        f = fields.UnsteadyField1D('x', d)

        data = np.asarray(range(len(f.val)))
        f.set_field(data)

        assert np.all(f.history[:] == f.val[:])

        return
Example #5
0
    def test_init(self):
        mesh = np.linspace(0, 1.0, 11)
        d = fields.Domain(mesh)
        f = fields.UnsteadyField1D('q', d)

        assert f.dt == None
        assert f.nt == 0
        assert f.t == 0
        assert f.save_interval == 1
        assert np.all(f.history == np.zeros((1, len(f.val))))

        return
Example #6
0
    def test_set_field(self):
        mesh = np.linspace(-1.0, 1.0, 11)
        mesh = fields.Domain(xh=mesh)
        mesh.set_expansion(order=3)

        y = np.asarray(range(len(mesh.xp)))

        f = fields.UnsteadyField1D('q', mesh)
        f.set_field(y)

        assert np.all(f.val == f.history[:])

        return
Example #7
0
    def test_init(self):
        mesh = np.linspace(-1.0, 1.0, 11)
        mesh = fields.Domain(xh=mesh)
        mesh.set_expansion(order=3)

        y = np.asarray(range(len(mesh.xp)))

        f = fields.UnsteadyField1D('q', mesh)

        assert f.dt == None
        assert f.nt == 0
        assert f.t == 0
        assert f.save_interval == 1
        assert np.all(f.history == np.zeros((1, len(f.val))))

        return
Example #8
0
    def test_update(self):
        mesh = np.linspace(-1.0, 1.0, 11)
        mesh = fields.Domain(xh=mesh)
        mesh.set_expansion(order=3)

        y = np.asarray(range(len(mesh.xp)))

        f = fields.UnsteadyField1D('q', mesh)
        f.set_field(y)
        f.set_timestep(0.1)

        f.update(y)

        assert np.all(f.history[-1, :] == f.val)
        assert f.t == 0.1

        return
Example #9
0
    def test_update(self):
        mesh = np.linspace(-0.05, 1.05, 12)

        d = fields.Domain(mesh)
        f = fields.UnsteadyField1D('x', d)
        data = np.asarray(range(len(f.val)))

        f.set_field(data)
        f.set_timestep(0.1)

        update = data[:]
        f.update(update)

        assert np.all(f.history[-1, :] == f.val[:])
        assert f.t == 0.1

        return
Example #10
0
    def test_set_save_interval(self):
        mesh = np.linspace(-0.05, 1.05, 12)
        d = fields.Domain(mesh)
        f = fields.UnsteadyField1D('x', d)
        f.set_timestep(0.1)

        f.set_save_interval()
        assert f.save_interval == 1

        f.set_save_interval(dt=0.1, nt=5)
        assert f.save_interval == 1

        f.set_save_interval(dt=0.3)
        assert f.save_interval == 3

        f.set_save_interval(nt=5)
        assert f.save_interval == 5

        return
Example #11
0
    def test_set_save_interval(self):
        mesh = np.linspace(-1.0, 1.0, 11)
        mesh = fields.Domain(xh=mesh)
        mesh.set_expansion(order=3)

        f = fields.UnsteadyField1D('q', mesh)
        f.set_timestep(0.1)

        f.set_save_interval()
        assert f.save_interval == 1

        f.set_save_interval(dt=0.1, nt=5)
        assert f.save_interval == 1

        f.set_save_interval(dt=0.3)
        assert f.save_interval == 3

        f.set_save_interval(nt=5)
        assert f.save_interval == 5

        return
Example #12
0
# set up initial and analytical solution
ufunc = mth.BurgersWave1D()

#set up problem
nx = 201
nt = 800
L = 2. * np.pi
dx = L / (nx - 1)
nu = 0.17
dt = 0.001
t = 0

x = np.linspace(0, L, nx)
x = fields.Domain(x)
u = fields.UnsteadyField1D('u', x)
u.set_timestep(dt)
u.set_save_interval(nt=5)

bcp = sb.general.fields.BoundaryCondition(name='periodic')

# bcn0 = sb.general.fields.BoundaryCondition( name='naive_adiabatic', indx= 0, val=0 )
bcn0 = sb.general.fields.BoundaryCondition(name='dirichlet', indx=0, val=5.0)
# bcn0 = sb.general.fields.BoundaryCondition( name='neumann',   indx= 0, val= 0.2 )

bcn1 = sb.general.fields.BoundaryCondition(name='naive_outflow',
                                           indx=-1,
                                           val=0)

u.add_boundary_condition(bcn0)
u.add_boundary_condition(bcn1)