SFEMaNS  version 4.1 (work in progress)
Reference documentation for SFEMaNS
 All Classes Files Functions Variables Groups Pages
Test 4: Maxwell with vacuum periodic P1-P2

Introduction

In this example, we check the correctness of SFEMaNS for a magnetic problem involving a conducting and an insulating domain. We consider periodic and Dirichlet boundary conditions.

We solve the Maxwell equations:

\begin{align} \begin{cases} \partial_t (\mu^c \mathbf{H}) + \nabla \times \left(\frac{1}{\Rm \sigma}\nabla \times \mathbf{H} \right) = \nabla\times (\bu^\text{given} \times \mu^c \mathbf{H}) + \nabla \times \left(\frac{1}{\Rm \sigma} \nabla\times \mathbf{j} \right) & \text{in } \Omega_1, \\ \text{div} (\mu^c \mathbf {H}) = 0 & \text{in } \Omega_1 ,\\ - \partial_t \DIV (\mu^v \GRAD( \phi)) = 0 & \text{in } \Omega_2 ,\\ \mathbf{H}_{|\{z=0\}} = \mathbf{H}_{|\{z=1\}}, & \\ \phi_{|\{z=0\}} = \phi_{|\{z=1\}}, & \\ \bH \times \bn^c + \nabla \phi \times \bn^v = 0 & \text{on } \Sigma, \\ \mu^c \bH \cdot \bn^c + \mu ^v \nabla \phi \cdot \bn^v = 0 & \text{on } \Sigma, \\ \phi = \phi_{\text{bdy}} & \text{on } \Gamma_2,\\ \bH_{|t=0}= \bH_0, \\ \phi_{|t=0}= \phi _0, \end{cases} \end{align}

in the domain \(\Omega= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in [0,1] \times [0,2\pi) \times [0,1]\} \). This domain is the union of a conducting domain \(\Omega_1= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in [0,0.5] \times [0,2\pi) \times [0,1]\} \) and an insulating domain \(\Omega_2= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in [0.5,1] \times [0,2\pi) \times [0,1]\} \). We also set \(\Sigma= \Omega_1 \cap \Omega_2 \), \(\Gamma_1= \partial \Omega_1\setminus \Sigma \) and \(\Gamma_2= \partial \Omega_2\setminus \Sigma \). The data are the source term \(\mathbf{j}\), the given velocity \(\bu^\text{given}\), the boundary data \(\phi_{\text{bdy}}\), the initial datas \(\bH_0\) and \(\phi _0\). The parameter \(\Rm\) is the magnetic Reynolds number. The parameter \(\mu^c\), respectively \(\mu^v\), is the magnetic permeability of the conducting region \(\Omega_1\), respectively of the vacuum region \(\Omega_2\). The parameter \(\sigma\) is the conductivity in the conducting region \(\Omega_1\).

Manufactured solutions

Tha manufactured solutions considered in this test involve the modified bessel function of the third kind. These functions are defined for an integer \(n\) and for any positive real argument \(x\). In the following, we denote this function \(BESSK(n,x)\). They are defined in the file bessel.f90 in the following directory: ($SFEMaNS_DIR)/FEMSUB. We refer to C.W. CLENSHAW, CHEBYSHEV SERIES FOR MATHEMATICAL FUNCTIONS, MATHEMATICAL TABLES, VOL.5, 1962 for more details on these functions and their definition.

We introduce the following real numbers:

\begin{align*} f_{1,r_0} &= \frac{1}{k_0} \left(\frac{2}{r_0} -\frac{m_0}{r_0} BESSK(m_0,z_0) \right), \\f_{2,r_0} &= \frac{m_0}{k_0 r_0} - \left( -BESSK(m_0-1,z_0) - \frac{m_0}{k_0 r_0} BESSK(m_0,z_0) \right), \\df_{2,r_0}&= \frac{m_0}{r_0} f_{1,r_0} - f_{2,r_0} -k_0 BESSK(m_0,z_0), \\A &= 3 f_{2,r_0} - r_0 df_{2,r_0}, \\B &= r_0 df_{2,r_0} - 2 f_{2,r_0}, \\f_1 &= (\frac{r}{r_0})^2 f_{1,r_0}, \\f_2 &= (\frac{r}{r_0})^2 \left( A+ B\frac{r}{r_0} \right), \\f_4 &= \frac{r}{r_0^2} \left( 3 A+ 4 B\frac{r}{r_0} \right) - m_0\frac{r}{r_0^2} f_{1,r_0}, \\df_3 &= \frac{2r}{r_0^2}, \end{align*}

