.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_prjfile/plot_manipulation.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_prjfile_plot_manipulation.py: How to Manipulate Prj-Files =========================== .. sectionauthor:: Jörg Buchwald (Helmholtz Centre for Environmental Research GmbH - UFZ) E.g., to iterate over three Young's moduli one can use the replace parameter method. .. GENERATED FROM PYTHON SOURCE LINES 12-13 Initialize the ogs6py object: .. GENERATED FROM PYTHON SOURCE LINES 13-27 .. code-block:: Python import ogstools as ogs from ogstools.definitions import EXAMPLES_DIR youngs_moduli = [1, 2, 3] filename = EXAMPLES_DIR / "prj/simple_mechanics.prj" for youngs_modulus in youngs_moduli: prj = ogs.Project(input_file=filename, output_file=filename) prj.replace_parameter_value(name="E", value=youngs_modulus) prj.replace_text( f"out_E={youngs_modulus}", xpath="./time_loop/output/prefix" ) prj.write_input() prj.run_model() .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/simple_mechanics.prj. Execution took 0.1439681053161621 s Project file written to output. OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/simple_mechanics.prj. Execution took 0.137037992477417 s Project file written to output. OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/simple_mechanics.prj. Execution took 0.12740135192871094 s Project file written to output. .. GENERATED FROM PYTHON SOURCE LINES 28-30 Instead of the `replace_parameter` method, the more general `replace_text` method can also be used to replace the young modulus in this example: .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python prj.replace_text(youngs_modulus, xpath="./parameters/parameter[name='E']/value") .. GENERATED FROM PYTHON SOURCE LINES 33-34 The Young's modulus in this file can also be accessed through 0'th occurrence of the place addressed by the xpath .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: Python prj.replace_text( youngs_modulus, xpath="./parameters/parameter/value", occurrence=0 ) .. GENERATED FROM PYTHON SOURCE LINES 39-40 The density can also be changed: .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python prj.replace_phase_property_value( mediumid=0, phase="Solid", name="density", value="42" ) .. GENERATED FROM PYTHON SOURCE LINES 45-48 For MPL (Material Property Library) based processes, like TH2M or Thermo-Richards-Mechanics, there exist specific functions to set phase and medium properties: e.g.:, `model.replace_medium_property_value(mediumid=0, name="porosity", value="0.24")` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.413 seconds) .. _sphx_glr_download_auto_examples_howto_prjfile_plot_manipulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_manipulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_manipulation.zip `