# 2. Numerical implementation¶

The following sections show how the numerical methods were implemented to solve the equations of conservation of mass, momentum and energy that were presented in the Basic theory section.

## 2.1. Mass and momentum equations¶

For a solution domain \(\Omega\), finding the flow velocity \(u_i=g_i+v_i\) and pressure \(P\) states the Galerkin weak formulation for Stokes’ flow, where \(g_i\) is a specified boundary velocity, \(v_i\) belongs to a set of functions \(\mathcal{V}\) in which every function is equal to zero on the boundary where the \(ith\) components of the velocity is \(g_i\), and \(P\) belongs to a set of functions \(\mathcal{P}\) such that the equations of conservation of mass and momentum can be written as follows [1]:

where \(w_i \in \mathcal{V}\) and \(q \in \mathcal{P}\) are weighting functions and the boundary conditions are defined:

where \(\Gamma_{h_i}\) is the boundary where the \(ith\) components of the forces are set to be \(h_i\), \(n_j\) is the normal vector at the boundary \(\Gamma_{h_i}\), and \(f_i=g\rho_0 \alpha \delta_{i3}\) [6]. The weak formulation can be re-written as below:

where \(c_{ijkl}=\eta(\delta_{ik}\delta_{jl}+\delta_{il}\delta_{jk})\) is obtained from the stress tensor equation (see Eq. 1.4 in the basic theory section).

The velocity field, the pressure field and the weighting functions shape functions that interpolate the grid points at every node are given:

where \(N_A\) is the shape function for the velocity at node A, \(M_B\) is the shape function for the pressure at node B, \(\Omega^{v}\) is the velocity nodes set, \(\Omega^{p}\) is the pressure nodes set and \(\Gamma^{g}_{g_i}\) is the velocity nodes set along the boundary \(\Gamma_{g_i}\). *Mandyoc* defines \(\Omega^{p}\) at the center of each element, while \(\Omega^{v}\) is defined at every element vertex. This avoids spurious flow solutions and numerical instabilities [1] and it keeps the velocity shape functions one order higher than the pressure shape functions, a common strategy used in finite element modeling of incompressible media [6].

From the shape functions above and the Galerkin weak formulation (Eq. 2.3), the following expression can be obtained:

and also:

The matrix representation of these two equations above can be presented:

where \(V\) is the vector of velocity values at \(\Omega^v\), \(P\) is the vector of pressure values at \(\Omega^p\), \(F\) is the resulting vector of the rigth-hand side of equations Eq. 2.9 or Eq. 2.10, \(K\) is the stiffness matrix, \(G\) is the discrete gradient operator, and \(G^T\) is the discrete divergence operator [1]. \(K\), \(G\) and \(G^T\) are derived from the first and second terms of Eq. 2.9 and Eq. 2.10.

The matrix operator \(B\) from Eq. 2.9 contains the spatial derivatives of the shapes function \(N\) and, for a 2-D plane, can be written as:

Again from Eq. 2.9 and for 2-D plane strain problems, the effective viscosity matrix \(D\) can be written:

The stiffness matrix \(K\) and the gradient operator \(G\) can be written:

where the subscripts \(A\) and \(B\) are the global velocity node numbers, \(i\) and \(j\) are the degree of freedom per grid node, ranging from \(1\) to \(n_{sd}\), \(l\) and \(m\) are global equation numbers for the velocity ranging from \(1\) to \(n_v n_{sd}\), where \(n_{v}\) is the number of velocity nodes in the grid.

## 2.2. Energy equation¶

It is possible to represent the energy conservation equation (Eq. 1.3) as a finite element problem for a solution domain \(\Omega_V\) as follow:

where \(\mathbf{M}\), \(\mathbf{K}_a\), \(\mathbf{K}_c\) and \(\mathbf{F}\) are written below:

where \(\mathbf{N}_V\) is a row vector of shape functions, \(\mathbf{a}_T\) is a column vector of the unknown temperature parameters, \(\mathbf{\dot{a}}_T\) is its time derivative, and \(\mathbf{B}_V \equiv \nabla \mathbf{N}_V\).

Note

The superscript \(T\) represents the transpose of the matrix, while the non-superscript \(T\) represents the temperature.

\(\mathbf{M}\) and \(\mathbf{K}_c\) are symmetric, but \(\mathbf{K}_a\) is not. This asymmetry decreases the accuracy of the solution when advection is more dominant than conduction ([7], chapter 2). To increase numerical accuracy and stability, *Mandyoc* uses the streamline upwind Petrov-Galerkin process to modify \(\mathbf{K}_a\) to \(\mathbf{K}_a^*\) [7, 8, 9]:

where \(N^{*}_{Vi}\) is:

where \(h^e\) is the characteristic element size in the advection velocity direction (\(\mathbf{v}\)), and \(\alpha_{opt}\) is:

The time discretization is made by an implicit scheme [3]:

where \(\theta=0.5\) is a weighting parameter. Multiplying both sides of Eq. 2.24 by \(\mathbf{M}(t+\Delta t)\) and assuming \(\mathbf{M}(t+\Delta t) \approx \mathbf{M}(t)\):

where \(\mathbf{K}_T=\mathbf{K}^*_a+\mathbf{K}_c\).

Rearranging Eq. 2.25 allows to rewrite it in a numerical form to solve the energy equation.

## 2.3. Free surface¶

*Mandyoc* uses the *Free Surface Stabilization Algorithm* [10] to modify the Stokes equation and avoid numerical instabilities that can occur on the surface of the model. The up-and-down oscillations around the steady state (“sloshing instability” or “drunken sailer effect”) would require small time steps, which would increase running time by unfeasible amounts.

The modification is done on the stiffness matrix \(K_e\), such that \(\tilde{K}_e=K_e+L_e\), where the correction \(L_e\) is evaluated at the boundary \(\Gamma_e\) of each finite element. The correction is given by the Eq. 2.27 below:

where \(\mathbf{N}\) is the element shape function, \(0 \leq \Theta \leq 1\) is a wight factor of the correction term, \(\Delta \rho\) is the density contrast between the two mediums, \(\Delta t\) is the numerical integration time step, \(\mathbf{g}\) is the gravity acceleration vector, and \(\mathbf{n}\) is the normal vector to the element.

## 2.4. Rheology¶

Considering a visco-plastic model, the effective viscosity \(\eta\) follows the formulation described by Moresi and Solomatov (1998) [11], which combines plastic deformation and viscous deformation:

where \(\tau_{yield}\) is the rupture tension and \(\dot{\varepsilon}_{II}=(\dot{\varepsilon}_{ij}'\dot{\varepsilon}_{ij}'/2)^{1/2}\) is the second invariant of the deviatoric strain rate tensor, and \(\eta_{plas}\) and \(\eta_{visc}\) are the plastic and ductile viscosities.

### 2.4.1. Plastic deformation¶

The plastic deformation can be calculated using the Byerlee Law [12] to compute \(\tau_{yield}\) and \(\eta_{plas}\). Eq. 2.29 shows the relationship implemented in *Mandyoc*.

where \(c_{0}\) in the internal cohesion of the rock, \(\mu\) is the friction coefficient, \(\rho\) is the density and \(z\) is the depth.

Alternatively, the user can choose to use the the Druker-Prager criterion [13], which is presented in Eq. 2.30.

where \(\varphi\) is the internal angle of friction.

### 2.4.2. Viscous deformation¶

*Mandyoc* contains several rheology models that the user can choose for viscous deformation. Among them, two will be discussed here.

The ductile rheology can be simulated using the Frank-Kamenetskii approximation, following the formulation described by Solomatov and Moresi (2000) [14], where the viscosity is a function of the temperature \(T\) as in the equation below. Such formulation was also used by Sacek (2017) [15] in an earlier *Mandyoc* version.

where \(\eta_r\) is the reference viscosity, \(C\) is a compositional factor to scale the effective viscosity, and \(b^*\) and \(\gamma = E_a / RT^2_b\) are constants, which in turn, \(E_a\) is the activation energy, \(R\) is the gas constant, and \(T_b\) is the basal temperature.

Additionally, the rheology can also be considered to follow a power law, as a function of the temperature \(T\), compositional factor \(C\), pressure \(P\) and strain rate \(\varepsilon\) as follows:

where \(A\) is a pre-exponential scale factor, \(n\) is the power law exponent, \(\dot{\varepsilon}\) is the square root of the second invariant of the strain rate tensor, \(Q\) is the activation energy, and \(V\) is the activation volume. The values of \(A\), \(n\), \(Q\), and \(V\) are measured under laboratory conditions [16, 17].

### 2.4.3. Non-linear iterations¶

When the non-linear option is chosen by the user, the effective viscosity is dependent on the velocity field, which is iteratively updated following the algorithm described by Thieulot (2014) [4]. In this algorithm, the velocity and effective viscosity field are iteratively updated until the following convergence criterion is satisfied:

where \(f\) represents an array with all the nodal values of the velocity components, \(tol\) is a tolerance factor, and \(\langle f\rangle\) is the mean value of \(f\). The superscript \(i\) and \(i+1\) indicate two consecutive iterations in the same time step. In each iteration, the momentum and mass equations are calculated with an updated effective viscosity field.