# Can OGS apply initial stress to a multilayer soil model?

**URL:** <https://discourse.opengeosys.org/t/can-ogs-apply-initial-stress-to-a-multilayer-soil-model/1549>\
**Category:** Help & Support\
**Tags:** ogs6\
**Created:** [January 6, 2025, 1:39pm UTC](https://discourse.opengeosys.org/t/can-ogs-apply-initial-stress-to-a-multilayer-soil-model/1549 "2025-01-06T13:39:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PHLi](https://discourse.opengeosys.org/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@PHLi](https://discourse.opengeosys.org/u/PHLi)\
**Post date:** [January 6, 2025, 1:39pm UTC](https://discourse.opengeosys.org/t/can-ogs-apply-initial-stress-to-a-multilayer-soil-model/1549/1 "2025-01-06T13:39:40Z")

</div>

Hello everyone!  
I’m simulating a model consisting of multiple layers of soil and energy piles. By learning the prj file of the benchmark in the OGS source code /test/data, I know how to define the material parameters of different soils. But when I was ready to put initial stress on the model, I ran into difficulties. It seems that the simulated objects in the existing reference files are all homogeneous soils, so an expression of a first-order function can be used in to express the increase of initial stress with depth. When I want to apply initial stress to multi-layer soil, I need to use a piecewise function to express the change of initial stress due to the different material properties of different soils. I tried to write several prj files, and found that \<initial\_stress\> can only be defined once, so I could not define the initial stress of different soils by defining multiple \<initial\_stress\>.  
Is there any way to solve the above problem? I am also curious if there are other ways to perform initial geostatic equilibrium in OGS.I look forward to your response. Thanks.  
 ![截图 2025-01-06 21-20-56](https://discourse.opengeosys.org/uploads/default/original/2X/d/d56a9eae202234c70c772ec7def216700063a013.png)

---

<div class="post-metadata">

**Author:** ![chleh](https://discourse.opengeosys.org/user_avatar/discourse.opengeosys.org/chleh/32/854_2.png) [@chleh](https://discourse.opengeosys.org/u/chleh)\
**Post date:** [January 7, 2025, 7:50am UTC](https://discourse.opengeosys.org/t/can-ogs-apply-initial-stress-to-a-multilayer-soil-model/1549/2 "2025-01-07T07:50:10Z")

</div>

Hi PHLi,

probably the easiest solution for your problem is to use advanced functional expressions for the initial stress.

In [this](https://gitlab.opengeosys.org/ogs/ogs/-/blob/master/Tests/Data/ThermoHydroMechanics/Linear/Beam_sealed_bimaterial/square_1e2_function.xml?ref_type=heads) XML snippet\* this has been used to model a bimaterial domain:

```xml
        <parameter>
            <name>E</name>
            <type>Function</type>
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
        </parameter>

```

`x`, `y`, `z` are the Cartesian coordinates of the location at which the expression is evaluated.  
Note that `<` and `>` must be escaped (`&lt;`, `&gt;`) since the expression is embedded in an XML file.

So, in your case the parameter would be something like

```xml
        <parameter>
            <name>sigma_ic</name>
            <type>Function</type>
            <!-- xx component -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
            <!-- yy component -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
            <!-- zz component -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
            <!-- xy component -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
            <!-- yz component, in 3D only -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
            <!-- xz component, in 3D only -->
            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>
        </parameter>

```

ExprTk is used to parse and evaluate the expressions.  
It allows great flexibility for the expressions.  
Take a look at the examples on the [ExprTk website](https://www.partow.net/programming/exprtk/index.html).

You can specify effective and total initial stresses. You can switch between them with the [`type` attribute](https://doxygen.opengeosys.org/d8/d11/ogs_file_attr __prj__ processes __process__ initial_stress__type.html) of the `<initial_stress>` setting.

Best regards,  
Christoph

\* Some info about OGS’s XML patch files can be found [here](https://www.opengeosys.org/docs/userguide/basics/project-file/#option-2-apply-patch-files-to-the-project-file).

---

<div class="post-metadata">

**Author:** ![PHLi](https://discourse.opengeosys.org/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@PHLi](https://discourse.opengeosys.org/u/PHLi)\
**Post date:** [January 7, 2025, 8:10am UTC](https://discourse.opengeosys.org/t/can-ogs-apply-initial-stress-to-a-multilayer-soil-model/1549/3 "2025-01-07T08:10:17Z")

</div>

Hi Christoph,  
Thank you very much for your detailed response. It has resolved a problem that has been troubling me for quite some time.  
I will try to follow your method.  
best regards，  
PHLi
