SFEMaNS  version 4.1 (work in progress) Reference documentation for SFEMaNS
Test 17: Maxwell Equations with vacuum and variable magnetic permeability in (r,z)

### Introduction

In this example, we check the correctness of SFEMaNS for stationary magnetic problem involving a conducting with a variable magnetic permeability in (r,z) and an insulating domain. The magnetic permeability in the conducting region is given. We consider Dirichlet boundary conditions. We use P2 finite elements. This set up is approximated over one time iteration with a large time step.

We solve the Maxwell equations with the magnetic field $$\bB=\mu \bH$$ as dependent variable:

\begin{align} \begin{cases} \partial_t (\mathbf{B}) + \nabla \times \left(\frac{1}{\Rm \sigma}\nabla \times( \frac{1}{\mu^c}\mathbf{B} ) \right) = \nabla\times (\bu^\text{given} \times \mathbf{B}) + \nabla \times \left(\frac{1}{\Rm \sigma} \nabla\times \mathbf{j} \right) & \text{in } \Omega_1, \\ \text{div} (\mathbf{B}) = 0 & \text{in } \Omega_1 ,\\ -\partial_t \DIV (\mu^v \GRAD( \phi)) = 0 & \text{in } \Omega_2 ,\\ \mathbf{H}\times \bn^c + \nabla \phi \times \bn^v = 0 & \text{on } \Sigma, \\ \bB \cdot \bn^c + \mu ^v \nabla \phi \cdot \bn^v = 0 & \text{on } \Sigma, \\ \phi = \phi_{\text{bdy}} & \text{on } \Gamma,\\ \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,10] \times [0,2\pi) \times [-10,10] \; | \; r^2+z^2 \leq 100\}$$. This domain is the union of a conducting domain $$\Omega_1= \{ (r,\theta,z) \in {R}^3 : (r,\theta,z) \in [0,1] \times [0,2\pi) \times [-1,1]\}$$ and an insulating domain $$\Omega_2$$ that is the complementary of $$\Omega_1$$ in $$\Omega$$. We also set $$\Sigma= \Omega_1 \cap \Omega_2$$ and $$\Gamma= \partial \Omega_2\setminus \Sigma$$. We define the outward normals $$\bn^c, \bn^v$$ to the surface $$\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

We define the magnetic permeability in the conducting region as follows:

\begin{align*} \mu^c(r,z)=\frac{1}{1+f_{17}(r,z)}, \end{align*}

with

\begin{align*} f_{17}(r,z)=2^6\left(1-\frac{1}{\text{ratio}_\mu}\right) \left(r(1-r)(z^2-1) \right)^3, \end{align*}

where $$\text{ratio}_\mu=50$$ represents the fraction of the minimum over the maximum of the magnetic permeability in the conducting region.

Tha manufactured solutions considered in this test involve two bessel functions denoted $$BESSJ0$$ and $$BESSJ1$$.They are defined for any positive real argument $$x$$ and satisfy the relation $$\partial_x BESSJ0 = - BESSJ1$$. These functions are defined in the file bessel.f90 in the following directory: (SFEMaNS_DIR)/FEMSUB. We approximate the following analytical solutions: \begin{align*} H_r(r,\theta,z,t) &= -(1+f_{17}(r,z)) \cosh(z) BESSJ(1,r), \\ H_{\theta}(r,\theta,z,t) &=0, \\ H_z(r,\theta,z,t) &= (1+f_{17}(r,z)) \sinh(z) BESSJ(0,r) , \\ \phi(r,\theta,z,t) &= \cosh(z) BESSJ(0,r), \end{align*} and remind that $$\bB=\mu\bH$$. We also set the given velocity field to zero. \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_17_0.1.FEM. The mesh size for the P1 approximation is $$0.1$$ in $$\Omega_1$$ and $$1$$ on the boundary $$\Gamma$$. You can generate this mesh with the files in the following directory: (SFEMaNS_MESH_GEN_DIR)/EXAMPLES/EXAMPLES_MANUFACTURED_SOLUTIONS/mesh_17_0.1.FEM. The following images show the mesh for P1 finite elements for the conducting and vacuum regions.

 Finite element mesh (P1) of the conducting region. 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_17.f90. This condlim also uses functions of the file test_17.f90 to define the function $$f_{17}$$, the magnetic permeability and its gradient. Here is a description of the subroutines and functions of interest of the file condlim_test_17.f90.

