I use the fenics to solve an optimization problem. The problem is like:
objective function: x^2+y^2.
Then, I can obtain the gradient of objective function corresponding to the variables x and y,
Gradient formulas: 2x and 2y
The problem is: how to call the gradient-based algorithm when the objective function and the gradient's formulas are obtained in fenics?
In fact, the optimization problem I face is far more difficult than this problem. Moreover, I am familiar with optimization process as follows
# Solve the Navier-Stokes equations
solve(F == 0, s, bcs=bcu+bcp)
# Define the optimisation proble,
alpha = Constant(1e-4)
J = Functional(inner(grad(u), grad(u))*dx + alpha*inner(f,f)*dx)
m = InitialConditionParameter(f)
rf = ReducedFunctional(J, m)
# Solve the optimisation problem
m_opt = minimize(rf, method="Newton-CG", tol=1e-8)
# Plot the optimised results
f.assign(m_opt)
solve(F == 0, s, bcs=bcu+bcp)
But, this case is different from my question because the gradient formula is given by "ReducedFunctional" while I can obtain the gradient formula by other computations.