This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Create mesh from list of nodes and elements

0 votes

Hello everybody

Is it possible to obtain a mesh from lists of the node coordinates and the element connections?

A simple example for one Element:

nodes = np.array([[0., 0., 0.],
                  [1., 0., 0.],
                  [0., 1., 0.],
                  [0., 0., 1.]])
elements = np.array([[1,2,3,4]])

And I want to do something like this:

from fenics import *
mesh = Mesh(nodes, elements)

Is this possible and how?

Thanks in advance!

asked Feb 10, 2015 by PaulR FEniCS Novice (420 points)

1 Answer

+5 votes
 
Best answer

Yes, use the MeshEditor-class:

from dolfin import *
import numpy as np
nodes = np.array([[0., 0., 0.],
                  [1., 0., 0.],
                  [0., 1., 0.],
                  [0., 0., 1.]])

cells = np.array([[0,1,2,3]], dtype=np.uintp)

mesh = Mesh()
editor = MeshEditor()
editor.open(mesh, 3, 3)
editor.init_vertices(4)
editor.init_cells(1)

[editor.add_vertex(i,n) for i,n in enumerate(nodes)]
[editor.add_cell(i,n) for i,n in enumerate(cells)]
editor.close()

plot(mesh)
interactive()
answered Feb 10, 2015 by Øyvind Evju FEniCS Expert (17,700 points)
selected Feb 16, 2015 by PaulR

Thank you for your response!
It works perfectly.

...