Introduction
In this example, we check the correctness of SFEMaNS for a thermohydrodynamic problem involving Dirichlet boundary conditions. The difference with tests 8 and 9 is that the temperature is computed in a domain including a solid subdomain in addition to the fluid subdomain. 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 of a solid by a fluid for example.
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 + \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 data are the source terms \(f_T\) and \(\bef\), the boundary data \(T_\text{bdy}\) and \(\bu_{\text{bdy}}\), the initial data \(T_0\), \(\bu_0\) and \(p_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\) and the thermal gravity number \(\alpha\).
Manufactured solutions
We approximate the following analytical solutions:
\begin{align*} T(r,\theta,z,t) & = \frac{1}{\lambda} r^2(rr_0)\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, \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.
The source terms \(f_T, \bef\) and the boundary data \(T_\text{bdy}, \bu_{\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 \(\textbf{f}\) in the NavierStokes equations and \(f_T\) in the temperature equations are set in the file condlim_test_30.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 thermal conductivity.
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

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)*sin(z)*cos(t) / lambda
ELSE
vv = 0.d0
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 = ((9*r + r**3 + 4*r0  r**2*r0) * lambda * Cos(t) + &
c * r**2 * (r + r0) * Sin(t)) * Sin(z) / lambda
ELSE IF (m==1) THEN
vv = ((8*r + r**3 + 3*r0  r**2*r0) * lambda * Cos(t) + &
c * r**2 * (r + r0) * Sin(t)) * Sin(z) / lambda
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) + (3*c(i) * r(i) * (r(i)  r0)**2 * r0 &
* Cos(t)**2 * Sin(2*z(i))) / (4 * lambda(i))
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)**2 * r0 &
* Cos(t)**2 * Sin(2*z(i))) / lambda(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) * r(i) * (r(i)  r0)**2 * r0 &
* Cos(t)**2 * Sin(2*z(i))) / (4 *lambda(i))
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 rest 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).
All the other subroutines present in the file condlim_test_30.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_30
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 \(3\) Fourier modes.
===Number of Fourier modes
3
The Fourier modes are not detailed so the first three modes \(0,1,2\) are solved.

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

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

We do not restart the computations from previous results.
===Restart on velocity (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

We set the interfaces between regions where only the temperature is solved and regions where velocity and temperature are solved. It is necessary to impose boundary conditions on the velocity at these interfaces.
===Number of interfaces between velocity and temperature only domains (for nst applications)
1
===List of interfaces between velocity and temperature only domains (for nst applications)
3

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

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 H1norm of error on T divided by H1norm of T 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_30
in ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. They are equal to:
============================================
(SOLID_FLUID_10.FEM)
===Reference results
1.3865165143422277E005 L2norm of error on u / L2norm of u exact
3.7119903151496659E004 L2norm of error on p
1.9280969339793415E005 L2norm of error on T / L2norm of T exact
2.2531697583639946E004 H1norm of error on T / H1norm of T exact
To conclude this test, we display the profile of the approximated pressure, velocity magnitude and temperature 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.
