SFEMaNS  version 5.3
Reference documentation for SFEMaNS
Test 36: Viscosity function of temperature

Introduction

In this example, we check the correctness of SFEMaNS in cases of problems where the variation of the kinematic viscosity with respect to temperature is taken into account. The viscosity parameter is a function of the temperature instead of being a constant. As the temperature evolves in the system, so does this parameter, which then presents time and space variations. This leads to an additional term in the RHS of the formulation, corresponding to the variable part of the viscous stresses.

The domain of computation is \(\Omega= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in [0,1) \times [0,2\pi) \times (-1,1)\} \). We enforce Dirichlet BCs for the temperature and the velocity on all the boundaries.

We solve the temperature equations:

\begin{align*} \begin{cases} \partial_t T + \bu \cdot \GRAD T - \kappa \LAP T &= f_T, \\ T_{|\Gamma} &= T_\text{bdy} , \\ T_{|t=0} &= T_0, \end{cases} \end{align*}

in the domain \(\Omega\).

We solve the Navier-Stokes equations:

\begin{align*} \begin{cases} \partial_t\bu + \left(\ROT\bu\right)\CROSS\bu + \GRAD p - div (2 \nu(T) \GRAD^s \bu) &= \bef, \\ \DIV \bu &= 0, \\ \bu_{|\Gamma} &= \bu_{\text{bdy}} , \\ \bu_{|t=0} &= \bu_0, \\ p_{|t=0} &= p_0, \end{cases} \end{align*}

in the domain \(\Omega\) as well, where \(\GRAD^s \bu = \frac{1}{2} ( \GRAD \bu + (\GRAD \bu)^T )\) is the symmetric part of the gradient.

The kinematic viscosity is a function of the temperature

\begin{align*} \nu(T) = \bar{\nu} + \tilde{\nu}(T) , \end{align*}

where \(\bar{\nu}\) is a constant, the maximum value of \(\nu(T)\), and \(\tilde{\nu}\) is the variable part.

The data are the source terms \(f_T\) and \(\bef\), the boundary data \(T_\text{bdy}\) and \(\bu_{\text{bdy}}\), and the initial data \(T_0\), \(\bu_0\) and \(p_0\). The parameters are the thermal diffusivity \(\kappa\) and the maximum kinematic viscosity \(\bar{\nu}\).

Manufactured solutions

We approximate the following analytical solution:

\begin{align*} T(r,\theta,z,t) & = \frac{r^3+e^z}{1+e}\cos(t)^2 , \\ u_r(r,\theta,z,t) &= 0, \\ u_{\theta}(r,\theta,z,t) &= r^2 \sin(t-z), \\ u_z(r,\theta,z,t) &= 0, \\ p(r,\theta,z,t) &= 0, \end{align*}

where the temperature is chosen to stay between 0 and 1 so that \(\tilde{\nu}\) stays negative. The variable part of the kinematic viscosity is defined by

\begin{align*} \tilde{\nu}(T) = - \frac{\bar{\nu}}{2} T . \end{align*}

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 RECT_10.FEM and has a mesh size of \(0.1\) for the P1 approximation. The following image shows the mesh for P1 finite elements.

fig_RECT_10.png
Finite element mesh (P1).

Information on the file condlim.f90

