# Cathode Shape Design for Steady-State Electrochemical Machining
## 2 Fundamentals and Methods
### Cathode Shape Design for Steady-State ECM  
In the majority of the examples shown in this work, the inverse problem of ECM is solved numerically by continuous adjoint-based shape optimization aimed at minimizing the (reduced) objective function (cf. [8], Equation (41)):  
\[j(\Omega)=J(\Omega,\Phi)=\frac{1}{2}\int_{\Gamma_{\Lambda}}\left(\frac{\partial \Phi}{\partial n}-\cos\theta\right)^{2}\mathrm{d}S, \tag{6}\]  
where \(\theta\) denotes the angle between the outer surface normal of the anode surface boundary and the feed direction of the cathode (see Figure 1b). Each iteration starts with solving for the electric potential \(\Phi\) (Equations (1)-(4)) and for the Lagrange multiplier \(\lambda_{\Omega}\) governed by the adjoint equations (cf. [PERSON] et al. [8], Equations (44)-(47)):  
\[\
abla\cdot(\
abla\lambda_{\Omega}) =0 \text{in }\Omega, \tag{7}\] \[\frac{\partial\lambda_{\Omega}}{\partial n} =0 \text{on }\Gamma_{\mathrm{N}},\] (8) \[\lambda_{\Omega} =0 \text{on }\Gamma_{\mathrm{C}},\] (9) \[\lambda_{\Omega} =-\left(\frac{\partial\Phi}{\partial n}-\cos\theta\right) \text{on }\Gamma_{\mathrm{A}}. \tag{10}\]  
When the domain \(\Omega\) is deformed infinitesimally into \(\Omega_{\varepsilon}=\{\underline{x}+\varepsilon\underline{v}(\underline{x}); \,\underline{x}\in\Omega\}\), the change in the reduced objective function \(j(\Omega)\) is given by the so-called reduced gradient,  
\[\mathrm{D}_{\Omega}j(\Omega)[\underline{v}]=\int_{\Gamma_{\mathrm{C}}}( \underline{v}\cdot\underline{n})\frac{\partial\lambda_{\Omega}}{\partial n} \frac{\partial\Phi}{\partial n}\,\mathrm{d}S. \tag{11}\]  
To optimize the shape of the cathode by the steepest descent method, each point \(\underline{x}\) on \(\Gamma_{\mathrm{C}}\) is moved according to (cf. [8], Equation (53))  
\[\underline{x}\to\underline{x}-\tau\frac{\partial\lambda_{\Omega}(\underline{ x})}{\partial n}\frac{\partial\Phi(\underline{x})}{\partial n}\underline{n}( \underline{x}) \tag{12}\]  
in an iteration step with step length \(\tau\). The numerical schemes and the mesh deformation method are similar to those applied when solving the direct problem. To evaluate the convergence of the optimization process, the maximum of the shape gradient,  
\[G_{\mathrm{max}}=\max_{\Gamma_{\mathrm{C}}}\left|\frac{\partial\lambda_{ \Omega}}{\partial n}\frac{\partial\Phi}{\partial n}\right|, \tag{13}\]  
and that of the integrand of the shape optimization objective function (Equation (6)),  
\[\delta_{\mathrm{max}}=\max_{\Gamma_{\mathrm{A}}}\left|\frac{1}{\cos\theta} \frac{\partial\Phi}{\partial n}-1\right|, \tag{14}\]  
are monitored (cf. [8], Section 3.2.1). A schematic diagram of the cathode shape design procedure is shown in Figure 2.  
In certain 2D cathode shape design problems, explicit analytical solutions can be found if the anode shape is analytic, i.e., \(\Gamma_{\rm A}=\{(x,z)\in\mathbb{R}^{2};\,z=F(x)\}\) with an analytic function \(F\). For these cases, the complex variable method [21] is used to calculate the surface profile of the unknown cathode as a curve with parameter \(\xi\) in the \(x\)-\(z\)-plane (cf. [8], Appendix C). The coordinates of the curve points are given by  
\[x_{\rm C}(\xi) = \xi-\mathrm{Im}[F(\xi+{\rm i})], \tag{15}\] \[z_{\rm C}(\xi) = 1+\mathrm{Re}[F(\xi+{\rm i})]. \tag{16}\]  
The complex variable method is used to discuss the existence of solutions in general cases and serves as an additional way to verify numerically computed solutions.  
Figure 2: Flowchart of the cathode shape design algorithm based on continuous adjoint shape optimization.