There are first-optimize-then-discretize (indirect) and first-discretize-then-optimize (direct) methods to deal with infinite dimensional optimal problems numerically by use of finite element methods. Generally, both discretization techniques lead to different structures. Regarding the indirect method, one derives optimality conditions of the considered infinite dimensional problems in appropriate function spaces firstly and then discretizes them into suitable finite element spaces. One has freedom to chose ansatz spaces for functions. On the contrary, w.r.t. the direct method, one doesn't need to investigate functional properties of the given problem, but transform the overall system into a standard finite dimensional optimal problem. Depending on the situation, each method has its own advantages and disadvantages.
View Different discretization techniques for solving optimal control problems with control complementarity constraints