Skip to content

Commit

Permalink
Merge pull request #196 from keiyamamo/add_separate_viz_pytest
Browse files Browse the repository at this point in the history
add pytest for separate visualization
  • Loading branch information
keiyamamo authored Nov 7, 2024
2 parents 0b54e24 + f968c95 commit 994fd1d
Showing 1 changed file with 57 additions and 2 deletions.
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"

0 comments on commit 994fd1d

Please sign in to comment.