[Gmsh] Volume of a whole mesh
Geordie McBain
gdmcbain at freeshell.org
Thu Feb 17 04:12:21 CET 2011
2011/2/16 Sajzew Gora <gora-sajzew at yandex.ru>:
> Hello deat gmsh team
>
> i have a quastion. I build a geomtry and mesh with gmsh but I have no idea how can I calculate a volume of the whole mesh. I hope you can help me.
This is an interesting one. I can tell you how to compute the volume,
but it is not as satisfactory an answer as I would like, and in does
raise a couple of questions.
Say I build a 2x3x5 cuboid, with volume.geo, as attached. This should
have a volume of 30.
Then I mesh it with "gmsh -3 volume.geo" to produce volume.msh, and
load that into Gmsh interactively with "gmsh volume.msh". Then, via
the GUI do
. Tools/Plugins:
- New view
- MathEval (Expression0 = 1)
- Integrate
this gives the answer 140. That puzzled me for a while until I
realized it was the sum (ignoring dimensions) of the volume of the box
(2*3*5 = 30), the areas of its faces (2*(2*3 + 2*5 + 3*5) = 62), the
lengths of its edges (4*(2+3+5) = 40), and the number of its vertices
(8).
Now, I didn't define any physical entities in volume.geo, so
volume.msh contains triangles, edges, and points in addition to the
tetrahedra. If I just want to mesh the volume, I define the box of
the volume as a Physical Volume, as in addenda.geo, attached. Then
generate a new mesh with only volume elements: "gmsh -3 volume.geo
addenda.geo -o volume1.msh" and run the same postprocessing as above
and you'll get the hoped-for answer of 30.
Of course there are also answers using third-party tools; e.g. after
loading volume.msh in Gmsh GUI, do File/Save As.../volume.stl and then
ADMesh (https://sites.google.com/a/varlog.com/www/) with "admesh
volume.stl" will tell you 30.000010. But a pure Gmsh solution would
be nice.
So that kind of answers your question, except it raises more:
Q1. What if you already have your .msh file and it does have area (or
even lower dimensional elements) it? This is a very common use case,
since a finite element mesh will very often require some boundary
elements (for inhomogeneous boundary conditions, or postprocessing) in
addition to the volume elements.
One can open the .msh file in a text editor and delete all elements of
types corresponding to lower dimension, but that's all I can think of.
I don't see a way to restrict Plugin(Integrate) to either elements of
a specific dimensionality or type, or, what would be really nice, to a
specific Physical Entity.
Q2. How does one script "Tools/Plugins/New view"?
I would have liked to have supplied the above postprocessing commands
in a script for you, but I didn't know how to script "New view".
Without that, Plugin(MathEval) complains it can't find View[-1], even
though it doesn't actually need to refer to it in this case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: volume.geo
Type: application/octet-stream
Size: 173 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110217/2305c02f/attachment.geo>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: addenda.geo
Type: application/octet-stream
Size: 33 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110217/2305c02f/attachment-0001.geo>