[Gmsh] Stress on Gauss Points

Max Orok morok at mevex.com
Sat Feb 16 17:35:43 CET 2019

Hi Gaetano,

Here I modified the script to each of the stress values separately as
The views will all be visible at once by default but can be toggled by
clicking the "Post-processing" text in the sidebar and then cycled through.

About that displacement question, I just meant I would defer to your
judgment as to whether the displacement matched the stresses, etc.


[image: image.png]

[image: image.png]
[image: image.png]

On Sat, Feb 16, 2019 at 6:30 AM Gaetano Camarda <gaetano_18 at live.it> wrote:

> Hi guys,
> Yes, the goal for me was to plot the data on Gmsh, but i would like to ask
> if there’s a way to show sigx, sigy and so on as view in Gmsh
> Post-processing, it’s look like all the tensor is plotted all together, am
> I wrong?
> I will do a little brief on my work, maybe it could be better
> understanding. I’m sorry in advance if my english is not so perfect.
> I’m working on a Multiscale RVE, not the one I’,ve send but another one
> more complex, but I’m working in parallel with this smaller one for having
> more control on the code and on the operations.
> First thing first, I’ve generated the mesh on Gmsh and I processed the
> operation on Matlab, part of the code was made by me, and for the solver
> I’ve used CalFem function (freeware script for matlab and python for
> studying FEM). The .txt file with stress matrix in gauss point and nodal
> forces for each element are the result of the Calfem function’s I’ve used.
> The Gauss stress matrix I’ve sent as .txt has 8 point for each element,
> this is why it has 512 row, cause the element are 64 with 8 gauss point =
> 512.
> Now the post-processing part, my goal is to plot the data on Gmsh
> postprocessing, thanks to Max now I’ve understood a little bit more about
> the input data Gmsh needed, but I would like to plot stress field
> separately (as sigx view, sigy view and so on); I also have another matrix
> for strain, but I didn’t sent because I think the process to do is the same
> for the gauss-points stresses.
> About this question from Max:
> “For the displacement, does it seem like it aligns? I don't want to make
> a mistake in interpreting the data. “
> I haven’t understand well your question, my english is a little bit
> limited, what to you mean with “it seem like it alligns?” If I’ve
> understood the question you mean the fact that displacement are not the
> same in faces dx and sx? if that’s your meaning, i’ve noticed it too, and I
> think it depends on the boundary conditions I gave to the element.
> Sincerily,
> Gaetano
> Inviato da Posta <https://go.microsoft.com/fwlink/?LinkId=550986> per
> Windows 10
> ------------------------------
> *Da:* Jeremy Theler <jeremy at seamplex.com>
> *Inviato:* Saturday, February 16, 2019 11:29:03 AM
> *A:* Max Orok
> *Cc:* Gaetano Camarda; gmsh at onelab.info
> *Oggetto:* Re: [Gmsh] Stress on Gauss Points
> Hey Max
> On Fri, 2019-02-15 at 11:01 -0500, Max Orok wrote:
> My impression going in was that the Gauss point steps were part of the
> simulation and the goal was just to plot the data.
> Well, there is a fine line here but it can be considered that the modeling
> [1] is finished when the stresses (or the heat fluxes, etc) are computed at
> the gauss points.
> Actually, I think the original question was: "given that I have data at
> the Gauss points (and not at the nodes nor at the cell centers), how can I
> plot them on Gmsh?"
> Indeed, I think Gaetano wanted to have Gmsh to do something like to
> re-mesh the base grid and have new cells around the gauss points and plot
> the data as cell-centered values. I do not know if I am clear, but for a
> 8-node hexa with 2 Gauss points per dimensions that would be to replace the
> original element with 8 little hexas, one in each octant and then assign a
> cell value from the dataset to each of them. For other elements it would be
> more complex.
> This is definetely in the post-processing step of the worflow.
> I think for this data set, the shared node data does repeat, but a single
> element will vary as a function of its nodes.
> As far as I can see, the data corresponding to the shared nodes does not
> repeat. Again, this is what is expected from secondary fields computed as
> derivatives of a primary field at the Gauss points.
> For any averaging etc., perhaps this could be done during the simulation?
> Yes, it could. This is why I am interested in this issue, and raised the
> question on how to average if the solver has to output nodal values of
> stresses. Weighted average? With the element's volume? With the element's
> quality?
> [1] https://www.seamplex.com/blog/say-modeling-not-simulation.html
> <https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.seamplex.com%2Fblog%2Fsay-modeling-not-simulation.html&data=02%7C01%7C%7C3651368f07bb492242d008d693f99612%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636859097498313953&sdata=cPWVCtVwxuo9fb8E2II9hE10fpEeh7LSXQcXkvKQaDg%3D&reserved=0>
> --
> Jeremy Theler
> www.seamplex.com

