Defining nonlinear problem in mixed space

Hi, i’m trying to define a nonlinear time dependent mixed element problem, there might be some problems with the nonlineaerity in time but assume i make it explicit

V = VectorElement('Lagrange',triangle,2)
Q = FiniteElement('Lagrange',triangle,1)
element = Q*V
Z = FunctionSpace(mesh,element)
(η,u) = TrialFunctions(Z)
(ϕ,w) = TestFunctions(Z)
(z_n) = Function(Z)
(z_) = Function(Z)
(dz_n) = Function(Z)
η_n, u_n = z_n.split()
η_, u_ = z_.split()
dη_n, du_n = dz_n.split()
def norma(u):
    return sqrt((u[0]+u[1])**2)
θ=0.5
ηc=θ*η+(1-θ)*η_n
Hc=ηc+h
U=θ*u+(1-θ)*u_n
dηc=θ*dη+(1-θ)*dη_n
dHc=dηc+h
dU=θ*du+(1-θ)*du_n
B = inner((η-η_n)/k,ϕ)*dx - inner(Hc*U,nabla_grad(ϕ))*dx + inner((u-u_n)/k,w)*dx +inner(dot(U,grad(U))+f*R*U-1/Hc*(c_d*norma(U)*U),w)*dx \
    -g*ηc*div(w)*dx + α_h*inner(grad(U),grad(w))*dx

If J is the derivative of B, i’d like to write something like:

problem = NonlinearVariationalProblem(B, u, bcs, J)
solver = NonlinearVariationalSolver(problem)
solver.solve()

and then iterate in time from some initial (\eta_0,u_0)
But my unknowns are (η,u) not just u. What am i missing?
Thanks

(η,u) = TrialFunctions(Z) splits the function. For the purposes of NonlinearVariationalProblem you want the whole mixed function, u_mixed=Function(Z) if you like. Note for a nonlinear problem I think you need to work with the Function, not TrialFunction. cf. fenics-tutorial/ft05_poisson_nonlinear.py at master · hplgit/fenics-tutorial · GitHub, also fenics-tutorial/ft09_reaction_system.py at master · hplgit/fenics-tutorial · GitHub

1 Like

That really helped, thanks!