How to compute the facet normal vectors (not symbolic normals)

7 months ago by
Hey everyone,

I am attempting to compute the facet normal vectors of my mesh to dot with the gradient of a heat equation to calculate the flux (these vectors would be used in a c function to calculate neumann conditions and applied to the RHS of the equation)

In a very simple model below I try and find the normal vectors but only get "n"

from dolfin import *
import time
import numpy as np

#define domain
x_min = y_min = z_min = 0.0
x_max = y_max = 1.0
z_max = 1.98/5.0

#define number of elements
nx = ny = 1
nz = 1

#define number of plot steps

#create mesh
mesh = BoxMesh(Point(x_min, y_min, z_min), Point(x_max, y_max, z_max), nx, ny, nz)

# define function space
V = FunctionSpace(mesh, 'P', 1)

b = FacetNormal(mesh)
print('size b', len(b))
print('type b', type(b))
print('b = ', b)

this is what I get:

size b 3
type b <class 'ufl.geometry.FacetNormal'>
b =  n

Any help would be greatly appreciated.



Community: FEniCS Project

2 Answers

6 months ago by
To compute the normals at a facet:
i = 0
while i < face_numbers:
   b_f = Facet(bmesh,i)
   n = [b_f.normal().x(), b_f.normal().y(), b_f.normal().z()]
   #print('type n', type(n))
   print('node # =', i,'    ','n = ', n)
   #print('size n', len(n))
7 months ago by
A search on AllAnswerd yields a useful workaround, I think:

The notion of a FacetNormal at a node is ambiguous, that's why a FacetNormal can only be evaluated in facet integral expressions (or lines on 2D meshes).

Another idea is to evaluate an integral of the FacetNormals over the facets and normalize using the cell-size. That expression could then be projected onto the nodes.
Thanks for your response. Unfortunately I need the actual vectors to export to a c function and dot with the gradient. My code is slightly convoluted it uses a super position involving both analytic and FE. I am not using the weak formulation, but a vectorized forward euler.
written 7 months ago by Terrence  
At which spatial points do you need the normal vectors? Or to put it in another way, where are your gradient vectors defined? Normal vectors on nodes are not easily defined and given your intended application I think you should rather try computing the normals manually.
written 7 months ago by klunkean  
The gradient is defined on the boundary (to calculate the analytic flux and apply the negative to FEM creating adiabatic conditions) of a 1x1x1 cubic mesh (this is to save considerably on computational cost). I was hoping to automate this process for complex geometries.

Do you have any suggestions of efficient ways to calculate these normals for complex geometries?

written 7 months ago by Terrence  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »