locally defined source returns zero?
Hi!
Why does my locally defined source "g" return just zero, while the same source integrated over the whole domain (replace "dx1" by "dx" in line 62) gives a nontrivial result? (The actual equations are simplified and made up from some other "real problem".)
Any suggestions how to include a local source? Achim.
from dolfin import *
import sys
logging(False)
# linear, coupled system; implicit Euler
k = 0.1 # time step
n = 10 # number of timesteps
# create mesh and function space
mesh = UnitSquare(20, 20)
V = FunctionSpace(mesh, "CG", 1)
W = V + V
# define the source domain
class WellDomain(
def inside(self, x, on_boundary):
return bool((0.3 <= x[0] and x[0] <= 0.7 and 0.3 <= x[1] and x[1] <= 0.7))
# mark the subdomain for the well
well = WellDomain()
subdomains = MeshFunction(
well.mark(
# define integrals over the well domain
dx1 = dx(1)
# area of the well
f1 = Constant(mesh, 1.0)
wellarea = assemble(f1*dx1, cell_domains=
print ""
print "test solver: dt = %g, n = %g, wellarea = %g" %(k, n, wellarea)
# define trial & testfunctions
(phi, psi) = TestFunctions(W)
(v, w) = TrialFunctions(W)
# define primal functions
s1 = Function(V); h1 = Function(V)#; f = Function(V)
# set initial condition
s0 = project(
h0 = project(
# define source term
temp = Expression(
g = project(temp, V)
t = 0.0
plot1 = plot(s0)
plot2 = plot(h0)
# go timestepping
for i in xrange(1,n+1,1): # i=1,2,...,n
# implicit Euler:
F = v*phi*dx - s0*phi*dx + k*( (v-w)*phi )*dx \
+ w*psi*dx - h0*psi*dx + k*( (w-v)*psi )*dx \
+ k*g*psi*dx1
# sort out left- & right hand side
L = lhs(F); R = rhs(F)
# construct the variational problem
problem = VariationalProb
# solve the discrete problem
(s1, h1) = problem.
t = t+k
print "t = %g, |s| = %g, |h| = %g" \
%(t, sqrt(assemble(
s0.assign(s1)
h0.assign(h1)
plot1.
plot2.
interactive()
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Zeljka Tutek
- Solved:
- Last query:
- Last reply: