Beispiel #1
0
def test_triangle_mesh():
    mesh = Mesh(
        MPI.comm_world, CellType.triangle,
        numpy.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]], dtype=numpy.float64),
        numpy.array([[0, 1, 2]], dtype=numpy.int32), [],
        cpp.mesh.GhostMode.none)
    assert mesh.num_entities_global(0) == 3
    assert mesh.num_entities_global(2) == 1
Beispiel #2
0
def test_read_mesh_data(tempdir, tdim, n):
    filename = os.path.join(tempdir, "mesh.xdmf")
    mesh = mesh_factory(tdim, n)

    encoding = XDMFFile.Encoding.HDF5
    ghost_mode = cpp.mesh.GhostMode.none

    with XDMFFile(mesh.mpi_comm(), filename, encoding) as file:
        file.write(mesh)

    with XDMFFile(MPI.comm_world, filename) as file:
        cell_type, points, cells, indices = file.read_mesh_data(MPI.comm_world)

    mesh2 = Mesh(MPI.comm_world, cell_type, points, cells, indices, ghost_mode)

    assert(mesh.cell_type == mesh2.cell_type)
    assert mesh.num_entities_global(0) == mesh2.num_entities_global(0)
    dim = mesh.topology.dim
    assert mesh.num_entities_global(dim) == mesh2.num_entities_global(dim)
Beispiel #3
0
        timer.stop()

        # Compute error (we should accurately recover initial condition)
        psi0_expression.t = step * float(dt)
        l2_error = sqrt(
            assemble(
                dot(psi_h - psi0_expression, psi_h - psi0_expression) * dx))

        # The global mass conservation error should be zero
        area_end = assemble(psi_h * dx)

        if comm.Get_rank() == 0:
            print("l2 error " + str(l2_error))

            # Store in error error table
            num_cells_t = mesh.num_entities_global(2)
            num_particles = len(x)
            try:
                area_error_half = np.float64((area_half - area_0))
            except BaseException:
                area_error_half = float("NaN")
                l2_error_half = float("NaN")

            area_error_end = np.float64((area_end - area_0))

            with open(output_table, "a") as write_file:
                write_file.write(
                    "%-12.5g %-15d %-20d %-10.2e %-20.3g %-20.2e %-20.3g %-20.3g \n"
                    % (
                        float(dt),
                        int(num_cells_t),
t = 0.
area_0 = assemble(psi_h * dx)
timer = Timer()
timer.start()

outfile.write(psi_h, t)
while step < num_steps:
    step += 1
    t += float(dt)

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

    AD.do_sweep()
    ap.do_step(float(dt))
    AD.do_sweep_failsafe(4)

    lstsq_psi.project(psi_h.cpp_object(), lb, ub)

    if step % store_step == 0:
        outfile.write(psi_h, t)

timer.stop()

area_end = assemble(psi_h * dx)
if comm.Get_rank() == 0:
    print('Num cells ' + str(mesh.num_entities_global(2)))
    print('Num particles ' + str(len(x)))
    print('Elapsed time ' + str(timer.elapsed()[0]))
    print('Area error ' + str(abs(area_end - area_0)))
    ap.do_step(float(dt))
    lstsq_psi.project(psi_h, lb, ub)

    psi_h_min = min(psi_h_min, psi_h.vector().min())
    psi_h_max = max(psi_h_max, psi_h.vector().max())
    if comm.rank == 0:
        print("Min max phi {} {}".format(psi_h_min, psi_h_max))

    if step % store_step == 0:
        outfile.write_checkpoint(psi_h,
                                 function_name="psi",
                                 time_step=t,
                                 append=True)
        # Dump particles to file
        p.dump2file(mesh, fname_list, property_list, "ab")

timer.stop()

area_end = assemble(psi_h * dx)
num_part = p.number_of_particles()
l2_error = np.sqrt(abs(assemble((psi_h0 - psi_h) * (psi_h0 - psi_h) * dx)))
if comm.Get_rank() == 0:
    print("Num cells " + str(mesh.num_entities_global(2)))
    print("Num particles " + str(num_part))
    print("Elapsed time " + str(timer.elapsed()[0]))
    print("Area error " + str(abs(area_end - area_0)))
    print("Error " + str(l2_error))
    print("Min max phi {} {}".format(psi_h_min, psi_h_max))

outfile.close()