Introduction
In this example, we check the correctness of SFEMaNS for a ferrohydrodynamic problem. Maxwell, NavierStokes and temperature equations are solved. The domain presents a solid and a fluid subdomain. A force known as the Kelvin force is added to the source term of NavierStokes. It represents the action of the magnetic field on the magnetic fluid. Boussinesq force is also present. Maxwell equations are reduced to the magnetoststic equations due to the quasistatic approximation for the magnetic field. The fluid and solid regions do not have the same thermal properties. The volumetric heat capacity and the thermal conductivity are different. This case is usefull to study the cooling by convection and magnetoconvection of a solid by a ferrofluid.
The domain of computation is \(\Omega= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in (0,1) \times [0,2\pi) \times (0,1)\} \). We note \(\Gamma= \partial \Omega\). It is composed of a solid and a fluid subdomain:
\begin{align*} \overline{\Omega} = \overline{\Omega_s} \cup \overline{\Omega_f}.\\ \end{align*}
The subdomains are defined followingly: \(\Omega_s = \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in (0,1/2) \times [0,2\pi) \times (0,1)\} \) and \(\Omega_f= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in (1/2,1) \times [0,2\pi) \times (0,1)\} \). We note \(\Gamma_f = \partial \Omega_f\).
We solve the temperature equations:
\begin{align*} \begin{cases} c\partial_t T+ c\tilde{\bu} \cdot \GRAD T  \DIV (\lambda \GRAD T) &= f_T, \\ T_{\Gamma} &= T_\text{bdy} , \\ T_{t=0} &= T_0, \end{cases} \end{align*}
in the domain \(\Omega\). The extended velocity is defined by \(\tilde{\bu} = \bu\) in \(\Omega_f\) and \(0\) in \(\Omega_s\). The volumetric heat capacity \(c\) and the thermal conductivity \(\lambda\) are piecewise constant functions of space: \(c = c_f\) in \(\Omega_f\) and \(c_s\) in \(\Omega_s\), with \(c_f = 2 c_s\); \(\lambda = \lambda_f\) in \(\Omega_f\) and \(\lambda_s\) in \(\Omega_s\), with \(\lambda_s = 10 \lambda_f\). We recall that these parameters are dimensionless.
We solve the NavierStokes equations:
\begin{align*} \begin{cases} \partial_t\bu+\left(\ROT\bu\right)\CROSS\bu  \frac{1}{\Re}\LAP \bu +\GRAD p &= \alpha T \textbf{e}_z + \chi(T) \GRAD \left( \frac{H^2}{2} \right) + \bef, \\ \DIV \bu &= 0, \\ \bu_{\Gamma_f} &= \bu_{\text{bdy}} , \\ \bu_{t=0} &= \bu_0, \\ p_{t=0} &= p_0, \end{cases} \end{align*}
in the domain \(\Omega_f\). We denote by \(\textbf{e}_z\) the unit vector in the vertical direction. The function of the temperature \(\chi\) in the Kelvin force is defined by
\begin{align*} \chi(T) = T^2 \end{align*}
We solve the magnetostatics equations:
\begin{align*} \begin{cases} \ROT \bH &= \bJ,\\ \DIV (\mu \bH) &= 0, \\ \bH \CROSS \bn &= \bH_{\text{bdy}} \CROSS \bn, \text{ on } \Gamma,\\ \bH_{t=0} &= \bH_0, \\ \end{cases} \end{align*}
in the domain \(\Omega\). The permeability \(\mu\) is constant in the whole domain. Solving magnetostatic equations is possible by using a very small electrical conductivity in the whole domain (see data file description). The other terms of the induction equation are thus neglectable in that case.
The data are the source terms \(f_T\), \(\bef\) and \(\bJ\), the boundary data \(T_\text{bdy}\), \(\bu_{\text{bdy}}\) and \(\bH_{\text{bdy}}\), the initial data \(T_0\), \(\bu_0\), \(p_0\) and \(\bH_0\). The parameters are the volumetric heat capacities \(c_s\) and \(c_f\), the thermal conductivities \(\lambda_s\) and \(\lambda_f\), the kinetic Reynolds number \(\Re\), the thermal gravity number \(\alpha\) and the permeability \(\mu\).
Manufactured solutions
We approximate the following analytical solutions:
\begin{align*} T(r,\theta,z,t) & = r^2(rr_0)^2\sin(z)(1+\cos(\theta))\cos(t), \\ u_r(r,\theta,z,t) &= (rr_0)^2\cos(z)(1+\cos(\theta))\cos(t), \\ u_{\theta}(r,\theta,z,t) &= (rr_0)^2\cos(z)(1+\cos(\theta))\cos(t), \\ u_z(r,\theta,z,t) &= \frac{rr_0}{r} \sin(z) ((3rr_0)(1+\cos(\theta))+(rr_0)\sin(\theta))\cos(t), \\ p(r,\theta,z,t) &= 0, \\ H_r(r,\theta,z,t) &=  r^3 \exp(z) (1 + \sin(\theta) \cos(t), \\ H_\theta(r,\theta,z,t) &= r^3 \exp(z) (1 + \sin(\theta)) \cos(t), \\ H_z(r,\theta,z,t) &= r^2 \exp(z) (4  \cos(\theta) + 4 \sin(\theta)) \cos(t), \end{align*}
where \(r_0 = 1/2\) is the limit between solid and fluid regions. The velocity is the curl of a vector field, it is thus divergence free. Same thing for the magnetic field.
The source terms \(f_T, \bef\), \(\bJ\) and the boundary data \(T_\text{bdy}, \bu_{\text{bdy}}\), \(\bH_{\text{bdy}}\) are computed accordingly.
Generation of the mesh
The finite element mesh used for this test is named SOLID_FLUID_10.FEM
and has a mesh size of \(0.1\) for the P1 approximation. You can generate this mesh with the files in the following directory: ($SFEMaNS_MESH_GEN_DIR)/EXAMPLES/EXAMPLES_MANUFACTURED_SOLUTIONS/SOLID_FLUID_10. The following image shows the mesh for P1 finite elements.
Finite element mesh (P1).

Information on the file condlim.f90
The initial conditions, boundary conditions and the forcing terms are set in the file condlim_test_33.f90
. Here is a description of the subroutines and functions of interest.

The subroutine
init_velocity_pressure
initializes the velocity field and the pressure at the times \(dt\) and \(0\) with \(dt\) being the time step. This is done by using the functions vv_exact and pp_exact as follows: time = 0.d0
DO i= 1, SIZE(list_mode)
mode = list_mode(i)
DO j = 1, 6
!===velocity
un_m1(:,j,i) = vv_exact(j,mesh_f%rr,mode,timedt)
un (:,j,i) = vv_exact(j,mesh_f%rr,mode,time)
END DO
DO j = 1, 2
!===pressure
pn_m2(:) = pp_exact(j,mesh_c%rr,mode,time2*dt)
pn_m1 (:,j,i) = pp_exact(j,mesh_c%rr,mode,timedt)
pn (:,j,i) = pp_exact(j,mesh_c%rr,mode,time)
phin_m1(:,j,i) = pn_m1(:,j,i)  pn_m2(:)
phin (:,j,i) = Pn (:,j,i)  pn_m1(:,j,i)
ENDDO
ENDDO

The subroutine
init_temperature
initializes the temperature at the times \(dt\) and \(0\) with \(dt\) the time step. This is done by using the function temperature_exact as follows: time = 0.d0
DO i= 1, SIZE(list_mode)
mode = list_mode(i)
DO j = 1, 2
tempn_m1(:,j,i) = temperature_exact(j, mesh%rr, mode, timedt)
tempn (:,j,i) = temperature_exact(j, mesh%rr, mode, time)
ENDDO
ENDDO

The function
vv_exact
contains the analytical velocity field. It is used to initialize the velocity field and to impose Dirichlet boundary conditions on the velocity field.

The limit between fluid and solid region is defined:
REAL(KIND=8) :: r0 = 0.5d0

We construct the radial and vertical coordinates r, z.

We define the velocity field depending of its TYPE (1 and 2 for the component radial cosine and sine, 3 and 4 for the component azimuthal cosine and sine, 5 and 6 for the component vertical cosine and sine) and of its mode m as follows:
IF (TYPE==1) THEN
IF ((m==0).OR.(m==1)) THEN
vv = (rr0)**2*cos(t)*cos(z)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE==3) THEN
IF ((m==0).OR.(m==1)) THEN
vv = (rr0)**2*cos(t)*cos(z)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE==5) THEN
IF ((m==0).OR.(m==1)) THEN
vv = (rr0)*cos(t)*sin(z)/r * (3*rr0)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE==6) THEN
IF (m==1) THEN
vv = (rr0)*cos(t)*sin(z)/r * (rr0)
ELSE
vv = 0.d0
END IF
ELSE
vv = 0.d0
END IF
where \(t\) is the time. It is important to specify the null types or modes to avoid nonsense results.

