.. 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-30 .. code-block:: Python from pathlib import Path from tempfile import mkdtemp import ogstools as ot from ogstools.definitions import EXAMPLES_DIR model_dir = Path(mkdtemp()) youngs_moduli = [1, 2, 3] filename = EXAMPLES_DIR / "prj/simple_mechanics.prj" for youngs_modulus in youngs_moduli: prj = ot.Project(input_file=filename, output_file=model_dir / 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(args=f"-m {EXAMPLES_DIR}/prj/ -o {model_dir}") .. 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.09558629989624023 s Project file written to output. OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/simple_mechanics.prj. Execution took 0.10382747650146484 s Project file written to output. OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/simple_mechanics.prj. Execution took 0.09942245483398438 s Project file written to output. .. GENERATED FROM PYTHON SOURCE LINES 31-33 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 33-35 .. code-block:: Python prj.replace_text(youngs_modulus, xpath="./parameters/parameter[name='E']/value") .. GENERATED FROM PYTHON SOURCE LINES 36-37 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 37-41 .. code-block:: Python prj.replace_text( youngs_modulus, xpath="./parameters/parameter/value", occurrence=0 ) .. GENERATED FROM PYTHON SOURCE LINES 42-43 The density can also be changed: .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python prj.replace_phase_property_value( mediumid=0, phase="Solid", name="density", value="42" ) .. GENERATED FROM PYTHON SOURCE LINES 48-51 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.305 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 `