Exemplo n.º 1
0
def test_remove_particles():
    interpolate_expression = Expression('x[0]', degree=1)
    mesh = UnitSquareMesh(5, 5)
    V = FunctionSpace(mesh, "DG", 1)

    v = Function(V)
    v.assign(interpolate_expression)

    np_min, np_max = 5, 10

    # Initialize particles
    x = RandomRectangle(Point(0.0, 0.0), Point(1., 1.)).generate([100, 100])
    s = assign_particle_values(x, interpolate_expression)
    # Broadcast to other procs
    x = comm.bcast(x, root=0)
    s = comm.bcast(s, root=0)

    property_idx = 1
    p = particles(x, [s], mesh)
    AD = AddDelete(p, np_min, np_max, [v])
    AD.do_sweep()

    # Must recover linear
    lstsq_rho = l2projection(p, V, property_idx)
    lstsq_rho.project(v.cpp_object())

    error = sqrt(
        assemble(
            (v - interpolate_expression) * (v - interpolate_expression) * dx))

    assert len(p.positions() == mesh.num_cells() * np_min)
    assert error < 1e-12
Exemplo n.º 2
0
def test_l2_projection_3D(polynomial_order, in_expression):
    xmin, ymin, zmin = 0.0, 0.0, 0.0
    xmax, ymax, zmax = 1.0, 1.0, 1.0
    nx = 25

    property_idx = 1
    mesh = BoxMesh(Point(xmin, ymin, zmin), Point(xmax, ymax, zmax), nx, nx,
                   nx)

    interpolate_expression = Expression(in_expression, degree=3)

    if len(interpolate_expression.ufl_shape) == 0:
        V = FunctionSpace(mesh, "DG", polynomial_order)
    elif len(interpolate_expression.ufl_shape) == 1:
        V = VectorFunctionSpace(mesh, "DG", polynomial_order)

    v_exact = Function(V)
    v_exact.assign(interpolate_expression)

    x = RandomBox(Point(0.0, 0.0, 0.0), Point(1.0, 1.0,
                                              1.0)).generate([4, 4, 4])
    s = assign_particle_values(x, interpolate_expression)

    # Just make a complicated particle, possibly with scalars and vectors mixed
    p = particles(x, [s], mesh)

    # Do AddDelete sweep
    AD = AddDelete(p, 13, 15, [v_exact])
    AD.do_sweep()

    vh = Function(V)
    lstsq_vh = l2projection(p, V, property_idx)
    lstsq_vh.project(vh.cpp_object())

    error_sq = abs(assemble(dot(v_exact - vh, v_exact - vh) * dx))
    if comm.Get_rank() == 0:
        assert error_sq < 1e-13
Exemplo n.º 3
0
        step = 0
        t = 0.0
        area_0 = assemble(psi0_h * dx)
        timer = Timer()

        timer.start()
        while step < num_steps:
            step += 1
            t += float(dt)

            if comm.rank == 0:
                print("Step " + str(step))

            # Advect particle, assemble and solve pde projection
            t1 = Timer("[P] Advect particles step")
            AD.do_sweep()
            ap.do_step(float(dt))
            AD.do_sweep_failsafe(4)
            del t1

            if projection_type == "PDE":
                t1 = Timer("[P] Assemble PDE system")
                pde_projection.assemble(True, True)
                del t1
                t1 = Timer("[P] Solve projection")
                pde_projection.solve_problem(psibar_h, psi_h, "mumps",
                                             "default")
                del t1
            else:
                t1 = Timer("[P] Solve projection")
                lstsq_psi.project(psi_h)
Exemplo n.º 4
0
k = 1
W_e = FiniteElement("DG", mesh.ufl_cell(), k)
T_e = FiniteElement("DG", mesh.ufl_cell(), 0)
Wbar_e = FiniteElement("DGT", mesh.ufl_cell(), k)

# Composition field space
Wh = FunctionSpace(mesh, W_e)
Th = FunctionSpace(mesh, T_e)
Wbarh = FunctionSpace(mesh, Wbar_e)

phi = interpolate(StepFunction(), Wh)
gamma0 = interpolate(StepFunction(), Wh)

ad = AddDelete(ptcls, 50, 55, [phi], [1], [0.0, 1.0])
ptcls.interpolate(phi, property_idx)
ad.do_sweep()

lambda_h = Function(Th)
psibar_h = Function(Wbarh)


# Elements for Stokes
W_e_2 = VectorElement("DG", mesh.ufl_cell(), k)
T_e_2 = VectorElement("DG", mesh.ufl_cell(), 0)
Wbar_e_2 = VectorElement("DGT", mesh.ufl_cell(), k)
Wbar_e_2_H12 = VectorElement("CG", mesh.ufl_cell(), k)["facet"]

Q_E = FiniteElement("DG", mesh.ufl_cell(), k-1)
Qbar_E = FiniteElement("DGT", mesh.ufl_cell(), k)

W_2 = FunctionSpace(mesh, W_e_2)