with \(m_0=1\), \(r_0=0.5\), \(k_0=2\pi\) and \(z_0=r_0 k_0\).

We approximate the following analytical solutions:

\begin{align*} H_r(r,\theta,z,t) &= \left(\frac{m_0 r}{r_0^2} -k_0 f_2\right) \cos(k_0 z) \cos(m_0\theta)\cos(t), \\ H_{\theta}(r,\theta,z,t) &= \left(k_0 f_1-df_3\right) \cos(k_0 z)\sin(m_0\theta) \cos(t), \\ H_z(r,\theta,z,t) &= f_4 \sin(k_0 z) \cos(m_0\theta)\cos(t), \\ \phi(r,\theta,z,t) &= BESS(m_0,k_0 r) \cos(k_0 z) \cos(m_0\theta) \cos(t). \end{align*}

We also set the given velocity field as follows:

\begin{align*} u^\text{given}_r(r,\theta,z,t) &= 0, \\ u^\text{given}_{\theta}(r,\theta,z,t) &= 0, \\ u^\text{given}_z(r,\theta,z,t) &= 0. \end{align*}

The source term \( \mathbf{j} \) and the boundary data \(\phi_{\text{bdy}}\) are computed accordingly.

Generation of the mesh

The finite element mesh used for this test is named Mesh_10_form.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/Mesh_10_form. The following images shows the mesh for P1 finite elements for the conducting and vacuum regions.

fig_Mesh_10_form.png
Finite element mesh (P1) of the conducting region.
fig_Mesh_10_form_vacuum.png
Finite element mesh (P1) of the vacuum region.

Information on the file condlim.f90