The initial conditions, boundary conditions and the forcing terms \(\textbf{f}\) in the Navier-Stokes equations and \(f_T\) in the temperature equations are set in the file condlim_test_36.f90. Here is a description of the subroutines and functions of interest.

  1. 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,time-dt)
    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,time-2*dt)
    pn_m1 (:,j,i) = pp_exact(j,mesh_c%rr,mode,time-dt)
    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
  2. 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, time-dt)
    tempn (:,j,i) = temperature_exact(j, mesh%rr, mode, time)
    ENDDO
    ENDDO
  3. 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 \(r\) and \(z\) coordinates of all nodes are defined. The velocity is azimuthal and carried by the mode 0.
    r = rr(1,:)
    z = rr(2,:)
    IF ((TYPE == 3) .AND. (m == 0)) THEN
    vv = r**2 * sin(t - z)
    ELSE
    vv = 0.d0
    END IF
  4. The function pp_exact contains the analytical pressure. It is used to initialize the pressure. The pressure is here equal to 0.
    vv = 0.d0
  5. The function temperature_exact contains the analytical temperature. It is used to initialize the temperature and to impose Dirichlet boundary condition on the temperature. Again, the coordinates array are defined for simplicity. The temperature is carried by the mode 0.
    r = rr(1,:)
    z = rr(2,:)
    IF ((TYPE == 1) .AND. (m == 0)) THEN
    vv = (r**3 + exp(z)) / (1.d0 + exp(1.d0)) * cos(t)**2
    ELSE
    vv = 0.d0
    END IF
  6. The function source_in_temperature computes the source term \(f_T = \partial_t T + \bu \cdot \GRAD T - \kappa \LAP T\) of the temperature equations. The second term is null. The diffusivity parameter \(\kappa\) is defined in the data file. The source term is carried by the mode 0.
    IF ((TYPE == 1) .AND. (m == 0)) THEN
    vv = - (r**3 + exp(z)) / (1.d0 + exp(1.d0)) * sin(2 * t) &
    - inputs%temperature_diffusivity(1) * (9 * r + exp(z)) / (1.d0 + exp(1.d0)) * cos(t)**2
    ELSE
    vv = 0.d0
    END IF
  7. The function source_in_NS_momentum computes the source term \(\bef = \partial_t\bu + \left(\ROT\bu\right)\CROSS\bu + \GRAD p - div (2 \nu(T) \GRAD^s \bu)\) of the Navier-Stokes equations. The implementation is done term by term (3 terms, the pressure term being null).
    r = rr(1,:)
    z = rr(2,:)
    nu_bar = inputs%Re**(-1)
    nu = nu_bar - (nu_bar/2) * (r**3 + exp(z)) / (1.d0 + exp(1.d0)) * cos(time)**2
    ! du/dt
    IF ((TYPE == 3) .AND. (mode == 0)) THEN
    vv = r**2 * cos(time - z)
    ELSE
    vv = 0.d0
    END IF
    ! (curl u) cross u
    IF ((TYPE == 1) .AND. (mode == 0)) THEN
    vv = vv - 3 * r**3 * sin(time - z)**2
    ELSE IF ((TYPE == 5) .AND. (mode == 0)) THEN
    vv = vv + r**4 * cos(time - z) * sin(time - z)
    END IF
    ! - 2 * div (nu * grads u)
    IF ((TYPE == 3) .AND. (mode == 0)) THEN
    vv = vv &
    + (nu_bar/2)/(1.d0 + exp(1.d0)) * r**2*cos(time)**2 * (3*r*sin(time - z) - exp(z)*cos(time - z)) &
    - nu * (3.d0 - r**2) * sin(time - z)
    END IF

