Hi, I am trying to construct a consistently oriented non-normalized normal field for an immersed mesh. Below is my best attempt, trying two slightly different things. Neither give the result I need.
from dolfin import *
from ufl import Jacobian
# create immersed mesh with non-uniform Jacobian
mesh = BoxMesh(Point(0, 0, 0), Point(2, 2, 2), 2, 2, 2)
mesh.coordinates()[:,0] *= .5
mesh.coordinates()[:,1] *= .5
srf = BoundaryMesh(mesh, "exterior", order=True) #False --> can't project
J = Jacobian(srf)
# Tangent basis
G1 = J[:,0]
G2 = J[:,1]
N = cross(G1, G2) # expect this to be outward facing scaled normal field
# Visualize
Nh = project(N, VectorFunctionSpace(srf, 'DG', degree=2, dim=3))
Nh.rename('n','n')
f = XDMFFile('Nh.xdmf') # plotting in red
f.write_checkpoint(Nh,'n', 0)
f.close()
# This also didn't work (using CellNormal for orientation and norm of N for magnitude)
global_normal = Expression(("x[0]", "x[1]", "x[2]"), degree=1)
srf.init_cell_orientations(global_normal)
n = CellNormal(srf)
N1 = sqrt(dot(N,N))*n
Nh1 = project(N1, VectorFunctionSpace(srf, 'DG', degree=2, dim=3))
Nh1.rename('n','n')
f = XDMFFile('Nh1.xdmf') # plotting in blue
f.write_checkpoint(Nh1,'n', 0)
f.close()
As you can can see in the screenshot, the second method gives slightly better results, but many of the normals still point inwards. What am I doing wrong? Thanks in advance!