The initial conditions, boundary conditions and the forcing term \(\textbf{j}\) in the Maxwell equations are set in the file condlim_test_4.f90. Here is a description of the subroutines and functions of interest.

  1. First we define the numbers \(r_0\), \(k_0\) and \(m_0\) at the begining of the module so that every subroutines has access to these real numbers.
    REAL(KIND=8), PRIVATE :: r0 = 0.5d0
    REAL(KIND=8), PRIVATE :: k0=6.28318530717958d0
    INTEGER , PRIVATE :: m0=1
  2. The subroutine init_maxwell initializes the magnetic field and the scalar potential at the time \(-dt\) and \(0\) with \(dt\) being the time step. It is done by using the functions Hexact, Phiexact as follows:
    time = -dt
    DO k=1,6
    DO i=1, SIZE(list_mode)
    Hn1(:,k,i) = Hexact(H_mesh,k, H_mesh%rr, list_mode(i), mu_H_field, time)
    IF (inputs%nb_dom_phi>0) THEN
    IF (k<3) THEN
    phin1(:,k,i) = Phiexact(k, phi_mesh%rr, list_mode(i) , mu_phi, time)
    ENDIF
    END IF
    ENDDO
    ENDDO
    time = time + dt
    DO k=1,6
    DO i=1, SIZE(list_mode)
    Hn(:,k,i) = Hexact(H_mesh,k, H_mesh%rr, list_mode(i), mu_H_field, time)
    IF (inputs%nb_dom_phi>0) THEN
    IF (k<3) THEN
    phin(:,k,i) = Phiexact(k, phi_mesh%rr, list_mode(i), mu_phi, time)
    ENDIF
    END IF
    ENDDO
    ENDDO
  3. The function Hexact contains the analytical magnetic field. It is used to initialize the magnetic field and to impose Dirichlet boundary conditions on \(\textbf{H}\times\textbf{n}\) with \(\textbf{n}\) the outter normal vector.
    1. We define the radial and vertical coordinates r, z.
      r = rr(1,:)
      z = rr(2,:)
    2. If the Fourier mode is not equal to \(m_0\), we set the magnetic field to zero.
      IF (m/=m0) THEN
      vv = 0
      RETURN
      END IF
    3. We define various real numbers.
      !value in r0
      z0 = r0*k0
      f3_r0 = 1.d0
      df3_r0 = 2.d0/r0
      f1_r0 = 1.d0/k0*(df3_r0-m0/r0*BESSK(m0,z0))
      !f2_r0 = m0/(k0*r0)*f3_r0 - (BESSI(m0-1,z0)-m0/(k0*r0)*BESSI(m0,z0))
      f2_r0 = m0/(k0*r0)*f3_r0 - (-BESSK(m0-1,z0)-m0/(k0*r0)*BESSK(m0,z0))
      df2_r0 = (m0/r0*f1_r0-f2_r0/r0-k0*BESSK(m0,z0))
      !to evaluate f2
      A = 3*f2_r0 - r0*df2_r0
      B = r0*df2_r0-2*f2_r0
      !function for all points
      f1 = (r/r0)**2*f1_r0
      f2 = (r/r0)**2*(A+B*r/r0)
      f3 = (r/r0)**2
      df3 = 2*r/r0**2
      df2 = r/r0**2*(2*A+3*B*r/r0)
      f4 = r/r0**2*(A+B*r/r0) + df2 - m0*r/r0**2*f1_r0
    4. For the Fourier modes \(m_0\), we define the magnetic 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) as follows:
      IF (TYPE == 1) THEN
      vv = (m0*r/r0**2-k0*f2)*COS(k0*z)
      ELSEIF (TYPE == 2) THEN
      vv = 0.d0
      ELSEIF (TYPE ==3) THEN
      vv = 0.d0
      ELSEIF (TYPE == 4) THEN
      vv = (k0*f1-df3)*COS(k0*z)
      ELSEIF (TYPE == 5) THEN
      vv = f4*SIN(k0*z)
      ELSEIF (TYPE == 6) THEN
      vv = 0.d0
      ENDIF
      vv = vv * COS(t)
      RETURN
  4. The function Phiexact contains the analytical scalar potential. It is used to initialize the scalar potential and to impose Dirichlet boundary conditions on the scalar potential.
    1. We define the radial and vertical coordinates r, z.
      r = rr(1,:)
      z = rr(2,:)
    2. We set the scalar potential to zero.
      vv(:) = 0.d0
    3. If we consider a Fourier mode different than \(m_0\) we are done.
      IF (m/=m0) RETURN
    4. For the Fourier modes \(m_0\), we define the scalar potential depending of its TYPE (1 for cosine and 2 for sine) as follows:
      IF (TYPE == 1) THEN
      DO n= 1, SIZE(rr,2)
      vv(n) = BESSK(m0,k0*r(n))*COS(k0*z(n))
      END DO
      ELSEIF (TYPE == 2) THEN
      vv = 0.d0
      ENDIF
      vv = vv*COS(t)
      RETURN
  5. The function Vexact is used to define the given velocity field \(\bu^\text{given}\). It is set to zero.
    vv = 0.d0
    RETURN
  6. The function Jexact_gauss is used to define the source term \(\textbf{j}\). It uses the function Eexact_gauss.
  7. The function Eexact_gauss is used to define the part of Jexact that matches the time derivative of the magnetic field.