All the other subroutines present in the file condlim_test_36.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_36 and can be found in the directory ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.

  1. We use a formatted mesh by setting:
    ===Is mesh file formatted (true/false)?
    .t.
  2. The path and the name of the mesh are specified with the two following lines:
    ===Directory and name of mesh file
    '.' 'RECT_10.FEM'
    where '.' refers to the directory where the data file is, meaning ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.
  3. We use \(4\) processors in the meridian section.
    ===Number of processors in meridian section
    4
  4. We solved the problem for \(2\) Fourier modes.
    ===Number of Fourier modes
    2
    The Fourier modes are not detailed so the first 2 modes \(0,1\) are solved. We verify that the second mode ( \(1\)) is null.
  5. We use \(2\) processors in Fourier space.
    ===Number of processors in Fourier space
    2
    It means that each processors is solving the problem for \(2/2=1\) Fourier modes.
  6. We approximate the Navier-Stokes equations by setting:
    ===Problem type: (nst, mxw, mhd, fhd)
    'nst'
  7. 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\).
  8. We use a time step of \(0.01\) and solve the problem over \(10\) time iterations.
    ===Time step and number of time iterations
    1.d-2 10
  9. We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the Navier-Stokes equations.
    ===Number of subdomains in Navier-Stokes mesh
    1
    ===List of subdomains for Navier-Stokes mesh
    1
  10. 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?
    3
    ===List of boundary pieces for full Dirichlet BCs on velocity
    2 3 4
  11. We set the constant part of the kinetic viscosity \(\bar{\nu}\) and indicate that the kinematic viscosity is variable.
    ===Kinematic viscosity
    10.d0
    ===Variable viscosity (true/false)?
    .t.
  12. The penalty term of the divergence of \(\bu\) has a coefficient of 1.
    ===Coefficient for penalty of divergence in NS?
    1.d0
  13. We give information on how to solve the matrix associated to the time marching of the velocity.
    1. ===Maximum number of iterations for velocity solver
      100
    2. ===Relative tolerance for velocity solver
      1.d-6
      ===Absolute tolerance for velocity solver
      1.d-10
    3. ===Solver type for velocity (FGMRES, CG, ...)
      GMRES
      ===Preconditionner type for velocity solver (HYPRE, JACOBI, MUMPS...)
      MUMPS
  14. We give information on how to solve the matrix associated to the time marching of the pressure.
    1. ===Maximum number of iterations for pressure solver
      100
    2. ===Relative tolerance for pressure solver
      1.d-6
      ===Absolute tolerance for pressure solver
      1.d-10
    3. ===Solver type for pressure (FGMRES, CG, ...)
      GMRES
      ===Preconditionner type for pressure solver (HYPRE, JACOBI, MUMPS...)
      MUMPS
  15. We give information on how to solve the mass matrix.
    1. ===Maximum number of iterations for mass matrix solver
      100
    2. ===Relative tolerance for mass matrix solver
      1.d-6
      ===Absolute tolerance for mass matrix solver
      1.d-10
    3. ===Solver type for mass matrix (FGMRES, CG, ...)
      CG
      ===Preconditionner type for mass matrix solver (HYPRE, JACOBI, MUMPS...)
      MUMPS
  16. We solve the temperature equation.
    ===Is there a temperature field?
    .t.
  17. 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
    1
    ===List of subdomains for temperature mesh
    1
  18. We set the thermal diffusivity parameter \(\kappa\).
    ===Diffusivity coefficient for temperature (1:nb_dom_temp)
    3.d0
  19. 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 3 4
  20. We give information on how to solve the matrix associated to the time marching of the temperature.
    1. ===Maximum number of iterations for temperature solver
      100
    2. ===Relative tolerance for temperature solver
      1.d-6
      ===Absolute tolerance for temperature solver
      1.d-10
    3. ===Solver type for temperature (FGMRES, CG, ...)
      GMRES
      ===Preconditionner type for temperature solver (HYPRE, JACOBI, MUMPS...)
      MUMPS
  21. 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:

  1. The L2-norm of error on u divided by L2-norm of u exact.
  2. The H1-norm of error on u divided by H1-norm of u exact.
  3. The L2-norm of error on p.
  4. The H1-norm of error on T divided by H1-norm of T exact.

These quantities are computed at the final time \(t=0.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_36 in ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. They are equal to:

============================================
(RECT_10.FEM)
===Reference results
5.858165337128355E-006 L2-norm of error on u / L2-norm of u exact
6.849107330069875E-005 H1-norm of error on u / H1-norm of u exact
4.361164116502296E-005 L2-norm of error on p
1.533231503293184E-006 L2-norm of error on T / L2-norm of T exact

To conclude this test, we display the profile of the approximated pressure, velocity and temperature at the final time. The figure is done in the plane \(y=0\) which is the union of the half plane \(\theta=0\) and \(\theta=\pi\).

fig_test_36_pre_tfin.png
Pressure in the plane y=0.
fig_test_36_vel_tfin.png
Azimuthal compound of the velocity in the plane y=0.
fig_test_36_temp_tfin.png
Temperature in the plane y=0.