## 3 Numerical Methods  
### Level Set Function  
The level set (LS) function has been widely used in applications, such as in breaking waves, bubble dynamics, and computer graphics [21]. In this study, the LS function is used to describe the fluid-solid interface:  
\[\phi\left(\overset{\rightarrow}{x},t\right)=\left\{\begin{array}{c}-\Gamma \left(\overset{\rightarrow}{x},t\right)\text{ {in solid}}\\ 0\text{ {interface}}\\ \Gamma\left(\overset{\rightarrow}{x},t\right)\text{ {in fluid}}\end{array}\right. \tag{10}\]  
where \(\Gamma\) is the distance from any point to the fluid-solid interface. The points on the fluid-solid boundary have \(\phi\left(\overset{\rightarrow}{x},t\right)=0\). For example, the LS function representing a sphere with radius of 1 is given by \(\phi=\sqrt{x^{2}+y^{2}+z^{2}}-1\). Since the LS function is a function of signed distance, the unit normal vector \(\overset{\rightarrow}{n}\) and the local curvature \(\varkappa\) of the interface can be evaluated by applying the derivative operators:  
\[\overset{\rightarrow}{n}=\frac{\
abla\phi}{|\
abla\phi|} \tag{11}\]  
\[\varkappa=\
abla\cdot\overset{\rightarrow}{n}=\
abla\cdot\frac{\
abla\phi}{ |\
abla\phi|} \tag{12}\]  
In Equations (11) and (12), \(\phi\) value and its variation are only dependent on the location of interface. It is easy to define the LS function \(\phi\) to describe the immersed interface of the solid body with simple geometry, such as a sphere, cube, etc. For carangiform fish, however, their body geometry is complex, and several multiple subfunctions are required to define its LS function \(\phi\). At some points near the interface, the contours of \(\phi\) may become too dense or sparse, making the interface thickness non-constant. The LS function is no longer a signed distance function, and its spatial gradient is much larger than one. Therefore, a re-initialization process [22] is needed to maintain the distancing property of the LS function \(|\
abla\phi|=1\), and its governing equation is expressed as:  
\[\frac{\partial\phi}{\partial\tau}+\text{sig}n(\phi)(|\
abla\phi|-1)=0 \tag{13}\]  
Here \(\tau\) is a pseudo-time, \(\text{sig}n(\phi)=\phi/\sqrt{\phi^{2}+\epsilon^{2}}\) is the smoothed sign function of \(\phi\), and \(\epsilon\) is set to three times the minimal grid size. To illustrate the re-initialization procedure, the shape of carangiform fish with the length of one, described by Equations (2) and (3), is considered as an example. In this case, the domain size is \(5\times 5\), and the number of grid points is \(512\times 512\). The initial LS function is described by a piecewise function, and the domain is divided into three parts:  
\[\phi(x,t)=\left\{\begin{array}{c}|y-2.5|,x\in[0,1.75)\cup x\in(2.75,5]\\ y-(2.5+h(x,t)+r(x)),x\in[1.75,2.75],y\geq 2.5\\ (2.5+h(x,t)-r(x))-y,x\in[1.75,2.75],y<2.5\end{array}\right. \tag{14}\]  
In Equation (14), \(r(x)\) is the half-width of fish body, and \(h(x,t)\) represents the midline motion of the fish body. The absolute value of \(\phi(x,t)\) without the re-initialization process is shown in Figure 3a. At the points of head and tail, \(x=1.75\) and \(2.75\), respectively, two discontinuities appeared with the large errors. But after 20 iterations of re-initialization, all the contour lines adjacent to the fish body become equally spaced. As shown in Figure 3b, the LS function has been corrected without solving the LS function implicitly.