# Output stress and strain on the ground surface

**URL:** <https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935>\
**Category:** PyLith\
**Created:** [July 30, 2021, 12:32pm UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935 "2021-07-30T12:32:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [July 30, 2021, 12:32pm UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/1 "2021-07-30T12:32:36Z")

</div>

Dear Pylith team,

PyLith supports output of the solution on any boundary of the domain by associating an output manager with a group of vertices corresponding to the surface of the boundary. The default output of this feature is displacement. I want to output stress and strain on the ground surface. Can this be achieved?  
Thank you in advance.

Nick

---

<div class="post-metadata">

**Author:** ![baagaard](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/baagaard/32/615_2.png) [@baagaard](https://community.geodynamics.org/u/baagaard)\
**Post date:** [July 30, 2021, 3:26pm UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/2 "2021-07-30T15:26:50Z")

</div>

For PyLith v2.x, only solution fields, such as displacement and velocity, can be output on boundaries. Stress and strain output are currently only available for materials.

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [July 31, 2021, 10:32am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/3 "2021-07-31T10:32:08Z")

</div>

Hi Brad,

Thank for your fast response.  
I looked at the step-upper-crust.h5 in the 3d/hex8/step06.cfg output and found that the number of vertices does not correspond to the number of stress and strain. In this result file, the number of vertices is 280 and the number of stress and strain in each time step is 72. How can the results of stress and strain correspond to the vertices? In addition, I want to get the stress and strain of the ground point, is there any good way?

The txt file are attached below:  
[step06-upper\_crust.txt](https://community.geodynamics.org/uploads/short-url/8NitIEFU1tkt2byUMRbAgvUN5eD.txt) (221.4 KB)

Nick

---

<div class="post-metadata">

**Author:** ![baagaard](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/baagaard/32/615_2.png) [@baagaard](https://community.geodynamics.org/u/baagaard)\
**Post date:** [July 31, 2021, 7:52pm UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/4 "2021-07-31T19:52:02Z")

</div>

Stress and strain are computed at the finite-element quadrature points. When you use CellFilterAvg on the field, it averages the values over the quadrature points to give values at one location per cell (centroid). This is the normal procedure for values computed at quadrature points because nearly all visualization tools only understand output that one location per cell.

To get stress and strain at the ground surface in PyLith v2.x, the best you can do is to get the stress and strain at all of the quadrature points in a cell and use the value closest to a target point. Unfortunately, we have not implemented output of the coordinates of the quadrature points. Thus, in practice your best bet is to get the stress and strain at the centroid of the cell closest to the target point.

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [August 1, 2021, 4:40am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/5 "2021-08-01T04:40:38Z")

</div>

Hi Brad,

I know what you mean. How can the stress and strain results in h5 file correspond to the centroid coordinates of per cell? The h5 file does not seem to contain centroid coordinates.  
Thanks again.

Nick

---

<div class="post-metadata">

**Author:** ![baagaard](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/baagaard/32/615_2.png) [@baagaard](https://community.geodynamics.org/u/baagaard)\
**Post date:** [August 1, 2021, 4:41pm UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/6 "2021-08-01T16:41:41Z")

</div>

The centroid of any cell can be computed directly from the coordinates of the vertices.

For example, see [pylith/plot\_soln.py at releases/v2.2 · geodynamics/pylith · GitHub](https://github.com/geodynamics/pylith/blob/releases/v2.2/examples/2d/gravity/plot_soln.py#L31)

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [August 4, 2021, 1:33am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/7 "2021-08-04T01:33:54Z")

</div>

Hi Brad,

The code you provided is very useful. Many thanks for your help.

Nick

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [August 10, 2021, 2:46am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/8 "2021-08-10T02:46:16Z")

</div>

Hi Brad,

What is the order of stress components in the material output H5 file? σxx, σyy, σzz, σxy, σyz, σxz or σxx, σxy, σxz, σyy, σyz, σzz?  
Thanks.

Nick

---

<div class="post-metadata">

**Author:** ![willic3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/willic3/32/598_2.png) [@willic3](https://community.geodynamics.org/u/willic3)\
**Post date:** [August 10, 2021, 4:02am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/9 "2021-08-10T04:02:57Z")

</div>

Hi Nick,

The order is actually: xx, yy, zz, xy, xz, yz.

Cheers,  
Charles

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [August 10, 2021, 7:27am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/11 "2021-08-10T07:27:40Z")

</div>

Hi Charles,

Thank you for your fast response. The order of components in tensor state-variables(total\_strain, stress, etc) for materials in the tutorial is shown in the following picture, so the order in the tutorial is wrong, right?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/geodynamics/original/1X/fd5d79d2c6fcfdf363db92f5a78fec5d99027d7b.png)

Nick

---

<div class="post-metadata">

**Author:** ![willic3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/willic3/32/598_2.png) [@willic3](https://community.geodynamics.org/u/willic3)\
**Post date:** [August 10, 2021, 7:31am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/12 "2021-08-10T07:31:40Z")

</div>

No. I mis-typed. The order in the manual is correct. Sorry about that.

Cheers,  
Charles

---

<div class="post-metadata">

**Author:** ![luxiaokong](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luxiaokong](https://community.geodynamics.org/u/luxiaokong)\
**Post date:** [August 10, 2021, 7:35am UTC](https://community.geodynamics.org/t/output-stress-and-strain-on-the-ground-surface/1935/13 "2021-08-10T07:35:03Z")

</div>

Okay, thanks again.

Nick
