Skip to content

Commit

Permalink
Merge branch 'API' into 'main'
Browse files Browse the repository at this point in the history
naming conventions, ogs6py API

Closes #85

See merge request ogs/tools/ogstools!199
TobiasMeisel committed Sep 6, 2024

Verified

This commit was signed with the committer’s verified signature.
radoering Randy Döring
2 parents 95820f1 + 6b0d1ca commit e1070b1
Showing 38 changed files with 542 additions and 556 deletions.
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
# 1. Let us convert only the points and cells at first.
import ifm_contrib as ifm

import ogstools as ot
import ogstools as ogs
from ogstools.examples import feflow_model_2layers
from ogstools.feflowlib import (
convert_geometry_mesh,
@@ -36,4 +36,4 @@
pv_mesh.save("2layers_model.vtu")
# %%
# 4. Use the ogstools plotting functionalities.
fig = ot.plot.contourf(pv_mesh.slice("z"), "P_HEAD")
fig = ogs.plot.contourf(pv_mesh.slice("z"), "P_HEAD")
21 changes: 10 additions & 11 deletions docs/examples/howto_conversions/plot_D_feflowlib_CT_simulation.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
import matplotlib.pyplot as plt
import numpy as np

import ogstools as ot
import ogstools as ogs
from ogstools.examples import feflow_model_2D_CT_t_560
from ogstools.feflowlib import (
component_transport,
@@ -28,9 +28,8 @@
write_point_boundary_conditions,
)
from ogstools.meshlib import Mesh
from ogstools.ogs6py import ogs

ot.plot.setup.show_element_edges = True
ogs.plot.setup.show_element_edges = True
# %%
# 1. Load a FEFLOW model (.fem) as a FEFLOW document, convert and save it. More details on
# how the conversion function works can be found here: :py:mod:`ogstools.feflowlib.convert_properties_mesh`.
@@ -41,15 +40,15 @@
feflow_mesh_file = temp_dir / "2D_CT_model.vtu"
feflow_pv_mesh.save(feflow_mesh_file)

feflow_concentration = ot.variables.Scalar(
feflow_concentration = ogs.variables.Scalar(
data_name="single_species_P_CONC",
output_name="concentration",
data_unit="mg/l",
output_unit="mg/l",
)
# The original mesh is clipped to focus on the relevant part of it, where concentration is larger
# than 1e-9 mg/l. The rest of the mesh has concentration values of 0.
ot.plot.contourf(
ogs.plot.contourf(
feflow_pv_mesh.clip_scalar(
scalars="single_species_P_CONC", invert=False, value=1.0e-9
),
@@ -62,12 +61,12 @@
# %%
# 3. Setup a prj-file (see: :py:mod:`ogstools.feflowlib.setup_prj_file`) to run a OGS-simulation.
path_prjfile = feflow_mesh_file.with_suffix(".prj")
prjfile = ogs.OGS(PROJECT_FILE=path_prjfile)
prj = ogs.Project(output_file=path_prjfile)
species = get_species(feflow_pv_mesh)
CT_model = component_transport(
saving_path=temp_dir / "sim_2D_CT_model",
species=species,
model=prjfile,
prj=prj,
dimension=2,
fixed_out_times=[48384000],
initial_time=0,
@@ -96,7 +95,7 @@
model.run_model(logfile=temp_dir / "out.log")
# %%
# 5. Read the results along a line on the upper edge of the mesh parallel to the x-axis and plot them.
ms = ot.MeshSeries(temp_dir / "sim_2D_CT_model.pvd")
ms = ogs.MeshSeries(temp_dir / "sim_2D_CT_model.pvd")
# Read the last timestep:
ogs_sim_res = ms.mesh(ms.timesteps[-1])
"""
@@ -109,7 +108,7 @@
fig, ax = plt.subplots(1, 1, figsize=(7, 5))
ogs_sim_res.plot_linesample(
"dist",
ot.variables.Scalar(
ogs.variables.Scalar(
data_name="single_species",
output_name="concentration",
data_unit="mg/l",
@@ -145,7 +144,7 @@
ogs_sim_res["concentration_difference"] = (
feflow_pv_mesh["single_species_P_CONC"] - ogs_sim_res["single_species"]
)
concentration_difference = ot.variables.Scalar(
concentration_difference = ogs.variables.Scalar(
data_name="concentration_difference",
output_name="concentration",
data_unit="mg/l",
@@ -154,7 +153,7 @@

bounds = [0.038, 0.045, 0, 0.01, 0, 0]

ot.plot.contourf(
ogs.plot.contourf(
ogs_sim_res.clip_box(bounds, invert=False),
concentration_difference,
)
24 changes: 11 additions & 13 deletions docs/examples/howto_conversions/plot_E_feflowlib_H_simulation.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
import numpy as np
import pyvista as pv

import ogstools as ot
import ogstools as ogs
from ogstools.examples import feflow_model_box_Neumann
from ogstools.feflowlib import (
convert_properties_mesh,
@@ -30,7 +30,6 @@
extract_point_boundary_conditions,
get_material_properties,
)
from ogstools.ogs6py import ogs

# %%
# 1. Load a FEFLOW model (.fem) as a FEFLOW document, convert and save it. More details on
@@ -70,12 +69,9 @@
# %%
# 3. Setup a prj-file (see: :py:mod:`ogstools.feflowlib.setup_prj_file`) to run a OGS-simulation.
path_prjfile = feflow_mesh_file.with_suffix(".prj")
prjfile = ogs.OGS(PROJECT_FILE=path_prjfile)
prj = ogs.Project(output_file=path_prjfile)
# Get the template prj-file configurations for a steady state diffusion process
ssd_model = steady_state_diffusion(
temp_dir / "sim_boxNeumann",
prjfile,
)
ssd_model = steady_state_diffusion(temp_dir / "sim_boxNeumann", prj)
# Include the mesh specific configurations to the template.
model = setup_prj_file(
bulk_mesh_path=feflow_mesh_file,
@@ -94,7 +90,7 @@
model.run_model(logfile=temp_dir / "out.log")
# %%
# 5. Read the results and plot them.
ms = ot.MeshSeries(temp_dir / "sim_boxNeumann.pvd")
ms = ogs.MeshSeries(temp_dir / "sim_boxNeumann.pvd")
# Read the last timestep:
ogs_sim_res = ms.mesh(ms.timesteps[-1])
"""
@@ -110,8 +106,10 @@
)
# %%
# 5.1 Plot the hydraulic head simulated in OGS with :py:mod:`ogstools.plot.contourf`.
head = ot.variables.Scalar(data_name="HEAD_OGS", data_unit="m", output_unit="m")
fig = ot.plot.contourf(ogs_sim_res.slice(normal="z", origin=[50, 50, 0]), head)
head = ogs.variables.Scalar(
data_name="HEAD_OGS", data_unit="m", output_unit="m"
)
fig = ogs.plot.contourf(ogs_sim_res.slice(normal="z", origin=[50, 50, 0]), head)


# %%
@@ -128,17 +126,17 @@
# %%
# 6.1 Plot the differences in the hydraulic head with :py:mod:`ogstools.plot.contourf`.
# Slices are taken along the z-axis.
diff_head = ot.variables.Scalar(
diff_head = ogs.variables.Scalar(
data_name="diff_HEAD", data_unit="m", output_unit="m"
)
slices = np.reshape(list(pyvista_mesh.slice_along_axis(n=4, axis="z")), (2, 2))
fig = ot.plot.contourf(slices, diff_head)
fig = ogs.plot.contourf(slices, diff_head)
for ax, slice in zip(fig.axes, np.ravel(slices), strict=False):
ax.set_title(f"z = {slice.center[2]:.1f} {ms.spatial_output_unit}")

# %%
# Slices are taken along the y-axis.
slices = np.reshape(list(pyvista_mesh.slice_along_axis(n=4, axis="y")), (2, 2))
fig = ot.plot.contourf(slices, diff_head)
fig = ogs.plot.contourf(slices, diff_head)
for ax, slice in zip(fig.axes, np.ravel(slices), strict=False):
ax.set_title(f"y = {slice.center[1]:.1f} {ms.spatial_output_unit}")
31 changes: 15 additions & 16 deletions docs/examples/howto_conversions/plot_F_feflowlib_HT_simulation.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
import ifm_contrib as ifm
import pyvista as pv

import ogstools as ot
import ogstools as ogs
from ogstools.examples import feflow_model_2D_HT_model
from ogstools.feflowlib import (
convert_properties_mesh,
@@ -27,15 +27,14 @@
extract_point_boundary_conditions,
get_material_properties_of_HT_model,
)
from ogstools.ogs6py import ogs

# %%
# 1. Load a FEFLOW model (.fem) as a FEFLOW document, convert and save it. More details on
# how the conversion function works can be found here: :py:mod:`ogstools.feflowlib.convert_properties_mesh`.
feflow_model = ifm.loadDocument(str(feflow_model_2D_HT_model))
feflow_pv_mesh = convert_properties_mesh(feflow_model)
feflow_temperature = ot.variables.temperature.replace(data_name="P_TEMP")
ot.plot.contourf(feflow_pv_mesh, feflow_temperature)
feflow_temperature = ogs.variables.temperature.replace(data_name="P_TEMP")
ogs.plot.contourf(feflow_pv_mesh, feflow_temperature)

temp_dir = Path(tempfile.mkdtemp("feflow_test_simulation"))
feflow_mesh_file = temp_dir / "2D_HT_model.vtu"
@@ -55,9 +54,9 @@
# %%
# 3. Setup a prj-file (see: :py:mod:`ogstools.feflowlib.setup_prj_file`) to run a OGS-simulation.
path_prjfile = feflow_mesh_file.with_suffix(".prj")
prjfile = ogs.OGS(PROJECT_FILE=path_prjfile)
prj = ogs.Project(output_file=path_prjfile)
# Get the template prj-file configurations for a hydro thermal process.
HT_model = hydro_thermal(temp_dir / "sim_2D_HT_model", prjfile, dimension=2)
HT_model = hydro_thermal(temp_dir / "sim_2D_HT_model", prj, dimension=2)
# Include the mesh specific configurations to the template.
model = setup_prj_file(
bulk_mesh_path=feflow_mesh_file,
@@ -76,7 +75,7 @@
model.run_model(logfile=temp_dir / "out.log")
# %%
# 5. Read the results and plot them.
ms = ot.MeshSeries(temp_dir / "sim_2D_HT_model.pvd")
ms = ogs.MeshSeries(temp_dir / "sim_2D_HT_model.pvd")
# Read the last timestep:
ogs_sim_res = ms.mesh(ms.timesteps[-1])
"""
@@ -86,28 +85,28 @@
)
"""
# Plot the hydraulic head/height, which was simulated in OGS.
hydraulic_head = ot.variables.Scalar(
hydraulic_head = ogs.variables.Scalar(
data_name="HEAD_OGS", data_unit="m", output_unit="m"
)
ot.plot.contourf(ogs_sim_res, hydraulic_head)
ogs.plot.contourf(ogs_sim_res, hydraulic_head)
# %%
# Plot the temperature, which was simulated in OGS.
ot.plot.contourf(ogs_sim_res, ot.variables.temperature)
ogs.plot.contourf(ogs_sim_res, ogs.variables.temperature)

# %%
# 6. Plot the difference between the FEFLOW and OGS simulation.
feflow_pv_mesh["HEAD"] = feflow_pv_mesh["P_HEAD"]
ogs_sim_res["HEAD"] = ogs_sim_res["HEAD_OGS"]
# Plot differences in hydraulic head/height.
diff_mesh = ot.meshlib.difference(feflow_pv_mesh, ogs_sim_res, "HEAD")
hydraulic_head_diff = ot.variables.Scalar(
diff_mesh = ogs.meshlib.difference(feflow_pv_mesh, ogs_sim_res, "HEAD")
hydraulic_head_diff = ogs.variables.Scalar(
data_name="HEAD_difference", data_unit="m", output_unit="m"
)
ot.plot.contourf(diff_mesh, hydraulic_head_diff)
ogs.plot.contourf(diff_mesh, hydraulic_head_diff)
# %%
feflow_pv_mesh["temperature"] = feflow_pv_mesh["P_TEMP"]
# Plot differences in temperature.
diff_mesh = ot.meshlib.difference(
feflow_pv_mesh, ogs_sim_res, ot.variables.temperature
diff_mesh = ogs.meshlib.difference(
feflow_pv_mesh, ogs_sim_res, ogs.variables.temperature
)
ot.plot.contourf(diff_mesh, ot.variables.temperature.difference)
ogs.plot.contourf(diff_mesh, ogs.variables.temperature.difference)
14 changes: 7 additions & 7 deletions docs/examples/howto_plot/plot_animation.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
import matplotlib.pyplot as plt
import numpy as np

import ogstools as ot
import ogstools as ogs
from ogstools import examples

mesh_series = examples.load_meshseries_CT_2D_XDMF()
@@ -34,9 +34,9 @@
# Let's use fixed scale limits to prevent rescaling during the animation.

# %%
ot.plot.setup.vmin = 0
ot.plot.setup.vmax = 100
ot.plot.setup.dpi = 50
ogs.plot.setup.vmin = 0
ogs.plot.setup.vmax = 100
ogs.plot.setup.dpi = 50

# %% [markdown]
# You can choose which timesteps to render by passing either an int array
@@ -58,7 +58,7 @@
# `plot_func` which can apply custom formatting and / or plotting.


def mesh_func(mesh: ot.Mesh) -> ot.Mesh:
def mesh_func(mesh: ogs.Mesh) -> ogs.Mesh:
"Clip the left half of the mesh."
return mesh.clip("-x", [0, 0, 0])

@@ -70,7 +70,7 @@ def plot_func(ax: plt.Axes, timevalue: float) -> None:

# %%
anim = mesh_series.animate(
ot.variables.saturation,
ogs.variables.saturation,
timevalues,
mesh_func=mesh_func,
plot_func=plot_func,
@@ -81,7 +81,7 @@ def plot_func(ax: plt.Axes, timevalue: float) -> None:
#
# .. code-block:: python
#
# ot.plot.utils.save_animation(anim, "Saturation", fps=5)
# ogs.plot.utils.save_animation(anim, "Saturation", fps=5)
#

# sphinx_gallery_start_ignore
24 changes: 12 additions & 12 deletions docs/examples/howto_plot/plot_aspect_ratios.py
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@
import numpy as np
import pyvista as pv

import ogstools as ot
import ogstools as ogs

print(f"{ot.plot.setup.min_ax_aspect=}")
print(f"{ot.plot.setup.max_ax_aspect=}")
print(f"{ogs.plot.setup.min_ax_aspect=}")
print(f"{ogs.plot.setup.max_ax_aspect=}")


# sphinx_gallery_start_ignore
@@ -44,32 +44,32 @@ def custom_mesh(dx: float, dy: float):
# proportions.

# %%
fig = ot.plot.contourf(custom_mesh(np.pi * 2, np.pi), "example")
fig = ogs.plot.contourf(custom_mesh(np.pi * 2, np.pi), "example")
# %% [markdown]
# This one would be too wide and thus and gets compressed to fit the maximum
# aspect ratio.

# %%
fig = ot.plot.contourf(custom_mesh(np.pi * 4, np.pi), "example")
fig = ogs.plot.contourf(custom_mesh(np.pi * 4, np.pi), "example")
# %% [markdown]
# When plotting multiple meshes together, this applies to each subplot.
# So here each subplot has true proportions again since each one fits the limits.

# %%
fig = ot.plot.contourf(
fig = ogs.plot.contourf(
[custom_mesh(np.pi * 2, np.pi), custom_mesh(np.pi * 2, np.pi)], "example"
)
# %% [markdown]
# The following figure would be to tall and is clipped to the minimum aspect
# ratio.

# %%
fig = ot.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
fig = ogs.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
# %% [markdown]
# The same is true here:

# %%
fig = ot.plot.contourf(
fig = ogs.plot.contourf(
[custom_mesh(np.pi, np.pi * 3), custom_mesh(np.pi, np.pi * 3)], "example"
)

@@ -79,12 +79,12 @@ def custom_mesh(dx: float, dy: float):
# very wide figure.

# %%
ot.plot.setup.min_ax_aspect = None
ot.plot.setup.max_ax_aspect = None
fig = ot.plot.contourf(custom_mesh(np.pi * 3, np.pi), "example")
ogs.plot.setup.min_ax_aspect = None
ogs.plot.setup.max_ax_aspect = None
fig = ogs.plot.contourf(custom_mesh(np.pi * 3, np.pi), "example")

# %% [markdown]
# And in this case we get a very tall figure.

# %%
fig = ot.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
fig = ogs.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
Loading

0 comments on commit e1070b1

Please sign in to comment.