[Gmsh] Post-processing stress field

Max Orok morok at mevex.com
Tue Jan 29 19:14:27 CET 2019


Hello Gaetano,

Here is a short program to plot 3x3 tensor data using the C++ gmsh API (it
shouldn't be too hard to port to Python or Julia if you're more comfortable
there). It only plots data for one element, but can be extended for your
case.

The "addModelData" call is expecting a vector of vectors with 9 entries
each for this case.
I think the vector ordering corresponding to the matrix is like this:
[elt11, elt12, elt13, elt21, elt22, ...]

I assume the stress matrix is symmetric and so only has 6 unique entries.
Therefore your vector entries will look like [x xy xz xy y yz xz yz z]
The tricky part will be importing the data in a sensible way.

Perhaps you could parse a CSV using python and add entries to the data
vector in a loop?
Please find attached the program as well as example input mesh and output
mesh files.



[image: image.png]

Sincerely,
Max

On Tue, Jan 29, 2019 at 11:24 AM Gaetano Camarda <gaetano_18 at live.it> wrote:

> Hello everyone,
>
> I’m having some difficult on post processing a mesh I created.
>
> I create a mesh on Gmsh all Hexa (so a brick with 8 nodes), i use this
> mesh and import it on Matlab,
>
> there i run some analisys and find the stress matrix:
>
> [sigx sigy sigz sigxy sigyz sigxz]
>
> …..    …..    …..   …..    …..    …..
>
>
>
> Now I would like to visualize the stress field on Gmsh, but I do not find
> any way to do so, I can export the matrix,
>
> I tried to generete a *.pos file, but I didn’t find a solution.
>
>
>
> Inviato da Posta <https://go.microsoft.com/fwlink/?LinkId=550986> per
> Windows 10
>
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh
>


-- 
Max Orok
Contractor
www.mevex.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20190129/1e474ba1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 51392 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190129/1e474ba1/attachment-0001.png>
-------------- next part --------------
// Jan 29 MXO

// example to plot 3x3 tensor data using gmsh API

#include <iostream>
#include <vector>
#include "gmsh.h"

int main(){

// step 1 of 2 -> import data for plotting (need the mesh and the simulation data)

  gmsh::initialize();

  // open mesh file to use as reference for plotting
  // we will write our results to another mesh file for output
  gmsh::open("model.msh");

  // tell gmsh what elements of the mesh we want to plot data for
  std::vector<int> elt_numbers;
  // only plot data for element 1 for simplicity
  elt_numbers.emplace_back(1);

  // fill a data vector corresponding to the element vector
  // the data vector's elements are vectors of length 9 (3x3 tensor)
  std::vector<std::vector<double>> elt_data;

///////////////////////////////////////////////////////////////////////////////

  // this is the tricky part -> how to import data in an intelligent way?
  // here we make a single zero vector of length 9 for demonstration
  elt_data.emplace_back(std::vector<double>(9, 0.0));

///////////////////////////////////////////////////////////////////////////////

// step 2 of 2 -> ask Gmsh API to plot the data (see gmsh.h for reference)

  //get model name
  std::vector<std::string> modelNames;
  gmsh::model::list(modelNames);
  auto modelName = modelNames[0];

  auto viewTag = gmsh::view::add("stress-data");

  gmsh::view::addModelData(viewTag, 0, modelName,
	"ElementData", elt_numbers, elt_data, 0.);

  //toggle here to see behaviour
  gmsh::view::write(viewTag, "stress-data.msh");

  //end gmsh run
  gmsh::finalize();
  return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model.msh
Type: application/octet-stream
Size: 762 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190129/1e474ba1/attachment-0002.msh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stress-data.msh
Type: application/octet-stream
Size: 1041 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190129/1e474ba1/attachment-0003.msh>


More information about the gmsh mailing list