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

How to calculate normal derivative

+1 vote

Hello,

I'm trying to calculate the normal derivative on the mesh boundary, but I can't quite get it to work:

$ cat boundary.py 
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import
from dolfin import *

set_log_level(PROGRESS)
mesh = Mesh('sphere_mesh.xml.gz')
V = FunctionSpace(mesh, 'Lagrange', 1)
u = TrialFunction(V)
v = TestFunction(V)
g = Expression('cos(2*atan2(x[0], x[1])) * (1 - pow(x[2], 2))')
offset = assemble(interpolate(g, V) * ds)
area = assemble(interpolate(Constant(1), V) * ds)
g = g - Constant(offset)/area
a = inner(grad(u), grad(v)) * dx
L = g * v * ds
psi = Function(V)
solve(a == L, psi, 
      solver_parameters = {'linear_solver': 'cg',
                           'preconditioner': 'ilu'})
bmesh = BoundaryMesh(mesh, 'exterior')
boundary_point = bmesh.coordinates()[0]
print('Looking at boundary point x=%.3f, y=%.3f, z=%.3f'
      % tuple(boundary_point))
print('Potential: %.3e' % psi(boundary_point))
dpsi_dn = project(dot(FacetNormal(mesh), grad(psi)), V)
print('Normal derivative: %.3e' % dpsi_dn(boundary_point))

If I run this, I get the following error:

$ python boundary.py 
Solving linear variational problem.
  Solving linear system of size 30566 x 30566 (PETSc Krylov solver).
  PETSc Krylov solver starting to solve 30566 x 30566 system.
  PETSc Krylov solver (cg, ilu) converged in 47 iterations.
Looking at boundary point x=0.294, y=-0.956, z=-0.000
Computed bounding box tree with 341893 nodes for 170947 entities.
Potential: 4.123e-01
Calling FFC just-in-time (JIT) compiler, this may take some time.
In instant.recompile: The module did not compile with command 'make VERBOSE=1', see '/home/nikratio/.instant/error/ffc_form_06881017b591909d8bfad457ee240e15167544cf/compile.log'
Traceback (most recent call last):
  File "boundary.py", line 25, in <module>
    dpsi_dn = project(dot(FacetNormal(mesh), grad(psi)), V)
[....]
  File "/home/nikratio/.local/FEniCS/lib/python2.7/site-packages/instant/output.py", line 57, in instant_error
    raise RuntimeError(text)
RuntimeError: In instant.recompile: The module did not compile with command 'make VERBOSE=1', see '/home/nikratio/.instant/error/ffc_form_06881017b591909d8bfad457ee240e15167544cf/compile.log'
$ tail /home/nikratio/.instant/error/ffc_form_06881017b591909d8bfad457ee240e15167544cf/compile.log 
In file included from /tmp/tmpGAwKwj2014-1-9-16-31_instant_c4c9d32dfa9e6be080c650f9133726de89e3bfda/ffc_form_06881017b591909d8bfad457ee240e15167544cf/ffc_form_06881017b591909d8bfad457ee240e15167544cfPYTHON_wrap.cxx:3092:0:
/tmp/tmpGAwKwj2014-1-9-16-31_instant_c4c9d32dfa9e6be080c650f9133726de89e3bfda/ffc_form_06881017b591909d8bfad457ee240e15167544cf/ffc_form_06881017b591909d8bfad457ee240e15167544cf.h: In member function ‘virtual void ffc_form_06881017b591909d8bfad457ee240e15167544cf_cell_integral_0_otherwise::tabulate_tensor(double*, const double* const*, const double*, int) const’:
/tmp/tmpGAwKwj2014-1-9-16-31_instant_c4c9d32dfa9e6be080c650f9133726de89e3bfda/ffc_form_06881017b591909d8bfad457ee240e15167544cf/ffc_form_06881017b591909d8bfad457ee240e15167544cf.h:839:27: error: ‘n1’ was not declared in this scope
/tmp/tmpGAwKwj2014-1-9-16-31_instant_c4c9d32dfa9e6be080c650f9133726de89e3bfda/ffc_form_06881017b591909d8bfad457ee240e15167544cf/ffc_form_06881017b591909d8bfad457ee240e15167544cf.h:839:64: error: ‘n0’ was not declared in this scope
/tmp/tmpGAwKwj2014-1-9-16-31_instant_c4c9d32dfa9e6be080c650f9133726de89e3bfda/ffc_form_06881017b591909d8bfad457ee240e15167544cf/ffc_form_06881017b591909d8bfad457ee240e15167544cf.h:839:101: error: ‘n2’ was not declared in this scope
make[2]: *** [CMakeFiles/_ffc_form_06881017b591909d8bfad457ee240e15167544cf.dir/ffc_form_06881017b591909d8bfad457ee240e15167544cfPYTHON_wrap.cxx.o] Error 1

What am I doing wrong? I suspect that I shouldn't be using FacetNormal, but the description sounds right, and I didn't find any other function with "norm" in its name either...

asked Jan 13, 2014 by Nikolaus Rath FEniCS User (2,100 points)

1 Answer

+1 vote
 
Best answer

These are known issues

Go through these reports for suggested workarounds. You can also vote for the issues to increase a chance of fixing it in a short time.

answered Jan 14, 2014 by Jan Blechta FEniCS Expert (51,420 points)
selected Jan 14, 2014 by Nikolaus Rath
...