Closed hbuesing closed 7 years ago
Hi @hbuesing, is this really minimal? E.g.:
I further reduced the example.
Thank you! Henrik
# coding: utf-8
'''
Minimum failing example 2p flow with dolfin-adjoint.
'''
from firedrake import *
from firedrake_adjoint import *
Nx=10
Ny=1
Nz=10
# Length in x- and y-direction.
Lx=1.0
Ly=1.0
# Layer height of extruded mesh
Delta_z = 1.0/Nz
# Length in z-direction
Lz = Delta_z*Nz
# Construction of FV mesh
meshbase = RectangleMesh(Nx, Ny, Lx, Ly, quadrilateral=True)
mesh = ExtrudedMesh(meshbase, Nz, Delta_z)
def forward():
horiz_elt = FiniteElement("DQ", quadrilateral, 0)
vert_elt = FiniteElement("DG", interval, 0)
elt = TensorProductElement(horiz_elt, vert_elt)
DG = FunctionSpace(mesh, elt)
# Mixed Space
W = DG * DG
# Nonlinear problem --> no Trial functions
u = Function(W)
u_old = Function(W)
pw, Sn = split(u)
pw_old, Sn_old = split(u_old)
v, q = TestFunctions(W)
# Define coordinate functions
#
z_func_expr = Expression("x[2]")
z_func = interpolate(z_func_expr, DG)
# no capillarity atm.
F = inner(Sn - Sn_old,v)*dx
# Hydrostatic water pressure (for imposing pw Dirichlet BC)
fun = Function(DG)
fun = z_func*1e1
# Boundary Conditions
# pw BC (right)
bc0 = DirichletBC(W.sub(0), fun, 2,method="geometric")
problem = NonlinearVariationalProblem(F,u,bcs=[bc0])
# Control PETSc options from the command line
solver = NonlinearVariationalSolver(problem,options_prefix="",solver_paramaters={'ksp_type': 'preonly', 'pc_type': 'lu','snes_atol': '1e-6', 'snes_rtol': '1e-6','snes_stol': '1e-6','snes_type': 'newtonls', 'snes_linesearch_type': 'basic', 'snes_max_it': '20'})
count = 0
try:
solver.solve()
except:
print("No convergence!")
else:
print("Convergence!")
forward()
OK. I agree that that's pretty minimal. I will try to find time imminently to walk through this. I wonder if it's the geometric BCs. That's a rarely used feature which we might have somehow dropped in the adjoint code...
I can reproduce this. Now trying to find out what's actually happening...
OK, one convenient flight from Munich to London later, I can see what's happening. The try clause is obscuring the actual error. Take that off and you find that dolfin-adjoint is raising an exception because it doesn't know how to annotate the assignment of UFL expressions. This is happening when the Dirichlet boundary conditions are being applied. The problematic line is therefore actually:
fun = z_func*1e1
This doesn't actually set the values of the Function
fun to zfunc*1e1
, instead it sets the variable fun
to the expression zfunc*1e1
. To work around this, instead use:
fun.interpolate(z_func*1e1)
As an aside, the code provided also misspells solver_parameters
so the solver options are not actually applied.
Dear David,
Thank you very much for sorting this out! Best regards and "Happy Easter"!
Henrik
Von: David A. Ham [notifications@github.com] Gesendet: Donnerstag, 13. April 2017 21:24 An: firedrakeproject/firedrake Cc: Buesing, Henrik; Mention Betreff: Re: [firedrakeproject/firedrake] Import of firedrake_adjoint leads to non-convergence (#1042)
OK, one convenient flight from Munich to London later, I can see what's happening. The try clause is obscuring the actual error. Take that off and you find that dolfin-adjoint is raising an exception because it doesn't know how to annotate the assignment of UFL expressions. This is happening when the Dirichlet boundary conditions are being applied. The problematic line is therefore actually:
fun = z_func*1e1
This doesn't actually set the values of the Function fun to zfunc1e1, instead it sets the variable fun to the expression zfunc1e1. To work around this, instead use:
fun.interpolate(z_func*1e1)
As an aside, the code provided also misspells solver_parameters so the solver options are not actually applied.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/1042#issuecomment-293998062, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APAHzryEvPZLmQKgzEVoYDF-UhdZtlqeks5rvnaJgaJpZM4M43Cv.
Dear all,
When I import firedrake_adjoint my Firedrake program does not convergence any more. I created the example below, which converges without firedrake_adjoint and does not with it. The issue has something to do with imposing bc0. Thank you for your help!
Henrik