.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_conversions/plot_D_feflowlib_CT_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_D_feflowlib_CT_simulation.py: Feflowlib: Component-transport model - conversion and simulation ================================================================ .. sectionauthor:: Julian Heinze (Helmholtz Centre for Environmental Research GmbH - UFZ) In this example we show how a simple mass transport FEFLOW model can be converted to a pyvista.UnstructuredGrid and then be simulated in OGS with the component transport process. .. GENERATED FROM PYTHON SOURCE LINES 11-12 0. Necessary imports .. GENERATED FROM PYTHON SOURCE LINES 12-33 .. code-block:: Python import tempfile import xml.etree.ElementTree as ET from pathlib import Path import ifm_contrib as ifm import matplotlib.pyplot as plt import numpy as np import ogstools as ogs from ogstools.examples import feflow_model_2D_CT_t_560 from ogstools.feflowlib import ( component_transport, convert_properties_mesh, get_material_properties_of_CT_model, get_species, setup_prj_file, write_point_boundary_conditions, ) from ogstools.meshlib import Mesh ogs.plot.setup.show_element_edges = True .. GENERATED FROM PYTHON SOURCE LINES 34-36 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 36-58 .. code-block:: Python feflow_model = ifm.loadDocument(str(feflow_model_2D_CT_t_560)) feflow_pv_mesh = convert_properties_mesh(feflow_model) temp_dir = Path(tempfile.mkdtemp("feflow_test_simulation")) feflow_mesh_file = temp_dir / "2D_CT_model.vtu" feflow_pv_mesh.save(feflow_mesh_file) 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. ogs.plot.contourf( feflow_pv_mesh.clip_scalar( scalars="single_species_P_CONC", invert=False, value=1.0e-9 ), feflow_concentration, ) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_001.png :alt: plot D feflowlib CT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 59-60 2. Save the point boundary conditions (see: :py:mod:`ogstools.feflowlib.write_point_boundary_conditions`). .. GENERATED FROM PYTHON SOURCE LINES 60-61 .. code-block:: Python write_point_boundary_conditions(temp_dir, feflow_pv_mesh) .. GENERATED FROM PYTHON SOURCE LINES 62-63 3. Setup a prj-file (see: :py:mod:`ogstools.feflowlib.setup_prj_file`) to run a OGS-simulation. .. GENERATED FROM PYTHON SOURCE LINES 63-93 .. code-block:: Python path_prjfile = feflow_mesh_file.with_suffix(".prj") 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, prj=prj, dimension=2, fixed_out_times=[48384000], initial_time=0, end_time=int(4.8384e07), time_stepping=list( zip([10] * 8, [8.64 * 10**i for i in range(8)], strict=False) ), ) # 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_CT_model(feflow_pv_mesh), process="component transport", species_list=species, model=CT_model, max_iter=6, rel_tol=1e-14, ) # The model must be written before it can be run. model.write_input(path_prjfile) # Print the prj-file as an example. ET.dump(ET.parse(path_prjfile)) .. rst-class:: sphx-glr-script-out .. code-block:: none 2D_CT_model.vtu single_species_P_BC_MASS.vtu CT ComponentTransport staggered 2 0 0 HEAD_OGS single_species AqueousLiquid viscosity Constant 1 density Constant 1 single_species decay_rate Constant 0.0 pore_diffusion Constant 3.5999998241701783e-10 retardation_factor Constant 16441.72737282367 porosity Constant 0.10999999940395355 longitudinal_dispersivity Constant 0.0 transversal_dispersivity Constant 0.0 permeability Constant 1.1574074074074073e-05 basic_picard DeltaX NORM2 1e-6 BackwardEuler FixedTimeStepping 0 48384000 10 8.64 10 86.4 10 864.0 10 8640.0 10 86400.0 10 864000.0 10 8640000.0 10 86400000.0 basic_picard DeltaX NORM2 1e-6 BackwardEuler FixedTimeStepping 0 48384000 10 8.64 10 86.4 10 864.0 10 8640.0 10 86400.0 10 864000.0 10 8640000.0 10 86400000.0 VTK /tmp/tmp7xtjxuqpfeflow_test_simulation/sim_2D_CT_model 1 48384000 single_species HEAD_OGS 48384000 6 DeltaX NORM2 1e-14 DeltaX NORM2 1e-14 C0 Constant 0 p0 Constant 0 single_species_P_BC_MASS MeshNode single_species_P_BC_MASS single_species_P_BC_MASS single_species 1 1 C0 Dirichlet single_species_P_BC_MASS single_species_P_BC_MASS HEAD_OGS 1 1 p0 basic_picard Picard 10 general_linear_solver general_linear_solver -i bicgstab -p ilut -tol 1e-10 -maxiter 10000 CG DIAGONAL 100000 1e-20 ct -ct_ksp_type bcgs -ct_pc_type bjacobi -ct_ksp_rtol 1e-16 -ct_ksp_max_it 10000 .. GENERATED FROM PYTHON SOURCE LINES 94-95 4. Run the model. .. GENERATED FROM PYTHON SOURCE LINES 95-96 .. 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/tmp7xtjxuqpfeflow_test_simulation/2D_CT_model.prj. Execution took 2.9462203979492188 s Project file written to output. .. GENERATED FROM PYTHON SOURCE LINES 97-98 5. Read the results along a line on the upper edge of the mesh parallel to the x-axis and plot them. .. GENERATED FROM PYTHON SOURCE LINES 98-142 .. code-block:: Python ms = ogs.MeshSeries(temp_dir / "sim_2D_CT_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_CT_model_ts_65_t_48384000.000000.vtu" ) """ profile = np.array([[0.038 + 1.0e-8, 0.005, 0], [0.045, 0.005, 0]]) fig, ax = plt.subplots(1, 1, figsize=(7, 5)) ogs_sim_res.plot_linesample( "dist", ogs.variables.Scalar( data_name="single_species", output_name="concentration", data_unit="mg/l", output_unit="mg/l", ), profile_points=profile, ax=ax, resolution=1000, grid="major", fontsize=18, label="OGS", color="black", linewidth=2, ) Mesh(feflow_pv_mesh).plot_linesample( "dist", feflow_concentration, profile_points=profile, ax=ax, resolution=1000, fontsize=16, label="FEFLOW", ls=":", linewidth=2, color="red", ) ax.legend(loc="best", fontsize=16) fig.tight_layout() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_002.png :alt: plot D feflowlib CT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 143-144 6. Concentration difference plotted on the mesh. .. GENERATED FROM PYTHON SOURCE LINES 144-160 .. code-block:: Python ogs_sim_res["concentration_difference"] = ( feflow_pv_mesh["single_species_P_CONC"] - ogs_sim_res["single_species"] ) concentration_difference = ogs.variables.Scalar( data_name="concentration_difference", output_name="concentration", data_unit="mg/l", output_unit="mg/l", ) bounds = [0.038, 0.045, 0, 0.01, 0, 0] ogs.plot.contourf( ogs_sim_res.clip_box(bounds, invert=False), concentration_difference, ) .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_003.png :alt: plot D feflowlib CT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 161-162 6.1 Concentration difference plotted along a line. .. GENERATED FROM PYTHON SOURCE LINES 162-177 .. code-block:: Python fig, ax = plt.subplots(1, 1, figsize=(7, 5)) ogs_sim_res.plot_linesample( "dist", concentration_difference, profile_points=profile, ax=ax, resolution=1000, grid="both", fontsize=18, linewidth=2, color="green", label="Difference FEFLOW-OGS", ) ax.legend(loc="best", fontsize=16) fig.tight_layout() .. image-sg:: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_004.png :alt: plot D feflowlib CT simulation :srcset: /auto_examples/howto_conversions/images/sphx_glr_plot_D_feflowlib_CT_simulation_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.184 seconds) .. _sphx_glr_download_auto_examples_howto_conversions_plot_D_feflowlib_CT_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_D_feflowlib_CT_simulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_D_feflowlib_CT_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_D_feflowlib_CT_simulation.zip `