.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_conversions/plot_F_feflowlib_HT_simulation.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_conversions_plot_F_feflowlib_HT_simulation.py: Feflowlib: Hydro-thermal model - conversion and simulation ========================================================== .. sectionauthor:: Julian Heinze (Helmholtz Centre for Environmental Research GmbH - UFZ) In this example we show how a simple hydro thermal FEFLOW model can be converted to a pyvista.UnstructuredGrid and then be simulated in OGS. .. GENERATED FROM PYTHON SOURCE LINES 11-12 0. Necessary imports .. GENERATED FROM PYTHON SOURCE LINES 12-31 .. code-block:: Python import tempfile import xml.etree.ElementTree as ET from pathlib import Path import ifm_contrib as ifm import pyvista as pv import ogstools as ogs from ogstools.examples import feflow_model_2D_HT_model from ogstools.feflowlib import ( convert_properties_mesh, hydro_thermal, setup_prj_file, ) from ogstools.feflowlib.tools import ( extract_point_boundary_conditions, get_material_properties_of_HT_model, ) .. GENERATED FROM PYTHON SOURCE LINES 32-34 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`. .. GENERATED FROM PYTHON SOURCE LINES 34-43 .. code-block:: Python feflow_model = ifm.loadDocument(str(feflow_model_2D_HT_model)) feflow_pv_mesh = convert_properties_mesh(feflow_model) 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" feflow_pv_mesh.save(feflow_mesh_file) print(feflow_pv_mesh) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_001.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none UnstructuredGrid (0x7cd46b5849a0) N Cells: 1565 N Points: 832 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: 34 .. GENERATED FROM PYTHON SOURCE LINES 44-45 2. Extract the point conditions (see: :py:mod:`ogstools.feflowlib.extract_point_boundary_conditions`). .. GENERATED FROM PYTHON SOURCE LINES 45-54 .. code-block:: Python point_BC_dict = extract_point_boundary_conditions(temp_dir, feflow_pv_mesh) # Since there can be multiple point boundary conditions on the bulk mesh, they are plotted iteratively. plotter = pv.Plotter(shape=(len(point_BC_dict), 1)) for i, (path, boundary_condition) in enumerate(point_BC_dict.items()): boundary_condition.save(path) plotter.subplot(i, 0) plotter.add_mesh(boundary_condition, scalars=Path(path).stem) plotter.view_xy() plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_002.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 55-56 3. Setup a prj-file (see: :py:mod:`ogstools.feflowlib.setup_prj_file`) to run a OGS-simulation. .. GENERATED FROM PYTHON SOURCE LINES 56-73 .. code-block:: Python path_prjfile = feflow_mesh_file.with_suffix(".prj") 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", prj, dimension=2) # Include the mesh specific configurations to the template. model = setup_prj_file( bulk_mesh_path=feflow_mesh_file, mesh=feflow_pv_mesh, material_properties=get_material_properties_of_HT_model(feflow_pv_mesh), process="hydro thermal", model=HT_model, ) # The model must be written before it can be run. model.write_input(path_prjfile) # Print the prj-file as an example. model_prjfile = ET.parse(path_prjfile) ET.dump(model_prjfile) .. rst-class:: sphx-glr-script-out .. code-block:: none 2D_HT_model.vtu P_BC_FLOW.vtu P_BC_HEAT.vtu HydroThermal HT 3 0 0 temperature HEAD_OGS AqueousLiquid specific_heat_capacity Constant 4200000.0 thermal_conductivity Constant 0.65 viscosity Constant 1 density Constant 1 Solid storage Constant 0.0 density Constant 1 specific_heat_capacity Constant 1633000.0 thermal_conductivity Constant 3.0 permeability Constant 1.1574074074074073e-05 1.1574074074074073e-05 porosity Constant 0.0 thermal_conductivity EffectiveThermalConductivityPorosityMixing thermal_transversal_dispersivity Constant 0.5 thermal_longitudinal_dispersivity Constant 5.0 basic_picard DeltaX NORM2 1e-16 BackwardEuler FixedTimeStepping 0 1e11 1 1e10 1 1e10 VTK /tmp/tmpclvdkfizfeflow_test_simulation/sim_2D_HT_model 1 1 T0 Constant 273.15 p0 Constant 0 P_BC_FLOW MeshNode P_BC_FLOW P_BC_FLOW P_BC_HEAT MeshNode P_BC_HEAT P_BC_HEAT temperature 1 1 T0 Dirichlet P_BC_HEAT P_BC_HEAT HEAD_OGS 1 1 p0 Dirichlet P_BC_FLOW P_BC_FLOW basic_picard Picard 100 general_linear_solver general_linear_solver -i bicgstab -p jacobi -tol 1e-20 -maxiter 10000 SparseLU true .. GENERATED FROM PYTHON SOURCE LINES 74-75 4. Run the model. .. GENERATED FROM PYTHON SOURCE LINES 75-76 .. code-block:: Python model.run_model(logfile=temp_dir / "out.log") .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmpclvdkfizfeflow_test_simulation/2D_HT_model.prj. Execution took 0.4532768726348877 s Project file written to output. .. GENERATED FROM PYTHON SOURCE LINES 77-78 5. Read the results and plot them. .. GENERATED FROM PYTHON SOURCE LINES 78-92 .. code-block:: Python ms = ogs.MeshSeries(temp_dir / "sim_2D_HT_model.pvd") # Read the last timestep: ogs_sim_res = ms.mesh(ms.timesteps[-1]) """ It is also possible to read the file directly with pyvista: ogs_sim_res = pv.read( temp_dir / "sim_2D_HT_model_ts_10_t_100000000000.000000.vtu" ) """ # Plot the hydraulic head/height, which was simulated in OGS. hydraulic_head = ogs.variables.Scalar( data_name="HEAD_OGS", data_unit="m", output_unit="m" ) ogs.plot.contourf(ogs_sim_res, hydraulic_head) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_003.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 93-94 Plot the temperature, which was simulated in OGS. .. GENERATED FROM PYTHON SOURCE LINES 94-96 .. code-block:: Python ogs.plot.contourf(ogs_sim_res, ogs.variables.temperature) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_004.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 97-98 6. Plot the difference between the FEFLOW and OGS simulation. .. GENERATED FROM PYTHON SOURCE LINES 98-106 .. code-block:: Python 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 = 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" ) ogs.plot.contourf(diff_mesh, hydraulic_head_diff) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_005.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 107-113 .. code-block:: Python feflow_pv_mesh["temperature"] = feflow_pv_mesh["P_TEMP"] # Plot differences in temperature. diff_mesh = ogs.meshlib.difference( feflow_pv_mesh, ogs_sim_res, ogs.variables.temperature ) ogs.plot.contourf(diff_mesh, ogs.variables.temperature.difference) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_006.png :alt: plot F feflowlib HT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_F_feflowlib_HT_simulation_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.018 seconds) .. _sphx_glr_download_auto_examples_howto_conversions_plot_F_feflowlib_HT_simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_F_feflowlib_HT_simulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_F_feflowlib_HT_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_F_feflowlib_HT_simulation.zip `