Thank you so much for the reply.
Unfortunately, I couldn’t create a minimal code that needs more than 20 iterations in each line search. But please consider the below example (same as the code in Using Dolfin-adjoint for optimization problem without PDE constraint - #2 by dokken). I have changed the options in this line ( u_opt = minimize(J_hat, method = "L-BFGS-B", options = {"gtol": 1e-6, "ftol": 1e-16, "maxfun": 30000, "maxiter": 30000, "maxls": 40})
)
The problem is that in my real code, although I am using these options, the code stops after trying 20 iterations for line search.
import numpy as np
import matplotlib.pyplot as plt
from dolfin import *
from dolfin_adjoint import *
import moola
n = 10
mesh = RectangleMesh(Point(-1,-1),Point(1,1), n, n)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
v = TestFunction(V)
S0 = Constant(1)
bc = DirichletBC(V, 1, "on_boundary")
v = project(u, V, bcs=bc)
J = assemble((0.5*inner(grad(v), grad(v)) - v*S0)*dx)
J_hat = ReducedFunctional(J, Control(u))
u_opt = minimize(J_hat, method = "L-BFGS-B", options = {"gtol": 1e-6, "ftol": 1e-16, "maxfun": 30000, "maxiter": 30000, "maxls": 40})
J_hat(u_opt)
fileY = File("temp.pvd");
fileY << v.block_variable.saved_output;
print(assemble(v*ds))