Hi @dokken ,
Yes, the mesheditor is really easy… on the surface. Unfortunately, it reorders my nodes in a way that messes up the cell orientations (see attached). If I set close(order=False) I obviously get an UFC error. Is there any way to get around this?
from dolfin import *
import numpy as np
topological_dim = 2
geometrical_dim = 3
COORDS = np.loadtxt("nodes.txt", dtype='float')
CON = np.loadtxt("elements.txt",dtype='uint') - 1 # from MATLAB, start from 0
num_local_vertices = COORDS.shape[0]
num_global_vertices = num_local_vertices # True if run in serial
num_local_cells = CON.shape[0]
num_global_cells = num_local_cells
# Create mesh object and open editor
mesh = df.Mesh()
editor = df.MeshEditor()
editor.open(mesh, "triangle", topological_dim, geometrical_dim)
editor.init_vertices_global(num_local_vertices, num_global_vertices)
editor.init_cells_global(num_local_cells, num_global_cells)
# Add verticess
for i, coord in enumerate(COORDS):
editor.add_vertex(i, coord)
# Add cells
for i, cell in enumerate(CON):
editor.add_cell(i, cell)
# Close editor
editor.close()
# editor.close(order=False) # Error: Unable to create mapping of degrees of freedom.
#*** Reason: Mesh is not ordered according to the UFC numbering convention. Consider calling mesh.order().
f = df.File('mesh.pvd')
f << mesh
np.testing.assert_equal(mesh.cells()[-1], CON[-1])
Dolfin needs to order the mesh to be able to work with high order function spaces. Why not use order=True? What do you Need the ordering for?
As a slight tangent, you can see the effect of ordering a mesh here: Cell node labeling - #2 by dokken
As your mesh looks like a sphere, you can easily use geometric information to adjust the normals.
Lets say the center of your sphere is at c[0], c[1], c[2].
J = Jacobian(mesh)
G1 = J[:,0]
G2 = J[:,1]
G3 = cross(G1, G2)
c = as_vector([[0,0,0]])
x = SpatialCoordinate(mesh)
r = x-c
n = G3*dot(G3, r)
gives you another non-unit normal.
If G3 is in outwards direction, dot(G3, r) is positive, otherwise it is negative.
You can then in turn normalize this vector.