# Python BC for M simulations: heterogeneous stress?

**URL:** <https://discourse.opengeosys.org/t/python-bc-for-m-simulations-heterogeneous-stress/800>\
**Category:** Help & Support\
**Tags:** ogs6\
**Created:** [June 14, 2021, 11:21am UTC](https://discourse.opengeosys.org/t/python-bc-for-m-simulations-heterogeneous-stress/800 "2021-06-14T11:21:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lurpi](https://discourse.opengeosys.org/user_avatar/discourse.opengeosys.org/lurpi/32/470_2.png) [@lurpi](https://discourse.opengeosys.org/u/lurpi)\
**Post date:** [June 14, 2021, 11:21am UTC](https://discourse.opengeosys.org/t/python-bc-for-m-simulations-heterogeneous-stress/800/1 "2021-06-14T11:21:32Z")

</div>

Hi all,

I am following the provided examples to define heterogeneous Neumann BC. I would like to define such a boundary condition for the horizontal stress component, based on the help of a python script:  
 ![image](https://discourse.opengeosys.org/uploads/default/original/1X/f1926547bd9f133c61b3f8b632a35bc60c9f2522.png)  
I have two questions.

1. The python script is accepted by OGS as follows:

where grad\_sigma is a function that returns

` return something*(-y), something_different*y`

Has anyone experience with this approach? I already obtained corresponding IC thanks to constrained displacement BCs, now I would like to match these IC with meaningful BC, replacing the constrained displacement with constrained stresses.  
To provide the full stress tensor as BC, is it enough to give the different components in the .prj file?

1. How do I access material ID from the python scripts, is there a quick way, similar to _coords_ for the spatial coordinates?

---

<div class="post-metadata">

**Author:** ![dmitri.naumov](https://discourse.opengeosys.org/user_avatar/discourse.opengeosys.org/dmitri.naumov/32/561_2.png) [@dmitri.naumov](https://discourse.opengeosys.org/u/dmitri.naumov)\
**Post date:** [June 16, 2021, 7:37am UTC](https://discourse.opengeosys.org/t/python-bc-for-m-simulations-heterogeneous-stress/800/2 "2021-06-16T07:37:37Z")

</div>

Hi,

for the second question, the material ids are not available on the python side. I’m also unsure how to implement this quickly. But the integration point coordinates are available. If the mapping x → materialID is simple you could directly use it (for particular problem).

For the first question I have no answer for now, just discussion. You can (have to) specify on which component of displacement the BC is applied, so you would have 3 BCs for displacement (in 3d). But the shape function used for the boundary element will be for 2d, so you would return a 2-vector from python…

– d

---

<div class="post-metadata">

**Author:** ![Thomas\_Nagel](https://discourse.opengeosys.org/user_avatar/discourse.opengeosys.org/thomas_nagel/32/573_2.png) [@Thomas\_Nagel](https://discourse.opengeosys.org/u/Thomas_Nagel)\
**Post date:** [June 16, 2021, 8:46am UTC](https://discourse.opengeosys.org/t/python-bc-for-m-simulations-heterogeneous-stress/800/3 "2021-06-16T08:46:23Z")

</div>

Hi Luca. Regarding the first question: the full stress tensor is no boundary condition, rather the traction vector (so the normal stress and the two shear stresses on the surface in 3D (one in 2D)). If you calculate that boundary traction vector, it has components in x, y (and z). These, you can specify as Neumann bc for the components analogous to displacement.
