To make the existing CHInterface and ACInterface kernels flexible enough to handle $$\kappa$$$as functions of phase field variables we need to rederive the residual equations. The phase field equations are \begin{eqnarray} \frac{\partial c_i}{\partial t} &= \nabla \cdot M_i \nabla \frac{\delta F}{\delta c_i}\\ \frac{\partial \eta_j}{\partial t} &= - L_j \frac{\delta F}{\delta \eta_j}. \end{eqnarray} The free energy $$F$$$ is defined as

F = \int_V \big[ f_{loc}(c_1, \ldots,c_N, \eta_1, \ldots, \eta_M) + f_{gr}(c_1, \ldots,c_N, \eta_1, \ldots, \eta_M) + E_{d} \big] \, dV,

where $$f_{gr}$$$is the gradient contribution in question, with f_{gr} = \sum_i^N \frac{\kappa_i}{2} |\nabla c_i|^2 + \sum^M_j \frac{\kappa_j}{2} |\nabla \eta_j|^2 = \sum^{N+M}_i \frac{\kappa_i}{2} |\nabla \nu_i|^2, where we let $$\vec \nu = (\vec c, \vec\eta)$$$ be an arbitrary order parameter.

We apply the fundamental lemma of calculus of variations

\frac{\delta F}{\delta c} = \frac{\partial f}{\partial c} - \nabla \cdot \frac{\partial f}{\partial\nabla c},

to compute the variational derivatives of the gradient contribution with respect to an arbitrary order parameter $$\nu_j$$\$ and obtain

\frac{\delta f_{gr}}{\delta \nu_j} = \sum^{N_M}_i \left[ \frac12 \frac{\partial\kappa_i}{\partial\nu_j}|\nabla \nu_i|^2 - \frac12\nabla\left(\frac{\partial\kappa_i}{\partial\nabla\nu_j}|\nabla\nu_i|^2\right) - \delta_{ij}\underbrace{\nabla(\kappa_i\nabla\nu_i)}_{=\kappa_i\nabla^2\nu_i+(\nabla\kappa_i)(\nabla\nu_i)}\right]