Max Orok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20190216/e7189d75/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 254888 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190216/e7189d75/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 188119 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190216/e7189d75/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 157164 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190216/e7189d75/attachment-0005.png>
-------------- next part --------------
# feb 16 mxo

import gmsh

model = gmsh.model
factory = model.occ

# spin up gmsh API
gmsh.option.setNumber("General.Terminal", 1)

# read in the stresses as arrays of floats
# -> assume 15 sigdigs is enough
with open("gauss-stress.txt") as file:
    six_stresses = [[float(val) for val in line.split()] for line in file]

# transform array to separate arrays
sigxx = []
sigyy = []
sigzz = []
sigxy = []
sigxz = []
sigyz = []

for stress_line in six_stresses:
    (sx, sy, sz, sxy, sxz, syz) = tuple(stress_line)

    # commented out -> this was to plot the x, y, z components as vectors
    #sigx.append([sx, sxy, sxz])
    #sigy.append([sxy, sy, syz])
    #sigz.append([sxz, syz, sz])


# read in the node forces
node_forces = []
data_stride = 3

with open("nodal-forces.txt") as file:
    elt_forces = [[float(val) for val in line.split()] for line in file]
    # remove elt number (not needed here)
    for sublist in elt_forces:
    # transpose elt forces (array of arrays of 24 elts)
    # to node forces (array of arrays of 3 elts)
    flat_elt_forces = [forces for sublist in elt_forces for forces in sublist]
    i = 0
    while i < len(flat_elt_forces):
            node_forces.append(flat_elt_forces[i:i + data_stride])
            i = i + data_stride

# --

# import the mesh

# find element & node tags
# -> exit if the type isn't hexa (5) as a quick precaution
(elt_types, elt_tags, node_tags) = gmsh.model.mesh.getElements()

hexa_type = 5 # (c.f. section 9.1 gmsh documentation)

if len(elt_types) != 1 or elt_types[0] != hexa_type:

# comes back as array of arrays, get the nodes as a bare array of ints
elt_tags = elt_tags[0]
node_tags = node_tags[0]

# --

# get the model name
model_names = gmsh.model.list()
curr_model = model_names[0]

# stress values plotted as scalars
sxx_tag = gmsh.view.add("sigx")
gmsh.view.addModelData(sxx_tag, 0, curr_model, "NodeData", node_tags, sigxx)
# y-stresses
syy_tag = gmsh.view.add("sigy")
gmsh.view.addModelData(syy_tag, 0, curr_model, "NodeData", node_tags, sigyy)
# z-stresses
szz_tag = gmsh.view.add("sigz")
gmsh.view.addModelData(szz_tag, 0, curr_model, "NodeData", node_tags, sigzz)

sxy_tag = gmsh.view.add("sigxy")
gmsh.view.addModelData(sxy_tag, 0, curr_model, "NodeData", node_tags, sigxy)

sxz_tag = gmsh.view.add("sigxz")
gmsh.view.addModelData(sxz_tag, 0, curr_model, "NodeData", node_tags, sigxz)

syz_tag = gmsh.view.add("sigyz")
gmsh.view.addModelData(syz_tag, 0, curr_model, "NodeData", node_tags, sigyz)

# make a view for the node forces
force_view_tag = gmsh.view.add("node forces")
# add the forces
gmsh.view.addModelData(force_view_tag, 0, curr_model, "NodeData", node_tags, node_forces)

# --

# output the data

out_filename = "10cm_data.msh"

# save as new mesh file
# stress data
# @arg False -> don't want to append for first view
gmsh.view.write(sxx_tag, out_filename, False)
gmsh.view.write(syy_tag, out_filename, True)
gmsh.view.write(szz_tag, out_filename, True)

gmsh.view.write(sxy_tag, out_filename, True)
gmsh.view.write(sxz_tag, out_filename, True)
gmsh.view.write(syz_tag, out_filename, True)

# --

# node force output
# @arg True -> want to append (otherwise would overwrite the stress data)
gmsh.view.write(force_view_tag, out_filename, True)

# close gmsh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 10cm_data.msh
Type: application/octet-stream
Size: 50933 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190216/e7189d75/attachment-0001.msh>

More information about the gmsh mailing list