In Part 1  of this paper we have studied discretization and optimization techniques for solving elliptic control problems with boundary control. Part 2 is devoted to optimization methods for elliptic control problems with distributed control. Boundary conditions are of mixed Dirichlet and Neumann type. The control process is subject to general control and state inequality constraints. Essentially the same discretization and optimization techniques as in Part 1 can be used for distributed control, the only difference being the fact that for distributed control the number of optimzation variables roughly doubles compared to that for boundary control.
For the class of elliptic problems considered in this paper, necessary optimality conditions have not yet been derived to full extent in the literature. Necessary conditions for more special classes of elliptic problems may be found in Bonnans, Casas [4,5,6]; cf. also Bergounioux et al. , Cañada et al. , Hettich et al. [17,18], Leung, Stojanovic , Lions  and Rotin . In section 2 we give a formal extension of the existing necessary conditions to the general elliptic problem treated in this paper. The conditions are specialized to cost functionals of tracking type and box constraints for control and state variables. In particular, a more detailed discussion is given for bang-bang and singular controls. In section 3 we show that the necessary conditions are consistent with their counterparts for the discretized problem which are obtained from the Kuhn-Tucker conditions.
In section 3, we discuss a full discretization approach in which both control and state variables are discretized. The resulting large-scale NLP-problem solved subsequently contains up to 80,000 variables. Six examples are considered in section 4. Optimal control and state as well as adjoint variables are computed which allow to check the discretized version of the necessary conditions with high accuracy. In Examples 2 and 5 we obtain an optimal bang-bang control which is especially remarkable in the distributed control example for which we are not aware of another instance in the literature.
The problems are formulated as AMPL  scripts and several optimization codes are applied. In particular, the interior point code LOQO  successfully and efficiently solved all problems. It needs to be stressed that more nonlinear formulations of these or other applications can be treated in the same way. The code LOQO was designed to solve general nonconvex NLP problems. For a comparison with other codes on several classes of optimization problems, see the benchmarks of .