The function
pp_exact
contains the analytical pressure. It is used to initialize the pressure. The pressure is equal to 0 (for every type or mode).

The function
temperature_exact
contains the analytical temperature. It is used to initialize the temperature and to impose Dirichlet boundary condition on the temperature.

The limit between fluid and solid region is defined:
REAL(KIND=8) :: r0 = 0.5d0

We construct the radial and vertical coordinates r, z.

We define the temperature depending on its TYPE (1 and 2 for cosine and sine) and on its mode as follows:
IF ((TYPE==1).AND.((m==0).OR.(m==1))) THEN
vv = r**2*(rr0)**2*sin(z)*cos(t)
ELSE
vv = 0.d0
END IF

The function
Hexact
contains the analytical magnetic field. It is used to initialize the magnetic field and enforce the boundary conditions.

We construct the radial and vertical coordinates r, z.

We define the magnetic field depending on its TYPE (1 and 2 for the component radial cosine and sine, 3 and 4 for the component azimuthal cosine and sine, 5 and 6 for the component vertical cosine and sine) and on its mode as follows:
IF (TYPE == 1) THEN
IF (m == 0) THEN
vv =  exp(z) * r**3 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 2) THEN
IF (m == 1) THEN
vv =  exp(z) * r**3 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 3) THEN
IF (m == 0) THEN
vv = exp(z) * r**3 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 4) THEN
IF (m == 1) THEN
vv = exp(z) * r**3 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 5) THEN
IF (m == 0) THEN
vv = 4 * exp(z) * r**2 * cos(t)
ELSE IF (m == 1) THEN
vv =  exp(z) * r**2 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE
IF (m == 1) THEN
vv = 4 * exp(z) * r**2 * cos(t)
ELSE
vv = 0.d0
END IF
END IF

