Hi!
I have a nonlinear system with MixedFunctionSpace and I want to give a initial guess using NonlinearVariationalProblem. When I try with
wini = as_vector((wini0,wini1, wini2))
I obtain
problem = NonlinearVariationalProblem(F,w=wini,bcs=bcs,J=J)
TypeError: init() got an unexpected keyword argument 'w'
Thanks
Jesus
from dolfin import *
import numpy, sys
nx = 10
degree = 1
mesh = UnitSquareMesh(nx, nx)
Define function spaces
V2 = FunctionSpace(mesh, "DG",degree)
V0 = FunctionSpace(mesh, "CG", degree)
W = MixedFunctionSpace([V0, V2,V2])
boundary
tol = DOLFIN_EPS
def left_boundary(x, on_boundary):
return on_boundary and abs(x[0]) < tol
def low_boundary(x, on_boundary):
return on_boundary and abs(x[1]) < tol
def right_boundary(x, on_boundary):
return on_boundary and abs(x[0]-1) < tol
def up_boundary(x, on_boundary):
return on_boundary and abs(x[1]-1) < tol
pex = Expression('x[0]x[1](1.0 -x[0])*(1.0 -x[1]) ')
Gamma_0 = DirichletBC(W.sub(0), pex , left_boundary)
Gamma_1 = DirichletBC(W.sub(0), pex , right_boundary)
Gamma_2 = DirichletBC(W.sub(0), pex, up_boundary)
Gamma_3 = DirichletBC(W.sub(0), pex , low_boundary)
bcs = [Gamma_0, Gamma_1, Gamma_2, Gamma_3]
(u, q1, q2) = TrialFunctions(W)
(ut, q1t, q2t) = TestFunctions(W)
w = Function(W)
u, q1,q2 = ( w[0], w[1], w[2])
Define parameters
alfa = 1.E-10
beta = 1.E-10
funciones auxiliares
h = Expression('(2.0 -x[0]) ')
uini = Expression(' x[0]x[1](1.0 -x[0])*(1.0 -x[1]) ')
px = Expression('x[1](1.0 -x[1])(1.0 -2.0x[0]) ')
fsec = -pex + hpx
wini = Function(W)
q1ex = Expression('x[1](1.0 -x[1])(1.0 -2.0x[0]) ')
q2ex = Expression('x[0](1.0 -x[0])(1.0 -2.0x[1]) ')
wini0 = interpolate(uini,V0)
wini1 = interpolate(q1ex,V0)
wini2 = interpolate(q2ex,V0)
system
a1 = -inner(hu , Dx(ut,0))dx - inner( u,Dx(ut,1))dx
a2 = inner(q1,q1t)dx + inner(-alfahu,Dx(q1t,0))dx
a3 = inner(-alfahu,Dx(q2t,1))dx + inner(q2,q2t)dx
L = fsecut*dx
F = a1 - L + a2 + a3
find form of jacobian - solve
J = derivative(F,w)
wini = as_vector((wini0,wini1, wini2))
problem = NonlinearVariationalProblem(F,w=wini,bcs=bcs,J=J)
solver = NonlinearVariationalSolver(problem)
solver.solve()
extract solutions from our mixed-space function
(u,q1,q2) = w.leaf_node().split()
u_k = interpolate(pex, V0)
auxp2 =interpolate(u, V0)
diff = auxp2.vector().array() - u_k.vector().array()
eps1 = numpy.linalg.norm(diff, ord=numpy.Inf)
Einf = eps1
print 'er absoluto norm = %g' % eps1