Technische Universität München Center for Mathematical Sciences, M17 Lucas Bonifacius, Korbinian Singhammer www-m17.ma.tum.de/lehrstuhl/lehresose16labcourseoptpde Summer 216 Introduction into Implementation of Optimization problems with PDEs: Sheet 3 Exercise 3.1 (State constraints): to point-wise state constraints We consider the linear quadratic elliptic problem subject min J(q, u) = 1 q L 2 (Ω), u H 1 (Ω) 2 u u d 2 L 2 (Ω) + α 2 q 2 L 2 (Ω) u + u = q in Ω, subject to n u = on Ω u u a in Ω. (1a) (1b) The domain is the square Ω = ( 1, 1) ( 1, 1), we take u d (x) = cos (πx 1 ) x 2, α = 1 3 and the state constraint is given by u a.4. We eliminate the state constraint by adding a Moreau-Yosida type regularization term with parameter γ to the objective functional min J(q γ, u γ ) + γ (max{, u a u γ }) 3 dx q γ L 2 (Ω), u γ H 1 (Ω) 3 Ω { uγ + u γ = q γ in Ω, subject to n u γ = on Ω. The corresponding optimality condition reads as ū γ + ū γ = q γ in Ω, n ū γ = on Ω, z γ + z γ = ū γ u d γ max{, u a ū γ } 2 in Ω, n z γ = on Ω, α q γ + z γ = in Ω. (2) Since (2) is a non-linear system we want to solve it by the Newton method. For that we follow the same steps as in Exercise.3 but now with the two variables u and z. a) First, substitute q γ in the state equation by the gradient condition α q γ + z γ =. Then, write down the weak forms of the corresponding equations of (2) such that the weak solutions to (2) are the roots of the residual r : H 1 (Ω) H 1 (Ω) H 1 (Ω) H 1 (Ω) with r(x γ )(ϕ) = where x γ = (u γ, z γ ) and ϕ = (ϕ u, ϕ z ). [ ] ru (u γ, z γ )(ϕ u ), (3) r z (u γ, z γ )(ϕ z ) 1/8
b) We use Newton s method on the residual. Formulate a Newton step by calculating the partial derivatives of the residuals in (3), i.e., r (x γ )(ϕ)(δx) = ( ) uγ r u (x γ )(ϕ u )(δx u ) zγ r u (x γ )(ϕ u )(δx z ) = r(x uγ r z (x γ )(ϕ z )(δx u ) zγ r z (x γ )(ϕ z )(δx z ) γ )(ϕ). (4) c) Discretize the state and adjoint state with piecewise linear finite elements (as before) and use the variational control discretization. Accordingly, we discretize (4). Write the discrete Newton step as system of linear equations of the form ( ) ( ) ( ) Auu A uz dxu ru =. (5) dx z r z A zu A zz Here, for example, A uu and A zu stand for uγ r u (u γ, z γ )(ϕ)(δu γ ) and zγ r u (u γ, z γ )(ϕ)(δu γ ), respectively. Implement all required forms and assemble the matrices and vectors. d) As a first plausibility check, set γ = and solve the optimization problem. This corresponds to the optimal control problem without state constraints. How many Newton steps should your implementation need to converge? e) To test your implementation, you can successively increase the regularization parameter γ, say γ = 1, 1, 1, 1. Determine for each choice the minimal value of ū γ. For γ = 1 3, your solution should look like Figure 1. 1 Control 1 State.67.5.5.53.5.5 1 1.5.5 1 1 1.5.5 1.4 Figure 1: Optimal control q γh and state ū γh for γ = 1 6, u a.4 and 8 mesh refines We would like to investigate the dependence of the regularization parameter γ and the mesh parameter h on the approximation error q q γh L 2 (Ω) and ū ū γh L 2 (Ω). f) Since we do not know the analytical solution, we have to compute first a reference solution on a sufficiently fine grid. As we expect the solution on the coarser grid to be an approximation to the solution on the finer grid, we can use the solution of the preceding iteration as an initial value for the next to improve the performance of the algorithm. You can use [meshref, u_1,..., u_n] = uniforminterpolate(meshref, u_1,..., u_n); to uniformly refine the mesh and interpolate the functions u_1 to u_n on the resulting mesh. 2/8
Then calculate a solution of the regularized problem as above. It is useful to wrap the solution of the optimality system in a separate function function [u, z, q] = solveoptimalitysystem(mesh, u, z, gamma, ua, alpha) with u in the function arguments being the initial value. Use γ = N with N the number of nodes. g) Solve the regularized problem for a the regularization parameters γ = 1, 5, 25, 125,..., 5 1 and on a sequence of uniformly refined meshes with prerefine 2, 3,..., 8. As before, use the function uniforminterpolate to use the solution of the preceding iteration as the initial value for the problem on the finer grid. h) In each iteration, compute the L 2 -errors q q γh L 2 (Ω) and ū ū γh L 2 (Ω) using the function ComputeError and store the values in a matrix. Plot the error with respect to the regularization parameter as in Figure 2. Describe qualitatively the coupling of γ and h. i) Can we replace the regularization term by γ 2 Ω (max{, u a u γ }) 2 without further modifications? For a possible solution see also Exercise 3.3 (Bonus). 1 1 1 1 1 1 q qγh 1 1 1 2 h =.5 h =.25 h =.125 h =.62 h =.31 h =.16 1 3 1 1 1 1 2 1 3 1 4 1 5 1 6 γ h =.5 h =.25 h =.125 h =.62 h =.31 h =.16 1 2 1 3 1 1 1 1 2 1 3 1 4 1 5 1 6 1 4 γ ū ūγh Figure 2: L 2 -error for the control (left) and the state (right) for different spatial discretizations and regularization parameter γ Exercise 3.2 (Finite dimensional control and inverse problem): The intention of this exercise is to show that optimal control problems have a wide of range of applications and we should not be too strict with the term control. Assume we are given some conducting material where the electrical conduction depends on the direction (orthotropic), e.g. graphite. We suppose that the exact conduction coefficients are unknown. For simplicity the material sample is of infinite length with cross-section Ω R 2. On two boundary parts Γ 1, Γ 2 Ω we apply a potential that in turn induces a current encoded in the functions f 1, f 2 H 1 (Ω). Let u denote the electrical potential. The lower part Γ Ω is 3/8
connected to ground, i.e. u Γ =. The remaining boundary parts are isolated, i.e. n u =. The shape is visualized in Figure 3. Furthermore, we are given measurements c d R 2 and an observation operator that maps the electrical potential to the observation. From this we can formulate the following optimization problem min J(q, u) = 1 q R 2, u H 1 (Ω) 2 Cu c d 2 R 2 A(q)u = in Ω, (6a) subject to u = on Γ n u = f 1 on Γ 1 (6b) n u = f 2 on Γ 2 n u = on Ω \ (Γ Γ 1 Γ 2 ), where A(q) with q R 2 is the differential operator A(q)u, ϕ = q 1 x1 u x1 ϕ + q 2 x2 u x2 ϕ, where Ω H 1 Γ (Ω) = { } ϕ H 1 (Ω): ϕ Γ =. u, ϕ H 1 Γ (Ω), In the examples considered so far the materials where isotropic, i.e. the diffusion was independent of the spatial direction. Here, A(q) models orthotropic materials. For well-posedness of the state equation we have to require that q >, otherwise the operator A(q) would not be elliptic. For simplicity we ignore this control constraint. Moreover, the observation operator C = (C 1, C 2 ) is given by C 1 u = u, Ω 1 C 2 u = u, Ω 2 with the observation domains We take f 1 = 5 and f 2 = 5. Ω 1 = {x Ω : x 1 <.5} Ω 2 = {x Ω : x 1 > 7.5}. The diffusion parameters q 1 and q 2 are unknown and should be estimated from the measurements c d R 2. Whence, in this setting the searched control is the pair of parameters q 1 and q 2. a) In order to optimize, we would like to have an expression for the gradient. We will use the Lagrange formalism and define the bilinear form a(q, u)(ϕ) = A(q)u, ϕ for all ϕ H 1 Γ (Ω). For all z H 1 Γ (Ω) it holds j(q) = J(q, u) = 1 2 Cu c d 2 R Γ 2 a(q, u)(z) + f 1 z + f 2 z. 1 Γ 2 Differentiate the equation above with respect to q. Verify that j (q)(δq) = (Cu c d, Cδu) a q(q, u)(δq, z) a u(q, u)(δu, z), 4/8
4 3 2 1 1 2 3 4 5 6 7 8 Figure 3: Mesh of cross section of the material with boundary parts. where δu = S (q)δq. Define z H 1 Γ (Ω) such that a u(q, u)(ϕ, z) = (C (Cu c d ), ϕ), ϕ H 1 Γ (Ω), to find an expression for j(q). Determine C, a q(q, u) and a u(q, u). Alternatively, you can use the operator approach. Convince yourself that A is continuously Fréchet differentiable and verify that δu = S (q)δq is the solution to Show that A(q)δu = A (q)(u, δq) in Ω, u = on Γ n u = on Γ 1 n u = on Γ 2 n u = on Ω \ (Γ Γ 1 Γ 2 ). j (q)(δq) = (S (q) C (CS(q) c d ), δq) R 2 = ( [A (q)(u)] [A(q) 1 ] C (CS(q) c d ), δq) R 2. We define z = [A(q) 1 ] C (CS(q) c d ) to be the adjoint state. Determine A (q)(u). b) On the computer, we first have to specify the mesh. The strength of the finite element method is that it can handle complex domains easily. Use the command [node, elem] = loadmesh( material.msh ); to load all the nodes and cells from a file. To specify the boundary, you can either enter the indices of the nodes (as we did before for the unit square) or you can give a logical expression, which is more convenient in this case. To select the boundary on the left-hand side, enter boundary = Boundary( gamma, @(x,y) near(x,)); The function near returns true, if x is close to the value specified in the second argument. Due to numerical errors we cannot just use x ==. You can define multiple boundary pieces as follows boundary = Boundary( gamma1, [..], gamma2, [..],..); The command visusimple(mesh) will plot the mesh as well as the boundary parts in different colors. Compare with Figure (3). 5/8
State 4 State 8 4 8 Figure 4: Electrical potential for conduction parameters q = (5,.2) (left) and q = (1, 1) (right). c) Write a function u = solvestate(q, args) that solves the state equation. The operator A(q) can be incorporated by modifying the function handle. Pass the parameter q via data.param to the handle. Since the values of the solution on the Dirichlet boundary part are fixed, solve the problem on the nodes that belong to the interior and to the Neumann boundary parts only. Because the set of the non Dirichlet nodes will be used frequently, we stored them in args.inner. Solve the (reduced) linear system as follows u = zeros(n,1); u(args.inner) = A(args.inner,args.inner)\args.Mf(args.inner); Solve the state equation for different q and compare with Figure 4. Now, we solve the parameter estimation problem numerically. e) Implement C and C. You can use the function ComputeFunctional(mesh, @func, data) to integrate over the domain Ω, where func has the signature function g = func(data). f) To estimate the parameters q 1 and q 2, we require measurements c d. For testing purposes, solve the state equation for q ref = (5,.2) and store the observation value in args.cd. g) Implement a function z = solveadjoint(q, u, args) that solves the discrete adjoint equation for a given state u h. h) Implement a function g = computejp(q, u, z, args) that calculates the discrete gradient of j. You have to write the function handles a_q1 and a_q2 to calculate a q(q, u)(ϕ, z) resp. A (q)(u). i) Verify the correctness of your implementation so far using CheckGradient(q, dq, @solvestate, @solveadjoint, @computej, @computejp, args); j) Use the gradient descent method GradientDescent(@solveState, @solveadjoint, @computej, @computejp, args); with initial value q = (5.5, 1.6) to solve the optimization problem. Remember that you have to pass the initial value via args.q_. Calculate the error between q ref and q h obtained from the optimization. What went wrong? 6/8
k) Suggest new observation domains Ω 1 and Ω 2 to improve the error q ref q h. l) Can we omit the earthing, i.e. can we replace the homogeneous Dirichlet boundary condition on Γ by say homogeneous Neumann boundary conditions? Exercise 3.3 (State constraints with primal-dual active set method (Bonus)): Instead of adding a cubic term to the objective functional, we now add a quadratic regularization term to eliminate the state constraint min J(q γ, u γ ) + γ (max{, u a u γ }) 2 dx q γ L 2 (Ω), u γ H 1 (Ω) 2 Ω { uγ + u γ = q γ in Ω, subject to n u γ = on Ω. The corresponding optimality condition reads as ū γ + ū γ = q γ in Ω, n ū γ = on Ω, z γ + z γ = ū γ u d γ max{, u a ū γ } in Ω, n z γ = on Ω, α q γ + z γ = in Ω. (7) a) We discretize again the state and adjoint state with piecewise linear finite elements (as before) and use the variational control discretization. Find the discrete optimality condition to (7) with matrices A and M and a vector u d such that Az = Mu u d γm max{, u a u}, Au = 1 α Mz. (8) b) The system (8) is nonlinear and nonsmooth. Therefore, we use the primal-dual active set strategy. Select arbitrary initial values u and z. In each iteration, we calculate the active set as { } A n = i {1,..., M}: ui n 1 u a <. Write as a system of linear equations ( ) ( ) ( ) M + MAn A z MAn u A 1 α M = a + u d, (9) u with an appropriate matrix M An. Solve the linear system using the backslash operator in Matlab. Terminate the iteration, if the active set does not change, i.e. A n = A n 1. c) Solve the regularized problem for a the regularization parameters γ = 5, 25,...,..., 5 1 and on a sequence of uniformly refined meshes with prerefine 2, 3,..., 8. As before, use the function uniforminterpolate to use the solution of the preceding iteration as the initial value for the problem on the finer grid. d) In each iteration, compute the L 2 -errors q q γh L 2 (Ω) and ū ū γh L 2 (Ω) using the function ComputeError and store the values in a matrix. Plot the error with respect to the regularization parameter as in Figure 5. 7/8
e) Recommend a choice for γ (depending on h) based your numerical observation. Use for h the length of the shortest side of the triangle. Since we have a uniform triangulation, all measures for h are equivalent. f) It can be shown that there is a constant C > such that q q γh 2 L 2 (Ω) C(h + γ 1 h 1 ), see [1, Corollary 3.8]. Determine the optimal choice of γ from the estimate above. Compare the rate of convergence (with respect to γ) with your numerical observation. Is the estimate sharp (for this example)? q qγh 1 1 1 1 1 1 2 1 3 h =.25 h =.125 h =.62 h =.31 h =.16 h =.8 O(γ 1/2 ) 1 4 1 1 1 1 2 1 3 1 4 1 5 1 6 γ h =.25 h =.125 h =.62 h =.31 h =.16 h =.8 O(γ 1 ) 1 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 1 1 2 1 3 1 4 1 5 1 6 1 8 γ ū ūγh Figure 5: L 2 -error for the control (left) and the state (right) for different spatial discretizations and regularization parameter γ Further Reading [1] M. Hintermüller and M. Hinze. Moreau-Yosida regularization in state constrained elliptic control problems: error estimates and parameter adjustment. In: SIAM J. Numer. Anal. 47.3 (29), pp. 1666 1683. issn: 36-1429. 8/8