The function
source_in_temperature
computes the source term \(f_T\) of the temperature equations.

Arrays c and lambda for the value of the volumetric heat capacity and thermal conductivity at each node must be declared.
REAL(KIND=8), DIMENSION(SIZE(rr,2)) :: vv, r, z, c, lambda

The limit between fluid and solid region is defined:
REAL(KIND=8) :: r0 = 0.5d0

We construct the radial and vertical coordinates r, z.

The c array is filled based on the data file. The solid volumetric heat capacity is used for the region \(r \le r_0\) and the fluid volumetric heat capacity is used in the fluid region \(r > r_0\).
DO i=1,SIZE(rr,2)
IF (r(i).LE.r0) THEN
c(i) = inputs%vol_heat_capacity(1)
ELSE
c(i) = inputs%vol_heat_capacity(2)
END IF
END DO

The lambda array is filled based on the data file. The solid conductivity is used for the region \(r \le r_0\) and the fluid conductivity is used in the fluid region \(r > r_0\). The temperature_diffusivity input contains the thermal conductivity when a volumetric heat capacity is used.
DO i=1,SIZE(rr,2)
IF (r(i).LE.r0) THEN
lambda(i) = inputs%temperature_diffusivity(1)
ELSE
lambda(i) = inputs%temperature_diffusivity(2)
END IF
END DO