All the other subroutines present in the file condlim_test_4.f90 are not used in this test. We remind that the bessel function \(BESSK\) are defined in the file bessel.f90 in the following directory: ($SFEMaNS_DIR)/FEMSUB. 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_4 and can be found in the following 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
    '.' 'Mesh_10_form.FEM'
    where '.' refers to the directory where the data file is, meaning ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.
  3. We use two processors in the meridian section. It means the finite element mesh is subdivised in two.
    ===Number of processors in meridian section
    2
  4. We solve the problem for \(1\) Fourier modes.
    ===Number of Fourier modes
    1
  5. We use \(1\) processors in Fourier space.
    ===Number of processors in Fourier space
    1
    It means that each processors is solving the problem for \(1/1=1\) Fourier modes.
  6. We select specific Fourier modes to solve by setting:
    ===Select Fourier modes? (true/false)
    .t.
  7. We give the list of the Fourier modes to solve.
    ===List of Fourier modes (if select_mode=.TRUE.)
    1
  8. We approximate the Maxwell equations by setting:
    ===Problem type: (nst, mxw, mhd, fhd)
    'mxw'
  9. 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 note that we need to say if we use a restart for the velocity. If yes, the \(\bu^\text{given}\) comes from a suite file and not the function Vexact.
  10. We use a time step of \(0.01\) and solve the problem over \(100\) time iterations.
    ===Time step and number of time iterations
    .01d0, 100
  11. We set periodic boundary condition.
    1. We set the number of pair of boundaries that has to be periodic.
      ===How many pieces of periodic boundary?
      1
    2. We give the label of the boundaries and the vector that lead to the first boundary to the second one.
      ===Indices of periodic boundaries and corresponding vectors
      4 2 .0 1.
      We note that we need as much as lines as the number of pairs of boundaries with periodic condition.
  12. 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
    1
    ===List of subdomains for magnetic field (H) mesh
    1
  13. We set the number of interface in H_mesh and give their respective labels.
    ===Number of interfaces in H mesh
    0
    ===List of interfaces in H mesh
    xx
    Such interfaces represent interfaces with discontinuities in magnetic permeability or interfaces between the magnetic field mesh and the temperature or the velocity field meshes.
  14. We set the number of boundaries with Dirichlet conditions on the magnetic field and give their respective labels.
    ===Number of Dirichlet sides for Hxn
    0
    ===List of Dirichlet sides for Hxn
    xx
  15. 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
  16. We set the conductivity in each domains where the magnetic field is approximated.
    ===Conductivity in the conductive part (1:nb_dom_H)
    1.d0
  17. We set the type of finite element used to approximate the magnetic field.
    ===Type of finite element for magnetic field
    1
  18. We set the magnetic Reynolds number \(\Rm\).
    ===Magnetic Reynolds number
    1.d0
  19. We set stabilization coefficient 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 these coefficients are usually set to \(1\).
  20. We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the scalar potential.
    ===Number of subdomains in magnetic potential (phi) mesh
    1
    ===List of subdomains for magnetic potential (phi) mesh
    2
  21. We set the number of boundaries with Dirichlet conditions on the scalar potential and give their respective labels.
    ===How many boundary pieces for Dirichlet BCs on phi?
    1
    ===List of boundary pieces for Dirichlet BCs on phi
    3
  22. We set the number of interface between the magnetic field and the scalar potential and give their respective labels.
    ===Number of interfaces between H and phi
    1
    ===List of interfaces between H and phi
    5
  23. We set the magnetic permeability in the vacuum domain.
    ===Permeability in vacuum
    1.d0
  24. We set the type of finite element used to approximate the scalar potential.
    ===Type of finite element for scalar potential
    2
  25. We set a stabilization coefficient used to penalize term across the interface between the magnetic field and the scalar potential.
    ===Stabilization coefficient (interface H/phi)
    1.d0
    We note this coefficient is usually set to \(1\).
  26. We give information on how to solve the matrix associated to the time marching of the Maxwell equations.
    1. ===Maximum number of iterations for Maxwell solver
      100
    2. ===Relative tolerance for Maxwell solver
      1.d-6
      ===Absolute tolerance for Maxwell solver
      1.d-10
    3. ===Solver type for Maxwell (FGMRES, CG, ...)
      GMRES
      ===Preconditionner type for Maxwell solver (HYPRE, JACOBI, MUMPS...)
      MUMPS

Outputs and value of reference

The outputs of this test are computed with the file post_processing_debug.f90 that can be found in the following directory: ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC.

To check the well behavior of the code, we compute four quantities:

  1. The L2 norm of the error on the magnetic field \(\textbf{H}\).
  2. The L2 norm of the error on the curl of the magnetic field \(\textbf{H}\).
  3. The L2 norm of the divergence of the magnetic field \(\textbf{B}=\mu\bH\).
  4. The H1 norm of the error on the scalar potential.

They are compared to reference values to attest of the correctness of the code. These values of reference are in the last lines of the file debug_data_test_4 in the directory ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. They are equal to:

============================================
Mesh_10_form.FEM, P1P2
===Reference results
0.117284337370832 L2 error on Hn
0.158175579990508 L2 error on Curl(Hn)
0.276743273545775 L2 norm of Div(mu Hn)
0.236676729274824 H1 error on phin

To conclude this test, we show the profile of the approximated magnetic field \(\textbf{H}\) and scalar potential \(\phi\) 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\).

fig_test_04_mag_tfin.png
Magnetic field magnitude in the plane plane y=0.
fig_test_04_phi_tfin.png
Scalar potential in the plane plane y=0.