Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pytest for separate visualization #196

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ def test_create_hdf5_solid_only(input_mesh, tmpdir):
last_time = f["displacement/vector_2"][0]
assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10)

# 7. create separate visualization
cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/")
_ = subprocess.check_output(cmd, shell=True)

# 8. check if the separate visualization exists
velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5"
velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf"
assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist"
assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist"

displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5"
displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf"
assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist"
assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist"


@pytest.mark.parametrize("input_mesh", [input_data_paths[0]])
def test_create_hdf5_entire_domain(input_mesh, tmpdir):
Expand Down Expand Up @@ -83,6 +98,16 @@ def test_create_hdf5_entire_domain(input_mesh, tmpdir):
last_time = f["displacement/vector_2"][0]
assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10)

# 7. create separate visualization
cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/")
_ = subprocess.check_output(cmd, shell=True)

# 8. check if the separate visualization exists (only fluid velocity)
velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5"
velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf"
assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist"
assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist"


@pytest.mark.parametrize("input_mesh", [input_data_paths[0]])
def test_create_hdf5_with_stride(input_mesh, tmpdir):
Expand Down Expand Up @@ -124,6 +149,21 @@ def test_create_hdf5_with_stride(input_mesh, tmpdir):
last_time = f["displacement/vector_1"][0]
assert np.isclose(last_time, 1.3776599148439903E-8, atol=1e-10)

# 7. create separate visualization
cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/")
_ = subprocess.check_output(cmd, shell=True)

# 8. check if the separate visualization exists
velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5"
velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf"
assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist"
assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist"

displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5"
displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf"
assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist"
assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist"


@pytest.mark.parametrize("input_mesh", [input_data_paths[0]])
def test_create_hdf5_with_time(input_mesh, tmpdir):
Expand All @@ -148,9 +188,9 @@ def test_create_hdf5_with_time(input_mesh, tmpdir):

# 5. check if the hdf5 file exists
velocity_hdf5_path = tmpdir / "1" / "Visualization_separate_domain" / "u.h5"
assert velocity_hdf5_path.exists()
assert velocity_hdf5_path.exists(), "Velocity hdf5 file does not exist"
displacement_hdf5_path = tmpdir / "1" / "Visualization_separate_domain" / "d_solid.h5"
assert displacement_hdf5_path.exists()
assert displacement_hdf5_path.exists(), "Displacement hdf5 file does not exist"

# 6. check if the hdf5 file has the correct values
with h5py.File(velocity_hdf5_path, "r") as f:
Expand All @@ -164,3 +204,18 @@ def test_create_hdf5_with_time(input_mesh, tmpdir):
assert np.isclose(first_time, 2.235075700301419E-9, atol=1e-10)
last_time = f["displacement/vector_1"][0]
assert np.isclose(last_time, 7.0569699656660426E-9, atol=1e-10)

# 7. create separate visualization
cmd = (f"vasp-create-separate-domain-viz --folder {tmpdir}/1/")
_ = subprocess.check_output(cmd, shell=True)

# 8. check if the separate visualization exists
velocity_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.h5"
velocity_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "velocity_fluid.xdmf"
assert velocity_h5_path.exists(), "Separate visualization for velocity does not exist"
assert velocity_xdmf_path.exists(), "Separate visualization for velocity does not exist"

displacement_h5_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.h5"
displacement_xdmf_path = tmpdir / "1" / "Visualization_separate_domain" / "displacement_solid.xdmf"
assert displacement_h5_path.exists(), "Separate visualization for displacement does not exist"
assert displacement_xdmf_path.exists(), "Separate visualization for displacement does not exist"
Loading