Skip to content
Snippets Groups Projects
Verified Commit 685b04b6 authored by Lars Bilke's avatar Lars Bilke
Browse files

[py] ruff fixes in Tests/Data/Mechanics/Linear/test_ip_data/2D-clamped-gravity.py.

parent b57489e0
No related branches found
No related tags found
No related merge requests found
...@@ -16,21 +16,23 @@ ...@@ -16,21 +16,23 @@
# # Deformation of a linear elastic Material due to its own gravity # # Deformation of a linear elastic Material due to its own gravity
# %% # %%
import os
import subprocess
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np import numpy as np
import pyvista as pv import pyvista as pv
from IPython.display import HTML, display
pv.set_jupyter_backend("static") pv.set_jupyter_backend("static")
import os # %
import subprocess
import matplotlib.pyplot as plt
# %% outdir = Path(os.environ.get("OGS_TESTRUNNER_OUT_DIR", "_out"))
outdir = os.environ.get("OGS_TESTRUNNER_OUT_DIR", "_out") if not outdir.exists():
if not os.path.exists(outdir): outdir.mkdir(parents=True)
os.makedirs(outdir) with (outdir / ".gitignore").open(mode="w") as fh:
with open(os.path.join(outdir, ".gitignore"), "w") as fh:
fh.write("*\n") fh.write("*\n")
# %% [markdown] # %% [markdown]
...@@ -141,7 +143,7 @@ def u_y_ana(y): ...@@ -141,7 +143,7 @@ def u_y_ana(y):
# # Run OGS # # Run OGS
# %% # %%
with open(os.path.join(outdir, "ogs-out.txt"), "w") as fh: with (outdir / "ogs-out.txt").open(mode="w") as fh:
subprocess.run( subprocess.run(
["ogs", "-o", outdir, "square_1e2_test_ip_data.prj"], ["ogs", "-o", outdir, "square_1e2_test_ip_data.prj"],
check=True, check=True,
...@@ -151,14 +153,14 @@ with open(os.path.join(outdir, "ogs-out.txt"), "w") as fh: ...@@ -151,14 +153,14 @@ with open(os.path.join(outdir, "ogs-out.txt"), "w") as fh:
# %% # %%
# convert last result to point cloud # convert last result to point cloud
with open(os.path.join(outdir, "point-cloud-out.txt"), "w") as fh: with (outdir / "point-cloud-out.txt").open(mode="w") as fh:
subprocess.run( subprocess.run(
[ [
"ipDataToPointCloud", "ipDataToPointCloud",
"-i", "-i",
os.path.join(outdir, "square_1e2_ts_4_t_1.000000.vtu"), outdir / "square_1e2_ts_4_t_1.000000.vtu",
"-o", "-o",
os.path.join(outdir, "square_1e2_ts_4_point_cloud.vtu"), outdir / "square_1e2_ts_4_point_cloud.vtu",
], ],
check=True, check=True,
stdout=fh, stdout=fh,
...@@ -185,8 +187,8 @@ def add_vertex_cells(mesh): ...@@ -185,8 +187,8 @@ def add_vertex_cells(mesh):
# %% # %%
mesh = pv.read(os.path.join(outdir, "square_1e2_ts_4_t_1.000000.vtu")) mesh = pv.read(outdir / "square_1e2_ts_4_t_1.000000.vtu")
mesh_pc = pv.read(os.path.join(outdir, "square_1e2_ts_4_point_cloud.vtu")) mesh_pc = pv.read(outdir / "square_1e2_ts_4_point_cloud.vtu")
mesh_pc = add_vertex_cells(mesh_pc) # add vertex cells to make pyvista vis work mesh_pc = add_vertex_cells(mesh_pc) # add vertex cells to make pyvista vis work
# %% # %%
...@@ -262,7 +264,6 @@ ax2.set_xlabel(r"$\Delta u_y$ / m") ...@@ -262,7 +264,6 @@ ax2.set_xlabel(r"$\Delta u_y$ / m")
ax.legend() ax.legend()
ax
fig.set_size_inches(12, 4) fig.set_size_inches(12, 4)
# %% # %%
...@@ -311,16 +312,10 @@ ax.set_ylabel("$y$ / m") ...@@ -311,16 +312,10 @@ ax.set_ylabel("$y$ / m")
ax.legend() ax.legend()
ax
fig.set_size_inches(12, 4) fig.set_size_inches(12, 4)
# %% [markdown]
# # Checks (Assertions)
# %% # %%
from IPython.display import HTML, display
def allclose(x, y, abstol): def allclose(x, y, abstol):
d = np.max(np.abs(x - y)) d = np.max(np.abs(x - y))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment