There are no facilities to modify the mesh in this way in a .geo file. But you
can do it quite easily with the Gmsh API.
Here's a small example, in python:
import gmsh
import sys
if len(sys.argv) < 2:
print "Usage: " + sys.argv[0] + " file.msh"
exit(0)
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.open(sys.argv[1])
nodeTags = {}
nodeCoords = {}
elementTypes = {}
elementTags = {}
elementNodeTags = {}
entities = gmsh.model.getEntities()
# get the nodes and elements
for e in entities:
nodeTags[e], nodeCoords[e], _ = gmsh.model.mesh.getNodes(e[0], e[1])
elementTypes[e], elementTags[e], elementNodeTags[e] = gmsh.model.mesh.getElements(e[0], e[1])
# change the node coordinates and recreate the mesh (this should be done in a
# separate step, as setNodes will delete the nodes and elements in the entity;
# in the next version of the API setNodes and setElements will be replaced with
# addNodes and addElements, and a new mesh::clear() function will be added)
for e in entities:
for i in range(2, len(nodeCoords[e]), 3):
nodeCoords[e][i] = 0
gmsh.model.mesh.setNodes(e[0], e[1], nodeTags[e], nodeCoords[e])
gmsh.model.mesh.setElements(e[0], e[1], elementTypes[e], elementTags[e], elementNodeTags[e])
gmsh.write('flat.msh')
gmsh.finalize()
Run 'python flatten.py your_mesh.msh'.
PS: note that the API for setting the mesh will change, as the current
functions can lead to invalid meshes if used incorrectly (as they delete
nodes/elements before adding new ones). The new functions will separate the
deletion of the mesh from the addition of new nodes/elements.
Christophe
> On 4 Jun 2019, at 14:37, Felix Salazar <[email protected]> wrote:
>
> I agree with Nathan's advice.
>
> The source of your issue might be your geometry. If you created the surface
> using gmsh, you can provide the .geo file. If you imported the surface from
> CAD, there might be some spurious geometrical vertex that are forced to
> belong to the triangulation, hence giving you non-zero Z components. If you
> specify a Physical Surface on your .geo, it might help.
>
> The solution of looping on your mesh file via Python (or your script language
> of choice) to substitute all z by zeros is also valid.
>
> Take care and good luck,
>
> F
>
> On Mon, Jun 3, 2019, 4:17 PM Nathan J. Neeteson <[email protected]> wrote:
> Hi Ricardo,
>
> If the issue is simply that you have some vertices with non-zero
> z-components, and you want them to all be zero, and if the mesh file is ASCII
> format, could you just write a script (say, in python) to automatically loop
> through the $Nodes section of the file and replace the z component of every
> vertex position with "0.0" in a new file? I don't think any derived geometric
> data (such as cell areas or volumes) is in a *.mesh file, so naively I would
> think this should work, and the script in question would probably be no more
> than a few dozen lines.
>
> Thanks,
>
> Nathan Neeteson, M.Sc., E.I.T.
> Flow Control Research Engineer
> RGL Reservoir Management Inc.
> Corporate Head Office
> P 780.851.8243 | C 613.929.6283
> [email protected] | rglinc.com
> API Q1™ and ISO 9001:2015 certified facilities.
>
> -----Original Message-----
> From: Ricardo Ruiz Baier [mailto:[email protected]]
> Sent: June 3, 2019 11:32 AM
> To: Nathan J. Neeteson <[email protected]>; Ricardo Ruiz Baier
> <[email protected]>
> Cc: [email protected]
> Subject: Re: [Gmsh] dilate to flatten a mesh
>
> Dear Nathan,
>
> thank you very much. This indeed resolves the syntax problem. However in my
> case it does not do anything since transformations can only be applied to the
> geometry, and in this case I want to apply the dilation to the mesh. I'll
> keep looking for other solutions.
>
> All the best,
>
> Ricardo
>
> > Hi Ricardo,
> >
> > The syntax for anisotropic dilation is as follows:
> >
> > Dilate { { expression-list }, { expression, expression, expression } }
> > { transform-list }
> >
> > The first expression-list is the homethetic center of the dilation.
> >
> > The set of three expressions are the X,Y,Z scaling factors of the dilation.
> >
> > The transform-list is the entities to be acted on.
> >
> > I think your syntax should be:
> >
> > Dilate{ {0,0,0}, {1,1,0} }{ Point{all_points[]}; }
> >
> > Assuming you want all points on the x-y plane at z=0.
> >
> > Nathan Neeteson, M.Sc., E.I.T.
> > Flow Control Research Engineer
> > RGL Reservoir Management Inc.
> > Corporate Head Office
> > P 780.851.8243 | C 613.929.6283
> > [email protected] | rglinc.com
> > API Q1(tm) and ISO 9001:2015 certified facilities.
> >
> > -----Original Message-----
> > From: gmsh [mailto:[email protected]] On Behalf
> > Of Ricardo Ruiz Baier
> > Sent: June 3, 2019 5:51 AM
> > To: [email protected]
> > Subject: [Gmsh] dilate to flatten a mesh
> >
> > Dear all,
> >
> > I have a .mesh triangulation which is supposed to be 2D. However it has
> > some vertices with (spurious) crazy large z-components. How can I flatten
> > these from e.g. a geo file?
> >
> > I've tried with "Dilate" in the manner mentioned below, but it does not
> > work (the compilation complains about the syntax and I have not found any
> > examples).
> >
> > Merge "testMesh.mesh";
> >
> > all_points[] = Point '*';
> >
> > Dilate { { all_points[] }, { 1, 1, 0} } {Surface(1) };
> >
> > Thank you so much!
> >
> > Kind regards,
> >
> >
> >
> > --
> > Ricardo Ruiz Baier
> > Mathematical Institute
> > University of Oxford
> > people.maths.ox.ac.uk/ruizbaier
> >
> > _______________________________________________
> > gmsh mailing list
> > [email protected]
> > https://can01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fonela
> > b.info%2Fmailman%2Flistinfo%2Fgmsh&data=02%7C01%7Cnneeteson%40rgli
> > nc.com%7C47bb41a5f6d1431e0c9d08d6e84967cf%7C1f2819e2b6f842cd9d720c61c1
> > a98107%7C0%7C0%7C636951799311766160&sdata=UWGz6UOQI3HwjrCcF032KsJo
> > TPbQSNtv5R7Naoe6aLY%3D&reserved=0
> > Email disclaimer located at
> > https://can01.safelinks.protection.outlook.com/?url=http%3A%2F%2Frglin
> > c.com%2Fdisclaimer&data=02%7C01%7Cnneeteson%40rglinc.com%7C47bb41a
> > 5f6d1431e0c9d08d6e84967cf%7C1f2819e2b6f842cd9d720c61c1a98107%7C0%7C1%7
> > C636951799311766160&sdata=0UeeOq8ZUzxetIh20vxRSt4AxnqJLVbenaD9tcmO
> > sD4%3D&reserved=0
>
>
> --
> Ricardo Ruiz Baier
> Mathematical Institute
> University of Oxford
> people.maths.ox.ac.uk/ruizbaier
> Email disclaimer located at http://rglinc.com/disclaimer
> _______________________________________________
> gmsh mailing list
> [email protected]
> http://onelab.info/mailman/listinfo/gmsh
> _______________________________________________
> gmsh mailing list
> [email protected]
> http://onelab.info/mailman/listinfo/gmsh
—
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine
_______________________________________________
gmsh mailing list
[email protected]
http://onelab.info/mailman/listinfo/gmsh