One may consult the very interesting textbook [HLT24] about the FreeFem implementation of many PDE-constrained optimization problems.
Contents: