Dear all, I need to import my own mesh which was not created using Gmsh, so I am trying to convert it to Gmsh format. I have some questions and I didn't find any documentation on this on the Gmsh website. For example, in the sample msh file attached there should be 40 elements and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 in the file) under "Elements" actually are. Also, in the actual elements (lines 96-135), what is the first quadruplet {3 2 0 5} after the global element number? Thanks, Anna.
Dear Anna, On 16/12/15 15:17, Anna Kalogirou wrote:
Dear all,
I need to import my own mesh which was not created using Gmsh, so I am trying to convert it to Gmsh format. I have some questions and I didn't find any documentation on this on the Gmsh website.
Before you try and do this conversion, where does the mesh come from? PETSc (and therefore we) claim to support the following formats read from file: - gmsh (extension .msh) - exodus (extension .e or .exo) - cgns (extension .cgns) Although boundary markers aren't supported - triangle (extension .node) We also, although it's not a public API, support building a mesh from a list of cells and their vertex coordinates. Would any of these suit you?
For example, in the sample msh file attached there should be 40 elements and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 in the file) under "Elements" actually are. Also, in the actual elements (lines 96-135), what is the first quadruplet {3 2 0 5} after the global element number?
The documentation for the gmsh file format is http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format Note that not all "elements" in the file are what you think of as elements, some of them will be lines and points I think. Lawrence
Anna, The first four entries with "15" under the column refer to the geometric vertices. The next 28 with "1' under the second column refer to the mesh straight lines aligning under the geometric straight lines connecting the aforementioned points The quadruplet information is described per the link Lawrence pointed to. ---- So I see that your mesh has no physical IDs (the "0" under the fourth column), which is needed for imposing boundary conditions. If this were done entirely with GMSH, they order the physical ID's based on the order you create them. If you don't do any of this, GMSH spits out every single geometric and mesh entity with a 0 ID. That's why you see some useless element entries like the four "15" vertices. Thanks, Justin On Wed, Dec 16, 2015 at 7:45 AM, Lawrence Mitchell < lawrence.mitchell@imperial.ac.uk> wrote:
Dear Anna,
On 16/12/15 15:17, Anna Kalogirou wrote:
Dear all,
I need to import my own mesh which was not created using Gmsh, so I am trying to convert it to Gmsh format. I have some questions and I didn't find any documentation on this on the Gmsh website.
Before you try and do this conversion, where does the mesh come from? PETSc (and therefore we) claim to support the following formats read from file:
- gmsh (extension .msh) - exodus (extension .e or .exo) - cgns (extension .cgns) Although boundary markers aren't supported - triangle (extension .node)
We also, although it's not a public API, support building a mesh from a list of cells and their vertex coordinates.
Would any of these suit you?
For example, in the sample msh file attached there should be 40 elements and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 in the file) under "Elements" actually are. Also, in the actual elements (lines 96-135), what is the first quadruplet {3 2 0 5} after the global element number?
The documentation for the gmsh file format is http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format
Note that not all "elements" in the file are what you think of as elements, some of them will be lines and points I think.
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Thank you very much guys, So the mesh I already have was constructed manually and has the following format (please also see attached): it has as many number of lines as the number of elements, with 12 values in each line. The first 8 values consist of 4 sets of coordinates (x,y) (without the brackets and comma, just 8 numbers) and the final 4 denote the global node number of the 4 points. Is it possible to build a mesh on Firedrake based on this file? Anna. On 16/12/15 16:58, Justin Chang wrote:
Anna,
The first four entries with "15" under the column refer to the geometric vertices.
The next 28 with "1' under the second column refer to the mesh straight lines aligning under the geometric straight lines connecting the aforementioned points
The quadruplet information is described per the link Lawrence pointed to.
----
So I see that your mesh has no physical IDs (the "0" under the fourth column), which is needed for imposing boundary conditions. If this were done entirely with GMSH, they order the physical ID's based on the order you create them. If you don't do any of this, GMSH spits out every single geometric and mesh entity with a 0 ID. That's why you see some useless element entries like the four "15" vertices.
Thanks, Justin
On Wed, Dec 16, 2015 at 7:45 AM, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk <mailto:lawrence.mitchell@imperial.ac.uk>> wrote:
Dear Anna,
On 16/12/15 15:17, Anna Kalogirou wrote: > Dear all, > > I need to import my own mesh which was not created using Gmsh, so I am > trying to convert it to Gmsh format. I have some questions and I didn't > find any documentation on this on the Gmsh website.
Before you try and do this conversion, where does the mesh come from? PETSc (and therefore we) claim to support the following formats read from file:
- gmsh (extension .msh) - exodus (extension .e or .exo) - cgns (extension .cgns) Although boundary markers aren't supported - triangle (extension .node)
We also, although it's not a public API, support building a mesh from a list of cells and their vertex coordinates.
Would any of these suit you?
> For example, in the sample msh file attached there should be 40 elements > and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 > in the file) under "Elements" actually are. Also, in the actual elements > (lines 96-135), what is the first quadruplet {3 2 0 5} after the global > element number?
The documentation for the gmsh file format is http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format
Note that not all "elements" in the file are what you think of as elements, some of them will be lines and points I think.
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds http://www1.maths.leeds.ac.uk/~matak/
On 16 Dec 2015, at 19:07, Anna Kalogirou <a.kalogirou@leeds.ac.uk> wrote:
Thank you very much guys,
So the mesh I already have was constructed manually and has the following format (please also see attached): it has as many number of lines as the number of elements, with 12 values in each line. The first 8 values consist of 4 sets of coordinates (x,y) (without the brackets and comma, just 8 numbers) and the final 4 denote the global node number of the 4 points.
Is it possible to build a mesh on Firedrake based on this file?
If you do: from firedrake.mesh import _from_cell_list Then you should be able to use that. It expects you to tell it the topological dimension of your cells, pass a 2d numpy array with the coordinates of your vertices. And a 2d numpy array indicating which vertices belong to which element. You can pass the object you get back to Mesh: dm= _from_cell_list(2, cells, vertices) mesh = Mesh(dm) There are some further examples using this in utility_meshes.py The format sounds sufficiently simple that you could add a reader in firedrake and we could incorporate it. Thanks, Lawrence
On 16/12/15 16:58, Justin Chang wrote: Anna,
The first four entries with "15" under the column refer to the geometric vertices.
The next 28 with "1' under the second column refer to the mesh straight lines aligning under the geometric straight lines connecting the aforementioned points
The quadruplet information is described per the link Lawrence pointed to.
----
So I see that your mesh has no physical IDs (the "0" under the fourth column), which is needed for imposing boundary conditions. If this were done entirely with GMSH, they order the physical ID's based on the order you create them. If you don't do any of this, GMSH spits out every single geometric and mesh entity with a 0 ID. That's why you see some useless element entries like the four "15" vertices.
Thanks, Justin
On Wed, Dec 16, 2015 at 7:45 AM, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote: Dear Anna,
On 16/12/15 15:17, Anna Kalogirou wrote:
Dear all,
I need to import my own mesh which was not created using Gmsh, so I am trying to convert it to Gmsh format. I have some questions and I didn't find any documentation on this on the Gmsh website.
Before you try and do this conversion, where does the mesh come from? PETSc (and therefore we) claim to support the following formats read from file:
- gmsh (extension .msh) - exodus (extension .e or .exo) - cgns (extension .cgns) Although boundary markers aren't supported - triangle (extension .node)
We also, although it's not a public API, support building a mesh from a list of cells and their vertex coordinates.
Would any of these suit you?
For example, in the sample msh file attached there should be 40 elements and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 in the file) under "Elements" actually are. Also, in the actual elements (lines 96-135), what is the first quadruplet {3 2 0 5} after the global element number?
The documentation for the gmsh file format is http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format
Note that not all "elements" in the file are what you think of as elements, some of them will be lines and points I think.
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
--
Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
http://www1.maths.leeds.ac.uk/~matak/ <sweVbuoy2D_mesh.in> _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Hello, I get the error " ImportError: cannot import name _from_cell_list " when running the following code (the mesh file can be found attached): from firedrake import * import numpy as np mesh_data = np.loadtxt("sweVbuoy2D_mesh.in") xcoords = mesh_data[:,[0,2,4,6]] ycoords = mesh_data[:,[1,3,5,7]] coords = np.asarray(np.meshgrid(xcoords, ycoords)).swapaxes(0, 2).reshape(-1, 2) cells = mesh_data[:,[8,9,10,11]].astype(int) #cells = np.asarray(cells).swapaxes(0, 2).reshape(-1, 4) from firedrake.mesh import _from_cell_list dm = _from_cell_list(2, cells, coords) mesh = Mesh(dm) V = FunctionSpace(mesh, "CG", 1) f = Function(V) f_file = File("f.pvd") f_file << f Anyone has any idea why this is happening? Thanks, Anna. On 16/12/15 19:43, Lawrence Mitchell wrote:
On 16 Dec 2015, at 19:07, Anna Kalogirou <a.kalogirou@leeds.ac.uk <mailto:a.kalogirou@leeds.ac.uk>> wrote:
Thank you very much guys,
So the mesh I already have was constructed manually and has the following format (please also see attached): it has as many number of lines as the number of elements, with 12 values in each line. The first 8 values consist of 4 sets of coordinates (x,y) (without the brackets and comma, just 8 numbers) and the final 4 denote the global node number of the 4 points.
Is it possible to build a mesh on Firedrake based on this file?
If you do:
from firedrake.mesh import _from_cell_list
Then you should be able to use that. It expects you to tell it the topological dimension of your cells, pass a 2d numpy array with the coordinates of your vertices. And a 2d numpy array indicating which vertices belong to which element. You can pass the object you get back to Mesh:
dm= _from_cell_list(2, cells, vertices)
mesh = Mesh(dm)
There are some further examples using this in utility_meshes.py
The format sounds sufficiently simple that you could add a reader in firedrake and we could incorporate it.
Thanks,
Lawrence
On 16/12/15 16:58, Justin Chang wrote:
Anna,
The first four entries with "15" under the column refer to the geometric vertices.
The next 28 with "1' under the second column refer to the mesh straight lines aligning under the geometric straight lines connecting the aforementioned points
The quadruplet information is described per the link Lawrence pointed to.
----
So I see that your mesh has no physical IDs (the "0" under the fourth column), which is needed for imposing boundary conditions. If this were done entirely with GMSH, they order the physical ID's based on the order you create them. If you don't do any of this, GMSH spits out every single geometric and mesh entity with a 0 ID. That's why you see some useless element entries like the four "15" vertices.
Thanks, Justin
On Wed, Dec 16, 2015 at 7:45 AM, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk <mailto:lawrence.mitchell@imperial.ac.uk>> wrote:
Dear Anna,
On 16/12/15 15:17, Anna Kalogirou wrote: > Dear all, > > I need to import my own mesh which was not created using Gmsh, so I am > trying to convert it to Gmsh format. I have some questions and I didn't > find any documentation on this on the Gmsh website.
Before you try and do this conversion, where does the mesh come from? PETSc (and therefore we) claim to support the following formats read from file:
- gmsh (extension .msh) - exodus (extension .e or .exo) - cgns (extension .cgns) Although boundary markers aren't supported - triangle (extension .node)
We also, although it's not a public API, support building a mesh from a list of cells and their vertex coordinates.
Would any of these suit you?
> For example, in the sample msh file attached there should be 40 elements > and not 72. I don't understand what the first 32 lines (i.e. lines 64-95 > in the file) under "Elements" actually are. Also, in the actual elements > (lines 96-135), what is the first quadruplet {3 2 0 5} after the global > element number?
The documentation for the gmsh file format is http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format
Note that not all "elements" in the file are what you think of as elements, some of them will be lines and points I think.
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
--
Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
http://www1.maths.leeds.ac.uk/~matak/ <sweVbuoy2D_mesh.in> _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Hi Anna, two things: On 17/12/15 16:00, Anna Kalogirou wrote:
Hello,
I get the error " ImportError: cannot import name _from_cell_list " when running the following code (the mesh file can be found attached):
from firedrake import * import numpy as np
mesh_data = np.loadtxt("sweVbuoy2D_mesh.in")
xcoords = mesh_data[:,[0,2,4,6]] ycoords = mesh_data[:,[1,3,5,7]] coords = np.asarray(np.meshgrid(xcoords, ycoords)).swapaxes(0, 2).reshape(-1, 2)
cells = mesh_data[:,[8,9,10,11]].astype(int)
I think you want this section to be: coords = np.empty((42, 2), dtype=float) cells = mesh_data[:,[8,9,10,11]].astype(int) - 1 coords[cells] = mesh_data[:, :8].reshape(-1, 4, 2)
from firedrake.mesh import _from_cell_list dm = _from_cell_list(2, cells, coords)
I'm not sure why _from_cell_list isn't available in firedrake.mesh, it definitely works for me. Cheers, Lawrence
Thanks Lawrence, Can you please explain where the number 42 in coords = np.empty((42, 2), dtype=float) comes from? I assumed it was N_elements + 12, but it doesn't work for a larger N_elements. Thanks, Anna. On 17/12/15 16:20, Lawrence Mitchell wrote:
Hi Anna,
two things:
On 17/12/15 16:00, Anna Kalogirou wrote:
Hello,
I get the error " ImportError: cannot import name _from_cell_list " when running the following code (the mesh file can be found attached):
from firedrake import * import numpy as np
mesh_data = np.loadtxt("sweVbuoy2D_mesh.in")
xcoords = mesh_data[:,[0,2,4,6]] ycoords = mesh_data[:,[1,3,5,7]] coords = np.asarray(np.meshgrid(xcoords, ycoords)).swapaxes(0, 2).reshape(-1, 2)
cells = mesh_data[:,[8,9,10,11]].astype(int) I think you want this section to be:
coords = np.empty((42, 2), dtype=float) cells = mesh_data[:,[8,9,10,11]].astype(int) - 1 coords[cells] = mesh_data[:, :8].reshape(-1, 4, 2)
from firedrake.mesh import _from_cell_list dm = _from_cell_list(2, cells, coords) I'm not sure why _from_cell_list isn't available in firedrake.mesh, it definitely works for me.
Cheers,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds http://www1.maths.leeds.ac.uk/~matak/
Ok found it! It's the number of nodes. Sorry for asking silly questions! Anna. On 17/12/15 17:41, Anna Kalogirou wrote:
Thanks Lawrence,
Can you please explain where the number 42 in coords = np.empty((42, 2), dtype=float) comes from? I assumed it was N_elements + 12, but it doesn't work for a larger N_elements.
Thanks, Anna.
On 17/12/15 16:20, Lawrence Mitchell wrote:
Hi Anna,
two things:
On 17/12/15 16:00, Anna Kalogirou wrote:
Hello,
I get the error " ImportError: cannot import name _from_cell_list " when running the following code (the mesh file can be found attached):
from firedrake import * import numpy as np
mesh_data = np.loadtxt("sweVbuoy2D_mesh.in")
xcoords = mesh_data[:,[0,2,4,6]] ycoords = mesh_data[:,[1,3,5,7]] coords = np.asarray(np.meshgrid(xcoords, ycoords)).swapaxes(0, 2).reshape(-1, 2)
cells = mesh_data[:,[8,9,10,11]].astype(int) I think you want this section to be:
coords = np.empty((42, 2), dtype=float) cells = mesh_data[:,[8,9,10,11]].astype(int) - 1 coords[cells] = mesh_data[:, :8].reshape(-1, 4, 2)
from firedrake.mesh import _from_cell_list dm = _from_cell_list(2, cells, coords) I'm not sure why _from_cell_list isn't available in firedrake.mesh, it definitely works for me.
Cheers,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
--
Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
http://www1.maths.leeds.ac.uk/~matak/
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds http://www1.maths.leeds.ac.uk/~matak/
On 17 Dec 2015, at 17:41, Anna Kalogirou <a.kalogirou@leeds.ac.uk> wrote:
Can you please explain where the number 42 in coords = np.empty((42, 2), dtype=float) comes from? I assumed it was N_elements + 12, but it doesn't work for a larger N_elements.
After you've pulled out the cells array it is: cells.max()+1 Lawrence
participants (3)
- 
                
                Anna Kalogirou
- 
                
                Justin Chang
- 
                
                Lawrence Mitchell