Esempio n. 1
0
def mk_scheme(N, Vname, Vorder, cpp_expr, expr_args, convection_inp, dim=2, comm=None):
    if comm is None:
        comm = MPI.comm_world

    parameters['ghost_mode'] = 'shared_vertex'
    if dim == 2:
        mesh = UnitSquareMesh(comm, N, N)
    else:
        mesh = UnitCubeMesh(comm, N, N, N)

    V = FunctionSpace(mesh, Vname, Vorder)
    C = Function(V)
    e = Expression(cpp_expr, element=V.ufl_element(), **expr_args)
    C.interpolate(e)

    D = Function(V)
    D.assign(C)

    sim = Simulation()
    sim.set_mesh(mesh)
    sim.data['constrained_domain'] = None
    sim.data['C'] = C
    for key, value in convection_inp.items():
        sim.input.set_value('convection/C/%s' % key, value)

    scheme_name = convection_inp['convection_scheme']
    return get_convection_scheme(scheme_name)(sim, 'C')
Esempio n. 2
0
def test_scalar_field():
    sim = Simulation()
    sim.input.read_yaml(yaml_string=INP)
    mesh = dolfin.UnitCubeMesh(2, 2, 2)
    sim.set_mesh(mesh)

    field_inp = sim.input.get_value('fields/1', required_type='Input')
    field = ScalarField(sim, field_inp)

    # t = 0
    t, A = 0, 1
    f = field.get_variable('rho')
    check_vector_value_histogram(f.vector(), {t * A + A: 125})

    # t = 1
    t, A = 1, 1
    sim.time = t
    field.update(1, t, 1.0)
    check_vector_value_histogram(f.vector(), {t * A + A: 125})

    # t = 2
    t, A = 2, 10
    sim.time = t
    sim.input.set_value('user_code/constants/A', A)
    field.update(2, t, 1.0)
    check_vector_value_histogram(f.vector(), {t * A + A: 125})
Esempio n. 3
0
def test_vector_field():
    sim = Simulation()
    sim.input.read_yaml(yaml_string=INP)
    mesh = dolfin.UnitCubeMesh(2, 2, 2)
    sim.set_mesh(mesh)

    field_inp = sim.input.get_value('fields/0', required_type='Input')
    field = VectorField(sim, field_inp)

    def verify(f, t, A):
        print(t, A)
        check_vector_value_histogram(f[0].vector(), {t + A: 125})
        check_vector_value_histogram(f[1].vector(), {t * A: 125})
        check_vector_value_histogram(f[2].vector(), {t * A + A: 125})

    # t = 0
    t, A = 0, 1
    f = field.get_variable('u')
    verify(f, t, A)

    # t = 1
    t, A = 1, 1
    sim.time = t
    sim.input.set_value('user_code/constants/A', A)
    field.update(1, t, 1.0)
    verify(f, t, A)

    # t = 2
    t, A = 2, 10
    sim.time = t
    sim.input.set_value('user_code/constants/A', A)
    field.update(2, t, 1.0)
    verify(f, t, A)
Esempio n. 4
0
def test_sharp_field_dg0():
    sim = Simulation()
    sim.input.read_yaml(yaml_string=INP)
    mesh = dolfin.UnitCubeMesh(2, 2, 2)
    sim.set_mesh(mesh)

    # Sharp jump at the cell boundaries
    field_inp = sim.input.get_value('fields/0', required_type='Input')
    f = SharpField(sim, field_inp).get_variable('rho')
    check_vector_value_histogram(f.vector(), {1: 24, 1000: 24}, round_digits=6)

    # Sharp jump in the middle of the cells
    field_inp['z'] = 0.25
    f = SharpField(sim, field_inp).get_variable('rho')
    hist = get_vector_value_histogram(f.vector())
    assert len(hist) == 4
    for k, v in hist.items():
        if round(k, 6) != 1:
            assert v == 8
        else:
            assert v == 24

    # Non-projected sharp jump between cells
    field_inp['local_projection'] = False
    field_inp['z'] = 0.50
    f = SharpField(sim, field_inp).get_variable('rho')
    check_vector_value_histogram(f.vector(), {1: 24, 1000: 24}, round_digits=6)

    # Non-projected sharp jump the middle of the cells
    field_inp['z'] = 0.25
    f = SharpField(sim, field_inp).get_variable('rho')
    hist = get_vector_value_histogram(f.vector())
    check_vector_value_histogram(f.vector(), {1: 40, 1000: 8}, round_digits=6)