# A Local Adaptive Mesh Refinement for JFO Cavitation Model on Cartesian Meshes
## 2 AMR Algorithm
### Neighbor Fixing  
AMR procedure usually requires the mesh satisfying 2:1 condition between neighbors, meaning the number of neighboring cells to a specified cell is not allowed to exceed three. In other words, the level difference between adjacent cells should be limited to 0, 1, and \(-1\). The 2:1 condition should be checked by the Neighbor finding () algorithm after mesh refinement and coarse operations. If the condition is not satisfied, the cells with more than three neighbor cells are divided into four cells by Mesh refining () algorithm operation. The 2:1 condition in the diagonal direction is also mandatory in the present AMR procedure. If the condition is not implemented, the interpolation scheme on hanging nodes becomes much complex, which is not what we want. Figure 4 shows the mesh satisfying 2:1 condition after the Neighbor fixing () algorithm operation. The mesh was fixed from the mesh of Figure 2. The 24 cells indicated by red lines are newly added. The Neighbor fixing () algorithm is shown in Algorithm 4. ```
while 1 if 2:1 condition is satisfied (checked by Neighbor finding () algorithm) break; end for each direction (N S W E) if the number of neighboring cells exceed three set refinement flag to 1; end end for each diagonal (NW NE SW SE) if the absolute mesh level difference between central cell and diagonal cell exceeds 1 set refinement flag to 1; end end end perform Mesh refining () algorithm;

Figure 3: Neighbor finding () algorithm. ### Handlingnode Interpolating

Hanging nodes are created at the interfaces between different level cells (see in Figure 2) [36]. Two cases need to be considered: (1) the calculation upon the coarse grids needs the interpolation of fine grids and (2) the calculation upon the fine grids needs the interpolation of coarse grids, as shown in Figure 5. In the case of (1), the value of the ghost node is simply calculated by the average value as

\[\varphi_{g}=(\varphi_{2}+\varphi_{3})/2, \tag{1}\]

where \(\varphi\) is the flow variable. In the case of (2), the value of the ghost node is calculated by quadratic interpolation as

\[\varphi_{g}=ax_{i}^{2}+bx_{i}+c, \tag{2}\]

where \(a\), \(b\), \(c\) are the coefficients determined by \(\varphi_{2}\), \(\varphi_{3}\), \(\varphi_{4}\), and \(x_{i}\) is the \(x\) coordinate of \(\varphi_{1}\). The quadratic interpolation is implemented by MATLAB function [37]. If a boundary or fine grid is encountered, case (2) is considered a particular case. The values of \(\varphi_{2}\) and \(\varphi_{4}\) are, respectively, taken as the value of the boundary condition and the average value of the fine grid, as follows

\[ \begin{array}{c}\varphi_{2}=\varphi_{b}\\ \varphi_{4}=(\varphi_{5}+\varphi_{6})/2\end{array}  \tag{3}\]

where \(\varphi_{b}\) is the value of the boundary condition. The present interpolation hybridizes linear and quadratic rules. Although all quadratic interpolations are feasible, more effort in programming is required. Other methods such as prolongation and restriction methods to handle interpolation can be seen in [38]. The Handingnode interpolating () algorithm is shown in Algorithm 5. ```
if the neighbor cell is a boundary (Neighbor finding () algorithm returns zero)  return the value of boundary condition; else if the number of neighbor cells is two (case (1))  return the average value using Equation (1);  end if if the number of neighbor cells is one and the level of neighbor cells is small than the level of the central cell (case (2))  return the quadratic interpolation value using Equation (2);  end if if the neighbor cell is the particular case (2)  return the quadratic interpolation value using Equation (3);  end end
```
**Algorithm 5**Handingnode interpolating ()

Figure 4: The mesh satisfying 2:1 condition. ### Periodic Matching

The west boundary and east boundary of the computational domain are paired into a periodic boundary condition. A periodic boundary condition is defined for the two boundaries where their values are linked in some defined way, such as interpolation or matching method.