1. 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
2. The function Hexact contains the analytical magnetic field. It is used to initialize the magnetic field.
1. If the Fourier mode m is not equal to 0, we set the magnetic field to zero.
IF (m/=0) THEN
vv(:) = 0.d0
RETURN
END IF
2. We define the function $$f_{17}$$ with the function f_test_T17 from the file test_17.f90.
vv = f_test_T17(rr(1,:),rr(2,:))
3. For the Fourier mode $$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 !Bessel functions defined for reals
vv = COSH(rr(2,:))*(1+vv)
DO n = 1, SIZE(rr,2)
vv(n) = -BESSJ1(rr(1,n))*vv(n)
END DO
ELSE IF (TYPE==5) THEN
vv = SINH(rr(2,:))*(1+vv)
DO n = 1, SIZE(rr,2)
vv(n) = BESSJ0(rr(1,n))*vv(n)
END DO
ELSE
vv = 0.d0
END IF
RETURN
3. 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. If the Fourier mode m is not equal to 0, we set the scalar potential to zero.
IF (m/=0) THEN
vv = 0.d0
RETURN
END IF
2. We define the radial and vertical coordinates $$(r, z)$$.
r = rr(1,:)
z = rr(2,:)
3. For the Fourier mode $$m=0$$, we define the scalar potential depending of its TYPE (1 for cosine and 2 for sine) as follows:
IF (TYPE==1) THEN !Bessel functions defined for reals
DO n = 1, SIZE(rr,2)
vv(n) = BESSJ0(r(n))*COSH(z(n))
END DO
ELSE
vv = 0.d0
END IF
RETURN
4. The function Vexact is used to define the given velocity field $$\bu^\text{given}$$. It is set to zero.
vv = 0.d0
5. The function Jexact_gauss is used to define the source term $$\textbf{j}$$. We remind that $$\bu^\text{given}=0$$ and $$\partial_t \textbf{H}=0$$ so it is defined such that $$\textbf{j}=\ROT \bH$$.
1. If the Fourier mode m is not equal to 0, it is set to zero.
IF (m/=0) THEN
vv = 0.d0
RETURN
END IF
2. We define the radial and vertical coordinates $$r, z$$.
r = rr(1)
z = rr(2)
3. For the Fourier mode $$m=0$$, we define the source term 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==3) THEN
vv = -dfdz_test_T17(r,z)*BESSJ1(r)*COSH(z) &
-dfdr_test_T17(r,z)*BESSJ0(r)*SINH(z)
ELSE
vv = 0.d0
END IF
RETURN
6. The function mu_bar_in_fourier_space defines the magnetic permeability that depends of the radial and vertical coordinates. It is done by using the function mu_bar_in_fourier_space_anal_T17 of the file test_17.f90.
IF( PRESENT(pts) .AND. PRESENT(pts_ids) ) THEN
vv=mu_bar_in_fourier_space_anal_T17(H_mesh,nb,ne,pts,pts_ids)
ELSE
vv=mu_bar_in_fourier_space_anal_T17(H_mesh,nb,ne)
END IF
RETURN
When the magnetic permeability depends of the time or the azimuthal direction (set "===Is permeability variable in theta (true/false)?" to true in the data file), this function is used to define a stabilization term mu_bar. It needs to be smaller than mu everywhere in the domain. The magnetic permeability is then defined with the function mu_in_real_space.
7. The function grad_mu_bar_in_fourier_space defines the gradient of the magnetic permeability. It is done by using the function grad_mu_bar_in_fourier_space_anal_T17 of the file test_17.f90.
RETURN
When the magnetic permeability depends of the time or the azimuthal direction, this function is used to define the gradient of a stabilization term mu_bar.