The source term \( f_T = c\partial_t T+ c\tilde{\bu} \cdot \GRAD T  \DIV(\lambda\GRAD T) \) is defined in two parts. Firstly, we define the part \( c\partial_t T  \DIV (\lambda\GRAD T) \):
IF (TYPE==1) THEN
IF (m==0) THEN
vv =  ((r**4 + 18*r*r0  2*r**3*r0  4*r0**2 + r**2*(16.d0 + r0**2))*lambda*Cos(t) &
+ c*r**2*(r  r0)**2*Sin(t))*Sin(z)
ELSE IF (m==1) THEN
vv = ((r**4 + 16*r*r0  2*r**3*r0  3*r0**2 + r**2*(15.d0 + r0**2))*lambda*Cos(t) &
+ c*r**2*(r  r0)**2*Sin(t))*Sin(z)
ELSE
vv = 0.d0
END IF
ELSE
vv = 0.d0
END IF
Secondly, we add the part \( c\tilde{\bu} \cdot \GRAD T \), which is different from 0 only in the fluid: IF (TYPE==1) THEN
IF (m==0) THEN
DO i=1,size(rr,2)
IF (r(i)>r0) THEN
vv(i) = vv(i) + c(i)*(3*r(i)*(r(i)  r0)**4*Cos(t)**2*Sin(2*z(i)))/4.d0
END IF
END DO
ELSE IF (m==1) THEN
DO i=1,size(rr,2)
IF (r(i)>r0) THEN
vv(i) = vv(i)  c(i)*r(i)*(r(i)  r0)**4*Cos(t)**2*Sin(2*z(i))
END IF
END DO
ELSE IF (m==2) THEN
DO i=1,size(rr,2)
IF (r(i)>r0) THEN
vv(i) = vv(i)  c(i)/lambda(i)*(r(i)*(r(i)  r0)**4*Cos(t)**2*Sin(2*z(i)))/4.d0
END IF
END DO
END IF
END IF
In the second part, the array is filled cell by cell because we have to test if the node is in the fluid region.

The function
source_in_NS_momentum
computes the source term \(\alpha T \textbf{e}_z+\bef\) of the NavierStokes equations.

The coefficient \(\alpha\) of the Boussinesq force is declared and the limit between fluid and solid region is defined:
REAL(KIND=8) :: alpha, r0 = 0.5d0

The coefficient \(\alpha\) is defined based on the data file.
alpha = inputs%gravity_coefficient

We construct the radial and vertical coordinates r, z.

We construct the first part of the source term containing the Boussinesq force \(\alpha T \be_z\) and the piece of \(\bef\) that cancels it.
IF (TYPE==5) THEN
vv = alpha*(opt_tempn(:,1,i)  temperature_exact(1,rr,mode,time))
ELSE IF (TYPE==6) THEN
vv = alpha*(opt_tempn(:,2,i)  temperature_exact(2,rr,mode,time))
ELSE
vv = 0.d0
END IF
The array opt_temp is an input argument and produces the Boussinesq force. The temperature_exact function is defined in the same file and leads to the cancelling term of \(\bef\).

