.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_conversions/plot_B_feflowlib_BC_mesh.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_conversions_plot_B_feflowlib_BC_mesh.py: Feflowlib: How to modify boundary conditions after conversion of a FEFLOW model. ================================================================================ This example shows how boundary conditions can be modified after converting a FEFLOW model. First we will change the values of the boundary conditions and later we will show how to define a new boundary mesh. .. GENERATED FROM PYTHON SOURCE LINES 10-11 0. Necessary imports .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: Python import numpy as np import ogstools as ot from ogstools.examples import feflow_model_2D_HT from ogstools.feflowlib import assign_bulk_ids .. GENERATED FROM PYTHON SOURCE LINES 18-20 1. Load a FEFLOW model (.fem) as a FeflowModel object to further work it. During the initialisation, the FEFLOW file is converted. .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python temp_dir = ot.definitions.temp_dir("converted_models", "examples") feflow_model = ot.FeflowModel(feflow_model_2D_HT, temp_dir / "HT_model") mesh = feflow_model.mesh # Print information about the mesh. print(mesh) .. rst-class:: sphx-glr-script-out .. code-block:: none UnstructuredGrid (0x7f0d8c7c8a00) N Cells: 6260 N Points: 3228 X Bounds: -2.500e+02, 9.000e+02 Y Bounds: 3.500e+02, 6.500e+02 Z Bounds: 0.000e+00, 0.000e+00 N Arrays: 33 .. GENERATED FROM PYTHON SOURCE LINES 26-27 2. Plot the temperature simulated in FEFLOW on the mesh. .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python fig = ot.plot.contourf(mesh, "P_TEMP", show_edges=True) fig.show() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_001.png :alt: plot B feflowlib BC mesh :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 30-34 3. As the FEFLOW data now are a pyvista.UnstructuredGrid, all pyvista functionalities can be applied to it. Further information can be found at https://docs.pyvista.org/user-guide/. For example it can be saved as a VTK Unstructured Grid File (\*.vtu). This allows to use the FEFLOW model for ``OGS`` simulation or to observe it in ``Paraview```. .. GENERATED FROM PYTHON SOURCE LINES 34-35 .. code-block:: Python ot.mesh.save(mesh, temp_dir / "HT_mesh.vtu") .. rst-class:: sphx-glr-script-out .. code-block:: none PosixPath('/tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_mesh.vtu') .. GENERATED FROM PYTHON SOURCE LINES 36-37 4. Run the FEFLOW model in OGS. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python feflow_model.setup_prj(end_time=1e11, time_stepping=[(1, 1e10)]) feflow_model.run() ms = ot.MeshSeries(temp_dir / "HT_model.pvd") .. rst-class:: sphx-glr-script-out .. code-block:: none ogs -o . /tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj ['ogs', '-o', '.', '/tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj'] .. GENERATED FROM PYTHON SOURCE LINES 41-42 5. Plot the temperature simulated in OGS. .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python ogs_sim_res = ms.mesh(ms.timesteps[-1]) fig = ot.plot.contourf(ogs_sim_res, ot.variables.temperature) fig.show() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_002.png :alt: plot B feflowlib BC mesh :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-49 6. The boundary meshes are manipulated to alter the model. The original boundary conditions are shown in this example: :ref:`sphx_glr_auto_examples_howto_conversions_plot_F_feflowlib_HT_simulation.py` 6.1 The Dirichlet boundary conditions for the hydraulic head are set to 0. Therefore, no water flows from the left to the right edge. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python bc_flow = feflow_model.subdomains["P_BC_FLOW"]["P_BC_FLOW"] feflow_model.subdomains["P_BC_FLOW"]["P_BC_FLOW"][bc_flow == 10] = 0 .. GENERATED FROM PYTHON SOURCE LINES 52-53 6.2 Overwrite the new boundary conditions and run the model. .. GENERATED FROM PYTHON SOURCE LINES 53-54 .. code-block:: Python feflow_model.run(overwrite=True) .. rst-class:: sphx-glr-script-out .. code-block:: none ogs -o . /tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj ['ogs', '-o', '.', '/tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj'] .. GENERATED FROM PYTHON SOURCE LINES 55-56 6.3 The corresponding simulation results look like. .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: Python ms = ot.MeshSeries(temp_dir / "HT_model.pvd") # Read the last timestep: ogs_sim_res = ms.mesh(ms.timesteps[-1]) fig = ot.plot.contourf(ogs_sim_res, ot.variables.temperature) fig.show() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_003.png :alt: plot B feflowlib BC mesh :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 62-63 6.4 Create a new boundary mesh and overwrite the existing subdomains with this boundary mesh. .. GENERATED FROM PYTHON SOURCE LINES 63-75 .. code-block:: Python assign_bulk_ids(mesh) # Get the points of the bulk mesh to build a new boundary mesh. wanted_pts = [1492, 1482, 1481, 1491, 1479, 1480, 1839, 1840] new_bc = mesh.extract_points( [pt in wanted_pts for pt in mesh["bulk_node_ids"]], adjacent_cells=False, include_cells=False, ) new_bc["bulk_node_ids"] = np.array(wanted_pts, dtype=np.uint64) # Define the temperature values of these points. new_bc["P_BC_HEAT"] = np.array([300] * len(wanted_pts), dtype=np.float64) feflow_model.subdomains["P_BC_HEAT"] = new_bc .. GENERATED FROM PYTHON SOURCE LINES 76-77 7. Run the new model and plot the simulation results. .. GENERATED FROM PYTHON SOURCE LINES 77-82 .. code-block:: Python feflow_model.run(overwrite=True) ms = ot.MeshSeries(temp_dir / "HT_model.pvd") ogs_sim_res = ms.mesh(ms.timesteps[-1]) fig = ot.plot.contourf(ogs_sim_res, ot.variables.temperature) fig.show() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_004.png :alt: plot B feflowlib BC mesh :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_B_feflowlib_BC_mesh_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ogs -o . /tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj ['ogs', '-o', '.', '/tmp/ogstools_root/examples/converted_models463d7b0069c24453aad18d493cf7729f/HT_model.prj'] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.290 seconds) .. _sphx_glr_download_auto_examples_howto_conversions_plot_B_feflowlib_BC_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://binder.opengeosys.org/v2/gh/bilke/binder-ogs-requirements/6.5.8-0.8.2?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgitlab.opengeosys.org%252Fogs%252Ftools%252Fogstools%26urlpath%3Dlab%252Ftree%252Fogstools/docs/examples/howto_conversions/plot_B_feflowlib_BC_mesh.py :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_B_feflowlib_BC_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_B_feflowlib_BC_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_B_feflowlib_BC_mesh.zip `