All the other subroutines present in the file condlim_test_17.f90 are not used in this test. We remind that the bessel function $$BESSJ0$$ and $$BESSJ1$$ 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. The following describes the functions of interest of the file test_17.f90. 1. First we define two real numbers $$\text{ratio}_\mu$$ and $$b$$. REAL (KIND=8), PARAMETER, PRIVATE :: ratio_mu_T17 = 50.d0 ! the variation of mu REAL (KIND=8), PRIVATE :: b_factor_T17_anal = (2**6) * (1.d0 - 1/ratio_mu_T17) 2. The function f_test_T17 defines the function $$f_{17}$$. vv = b_factor_t17_anal*(r*(1-r)*(z**2-1))**3 RETURN 3. The function dfdr_test_T17 defines the r-derivative of $$f_{17}$$. vv = 3 * b_factor_t17_anal * (z**2-1)**3 * (r*(1-r))**2 * (1-2*r) RETURN 4. The function dfdz_test_T17 defines the z-derivative of $$f_{17}$$. vv = 3*b_factor_t17_anal*(r*(1-r))**3*(z**2-1)**2*(2*z) RETURN 5. The function mu_bar_in_fourier_space_anal_T17 defines the magnetic permeability. IF( PRESENT(pts) .AND. PRESENT(pts_ids) ) THEN !Computing mu at pts r=pts(1,nb:ne) z=pts(2,nb:ne) ELSE r=H_mesh%rr(1,nb:ne) !Computing mu at nodes z=H_mesh%rr(2,nb:ne) END IF vv=1.d0/(1.d0+f_test_T17(r,z)) RETURN 6. The function grad_mu_bar_in_fourier_space_anal_T17 defines the gradient of the magnetic permeability on gauss points. r=pt(1) z=pt(2) tmp=(1.d0 +f_test_T17(r,z))**2 vv(1)=-dfdr_test_T17(r(1),z(1))/tmp(1) vv(2)=-dfdz_test_T17(r(1),z(1))/tmp(1) RETURN ### Setting in the data file We describe the data file of this test. It is called debug_data_test_17 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_17_0.1.FEM'
where '.' refers to the directory where the data file is, meaning ($SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. 3. We use one processor in the meridian section. It means the finite element mesh is not subdivised. ===Number of processors in meridian section 1 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 do not select specific Fourier modes to solve. ===Select Fourier modes? (true/false) .f. As a consequence, the code approximates the problem on the first Fourier mode $$m=0$$. 7. We approximate the Maxwell equations by setting: ===Problem type: (nst, mxw, mhd, fhd) 'mxw' 8. 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$$. 9. We use a time step of $$10^{40}$$ and solve the problem over $$1$$ time iteration. ===Time step and number of time iterations 1d40, 1 10. We use the magnetic field $$\textbf{B}$$ as dependent variable for the Maxwell equations. ===Solve Maxwell with H (true) or B (false)? .f. This parameter is set to false by default. 11. We set the number of domains and their label, see the files associated to the generation of the mesh, where the code approximates the Maxwell equations. ===Number of subdomains in magnetic field (H) mesh 1 ===List of subdomains for magnetic field (H) mesh 1 12. We set the number of interface in H_mesh. ===Number of interfaces in H mesh 0 Such interfaces represent interfaces with discontinuities in magnetic permeability or interfaces between the magnetic field mesh and the temperature or the velocity field meshes. 13. We set the number of boundaries with Dirichlet conditions on the magnetic field. ===Number of Dirichlet sides for Hxn 0 14. The magnetic permeability is defined with a function of the file condlim_test_17.f90. ===Is permeability defined analytically (true/false)? .t. 15. We construct the magnetic permeability on the gauss points without using its value on the nodes and a finite element interpolation. ===Use FEM Interpolation for magnetic permeability (true/false)? .f. 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 2 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 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 2 23. We set the magnetic permeability in the vacuum domain. ===Permeability in vacuum 1 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 divergence of the magnetic field $$\textbf{B}=\mu\textbf{H}$$.
2. The L2 norm of the error on the curl of the magnetic field $$\textbf{H}$$.
3. The L2 norm of the error on the magnetic field $$\textbf{H}$$.
4. The L2 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_17 in the directory (\$SFEMaNS_DIR)/MHD_DATA_TEST_CONV_PETSC. They are equal to:

============================================
mesh_17_0.1.FEM, dt=1d40, it_max=1
===Reference results
3.658447514681710E-003 !L2 norm of div(mu (H-Hexact))
4.500377040641551E-004 !L2 norm of curl(H-Hexact)
5.441900368783823E-003 !L2 norm of H-Hexact
1.586225425289322E-003 !L2 norm of phi-phiexact

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$$.

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