The part of the source term \( \partial_t\bu+\left(\ROT\bu\right)\CROSS\bu  \frac{1}{\Re}\LAP \bu +\GRAD p\) is then added. It depends on the TYPE (16) and the mode (02).
IF (TYPE==1) THEN
IF (mode==0) THEN
vv = vv (2*r*(r**4  2*r**3*r0 + r0**2 + r**2*(3 + r0**2))*Cos(time)*Cos(z) + &
(r  r0)*Re*Cos(time)**2*(14*r**3  5*r**2*r0  5*r*r0**2 + 2*r0**3 + &
(9*r**5  21*r**4*r0 + 5*r*r0**2  2*r0**3 + r**3*(14 + 15*r0**2) + r**2*(5*r0  3*r0**3))*Cos(2*z))  &
2*r**3*(r  r0)**2*Re*Cos(z)*Sin(time))/(2.*r**3*Re)
ELSE IF (mode==1) THEN
vv = vv +((r*(r**4  2*r*r0  2*r**3*r0 + 2*r0**2 + r**2*(2 + r0**2))*Cos(time)*Cos(z))  &
(3*r**2  4*r*r0 + r0**2)*Re*Cos(time)**2*(3*r**2  r0**2 + (2*r**4  4*r**3*r0 + r0**2 + &
r**2*(3 + 2*r0**2))*Cos(2*z)) + r**3*(r  r0)**2*Re*Cos(z)*Sin(time))/ (r**3*Re)
ELSE IF (mode==2) THEN
vv = vv ((r  r0)*Cos(time)**2*(4*r**2  r*r0  r0**2 + (3*r**4  7*r**3*r0 + r0**2 + &
r**2*(4 + 5*r0**2) + r*(r0  r0**3))*Cos(2*z)))/(2.*r**2)
END IF
ELSE IF (TYPE==2) THEN
IF (mode==1) THEN
vv = vv + ((r  r0)**2*Cos(time)*(2*r*Cos(z) + Re*Cos(time)*(r**4  r*r0  2*r**3*r0 + &
r0**2 + r**2*(3 + r0**2) + (3*r**2 + r*r0  r0**2)*Cos(2*z))))/(r**3*Re)
ELSE IF (mode==2) THEN
vv = vv + ((r  r0)**2*Cos(time)**2*(r**4  r*r0  2*r**3*r0 + r0**2 + r**2*(3 + r0**2) + &
(3*r**2 + r*r0  r0**2)*Cos(2*z)))/(2.*r**3)
END IF
ELSE IF (TYPE==3) THEN
IF (mode==0) THEN
vv = vv + (3*r*(r  r0)**3*(3*r  r0)*Re*Cos(time)**2 + 2*(r**4  2*r**3*r0 + r0**2 + &
r**2*(3 + r0**2))*Cos(time)*Cos(z)  2*r**2*(r  r0)**2*Re*Cos(z)*Sin(time))/(2.*r**2*Re)
ELSE IF (mode==1) THEN
vv = vv (2*r*(r**4  2*r*r0  2*r**3*r0 + 2*r0**2 + r**2*(2 + r0**2))*Cos(time)*Cos(z) + &
(r  r0)**3*(3*r  r0)*Re*Cos(time)**2*(1 + 4*r**2  Cos(2*z)) + &
2*r**3*(r  r0)**2*Re*Cos(z)*Sin(time))/(2.*r**3*Re)
ELSE IF (mode==2) THEN
vv = vv + ((r  r0)**3*(3*r  r0)*Cos(time)**2*(1  r**2 + Cos(2*z)))/(2.*r**3)
END IF
ELSE IF (TYPE==4) THEN
IF (mode==1) THEN
vv = vv + ((r  r0)**2*Cos(time)*(4*r*Cos(z) + Re*Cos(time)*((3*r + r0)**2 + &
(2*r**4 + 6*r*r0  4*r**3*r0  r0**2 + r**2*(9 + 2*r0**2))*Cos(2*z))))/(2.*r**3*Re)
ELSE IF (mode==2) THEN
vv = vv + ((r  r0)**2*Cos(time)**2*(4*r  2*r0 + (r*(4 + (r  r0)**2) + 2*r0)*Cos(2*z)))/(2.*r**2)
END IF
ELSE IF (TYPE==5) THEN
IF (mode==0) THEN
vv = vv + (((3*r**4  4*r**3*r0  r0**2 + r**2*(3 + r0**2))*Cos(time) + &
r*(r  r0)**2*(3*r**4  r*r0  6*r**3*r0 + 2*r0**2 + r**2*(4 + 3*r0**2))*Re*Cos(time)**2*Cos(z)  &
r**2*(3*r**2  4*r*r0 + r0**2)*Re*Sin(time))*Sin(z))/(r**3*Re)
ELSE IF (mode==1) THEN
vv = vv + ((3*r**3  4*r0  4*r**2*r0 + r*r0**2)*Cos(time)*Sin(z)  r*(3*r**2  4*r*r0 + r0**2)*Re*Sin(time)*Sin(z) + &
((r  r0)**2*(4*r**4  2*r*r0  8*r**3*r0 + 3*r0**2 + r**2*(5 + 4*r0**2))*Re*Cos(time)**2*Sin(2*z))/2.)/(r**2*Re)
ELSE IF (mode==2) THEN
vv = vv + ((r  r0)**2*(r**4  r*r0  2*r**3*r0 + r0**2 + r**2*(1 + r0**2))*Cos(time)**2*Sin(2*z))/(2.*r**2)
END IF
ELSE IF (TYPE==6) THEN
IF (mode==1) THEN
vv = vv ((((r**3 + 2*r0 + 2*r**2*r0  r*r0**2)*Cos(time) + 4*r*(r  r0)**3*Re*Cos(time)**2*Cos(z) + &
r*(r  r0)**2*Re*Sin(time))*Sin(z))/(r**2*Re))
ELSE IF (mode==2) THEN
vv = vv (((r  r0)**3*Cos(time)**2*Sin(2*z))/r)
END IF
END IF

