I am trying to solve a variational formulation with 3 weighting functions.
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(*divisio M is mixed function spacens)
V = FunctionSpace(mesh,"Lagrange",degree) # Function space for u ( Temperature)
Q= FunctionSpace(mesh,"Lagrange",degree) # Function space for \mu ( materi
L = FunctionSpace(mesh,"Lagrange",degree) # Function space for \lembda
M = MixedFunctionSpace([V,Q,L])
# Boundary Conditions
def boundary_ul(x,on_boundary):
on_boundary and near(x[0],0.0) and near(x[0],1.0) \
and near(x[1],0.0) and near(x[1],1.0)
def boundary_mu(x,on_boundary):
on_boundary and near(x[1],0.0) and near(x[0],1.0)
u is prescribed on entire boundary
PrescribedU=Expression("0.25(pow(x[0],2)+pow(x[1],2))-x[0]x[1]0.5-x[0]+0.5x[1]")
bcs_u = DirichletBC(M.sub(0),PrescribedU , boundary_ul)
\mu prescribed where vector(a).vector(n) < 0 ,i.e inflow boudaries
inflow boundaries are x[0]=1. and x[1]=0.
PrescribedMU= Expression("(2/(exp(2)-1))(exp(2x[0])+2*x[1])")
bcs_mu=DirichletBC(M.sub(1),PrescribedMU,boundary_mu)
\lmd is 0. on entire boundary
bcs_lmd=DirichletBC(M.sub(2),Constant(0.0),boundary_ul)
bcs=[bcs_u ,bcs_mu , bcs_lmd]
Trial and test functions
Tstfnc = TestFunction(M)
(v,q,w) =split(Tstfnc)
Trlfnc = Function(M)
(u,mu,lmd) = split(Trlfnc)
Weak form
F=vudx + qmudx +wlmddx
solving the variational problem
results=Function(M)
solve(F==0,results,bcs)
Output , Error message
Traceback (most recent call last):
File "objmin_var.py", line 71, in
solve(F==0,results,bcs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 268, in solve
_solve_varproblem(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 311, in _solve_varproblem
form_compiler_parameters=form_compiler_parameters)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 118, in __init__
J = Form(J, form_compiler_parameters=form_compiler_parameters)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/form.py", line 56, in __init__
common_cell)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 66, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 154, in jit
return jit_compile(form, parameters=p, common_cell=common_cell)
File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 77, in jit
return jit_form(ufl_object, parameters, common_cell)
File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 159, in jit_form
element_mapping=element_mapping)
File "/usr/lib/python2.7/dist-packages/ufl/form.py", line 123, in compute_form_data
element_mapping=element_mapping)
File "/usr/lib/python2.7/dist-packages/ufl/algorithms/preprocess.py", line 210, in preprocess
ufl_assert(len(compute_form_arities(form)) == 1, "All terms in form must have same rank.")
File "/usr/lib/python2.7/dist-packages/ufl/assertions.py", line 37, in ufl_assert
if not condition: error(*message)
File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 154, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: All terms in form must have same rank.
Please let me know what mistake I am doing. Thanks.