This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

initial guess with mixed spaces for nonlinear system

+1 vote

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 + h
px

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(-alfa
hu,Dx(q2t,1))dx + inner(q2,q2t)dx
L = fsec
ut*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

closed with the note: Solved
asked Jun 4, 2016 by jesus FEniCS Novice (300 points)
closed Jun 5, 2016 by jesus

1 Answer

0 votes
 
Best answer

Hi, consider

wini = interpolate(Expression(('w0', 'w1', 'w2'), w0=wini0, w1=wini1, w2=wini2), W)
problem = NonlinearVariationalProblem(F, wini, bcs=bcs,J=J)

Note that the second argument must be a Function and not ListTensor which is what as_vector gives you. Also, the solver does not converge. Finally, in the future please format your code properly.

answered Jun 4, 2016 by MiroK FEniCS Expert (80,920 points)
selected Jun 6, 2016 by johannr

Thanks for your fast answer and I'm sorry for my code.
Now run! I will work the convergence.
Thank you.

...