The last part of the source term \( \chi(T) \GRAD \left( \frac{H^2}{2} \right)\) is then added. It depends on the TYPE (16) and the mode (04).
IF (TYPE == 1) THEN
IF (mode == 0) THEN
vv = vv  0.25 * exp(2*z) * r**7 * (215.d0 + 51*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 1) THEN
vv = vv  5 * exp(2*z) * r**7 * (11.d0 + 3*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv + 14 * exp(2*z) * r**7 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv + exp(2*z) * r**7 * (19.d0 + 3*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv + 0.75 * exp(2*z) * r**7 * (5.d0 + r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 2) THEN
IF (mode == 1) THEN
vv = vv  3 * exp(2*z) * r**7 * (24.d0 + 5*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv  4 * exp(2*z) * r**7 * (13.d0 + 3*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv  exp(2*z) * r**7 * (8.d0 + 3*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv + 2 * exp(2*z) * r**7 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 3) THEN
IF (mode == 0) THEN
vv = vv  exp(2*z) * r**7 * (15.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 1) THEN
vv = vv  0.5 * exp(2*z) * r**7 * (48.d0 + 7*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv  2 * exp(2*z) * r**7 * (5.d0 + r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv  0.5 * exp(2*z) * r**9 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv + exp(2*z) * r**7 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 4) THEN
IF (mode == 1) THEN
vv = vv  0.5 * exp(2*z) * r**7 * (25.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv  0.25 * exp(2*z) * r**7 * (61.d0 + 6*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv  0.5 * exp(2*z) * r**7 * (17.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv  0.125 * exp(2*z) * r**7 * (15.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 5) THEN
IF (mode == 0) THEN
vv = vv  0.125 * exp(2*z) * r**8 * (215.d0 + 34*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 1) THEN
vv = vv  2.5 * exp(2*z) * r**8 * (11.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv + 7 * exp(2*z) * r**8 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv + 0.5 * exp(2*z) * r**8 * (19.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv + 0.125 * exp(2*z) * r**8 * (15.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 6) THEN
IF (mode == 1) THEN
vv = vv  exp(2*z) * r**8 * (36.d0 + 5*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 2) THEN
vv = vv  2 * exp(2*z) * r**8 * (13.d0 + 2*r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 3) THEN
vv = vv  exp(2*z) * r**8 * (4.d0 + r**2) * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE IF (mode == 4) THEN
vv = vv + exp(2*z) * r**8 * (r  r0)**4 * cos(time)**4 * sin(z)**2
ELSE
vv = 0.d0
END IF
END IF

The function
Jexact_gauss
computes the source term \(\bJ\) of the magnetostatic eaquations.

We construct the radial and vertical coordinates r, z.

The current density is defined by type and mode.
IF (TYPE == 1) THEN
IF (m == 0) THEN
vv =  exp(z) * r**3 * cos(t)
ELSE IF (m == 1) THEN
vv = 4 * exp(z) * r * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 2) THEN
IF (m == 1) THEN
vv =  exp(z) * r * (1.d0 + r**2) * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 3) THEN
IF (m == 0) THEN
vv =  exp(z) * r * (8.d0 + r**2) * cos(t)
ELSE IF (m == 1) THEN
vv = 2 * exp(z) * r * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 4) THEN
IF (m == 1) THEN
vv =  exp(z) * r * (8.d0 + r**2) * cos(t)
ELSE
vv = 0.d0
END IF
ELSE IF (TYPE == 5) THEN
IF (m == 0) THEN
vv = 4 * exp(z) *r**2 * cos(t)
ELSE IF (m == 1) THEN
vv = exp(z) * r**2 * cos(t)
ELSE
vv = 0.d0
END IF
ELSE
IF (m == 1) THEN
vv = 4 * exp(z) * r**2 * cos(t)
ELSE
vv = 0.d0
END IF
END IF

The function
kelvin_force_coeff
computes the coefficient \(\chi(T)\) of the Kelvin force. It takes a real \(T\) and gives the real \(\chi(T)\). In this case \(\chi(T) = T^2\) so we implement:
All the other subroutines present in the file condlim_test_33.f90
are not used in this test. We refer to the section Fortran file condlim.f90 for a description of all the subroutines of the condlim file.
Setting in the data file
We describe the data file of this test. It is called debug_data_test_33
and can be found in the directory ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.

We use a formatted mesh by setting:
===Is mesh file formatted (true/false)?
.t.

The path and the name of the mesh are specified with the two following lines:
===Directory and name of mesh file
'.' 'SOLID_FLUID_10.FEM'
where '.' refers to the directory where the data file is, meaning ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.

We use one processor in the meridian section. It means the finite element mesh is not subdivised.
===Number of processors in meridian section
1

We solved the problem for \(5\) Fourier modes.
===Number of Fourier modes
5
The Fourier modes are not detailed so the first three modes \(0,1,2,3,4\) are solved.

We use \(5\) processors in Fourier space.
===Number of processors in Fourier space
5
It means that each processors is solving the problem for \(5/5=1\) Fourier modes.

We approximate the ferrohydrodynamic equations by setting:
===Problem type: (nst, mxw, mhd, fhd)
'fhd'

We do not restart the computations from previous results.
===Restart on velocity (true/false)
.f.
===Restart on magnetic field (true/false)
.f.
It means the computation starts from the time \(t=0\).

We use a time step of \(0.01\) and solve the problem over \(100\) time iterations.
===Time step and number of time iterations
1.d2 100

We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the NavierStokes equations.
===Number of subdomains in NavierStokes mesh
1
===List of subdomains for NavierStokes mesh
2

We set the number of boundaries with Dirichlet conditions on the velocity field and give their respective labels.
===How many
boundary pieces
for full Dirichlet BCs on velocity?
4
===List of
boundary pieces
for full Dirichlet BCs on velocity
2 3 4 5

We set the kinetic Reynolds number \(\Re\).

We give information on how to solve the matrix associated to the time marching of the velocity.

===Maximum number of iterations for velocity solver
100

===Relative tolerance for velocity solver
1.d6
===Absolute tolerance for velocity solver
1.d10

===Solver type for velocity (FGMRES, CG, ...)
GMRES
===Preconditionner type for velocity solver (HYPRE, JACOBI, MUMPS...)
MUMPS

We give information on how to solve the matrix associated to the time marching of the pressure.

===Maximum number of iterations for pressure solver
100

===Relative tolerance for pressure solver
1.d6
===Absolute tolerance for pressure solver
1.d10

===Solver type for pressure (FGMRES, CG, ...)
GMRES
===Preconditionner type for pressure solver (HYPRE, JACOBI, MUMPS...)
MUMPS

We give information on how to solve the mass matrix.

===Maximum number of iterations for mass matrix solver
100

===Relative tolerance for mass matrix solver
1.d6
===Absolute tolerance for mass matrix solver
1.d10

===Solver type for mass matrix (FGMRES, CG, ...)
CG
===Preconditionner type for mass matrix solver (HYPRE, JACOBI, MUMPS...)
MUMPS

We solve the temperature equation.
===Is there a temperature field?
.t.

We set the coefficient \(\alpha\) of Boussinesq force.
===Nondimensional gravity coefficient
1.d0

We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the temperature equation.
===Number of subdomains in temperature mesh
2
===List of subdomains for temperature mesh
1 2

We set the volumetric heat capacity \(c\) and the thermal conductivity \(\lambda\).
===Volumetric heat capacity (1:nb_dom_temp)
1.d0 2.d0
===Thermal conductivity (1:nb_dom_temp)
10.d0 1.d0

We set the number of boundaries with Dirichlet conditions on the velocity and give their respective labels.
===How many
boundary pieces
for Dirichlet BCs on temperature?
3
===List of
boundary pieces
for Dirichlet BCs on temperature
2 4 5

Setting the interfaces between regions where only the temperature is solved and regions where velocity and temperature are solved is not required for 'fhd' problems.

We give information on how to solve the matrix associated to the time marching of the temperature.

===Maximum number of iterations for temperature solver
100

===Relative tolerance for temperature solver
1.d6
===Absolute tolerance for temperature solver
1.d10

===Solver type for temperature (FGMRES, CG, ...)
GMRES
===Preconditionner type for temperature solver (HYPRE, JACOBI, MUMPS...)
MUMPS

We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the magnetic field.
===Number of subdomains in magnetic field (H) mesh
2
===List of subdomains for magnetic field (H) mesh
1 2

We set the number of interfaces in H_mesh and give their respective labels.
===Number of interfaces in H mesh
1
===List of interfaces in H mesh
3
There is no permeability jump but it is necessary to indicate that there is an interface in H_mesh in order to impose boundary conditions on the velocity on this interface.

We set the number of boundaries with Dirichlet conditions on the magnetic field and give their respective labels.
===Number of Dirichlet sides for Hxn
3
===List of Dirichlet sides for Hxn
2 4 5

We set the magnetic permeability in each domains where the magnetic field is approximated.
===Permeability in the conductive part (1:nb_dom_H)
1.d0 1.d0

We set the conductivity in each domains where the magnetic field is approximated.
===Conductivity in the conductive part (1:nb_dom_H)
1.d20 1.d20

We set the type of finite element used to approximate the magnetic field.
===Type of finite element for magnetic field
2

We set the magnetic Reynolds number \(\Rm\).
===Magnetic Reynolds number
1.d0

We set the stabilization coefficients for the divergence of the magnetic field and the penalty of the Dirichlet and interface terms.
===Stabilization coefficient (divergence)
1.d0
===Stabilization coefficient for Dirichlet H and/or interface H/H
1.d0
We note that these coefficients are usually set to \(1\).

We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the potential scalar: none, only an H formulation is used.
===Number of subdomains in magnetic potential (phi) mesh
0

We give information on how to solve the matrix associated to the time marching of the Maxwell equations.

===Maximum number of iterations for Maxwell solver
100

===Relative tolerance for Maxwell solver
1.d6
===Absolute tolerance for Maxwell solver
1.d10

===Solver type for Maxwell (FGMRES, CG, ...)
GMRES
===Preconditionner type for Maxwell solver (HYPRE, JACOBI, MUMPS...)
MUMPS

To get the total elapse time and the average time in loop minus initialization, we write:
===Verbose timing? (true/false)
.t.
These informations are written in the file lis
when you run the shell debug_SFEMaNS_template
.
Outputs and value of reference
The outputs of this test are computed with the file post_processing_debug.f90
that can be found in: ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.
To check the well behavior of the code, we compute four quantities:

The L2norm of error on u divided by the L2norm of u exact.

The L2norm of error on p.

The L2norm of error on T divided by L2norm of T exact.

The L2norm of error on H divided by L2norm of H exact.
These quantities are computed at the final time \(t=1\). They are compared to reference values to attest of the correct behavior of the code. These values of reference are in the last lines of the file debug_data_test_33
in ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. They are equal to:
============================================
(SOLID_FLUID_10.FEM)
===Reference results
1.4187255271887924E005 L2norm of error on u / L2norm of u exact
3.8560343941823795E004 L2norm of error on p
7.6074949015744113E005 L2norm of error on T / L2norm of T exact
8.6058450660818920E005 L2norm of error on H / L2norm of H exact
To conclude this test, we display the profile of the approximated pressure, velocity magnitude, temperature and magnetic field magnitude at the final time. These figures are done in the plane \(y=0\) which is the union of the half plane \(\theta=0\) and \(\theta=\pi\).
Pressure in the plane y=0.

Velocity magnitude in the plane y=0.

Temperature in the plane y=0.

Magnetic field magnitude in the plane y=0.
