Form seems to be zero: cannot compile it.
Hi,
I'm trying to model a variant of the "nonlinear Poisson" problem described in the Dolfin tutorial with the difference that the source term is variable (it is adjusted in an optimization loop). Here's my code:
----
from dolfin import *
import numpy as np
# Create mesh and define function space
mesh = UnitSquare(2,2)
U = FunctionSpace(mesh, "CG", 1)
F = FunctionSpace(mesh, "CG", 1)
V = U * F
# Dirichlet boundary condition (doesn't really seem to matter)
class DirichletBounda
def inside(self, x, on_boundary):
return on_boundary
g = Constant(1.0)
bc = DirichletBC(
# Define nonlinear form and its Jacobian.
uf = Function(V) ; u, f = uf.split()
v, w = TestFunctions(V)
duf = TrialFunction(V)
L = dot(grad(v), (1 + u**2)*grad(u))*dx - v*f*dx
a = derivative(L, uf, duf) # Jacobian.
uf.vector()[:] = np.random.
b = assemble(L, mesh=mesh) ; print b.array()
A = assemble(a, mesh=mesh)
----
I have 2 questions about this code:
1) I wonder why the statement "print b.array()" in the line before last always prints a vector with all zeros in the second half (corresponding to the variable f). It seems as if the derivative with respect to f had not been taken ?!
2) The last line fails with:
Form (<empty Form>) seems to be zero: cannot compile it.
Traceback (most recent call last):
File "nlpoisson-opt.py", line 54, in <module>
A = assemble(a, mesh=mesh)
File "/Applications/
common_
File "/Applications/
common_cell)
File "/Applications/
return local_jit(*args, **kwargs)
File "/Applications/
return jit_compile(form, parameters=p, common_
File "/Users/
File "/Users/
File "/Users/
File "/Users/
File "/Users/
File "/Users/
File "/Users/
File "<string>", line 1, in <lambda>
File "/Users/
Exception: Form (<empty Form>) seems to be zero: cannot compile it.
Can you easily see what's wrong with my code?
I'm using the most recent stable pre-packaged FEniCS dmg for OSX (11.05 from May 20th).
Many thanks in advance!
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Marie Rognes
- Solved:
- Last query:
- Last reply: