I understand the cause of the error. (Please first have a look at the code and the error message, which is at the end of the code) u is of type and u_m ( some projection of analytical solution onto M.sub(0)) is of type none. So '-' operation in F( term u-u_m) is not supported . Can someone please suggest me a way to avoid this problem?
Code and the error message is as follows.
from dolfin import *
import numpy, sys
# create mesh and function spaces
degree = int(sys.argv[1])
divisions =[int(arg) for arg in (sys.argv[2:])]
mesh=UnitSquareMesh(*divisions)
V = FunctionSpace(mesh,"Lagrange",degree) # Function space for u ( Temperature)
Q = FunctionSpace(mesh,"Lagrange",degree) # Function space for \mu ( materi
#property
L = FunctionSpace(mesh,"Lagrange",degree) # Function space for \lembda
#Mixed function space
M = MixedFunctionSpace([V,Q,L]) # M is mixed function space
# Define the test function space
TestFunction = TestFunction(M)
(v,q,w) = split(TestFunction)
# split the mixed function space into components
# Define the trial function space
solution = Function(M)
(u,mu,lmd) = split(solution)
PrescribedU=Expression("0.25*(pow(x[0],2)+pow(x[1],2))-x[0]*x[1]*0.5-x[0]+0.5*x[1]")
# projecting analytical solution on the function space
u_m = project(PrescribedU, M.sub(0))
PrescribedU=Expression("0.25*(pow(x[0],2)+pow(x[1],2))-x[0]*x[1]*0.5-x[0]+0.5*x[1]")
# projecting analytical solution on the function space
s = Function(V)
u_m = s.interpolate(PrescribedU)
F=inner(nabla_grad(lmd),nabla_grad(v))*mu*dx \
+inner(nabla_grad(lmd),nabla_grad(u))*q*dx\
+inner(nabla_grad(w),nabla_grad(u))*mu*dx+inner(u-u_m,v)*dx
Error message is :
Traceback (most recent call last):
File "objmin_var.py", line 38, in
+inner(nabla_grad(w),nabla_grad(u))mudx+inner(u-u_m,v)*dx
TypeError: unsupported operand type(s) for -: 'Indexed' and 'NoneType'
.