### error: This integral is missing an integration domain

174
views
0
3 months ago by
# coding: utf-8

# In[ ]:

# coding: utf-8

# In[ ]:

"""
FEniCS tutorial demo program: Diffusion of a Gaussian hill.
u'= Laplace(u) + f  in a square domain
u = u_D             on the boundary
u = u_0             at t = 0
u_D = f = 0
The initial condition u_0 is chosen as a Gaussian hill.
"""

from __future__ import print_function
from fenics import *
import time
import numpy as np
T = 5            # final time
num_steps = 200   # number of time steps
dt = T / num_steps # time step size
lambda_1=-0.5
D0=1.0
# Create mesh and define function space
nx = ny = 30
mesh = RectangleMesh(Point(-2, -2), Point(2, 2), nx, ny)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
def boundary(x, on_boundary):
return on_boundary

bc = DirichletBC(V, Constant(0), boundary)

# Define initial value
u_0 = Expression('exp(-a*pow(x[0], 2) - a*pow(x[1], 2))',
degree=2, a=5)
u_n = interpolate(u_0, V)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
D = Constant(D0)

a, L = lhs(F), rhs(F)

# Create VTK file for saving solution
vtkfile = File('heat_gaussian/solution.pvd')

# Time-stepping
u = Function(V)
t = 0
# Update current time
t += dt

# Compute solution
solve(a == L, u, bc)

# Save to file and plot solution
vtkfile << (u, t)
u_n.assign(u)
for n in range(num_steps):

# Update current time
t += dt

# Compute solution
solve(a == L, u, bc)

# Save to file and plot solution
vtkfile << (u, t)

# Update previous solution

# Update D_0
D = D0*np.exp(-lambda_1*t)
D = Constant(D)

u1 = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
# Update F
a, L = lhs(F), rhs(F)
u_n.assign(u)



the errors are

This integral is missing an integration domain.
---------------------------------------------------------------------------
UFLException                              Traceback (most recent call last)
<ipython-input-56-459d27db8357> in <module>()
57 D = Constant(D0)
58
---> 59 F = u*v*dx + dt*D*dot(grad(u), grad(v))*dx - (u_n + dt*f)*v*dx
60 a, L = lhs(F), rhs(F)
61

/usr/local/lib/python2.7/dist-packages/ufl/measure.pyc in __rmul__(self, integrand)
444                 domain, = domains
445             elif len(domains) == 0:
--> 446                 error("This integral is missing an integration domain.")
447             else:
448                 error("Multiple domains found, making the choice of integration domain ambiguous.")

/usr/local/lib/python2.7/dist-packages/ufl/log.pyc in error(self, *message)
170         "Write error message and raise an exception."
171         self._log.error(*message)
--> 172         raise self._exception_type(self._format_raw(*message))
173
174     def begin(self, *message):

UFLException: This integral is missing an integration domain.

Community: FEniCS Project

0
3 months ago by
I'm guessing that you're using Python 2.x, and the problem is that

dt = T / num_steps

is truncating the result to zero.  In Python 2.x, division of two integers throws away any remainder.  (In Python 3.x, there is a separate operator (//) for integer division, and the plain old / operator will return a float approximating the remainder.)  The zero dt is then interacting badly with the form compiler (which tries to optimize by simplifying terms that are multiplied by zero), leading to the error.

dt = T / float(num_steps)