Skip to content

Commit

Permalink
Add tests for time dependent mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
ampdes committed Aug 30, 2024
1 parent 80265ae commit 3f8128e
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions python/test/unit/io/test_adios2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,101 @@ def test_mesh_read_write(encoder, suffix, ghost_mode, dtype, dim, simplex, tmp_p
)


# TODO: Fix problems with ("HDF5", ".h5"), ("BP4", ".bp"),
@pytest.mark.adios2
@pytest.mark.parametrize("encoder, suffix", [("BP5", ".bp")])
@pytest.mark.parametrize("ghost_mode", [GhostMode.shared_facet, GhostMode.none])
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
@pytest.mark.parametrize("dim", [2, 3])
@pytest.mark.parametrize("simplex", [True, False])
def test_timedep_mesh_read_write(encoder, suffix, ghost_mode, dtype, dim, simplex, tmp_path):
"Test writing of a time dependent mesh"
from dolfinx.io import ADIOS2, read_mesh, read_timestamps, update_mesh, write_mesh

N = 5
# Consistent tmp dir across processes
fname = MPI.COMM_WORLD.bcast(tmp_path, root=0)
file = fname / f"adios_timedep_mesh_{encoder}"

mesh = generate_mesh(dim, simplex, N, dtype)

def displace(x):
return np.asarray(
[
x[0] + 0.1 * np.sin(x[0]) * np.cos(x[1]),
x[0] + 0.6 * np.cos(x[0]) * np.sin(x[1]),
x[2],
]
)

adios = ADIOS2(mesh.comm)
tag_write = "mesh-write"
adios.add_io(
filename=str(file.with_suffix(suffix)), tag=tag_write, engine_type=encoder, mode="write"
)

# Write mesh
write_mesh(adios, tag_write, mesh, time=0.0)

delta_x1 = displace(mesh.geometry.x.T).T
mesh.geometry.x[:] += delta_x1

write_mesh(adios, tag_write, mesh, time=1.0)

delta_x2 = displace(mesh.geometry.x.T).T
mesh.geometry.x[:] += delta_x2

write_mesh(adios, tag_write, mesh, time=2.0)

adios.close(tag_write)

# reset mesh geometry to the one at time=0.0
mesh.geometry.x[:] -= delta_x1 + delta_x2

tag_rra = "mesh-readrandomaccess"
adios.add_io(
filename=str(file.with_suffix(suffix)),
tag=tag_rra,
engine_type=encoder,
mode="readrandomaccess",
)
times = read_timestamps(adios, tag_rra)
adios.close(tag_rra)
assert np.all(np.isclose(times, [0.0, 1.0, 2.0]))

tag_read = "mesh-read"
adios.add_io(
filename=str(file.with_suffix(suffix)), tag=tag_read, engine_type=encoder, mode="read"
)
mesh_adios = read_mesh(adios, tag_read, MPI.COMM_WORLD, ghost_mode=ghost_mode)

mesh_adios.comm.Barrier()
mesh.comm.Barrier()

# Check that integration over different entities are consistent
measures = [ufl.ds, ufl.dx] if ghost_mode is GhostMode.none else [ufl.ds, ufl.dS, ufl.dx]
for step, time in enumerate(times):
if step == 1:
mesh.geometry.x[:] += delta_x1
if step == 2:
mesh.geometry.x[:] += delta_x2

# FIXME: update_mesh at time time=0.0 should work!?
if step > 0:
update_mesh(adios, tag_read, mesh_adios, step)

mesh_adios.comm.Barrier()
mesh.comm.Barrier()

for measure in measures:
c_adios = assemble_scalar(form(1 * measure(domain=mesh_adios), dtype=dtype))
c_ref = assemble_scalar(form(1 * measure(domain=mesh), dtype=dtype))
assert np.isclose(
mesh_adios.comm.allreduce(c_adios, MPI.SUM),
mesh.comm.allreduce(c_ref, MPI.SUM),
)


@pytest.mark.adios2
class TestFides:
@pytest.mark.parametrize("dim", [2, 3])
Expand Down

0 comments on commit 3f8128e

Please sign in to comment.