25 minutes ago by
Hello all,
I need to calculate the normal vectors of the boundary mesh for my model. When I do this the orientation of the vector is correct but the sign of the vectors seem to be randomly positive or negative. My model involves a somewhat complicated geometry so testing each cell would be difficult.
Below is a short working example of the problem with a unit cube. The code prints the value of the z component of the normal vector of the two cells on the top face.
from dolfin import *
import time
import numpy as np
import neumann
x_min = y_min = z_min = 0.0
x_max = y_max = z_max= 1.0
nx = ny =1
nz =1
mesh = BoxMesh(Point(x_min, y_min, z_min), Point(x_max, y_max, z_max), nx, ny, nz)
bmesh = BoundaryMesh(mesh,'exterior')
for i, cell in enumerate(cells(bmesh)):
if cell.midpoint().z()==z_max:
print('z-direction top surface normal',cell.cell_normal().z())
with the following result:
z-direction top surface normal -1.0
z-direction top surface normal 1.0
Both should be 1.0.
Any help would be greatly appreciated!
Cheers,
Terrence