You are on page 1of 60

Cite as: Tassone, A.: Magnetic induction and electric potential solvers for incompressible MHD flows.

In
Proceedings of CFD with OpenSource Software, 2016, Edited by Nilsson. H.,
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2016

CFD with OpenSource software


A course at Chalmers University of Technology
Taught by Håkan Nilsson

Project work:

Magnetic induction and electric potential


solvers for incompressible MHD flows

Developed for OpenFOAM-4.x

Author:
Peer reviewed by:
Alessandro Tassone
Håkan Nilsson
Sapienza University of Rome
Milad Setareh
alessandro.tassone@uniroma1.it

Licensed under CC-BY-NC-SA, https://creativecommons.org/licenses/

Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some
other OpenSource software are introduced to the students. Any reader should be aware that it
might not be free of errors. Still, it might be useful for someone who would like learn some details
similar to the ones presented in the report and in the accompanying files. The material has gone
through a review process. The role of the reviewer is to go through the tutorial and make sure that
it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no
responsibility for the contents.

January 16, 2017


Learning outcomes

The main requirements of a tutorial is that it should teach the four points: How to use it, The
theory of it, How it is implemented, and How to modify it. Therefore the list of learning outcomes
is organized with those headers.

The reader will learn:

How to use it:


• Simulation of liquid metal MHD flows

• Modeling of 2D MHD flows in rectangular ducts with walls of uniform and non-uniform elec-
trical conductivity
• How to use the standard OpenFOAM solver (mhdFoam) to simulate an Hartmann flow
The theory of it:

• The equations and the fundamental parameters governing an incompressible MHD flow
• Induction-less approximation of the MHD equations and the φ-formulation
How it is implemented:

• How a solver based on the magnetic induction formulation is implemented (mhdFoam)


• What are the conditions to meet to have a monotonic, convergent MHD numerical scheme
How to modify it
• How to write from scratch a solver based on the φ-formulation (epotFoam)

1
Prerequisites

The reader is expected to know the following in order to get maximum benefit out of this report:
• Basic knowledge about hydrodynamics, which can be acquired reading: G.K. Batchelor, An
introduction to fluid dynamics, 2000, Cambridge University Press.
• Fundamental knowledge about the finite volume method and, in general, computational fluid
dynamics codes, which can be acquired reading: H.K. Versteeg & W. Malalasekhara, An
Introduction to Computational Fluid Dynamics:The finite volume method, 2007, Longman
Scientific and Technical.
• A certain acquaintance with the principles of electromagnetism, which can be obtained reading:
W.K.H. Panofsky & M. Phillips, Classical electricity and magnetism, 2005, Courier Corpora-
tion
• The reader should know how to use the OpenFOAM to run tutorials, like damBreak and cavity.
• Have read the OpenFOAM Programmer’s Guide.

2
Contents

1 Introduction 4

2 Theoretical background 5
2.1 MHD equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Fundamental parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 The mhdFoam solver 9


3.1 Code description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Hartmann tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2.1 The blockMeshDict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2.2 The 0 directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.3 The constant directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.4 The system directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.5 Results for M = 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2.6 Results for M = 50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4 The epotFoam solver 26


4.1 Code description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2 Code implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.2.1 epotFoam.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2.2 createFields.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5 Tutorials for laminar 2D MHD flow 32


5.1 Case directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2 Shercliff tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2.1 mhdFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.2.2 epotFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.3 Hunt tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.3.1 mhdFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.3.2 epotFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

3
Chapter 1

Introduction

This tutorial describes the theoretical background and the implementation of OpenFOAM solvers
suitable for the simulation of incompressible magneto-hydrodynamic (MHD) flows. This class is
a topic of interest for many research activities and industrial applications including nuclear fusion
reactors, materials engineering and metallurgy. The main purpose of this document is to help
the reader to get accustomed with the relevant phenomena and peculiar challenges of this kind of
problems. In order to accomplish this goal it will focus the attention on the 2D MHD flows that
arise in a rectangular duct with walls of arbitrary electrical conductivity when an electric conductive
fluid moves in the presence of a transverse magnetic field.
In chapter 2, the equations and the fundamental parameters that govern a MHD flow are briefly
presented. The MHD governing equations would be presented both in the complete structure,
which accounts for the self-induced magnetic field and is therefore dubbed B-formulation, and in the
relevant induction-less approximation which is employed for the treatment of flows characterized by
a low value of the magnetic Reynolds number (Rem ). Since this assumption is verified for almost
all the applications involving liquid metals, an alternative formulation based on it called electric
potential or φ-formulation, will be discussed. Both the formulation can be employed to model the
2D MHD flows and, in fact, they have been used.
In chapter 3, the solver available in the OpenFOAM current distribution, called mhdFoam, would
be described. Based on the B-formulation, it was developed by Henry Weller and it was presented,
among other solvers, in what can be considered as the ”founding paper” of the OpenFoam software
[1]. The code algorithm is described and presented in the tutorial distributed with the solver: the
Hartmann problem. This is the MHD flow that occurs in the presence of a transverse applied
magnetic field, constant and uniform, which is bounded by two plates parallel, infinite, insulating
and orthogonal to the magnetic field. The case directory structure would be described and then
employed to simulate the flow for different values of the Hartmann number.
In chapter 4, a solver based on the φ-formulation (epotFoam) is presented and implemented from
the standard icoFoam application. The code algorithm is described and differences with mhdFoam
are highlighted.
In chapter 5, two tutorials are provided for the simulation of 2D MHD flows employing the
solvers described in the previous chapters. Starting from the available Hartmann case, the Shercliff
and Hunt case are developed and the results validated against analytical solutions available in the
literature.

4
Chapter 2

Theoretical background

In this chapter, the equations and the parameters governing a laminar and incompressible MHD
flow are presented. First, the equations according to the magnetic induction formulation are de-
rived by the combination of the Navier-Stokes’ and Maxwell’s ones. Therefore, the induction-less
approximation is introduced and the MHD set is reformulated accordingly. A different form of the
MHD equations, called electric potential formula, is also presented in which the fundamental elec-
tromagnetic variable considered is the current density J instead of B. Fundamental parameters and
boundary conditions of MHD flows are briefly discussed.

2.1 MHD equations


A magneto-hydrodynamic flow occurs whenever the motion of an electric conductive fluid happens
in the presence of an imposed magnetic field. Currents are induced and the velocity distribution
of the flow is significantly modified by the arising of Lorentz forces which oppose the movement in
directions perpendicular to the field lines. However, the influence exerted by the magnetic field is
far from being unidirectional: the same currents generate a secondary field which, abiding to the
Faraday’s law, lessen the imposed one. Therefore, the velocity and magnetic field are coupled and
the flow features can no longer be described by the ordinary hydrodynamics laws but a new set
of governing equations is needed. A full discussion of the topic summarized in this section can be
found in textbooks dedicated to magnetohydrodynamics, such as the one by Davidson [2] or the
more recent by Müller and Bühler [3].
For a laminar and incompressible MHD flow, the governing equations are obtained by combining
the Navier-Stokes and Maxwell equations. Considering an externally applied magnetic field B0 , the
total field acting on the fluid can be represented by the sum of the external and the induced one.

B = B0 + b (2.1)

The magnetic field influence on the flow could be represented by proper source terms added to the
momentum and energy equations.
∇·u=0 (2.2)

Du
= −∇(p/ρ) + ν∇2 u + (J × B)/ρ + Sm (2.3)
Dt
DT k
= ∇T 2 + J 2 /σ + St (2.4)
Dt cp ρ
The symbols ρ, ν, cp , k and σ represent density, kinematic viscosity, specific heat capacity, thermal
and electrical conductivity. The term (J × B)/ρ in equation (2.3) accounts for the retarding effect
of the Lorentz force or electromagnetic drag, whereas the group J 2 /σ in equation (2.4) represents
the heat generation in the fluid due to the Joule effect. However, the above set lacks equations to

5
2.2. FUNDAMENTAL PARAMETERS CHAPTER 2. THEORETICAL BACKGROUND

determine J and B. For this purpose, equations are introduced to give closure to the system together
with the magnetic permeability µ. From the Ohm’s and Ampere’s law the magnetic induction
equation is deduced
∂B 1 2
= ∇ × (u × B) + ∇ B (2.5)
∂t µσ
that can be used to calculate the magnetic field distribution, which must satisfy the Gauss’ law for
magnetism
∇·B=0 (2.6)
In turn, the current density distribution is obtained from the Ampere’s law
1
J= ∇×B (2.7)
µ

The flow considered is described completely by (2.1-5), which is known as the magnetic induction
formulation of the MHD equations. The non-linear and mutual coupling between the velocity and
magnetic field is evident in the first term on the left-hand side of equation (2.5).
It is possible to reduce the MHD problem complexity by employing some assumptions. One of
the most widely employed is the induction-less approximation. The coupling intensity between the
velocity and magnetic field can be represented by the magnetic Reynolds number, which is defined
as
Momentum advection
Rem = = µσu0 L (2.8)
Magnetic diffusivity
If Rem  1, the magnetic field is not dependent from the flow velocity distribution and determined
exclusively by the boundary conditions. In other terms, the induced field b in (2.1) can be neglected
and we can declare that B ' B0 . Therefore, equation (2.5) is simplified accordingly in a pure
diffusion one
∂B 1 2
= ∇ B (2.9)
∂t µσ
If the induction-less approximation is valid, the MHD equations can be casted in a different
formulation. Employing Ohm’s law and the charge conservation condition (DJ/Dt = 0), a Poisson
equation for the electric potential φ is given by

∇2 φ = ∇ · (u × B) (2.10)

From the Ohm’s law, the current density distribution is given by

J = σ(−∇φ + u × B) (2.11)

If (2.10) is substituted to (2.9), the electric potential formulation of the MHD equations is ob-
tained where the current density J is considered as the fundamental electromagnetic variable in-
stead of the magnetic induction B. Both formulas can be implemented into computational magneto-
hydrodynamic numerical codes, although the electric potential one is generally preferred due to
reasons that would be discussed in section 4.1. In the following, we will always assume that the
induction-less approximation is valid.

2.2 Fundamental parameters


The parameters of interest for a laminar, incompressible and induction-less MHD flow are essentially
three: the Hartmann number (M), the interaction parameter or Stuart number (N) and the wall
conductance ratio (c).
The Hartmann number expresses the relation between electromagnetic and viscous forces acting
on the fluid, hence representing the magnetic field intensity and the deviation from the ordinary

6
2.2. FUNDAMENTAL PARAMETERS CHAPTER 2. THEORETICAL BACKGROUND

hydrodynamic behavior. In a typical fusion reactor blanket, this parameter can reach up to 104 . It
is formulated as  1/2 r
Electromagnetic forces σ
M= = BL (2.12)
Viscous forces ρν
The characteristic length L for a rectangular duct is the half-length in the magnetic field lines
direction.
The boundary layer structure is dependent on the associated wall orientation with the magnetic
field. For perpendicular walls an Hartmann layer is formed, whereas for parallel walls a Shercliff
layer occurs. The scaling of these layers depends by the Hartmann number according to the relations

δH = 1/M (2.13a)
1/2
δS = 1/M (2.13b)
Therefore, we define Hartmann walls those where the former condition applies and, conversely, side
walls for the latter. In the more general case where the magnetic field direction is arbitrary (i.e.
not aligned with any pair of walls), the Hartmann layer behavior is dominant wherever it exists a
non-null normal component of the magnetic field to the wall.
The interaction parameter measures the relative strength of the electromagnetic and inertial
forces. Thus, it is correlated to both the Hartmann and Reynolds number through the relation
Electromagnetic forces M2 B2 L σ L
N= = = = (2.14)
Inertial forces Re ρ u0 u0 τ
The group ρ/σB 2 is called magnetic damping time τ and represents the characteristic time in which
the magnetic field dissipate the kinetic energy carried by the flow. If N  1, then τ is big and the
flow is unaffected by the electromagnetic drag. Otherwise, the flow is dominated by the Lorentz
force and it can be considered as inertia-less. The turbulence structures are largely suppressed and
the existence region of the laminar regime is extended. In a typical fusion reactor blanket, this
parameter can reach up to 104 .
The electromagnetic drag caused is not uniformly distributed on the duct cross-section but is
dependent on the induced current paths inside the fluid. Mean path resistivity influences the MHD
pressure drops severity, whereas the path geometry can create local areas where the Lorentz force is
reduced, hence causing the onset of jets. Therefore, the flow features are influenced by the relative
conductivity between the duct wall and the fluid which is expressed by the wall conductance ratio
σw t
c= (2.15)
σ L
A value of c → 0 characterizes a duct with poorly conductive walls, whereas a duct with c > 1
is associated to well conducting walls. Even small variations for the value of this parameter can
drastically change the flow features, i.e. triggering the onset of turbulence or high velocity jets.
Three relevant cases for the flow of an electrically conductive fluid in a duct with rectangular cross-
section are identified depending on the wall conductance ratio:
• Shercliff flow, for perfectly insulating walls (c = 0) [4]
• Ufland flow, for perfectly conducting walls (c = ∞)
• Hunt flow, for side walls perfectly insulating and Hartmann walls of arbitrary conductivity
(cs = 0, ch > 0) [5]
These cases are called 2D MHD flows since the currents induced in the conductive fluid, which cause
the transition from the ordinary hydrodynamic behavior, are confined to the cross-section plane.
In particular, the Shercliff and Hunt flows have been extensively studied, both theoretically and
numerically, in the past and are considered as relevant benchmarks for the validation of numerical
codes [6]. In chapter 5, these two cases would be developed as tutorials for the solvers discussed in
chapters 3 and 4.

7
2.3. BOUNDARY CONDITIONS CHAPTER 2. THEORETICAL BACKGROUND

2.3 Boundary conditions


Since we are considering a MHD bounded flow, it is possible to set the classic no-slip boundary
condition at the duct walls (u = 0). Dirichlet boundary conditions are employed at the inlet (mean
velocity) and outlet (zero pressure) surfaces. Electromagnetic boundary conditions should also be
specified to give closure to the problem.
For a fully developed 2D flow, the magnetic field is constant along the duct axis and thus it is a
stream-function of the current density. Therefore, a simple Dirichlet or Neumann boundary condition
can be set at the wall depending on the wall conductivity. Assuming uniform conductivity, for a
perfectly conducting wall the current density flux is conserved at the fluid/solid interface Γ and
the tangential component JΓ must be zero, hence from the Ampere’s law (2.7) we obtain that the
magnetic induction gradient normal to the wall must be equal to zero. Otherwise, for a perfectly
insulating wall JΓ 6= 0 and the interface can be considered as an isosurface of the magnetic field.
Thus, the value can be set to the applied field intensity B0 . The BCs for the B-formulation can be
summarized as

∂B
=0 (valid for c = ∞) (2.16a)
∂n
B(Γ) = B0 (valid for c = 0) (2.16b)
In an analog way, for the φ-formula BCs can be expressed for the cases discussed with the relations
φ(Γ) = 0 (valid for c = ∞) (2.17a)
∂φ
=0 (valid for c = 0) (2.17b)
∂n
A considerable layer of complexity is added to this straightforward problem when the walls have
an arbitrary conductivity. Assuming that the duct is immersed in a purely dielectric material (i.e.
air) the current density at the external duct surface (Γ0 ) must have a null normal component,
whereas at the interface there is conservation of current density and potential
JΓ0 = 0 (2.18a)
J · n = Jw · n (2.18b)
φ = φw (2.18c)
For the φ-formula, it is possible to employ these conditions to solve the Poisson equation in both
the solid and fluid domains. For the latter the (2.11) is employed, whereas for the former
Jw = −σw ∇φw (2.19)
If the wall thickness tw is much lower than the characteristic length L, it can be assumed that the
currents in the wall turns in a quasi bi-dimensional way in the tangential direction. Therefore the
Jw,t and φw are constant across the wall. The component of Jw normal to the wall can be obtained
by a balance on the wall element, leading to
J · n = Jw · n = ∇T · (tw σw ∇T φw ) (2.20)
This is called the thin wall condition and can be used to couple the fluid and solid domain [7].
For the B-formulation it is not possible to define easily a local BC at the duct external surface
since we have to consider the magnetic field in the space surrounding the duct. From (2.18a), the
equation (2.7) takes the form
∇×B=0 (2.21)
It is then possible to define B as the gradient of a magnetic scalar potential ψ. A fixed value of
ψ must therefore be provided at Γ, in order to ensure the magnetic field divergence-free condition,
whereas in the outside space it must be true the condition
∇2 ψ = 0 (2.22)

8
Chapter 3

The mhdFoam solver

In this chapter the mhdFoam solver is presented. It employs the magnetic induction formulation of
the MHD equations and it is part of the OpenFOAM-4.x distribution. A tutorial is also provided:
the 2D flow which occurs between two infinite plates perpendicular to the direction of the magnetic
field, known as Hartmann flow. The source code is briefly revised and the tutorial setup is discussed.
Additional tutorials for this solver can be found in the chapter 5 for the cases of Shercliff and Hunt
flow.

3.1 Code description


The mhdFoam application solves the complete set of the MHD governing equations described in
chapter 2 and thus takes into consideration the complete coupling between the magnetic and velocity
field. At high Hartmann numbers The most critical aspect is to ensure that the total magnetic field
B, composed by the sum of the applied B0 and induced b, meets the divergence-free condition stated
in equation (2.6) for every timestep. This condition is automatically satisfied in 1D simulations but
not so for multi-dimensional ones: non-null divergence of the magnetic field can lead to inaccurate
results and unstable schemes.
Different methods were proposed in the past to overcome this issue [8]. The Projection method
was the one chosen for mhdFoam and it consists in the correction at the end of the timestep of the
0
calculated B into a similar but divergence-free B by means of an arbitrary numerical scheme. For
the code considered in this chapter, a PISO-like loop called BPISO is employed to perform the
necessary corrections exploiting the analogy with the velocity field highlighted by the continuity
equation.
An example of the source code of mhdFoam can be found in the directory reached by typing in
the shell the following string.

cd $FOAM_SOLVERS/electromagnetics/mhdFoam

The directory structure is provided for the reader convenience

createControl.H
createFields.H
createPhiB.H
magneticFieldErr.H
Make
files
options
mhdFoam.C
readBPISOControls.H

9
3.1. CODE DESCRIPTION CHAPTER 3. THE MHDFOAM SOLVER

It contains the main source files mhdFoam.C and createFields.H; the file associated with the
BPISO loop createPhiB.H (generates magnetic field flux φB ), readBPISOControls.H and magneticFieldErr.H
(print magnetic field divergence deviation from null value); and the createControl.H for the ini-
tialization of PISO an BPISO loops. Let have a closer look to mhdFoam.C.

#include "CourantNo.H"

{
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvc::div(phiB, 2.0*DBU*B)
- fvm::laplacian(nu, U)
+ fvc::grad(DBU*magSqr(B))
);

if (piso.momentumPredictor())
{
solve(UEqn == -fvc::grad(p));
}

After the usual header, file included and time step initialization; the definition of the momentum
equation can be found. The Lorentz force is not explicitly defined as in equation (2.3) but, recalling
(2.7), it can be reformulated as
1 1 1 1
(J × B) = (∇ × B × B) = − ∇B 2 + (B · ∇)B (3.1)
µ ρµ 2ρµ ρµ
These terms corresponds to fvc::grad(DBU*magSqr(B)) and fvc::div(phiB, 2.0*DBU*B) in the
mhdFoam code. The definition of the scalar DBU can be found in createFields.H, alongside the
magnetic diffusivity DB. They are reported here for the reader’s convenience.

dimensionedScalar DB = 1.0/(mu*sigma);
DB.name() = "DB";

dimensionedScalar DBU = 1.0/(2.0*mu*rho);


DBU.name() = "DBU";

The code goes on with the introduction of the standard PISO loop. Afterwards, the BPISO
starts. Its structure resembles closely the previous hydrodynamic loop. In this case, the momentum
predictor role is fulfilled by the magnetic induction equation (2.5) which calculates the magnetic
field taking into account the influence of the velocity.

// --- B-PISO loop


while (bpiso.correct())
{
fvVectorMatrix BEqn
(
fvm::ddt(B)
+ fvm::div(phi, B)
- fvc::div(phiB, U)
- fvm::laplacian(DB, B)
);

10
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

BEqn.solve();

The flux φB distribution is then calculated on cell faces with the correction from the magnetic-
velocity coupling.

volScalarField rAB(1.0/BEqn.A());
surfaceScalarField rABf("rABf", fvc::interpolate(rAB));

phiB = fvc::flux(B) + rABf*fvc::ddtCorr(B, phiB);

A Poisson equation is derived for the fictitious magnetic pressure pB and solved. The variable
distribution is then employed to correct the φB values. The magnetic field divergence errors are
printed and the loop starts again from the B prediction step, which now will use the updated φB
values. The loop exits after the prescribed iterations stated in the fvSolution file.

while (bpiso.correctNonOrthogonal())
{
fvScalarMatrix pBEqn
(
fvm::laplacian(rABf, pB) == fvc::div(phiB)
);

pBEqn.solve(mesh.solver(pB.select(bpiso.finalInnerIter())));

if (bpiso.finalNonOrthogonalIter())
{
phiB -= pBEqn.flux();
}
}

#include "magneticFieldErr.H"

It should be noted that, although similar in any aspect to the hydrodynamic PISO loop, the
BPISO is lacking the boundary conditions updating step. Moreover, B is not actually corrected at
the end of the scheme but just through the flux φB [8]. Even the divergence error is computed from
the magnetic flux, as it can be found in magneticFieldErr.H

Info<< "magnetic flux divergence error = "


<< runTime.deltaTValue()
*mag(fvc::div(phiB))().weightedAverage(mesh.V ()).value()
<< endl;

For the simulation of liquid metal MHD flows, it is not a limitation. However, it could be
possible that for cases where the induced field b plays a greater role (i.e. finite Rem ) this inaccurate
treatment of the numerical scheme could lead to unphysical results.

3.2 Hartmann tutorial


In order to better present to the reader the behavior of the discussed solver, we will employ the
tutorial available in the OpenFOAM-4.x distribution. A description of this tutorial is also available

11
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.1: Hartmann flow between two infinite insulated plates orthogonal to the magnetic field

in the OpenFOAM Programmer’s Guide. The case studied is the classical Hartmann problem (3.1):
an electrically conductive fluid is driven by a constant pressure gradient between two infinite and
insulated plates which are orthogonal to the magnetic field direction. Since the side walls of the
channel are considered at infinity, the flow is bi-dimensional.
It could be found in the tutorials directory, type the following instructions in the shell

OF4x
cd $FOAM_TUTORIALS/electromagnetics/mhdFoam/hartmann

The directory structure is reported below


hartmann
0
Allclean
Allrun
constant
system

Allclean and Allrun are scripts that can be used to run the tutorials, whereas the directories
0, constant and system store respectively the initial and boundary conditions; the mesh and
fluid properties; the simulation controls and dictionaries. The content of this directories would be
described in detail in the following.

3.2.1 The blockMeshDict


The case geometry is defined in the blockMeshDict inside the system directory. Since the flow
is bi-dimensional, only a slice of the duct in the xy-plane is modelled whereas just one node is
provided in the z-direction. The mesh is composed of a single block. The full dictionary is shown
below: please note that the patches upperWall and lowerWall are the Hartmann walls whereas the
frontAndBack are for the z-direction.

(header omitted)
convertToMeters 1;

vertices
(
(0 -1 0)
(20 -1 0)
(20 1 0)
(0 1 0)
(0 -1 0.1)
(20 -1 0.1)
(20 1 0.1)

12
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

(0 1 0.1)
);

blocks
(
hex (0 1 2 3 4 5 6 7) (100 40 1) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
);
}
outlet
{
type patch;
faces
(
(2 6 5 1)
);
}
lowerWall
{
type patch;
faces
(
(1 5 4 0)
);
}
upperWall
{
type patch;
faces
(
(3 7 6 2)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);

13
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

}
);

mergePatchPairs
(
);

// ************************************************************************* //

A uniform 100 × 40 mesh is generated in the domain. Since the default tutorial is prepared for
M = 20, remembering the scaling law (2.13a) this means that 1 node is present in the Hartmann
boundary layer region, which is critical for the resolution of the velocity profile. The length scale is
chosen as L = 1.

3.2.2 The 0 directory


0
B
p
pB
U
Ux
Uy
Uz

The file 0/B specifies the initial and boundary conditions for the magnetic field. A uniform applied
field of 20 T is initialized in the computational domain. Recalling what was exposed in section 2.3,
since the plates are considered as perfectly insulating the corresponding patches lowerWall and
upperWall have a boundary condition of type fixedValue equal to the internal field value. A
zeroGradient is employed for inlet and outlet, whereas the patches frontAndBack are specified
as empty in order to run a 2D simulation. This last setting is the same for all the files in the 0
directory.

(header omitted)

dimensions [1 0 -2 0 0 -1 0];

internalField uniform (0 20 0);

boundaryField
{
inlet
{
type zeroGradient;
}

outlet
{
type zeroGradient;
}

lowerWall
{
type fixedValue;

14
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

value uniform (0 20 0);


}

upperWall
{
type fixedValue;
value uniform (0 20 0);
}

frontAndBack
{
type empty;
}
}

The files 0/p and 0/U contain the settings for the pressure and velocity fields. The boundary
conditions are the same that could be expected in the analogous flow in absence of the magnetic
field (inlet-velocity/pressure-outlet, no slip, etc.). An uniform velocity U = (1, 0, 0) is imposed at
the inlet. The files 0/Ux, 0/Uy and 0/Uz are used by the functionObject components to calculate
the velocity vector components from the U field for postprocesing purpose. More interesting is the
0/pB for the fictitious magnetic pressure

(header omitted)

dimensions [1 1 -3 0 0 -1 0];

internalField uniform 0;

boundaryField
{
inlet
{
type fixedValue;
value uniform 0;
}

outlet
{
type fixedValue;
value uniform 0;
}

lowerWall
{
type zeroGradient;
}

upperWall
{
type zeroGradient;
}

frontAndBack
{

15
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

type empty;
}
}

// ************************************************************************* //

Since the pB variable is a measure of the error on magnetic field divergence, it is not a surprise
that it is initialized as zero in the domain. The other boundary conditions are what would be
expected for a pressure-like field.

3.2.3 The constant directory


The only file present in the constant directory for the clean tutorial is the transportProperties
dictionary. It defines the properties of the fluid considered in the simulation, which are assumed
constant and uniform.

rho [1 -3 0 0 0 0 0] 1; //density

nu [0 2 -1 0 0 0 0] 1; //kinematic viscosity

mu [1 1 -2 0 0 -2 0] 1; //magnetic permeability

sigma [-1 -3 3 0 0 2 0] 1; //electrical conductivity

Please note that the header is omitted. Since all the properties are equal to one, the Hartmann
number is fixed by the magnetic field intensity which is specified in the file 0/B. Therefore, to
modify M it is only necessary to adjust this parameter.
From what we have seen so far, it is clear that the characteristic length is assumed as L = 1 m and
the mean velocity as U0 = 1 ms− 1. Recalling (2.8), (2.12), (2.14), (2.15) and the classical definition
of the Reynolds number we obtain the parameters of the tutorial: Rem = 1, M = 20, Re = 2, N = 50
and c = 0.

3.2.4 The system directory


system
blockMeshDict
controlDict
fvSchemes
fvSolution
sample
The blockMeshDict is already discussed in the subsection 3.2.1. The controlDict dictionary
contains the general setting for the simulation and the functionObjects executed at runtime. The
code is reported below with the header and not-solver relevant sections omitted.

(omissis)

application mhdFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

16
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

endTime 2;

deltaT 0.005;

(omissis)

functions
{
#includeFunc components(U)
}

// ************************************************************************* //

The deltaT entry determines the time step for the simulation. Some costraints on the time step must
be specified in order to have a stable and monotone numerical scheme. The Courant-Friedrichs-Lewy
condition for a 2D problem must be satisfied

C ≤ 0.5 (3.2)

Moreover, additional conditions must be introduced due to the coupling between the fluid velocity
and the magnetic field. In particular, the magnetic damping time, defined in (2.14) must be greater
than the time step [2].
∆t < τ (3.3)
A Von Neumann stability analysis carried over for a 1D simulation individuated the parameter L,
defined as
σB02 ∆t
L= (3.4)
ρ
It was found that in order to have a stable numerical scheme L ≤ 2∪L =
6 1, whereas the best accuracy
was found for L → 2 and L → 0. A value of L < 0.2 was recommended for the performance of a
3D simulation [8]. For increasing values of the Hartmann number, the condition on L is the most
demanding. Moreover, for a monotone scheme the condition that should be met can be expressed
as
ν∆t
C + 2L + ≤1 (3.5)
(∆x)2

For the ∆t chosen in the default controlDict we calculate that C = 0.1, L = 2 and τ = 2.5 e − 3 s.
In the fvSchemes file, we can find that the spacial discretization is executed with a simple central
differencing scheme (Gauss linear), whereas for the temporal is used the first order implicit Euler
scheme.

(header omitted)

ddtSchemes
{
default Euler;
}

gradSchemes
{
default Gauss linear;
}

17
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

divSchemes
{
default none;
div(phi,U) Gauss linear;
div(phiB,U) Gauss linear;
div(phi,B) Gauss linear;
div(phiB,((2*DBU)*B)) Gauss linear;
}

laplacianSchemes
{
default Gauss linear corrected;
}

interpolationSchemes
{
default linear;
}

snGradSchemes
{
default corrected;
}

// ************************************************************************* //

In fvSolution is specified the linear solvers for all the variable set for the simulation run. For the
pressure and the pseudo-magnetic pressure fields, a Preconditioned conjugate gradient (PCG) solver
is used together with a diagonal incomplete-Cholesky preconditioner (DIC). For the coupled velocity-
magnetic field, a single Gauss-Seidel smoother is employed. Three iteration cycles are required for
both the PISO and the BPISO.

(header omitted)

solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0.05;
}

pFinal
{
$p;
relTol 0;
}

pB
{
$p;
tolerance 1e-05;

18
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

relTol 0;
}

pBFinal
{
$pB;
relTol 0;
}

"(U|B)"
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-05;
relTol 0;
}
}

PISO
{
nCorrectors 3;
nNonOrthogonalCorrectors 0;
}

BPISO
{
nCorrectors 3;
}

The last file in the system directory is just a sampling dictionary for the postProcess utility
called sample. When run, it will extract the velocity profile at the centre of the duct between the
plates for every written time step and store it in the new created postProcessing folder. In the
next part, the results of the tutorial would be validate against a theoretical solution employing this
file.

type sets;
libs ("libsampling.so");

interpolationScheme cellPoint;

setFormat raw;

sets
(
line_centreProfile
{
type uniform;
axis distance;
start (10.001 -1 0.01);
end (10.001 1 0.01);
nPoints 100;
}
);

19
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

fields ( Ux );

3.2.5 Results for M = 20


In order to run the tutorial, we will move a fresh copy to the user run directory. As we have seen in
the previous subsection, the case is defined for M = 20, Re = 2 and c = 0.

cd $FOAM_RUN
mkdir -p electromagnetics/mhdFoam
cd electromagnetics/mhdFoam
cp -r $FOAM_TUTORIALS/electromagnetics/mhdFoam/hartmann .

The mesh is generated with the utility blockMesh. Before to launch the case, it could be helpful
to modify the system/sample dictionary in order to obtain more meaningful data for the results
validation.

cd hartmann
blockMesh
sed -i s/distance/y/g system/sample
sed -i s/100/200/g system/sample
mhdFoam >& log&

The residual profiles for the simulation variables, plotted from the log file, are available in Figure
3.2, 3.3 and 3.4. To validate the tutorial results, we will employ the analytical solution available in
the OpenFOAM Programmer’s Guide and presented also by Weller et al. [1].

cosh M − cosh M (y/L)


Ux = U0 (3.6)
cosh M − sinh M/L
After the run is completed, to extract the velocity profile data it is necessary to type the command
to activate the sampling function for the field Ux
postProcess -func sample
To plot it, the software gnuplot can be used. It can be accessed from the shell typing gnuplot and
then plot "<dataFileName>" to generate the image from the desired file. However, the result of
this simple procedure can be a bit bare. A simple script can be employed to obtain a better picture.

touch plot.sh
gedit plot.sh

(add the following in plot.sh)


#!/usr/bin/gnuplot
set term png enhanced
set out "plot_vs_reference.png"

set key bottom center


set title "Hartmann flow profile for M=20 and Re=2"
set xlabel "y/L"
set ylabel "Ux"

plot "postProcessing/sample/2/line_centreProfile_Ux.xy" u ($1):2 w l ls 2 t "OF"


(save and return to shell)

./plot.sh

20
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.2: Velocity residuals for M = 20, Re = 2 and ∆t = 0.005 s

Figure 3.3: Pressure and magnetic pressure (pB) residuals for M = 20, Re = 2 and ∆t = 0.005 s

21
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.4: Magnetic induction residuals for M = 20, Re = 2 and ∆t = 0.005 s

Figure 3.5: mhdFoam results against theoretical solutions for M = 20

22
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

In Figure 3.5 a comparison of the numerical results and the analytical solution (3.6) is presented.
The maximum error on the profile is calculated with the relation
 
|Ux − Ux, theory |
 = max · 100 = 1.3% (3.7)
Ux, theory

The error is due to the uniform mesh employed which is not able to accurately resolve the intense
gradient in the Hartmann layer and therefore underestimates the velocity in the core region. This
issue becomes critical at higher M . To reduce the error it is necessary to concentrate the mesh
toward the walls. A minimum of 4 nodes in the Hartmann layer is usually suggested [8].

3.2.6 Results for M = 50


We want now to run the tutorial case for an higher value of the Hartmann number. Some minor
modifications are needed to run the case successfully, nevertheless the author believes that it would
help to highlight some issues typical of the computational MHD.
The parameters and properties used for the previous run are left untouched, unless for the
magnitude of the applied magnetic field which is raised from 20 T to 50 T. Since all the properties
of the fluid considered are equal to the unity, this modification translates in a correspondingly rise
in the value of M . A copy of the hartmann tutorial is employed.

cd $FOAM_RUN
mkdir -p electromagnetics/mhdFoam
cd electromagnetics/mhdFoam
cp -r $FOAM_TUTORIALS/electromagnetics/mhdFoam/hartmann .
mv hartmann hartmann50
cd hartmann50
sed -i s/20/50/g 0/B
sed -i s/distance/y/g system/sample

From (2.13a) we expect a shrinking of the Hartmann layer. In order to move four nodes inside
it, we will employ a non-uniform 120x40 mesh with a concentration factor of 25 towards the wall.
In order to do so, it is necessary to edit the blockMeshDict. Substitute the lines

blocks
(
hex (0 1 2 3 4 5 6 7) (100 40 1) simpleGrading (1 1 1)
);

with the following

blocks
(
hex (0 1 2 3 4 5 6 7) (120 40 1)
simpleGrading
(1
(
(50 50 25) //50% y-direction, 50% cells, 25 grading factor
(50 50 0.04) //50% y-direction, 50% cells, 1/25 grading factor
)
1)
);

23
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.6: mhdFoam results against theoretical solutions for M = 50

Besides the flow features, the higher magnetic fields affects the time step value through the
parameter L. Therefore, it is necessary to lessen the time step to run a successful simulation. De-
creasing from ∆t = 0.005 to 0.0025 is enough to ensure convergence for this case. The controlDict
should be modified accordingly before running the case.

sed -i s/0.005/0.0025/g system/controlDict


sed -i s/100/200/g system/controlDict
blockMesh
mhdFoam >& log &
postProcess -func sample

The result obtained is then compared with the solution (3.6) for M = 50 (Figure 3.6). The max-
imum error for the velocity profile is evaluated with the relation (3.7) as  = 0.26%. A comparison
of the velocity profiles obtained for values of M ∈ [0, 50] is available in Figure 3.7.

24
3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.7: Velocity profile for M from 0 to 50

25
Chapter 4

The epotFoam solver

In this chapter the epotFoam solver is presented. It is based on the application originally developed
by Vincent Dousset of the Coventry University for a previous version of OpenFOAM and the φ-PISO
algorithm developed by Elisabet Mas de les Valls of the Universitat Politecnica de Catalunya [8]
[9]. It employs the induction-less approximation to solve the MHD governing equations. The source
code is briefly revised and implemented starting from the distribution solver icoFoam. The final
code, obtained following the instructions contained in this chapter, is available in the accompanying
files of this document. Tutorials for the solver can be found in the chapter 5 for the cases of Shercliff
and Hunt flow.

4.1 Code description


The advantages of using the electric potential formulation over the magnetic induction one for the
implementation in a CFD core are several:

• In order to obtain the J distribution, a scalar equation (2.10) must be solved instead of a
vectorial (2.9) reducing the overall scheme complexity and thus improving its velocity [10].
• Only the current density J is influenced from the velocity u, whereas the magnetic field B is
determined just by the boundary conditions. The MHD coupling non-linearity is lessened and
the numerically stability is improved [11].

• Boundary conditions are easier to implement and, for complex geometries and non-uniform
magnetic fields, are the only suitable options [7].

For the design of fusion reactor blankets, the inductionless approximation is always applicable and
almost the totality of the studies in the literature employs the electric potential formula. However,
this approach is not without drawbacks.
In section 2.1, it was discussed the introduction of the Lorentz force in the momentum equation
(2.3) as a source term. Although formally correct, this treatment can lead to inaccurate and even
unphysical results when employed in numerical codes. In particular, the momentum conservation
could be violated for unstructured meshes and high M values due to the non-conservative formulation
of the Lorentz force. This issue is worsened when inconsistent interpolation techniques are used for
the computation of cell center values of current density which can result in a field which does not
satisfy the charge conservation, a critical condition for high M flows.
For a collocated mesh, a conservative and consistent numerical scheme was developed in 2007 by
Ni et al. for both structured [10] and unstructured [11] grids in order to address these issues. The
authors demonstrated the capability of the scheme to correctly simulate 2D and 3D MHD flows and
since then it is considered as the state-of-the-art, being employed in the development of codes for
fusion reactor blanket design [12] [13].

26
4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

In the epotFoam implementation that would be described in section 4.2, the Lorentz force is
still treated as a source term but, thanks to the consistent interpolation technic employed for the
J reconstruction at the cell center, it can ensure the conservation of both momentum and charge.
The general four step projection method for MHD flows developed in [10] was modified in order to
employ a PISO loop for a stronger pressure-velocity coupling as described in [14] and [8].
The algorithm of epotFoam can be briefly summarized as:
1. Creation of initial distribution of u, p and velocity flux φu . Initialization of Lorentz force (L)
2. Discretization of momentum equation coefficients and solution in order to obtain velocity field
prediction for the PISO loop
∂u
+ ∇ · (φu , u) − ∇2 (ν, u) − (1/ρ)L = −∇(p)
∂t

3. Execution of the PISO loop for a fixed number of iterations, a Poisson equation is solved to
obtain the pressure field which is therefore employed to correct the velocity field predicted at
the previous step.
4. Continuity equation is solved to estimate errors and boundary conditions for velocity are
updated
5. Evaluation of magnetic flux term on cell faces

χ = (u × B) &Sf

6. Solve Poisson equation for electric potential

∇2 (φ) − ∇ · χ = 0

7. Computation of current density flux from normal gradient of electric potential on cell faces
and magnetic flux. The value at the center of the face is considered.

jf = −∇sn φ &Sf + χ

8. Reconstruction of current density in the cell centroid employing consistent scheme: a volume-
weighted interpolation between cell face center and centroid.
nf
1 X
Jc = jf (rf − rp ) · Sf
Ωp
f =1

9. The final, conservative, current density distribution is employed for the Lorentz force calcula-
tion
L = Jc × B

The present algorithm would be implemented in the section 4.2 inside the icoFoam solver to
obtain an electric potential solver for MHD flows.

4.2 Code implementation


The epotFoam solver can be very easily obtained with just some minor modifications from the default
solver icoFoam. In order to do so, a vanilla copy of the latter is needed. A good practise to follow
during the development of a new solver is to maintain the directory general structure of the OpenFOAM
source code. Abiding to this rule, if they are not present we will first create the necessary directories
and then copy icoFoam in the bottom one.

27
4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

cd $WM_PROJECT_USER_DIR //go to user directory


mkdir -p applications/solvers/electromagnetics //create directory structure
cd applications/solvers/electromagnetics
cp -r $FOAM_SOLVERS/incompressible/icoFoam . //copy from source code to working directory

The parent directory of our new icoFoam is labelled electromagnetics and this change of
environment would be soon justified. For now, to properly compile the code a few name changes are
needed to the source files.
mv icoFoam epotFoam //rename solver directory
cd epotFoam
mv icoFoam.C epotFoam.C //rename source file

//modify Make/files for new solver


sed -i s/icoFoam/epotFoam/g Make/files
sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN/g Make/files

In the next subsections, the files epotFoam.C and createFields.H would be modified in order to
generate the proper source code for the solver epotFoam.

4.2.1 epotFoam.C
To start open the epotFoam.C file in a text editor, for example gedit or notepadqq. First, we need
to initialize the Lorentz force field before the time loop start. Just after the IO printing add the
following lines:
//Lorentz force term initialization
volVectorField lorentz = sigma * (-fvc::grad(PotE) ^ B0) + sigma * ((U ^ B0) ^ B0);

The Lorentz force is described as a volume vector field object which is computed as the cross product
J × B, where the current density distribution is obtained by the Ohm’s Law (2.11).
Now that the Lorentz force is defined, it must be included in the momentum equation. Inside
the time cycle, the UEqn must be altered accordingly with the source term addition.
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
- (1.0/rho) * lorentz //Lorentz term
);

Thus, the velocity field is estimated in the momentum predictor step of the PISO loop considering
the magnetic field influence. No further modification are needed for the velocity-pressure coupling
and we can skip at the PISO loop end.
To calculate the electric potential distribution needed for the computation of the Lorentz force
we have to solve the Poisson equation (2.10) in which the cross product u × B is present. Employing
the updated velocity values after the conclusion of the PISO loop, the quantity psiub would be
estimated interpolating the cross product result at the cell faces. The following lines must be added
//Interpolating cross product u x B over mesh faces
surfaceScalarField psiub = fvc::interpolate(U ^ B0) & mesh.Sf();

28
4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

The matrix PotEEqn is then introduced which, once solved, will give the electric potential distribu-
tion. Since it is defined in a similar way to the pressure field, it would need a reference cell that would
be employed as the null potential location. This would be specified later in the createFields.H
file. Just after the psiub line, the following lines must be added.

//Poisson equation for electric potential


fvScalarMatrix PotEEqn
(
fvm::laplacian(PotE)
==
fvc::div(psiub)
);

//Reference potential
PotEEqn.setReference(PotERefCell, PotERefValue);

//Solving Poisson equation


PotEEqn.solve();

From the electric potential distribution the current density at the cell center would be calculated
first by computing the current density fluxes on the cell faces and then interpolating to obtain the
desired value. Therefore, the current density distribution is used to update the boundary condition.
The following lines must be added after the PotEEqn.solve() line.
//Computation of current density at cell faces
surfaceScalarField jn = -(fvc::snGrad(PotE) * mesh.magSf()) + psiub;

//Current density at face center


surfaceVectorField jnv = jn * mesh.Cf();

//Interpolation of current density at cell center


volVectorField jfinal = fvc::surfaceIntegrate(jnv) - (fvc::surfaceIntegrate(jn) * mesh.C());

//Update current density distribution and boundary condition


jfinal.correctBoundaryConditions();

Finally, the Lorentz force term is calculated. The following line must be added just before the
runTime.write() string.

//Lorentz force computation


lorentz = sigma* (jfinal ^ B0);

No further modifications are needed to this file. A complete version of epotFoam.C is available in
the Appendix as a mean of comparison with the user file redacted following the instructions of this
section.

4.2.2 createFields.H
The standard file valid for the icoFoam solver must be modified in order to account for the new
quantities introduced in epotFoam. Two additional properties (rho and sigma) are added to the al-
ready present transportProperties dictionary, whereas a new one (electromagneticProperties)
is created to define the magnetic field. Regarding fields, the only new one is the PotE which being
a volScalarField object could be modelled starting from the pressure field entry.

29
4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

After opening createFields.H in a suitable text editor, the first modification would be the
reading and the declaration of the new dictionary in the preamble. This can be made by copying
the transportProperties entry and changing the name tags:
Info<< "Reading electromagneticProperties\n" << endl;

//Additional dictionary for magnetic field definition


IOdictionary electromagneticProperties
(
IOobject
(
"electromagneticProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);

Therefore, the new quantities can be defined according to the linked dictionaries. The entry for the
kinematic viscosity can be used as template, modifying the dimensionSet variables

//Density
dimensionedScalar rho
(
"rho",
dimDensity,
transportProperties.lookup("rho")
);

//Electrical conductivity
dimensionedScalar sigma
(
"sigma",
dimensionSet(-1, -3, 3, 0, 0, 2, 0),
transportProperties.lookup("sigma")
);

//Magnetic field
dimensionedVector B0
(
"B0",
dimensionSet(1, 0, -2, 0, 0, -1, 0),
electromagneticProperties.lookup("B0")
);

The only difference with a standard incompressible solver is the inclusion of the magnetic field in
a separate dictionary. After the #include createPhi.H line, the electric potential field is added.
The entry can be generated copying the pressure field and modifying accordingly the name tags, as
follows

//Electric potential field


Info<< "Reading field PotE\n" << endl;
volScalarField PotE

30
4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

(
IOobject
(
"PotE",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

Since an entry for the pressure is already present, the same procedure could be repeated also for the
potential reference point
//Electric potential reference point
label PotERefCell = 0;
scalar PotERefValue = 0.0;
setRefCell(PotE, mesh.solutionDict().subDict("PotE"), PotERefCell, PotERefValue);
mesh.setFluxRequired(PotE.name());

No further modifications are needed to this file. A complete version of createFields.H is


available in the Appendix as a mean of comparison with the user file redacted following the previous
instructions.
The implementation of the new solver is completed. The last step is the compilation of epotFoam
which can be accomplished running the wmake command in the solver directory.

cd $WM_PROJECT_USER_DIR/applications/solvers/electromagnetics/epotFoam
wmake

The final directory structure should look like this

createFields.H
epotFoam.C
Make
files
options

31
Chapter 5

Tutorials for laminar 2D MHD flow

In this chapter, tutorials for elementary 2D MHD flows would be presented: the flow in a rectangular
duct which walls are perfectly insulating (Shercliff flow) and the one were the Hartmann walls are
considered as perfectly conducting, whereas the side are perfect insulators (Hunt flow). These cases
are developed for the solvers described in the chapters 3 and 4 due to their importance as benchmarks
for the validation of computational MHD codes [6]. Both the tutorials are executed at M = 20 and
Re = 2. Analytical solutions are available in the Appendix for the reader which would like to
stress test the tutorials at higher Hartmann and Reynolds numbers than the one presented in this
document.

5.1 Case directory structure


The case directory setup for the tutorials of this chapter is very similar to the one presented in the
section 3.2 for the mhdFoam Hartmann problem case. The main difference are encountered in the
initial and boundary conditions settings, the discretization schemes and time step used. In Figure
5.1, an overview of the general directory structure is available.
In the following sections we will describe the changes to perform on the OpenFOAM distribution files
in order to generate the tutorials from scratch. The final tutorials are available in the accompanying
files of this document.

5.2 Shercliff tutorial


Consider the flow of an electric conductive fluid in a square duct where a constant and uniform
magnetic field is applied alongside the y-axis (Figure 5.2). The duct walls (half-length L = 1 m)
have null electrical conductivity and are therefore assumed as perfectly insulating. The fluid is driven
by a constant pressure gradient ∇p, parallel to the x-axis, and at the inlet its velocity is assumed
as uniform on the cross section and equal to u = 1 m/s.
If these assumptions are valid, all the flow variables except the pressure are constant in the
duct axis direction and the flow is bi-dimensional. The flow cross-section can be divided in three
zones. The inviscid core region occupies the duct center and it is characterized by a slug flow
with a uniform velocity where the Lorentz force compensates the pressure gradient. The Hartmann
boundary layers of thickness δH = O(M −1 ) are localized near the walls orthogonal to the magnetic
field and experience an exponential decay in the velocity. Finally, the more thick side boundary
layers (δS = O(M −1/2 )) are found close to the walls parallel to the magnetic field direction. Since
the walls are non-conductive, the induced currents in the fluid generated by the interaction between
the velocity and magnetic field can not penetrate the solid domain and therefore must close through
the boundary layers to satisfy the charge conservation condition.
This case was first studied by Shercliff in [4] which formulated the analytical solution to the
problem as a Fourier series dependent by M . This approach was successively extended by Hunt

32
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.1: Directory structure for the 2D MHD flow tutorials

33
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.2: Shercliff flow

for the flows where the Hartmann walls have arbitrary conductive, of which the Shercliff flow is
a particular case. The Hunt-Shercliff formula was re-casted by Ni et al. [11] to suit the need of
computer calculations at high M number and in this updated form is employed to validate the
numerical results of this document. The full expression is available in the Appendix.

5.2.1 mhdFoam
A Shercliff flow case can be produced employing the already available Hartmann flow tutorial (see
section 3.2). Since the side walls can no longer be considered at infinite distance from the flow plane,
the blockMeshDict must be modified in order to remove the empty patches and generate a 3D mesh.
A copy of the hartmann tutorial will be renamed as shercliffFlow

cd $FOAM_RUN/electromagnetics/mhdFoam
cp -r $FOAM_TUTORIALS/electromagnetics/mhdFoam/hartmann shercliffFlow

A non-uniform 40x40x40 mesh would be used to run the simulation with a concentration factor
of 5 toward the walls. Open the blockMeshDict and replace the lines
(omissis)

vertices
(
(0 -1 0)
(20 -1 0)
(20 1 0)
(0 1 0)
(0 -1 0.1)
(20 -1 0.1)
(20 1 0.1)
(0 1 0.1)
);

blocks
(
hex (0 1 2 3 4 5 6 7) (100 40 1) simpleGrading (1 1 1)
);

(omissis)

34
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}

with the lines


(omissis)

vertices
(
(0 -1 -1) //0
(20 -1 -1) //1
(20 1 -1) //2
(0 1 -1) //3
(0 -1 1) //4
(20 -1 1) //5
(20 1 1) //6
(0 1 1) //7
);

blocks
(
hex (0 1 2 3 4 5 6 7) (40 40 40)
simpleGrading
(
1
(
(50 50 5)
(50 50 0.2)
)
(
(50 50 5)
(50 50 0.2)
)
)
);

(omissis)

rightWall
{
type patch;
faces
(
(4 5 6 7)
);
}

35
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

leftWall
{
type patch;
faces
(
(0 3 2 1)
);
}

Since two new patches have been created (rightWall and leftWall), boundary conditions must
be added in the 0/* files. Open the 0/B and replace the lines

(omissis)

frontAndBack
{
type empty;
}

with the following

(omissis)

rightWall
{
type fixedValue;
value uniform (0 20 0);
}
leftWall
{
type fixedValue;
value uniform (0 20 0);
}

The same procedure can be repeated for the other files in the 0 directory, copying and renaming
the upperWall entry to apply it for the new set of walls. Since we are employing a non-uniform
mesh the time step must be lowered in order for the simulation to be stable (see subsection 3.2.6).
Edit the controlDict file from

(omissis)
startFrom startTime;

startTime 0;

stopAt endTime;

endTime 2;

deltaT 0.005;
(omissis)

into

36
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

(omissis)
startFrom startTime;

startTime 0;

stopAt endTime;

endTime 1;

deltaT 0.0025;
(omissis)

To post process the results is useful to modify the default sample directory to plot the velocity
profile between the pair of side and Hartmann walls. Edit the lines

sets
(
line_centreProfile
{
type uniform;
axis distance;
start (10.001 -1 0.01);
end (10.001 1 0.01);
nPoints 100;
}
);

fields ( Ux );

into

sets
(
line_hartmannProfile
{
type uniform;
axis distance;
start (9.99 0 0);
end (9.99 1 0);
nPoints 50;
}
line_sideProfile
{
type uniform;
axis distance;
start (9.99 0 0);
end (9.99 0 1);
nPoints 50;
}
);

To run the tutorial and process the results, type the following commands in the shell

37
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.3: mhdFoam velocity results for M = 20 and Re = 2. The side profile is plotted at y = 0, the
Hartmann at z = 0

Figure 5.4: Residuals for magnetic field

38
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.5: Residuals for pressure and magnetic field fictitious pressure

Figure 5.6: Residuals for velocity

39
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

blockMesh
mhdFoam >& log &
postProcess -func sample
./plot.sh

In Figure 5.4, 5.5 and 5.6 the plot of the residuals for the simulation are available. Employing
the new sample dictionary and the shercliff.dat file containing the analytical solution ([11]) to
validate the numerical results a perfect agreement should be found (see Figure 5.3).

5.2.2 epotFoam
The mesh generated for the mhdFoam tutorial could be employed also for the one based on the
epotFoam without any issues. However, since the flow presents a symmetry plane at y = 0 for
both the velocity and the electric potential it is possible to simulate just one half of the duct. The
vertices entries must be modified accordingly and the lowerWall patch can be transformed in a
symmetryPlane. The updated section of the blockMeshDict is shown below

(omissis)

vertices
(
(0 0 -1) //0
(20 0 -1) //1
(20 1 -1) //2
(0 1 -1) //3
(0 0 1) //4
(20 0 1) //5
(20 1 1) //6
(0 1 1) //7
);
blocks
(
hex (0 1 2 3 4 5 6 7) (40 40 40)
simpleGrading
(
1
0.2
(
(50 50 5)
(50 50 0.2)
)
)
);

(omissis)

symmetryPlane
{
type symmetryPlane;
faces
(
(1 5 4 0)
);
}

40
5.2. SHERCLIFF TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

It is useful to highlight again how a proper resolution of the boundary layers, especially the Hartmann
one, it is of paramount importance to obtain meaningful physical results. This is even more critical
for a Shercliff flow solved with the φ-formulation where the currents close through the layers.
In the 0 directory, create an empty file called PotE. This will define the initial and boundary con-
ditions for the electric potential field. Since all the walls are insulating, we will set the zeroGradient
entry on all the patches except the symmetryPlane one (see subsection 2.3). The following lines must
be copied within the new file.
(header omitted)

dimensions [1 2 -3 0 0 -1 0];

internalField uniform 0;

boundaryField
{
inlet
{
type zeroGradient;
}

outlet
{
type zeroGradient;
}

symmetryPlane
{
type symmetryPlane;
}

upperWall
{
type zeroGradient;
}

rightWall
{
type zeroGradient;
}

leftWall
{
type zeroGradient;
}
}

For the pressure and velocity files, the file generated for the previous tutorial can be used changing the
name tag from lowerWall to symmetryPlane and imposing the corresponding boundary condition.
All the other patches must not be modified.
In the constant directory, create an file called electromagneticProperties. This will store
the applied magnetic field. Copy the following lines inside the new dictionary

41
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

(header omitted)

B0 [1 0 -2 0 0 -1 0] (0 20 0);

In the system directory, edit the application entry in the controlDict file from mhdFoam to
epotFoam. This solver is more numerically stable than the previous one, therefore is possibly to
employ the explicit, second order accurate Crank-Nicholson scheme for the time discretization.
In the fvSchemes, edit the default entry for the ddtSchemes from Euler to CrankNicolson 1.
Clean all the entries besides the default one for the other dictionaries and modify the one for the
snGradSchemes from corrected to orthogonal. At the end of the fvSolution dictionary, add the
following lines
PotE
{
nCorrectors 0;
nNonOrthogonalCorrectors 0;
PotERefCell 0;
PotERefValue 0;
}

To run the tutorial and process the results, type the following commands in the shell
blockMesh
epotFoam >& log &
postProcess -func sample
./plot.sh

The residuals are shown in Figure 5.7. Employing the shercliff.dat file containing the analytical
solution [11] to validate the numerical results a perfect agreement should be found (see Figure 5.8).
A plot of the electric potential for y = 0 is also provided in Figure 5.9.

5.3 Hunt tutorial


Consider the flow of an electric conductive fluid in a square duct where a constant and uniform
magnetic field is applied alongside the y-axis (Figure 5.10). The duct walls (half-length L = 1 m)
have non-uniform electrical conductivity. The pair of Hartmann walls are assumed to be perfectly
conducting, whereas the side walls are composed of a perfect dielectric material. The fluid is driven
by a constant pressure gradient ∇p, parallel to the x-axis, and at the inlet its velocity is assumed
as uniform on the cross section and equal to u = 1 m/s.
If these assumptions are valid, all the flow variables except the pressure are constant in the duct
axis direction and the flow is bi-dimensional. The currents induced in the fluid can not enter the
insulating side walls and therefore are forced to flow alongside them to close through the conductive
Hartmann walls. In a very similar way to what happen for a Shercliff case, the flow cross-section
can be divided in three zones. The core and Hartmann layers region are analog to the one described
for the Shercliff case (see 5.2). In the side layers, the component of the current density tangential
to the wall becomes dominant over the normal one (i.e. Jt  Jn with Jn → 0) and therefore the
Lorentz force is greatly weakened compared with the other regions. This phenomenon causes the
formation of high velocity which can carry a relevant fraction of the flow rate in the thin side layers
region. The velocity profile among the side walls assumes the characteristic M-shape.
This case was first studied by Hunt, which formulated the analytical solution to the problem as
a Fourier series dependent by M [5]. The Hunt formula was re-casted by Ni et al. to suit the need
of computer calculations at high M number and in this updated form is employed to validate the
numerical results of this document [11]. The full expression is available in the Appendix.

42
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.7: Residuals plot for the Shercliff run

Figure 5.8: epotFoam velocity results for M = 20 and Re = 2. The side profile is plotted at y = 0, the
Hartmann at z = 0

43
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.9: epotFoam velocity results for M = 20 and Re = 2 at y = 0

Figure 5.10: Hunt flow. The main difference with the Shercliff flow is the presence of the conductive
Hartmann walls

44
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

5.3.1 mhdFoam
The tutorial can be created by modifying the Shercliff case in order to have conductive Hartmann
walls. In the following it is assumed that the reader has already followed the instructions in subsection
5.2.1.
The same mesh and solver control settings can be used for the Hunt tutorial, just the boundary
conditions for the magnetic field must be modified in order to take into consideration the non-uniform
wall conductivity. Therefore, the 0/B file must be edited replacing the following lines
(omissi)
lowerWall
{
type fixedValue;
value uniform (0 20 0);
}

upperWall
{
type fixedValue;
value uniform (0 20 0);
}
(omissis)

with the lines reported below


lowerWall
{
type zeroGradient;
}

upperWall
{
type zeroGradient;
}

The physical meaning of this modification can be clearly understood recalling what exposed in the
subsection 2.3.
To run the tutorial and process the results, type the following commands in the shell

blockMesh
mhdFoam >& log &
postProcess -func sample
./plot.sh

In Figure 5.12, 5.13 and 5.14 the plot of the residuals for the simulation are available. Employing
the hunt.dat file containing the analytical solution ([11]) to validate the numerical results a perfect
agreement should be found (see Figure 5.11).

5.3.2 epotFoam
The tutorial can be created by modifying the Shercliff case in order to have conductive Hartmann
walls. In the following it is assumed that the reader has already followed the instructions in subsection
5.2.2.

45
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.11: mhdFoam velocity results for M = 20 and Re = 2. The side profile is plotted at y = 0, the
Hartmann at z = 0

Figure 5.12: Residuals for magnetic field

46
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.13: Residuals for pressure and magnetic field fictitious pressure

Figure 5.14: Residuals for velocity

47
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.15: Residuals plot for the Hunt run

The same mesh and solver control settings can be used for the Hunt tutorial, just the boundary
conditions for the electric potential must be modified in order to take into consideration the non-
uniform wall conductivity. Recalling what exposed in subsection 2.3, the upperWall entry in the
0/PotE must be replaced with the following lines
upperWall
{
type fixedValue;
value uniform 0;
}

To run the tutorial and process the results, type the following commands in the shell
blockMesh
epotFoam >& log &
postProcess -func sample
./plot.sh

The residuals are shown in Figure 5.15. Employing the hunt.dat file containing the analytical
solution ([11]) to validate the numerical results a perfect agreement should be found (see Figure
5.16). A plot of the electric potential for y = 0 is also provided in Figure 5.17.

48
5.3. HUNT TUTORIAL CHAPTER 5. TUTORIALS FOR LAMINAR 2D MHD FLOW

Figure 5.16: epotFoam velocity results for M = 20 and Re = 2. The side profile is plotted at y = 0, the
Hartmann at z = 0

Figure 5.17: epotFoam velocity results for M = 20 and Re = 2 at y = 0

49
Bibliography

[1] H.G. Weller et al. A tensorial approach to computational continuum mechanics using object-
oriented techniques. Computers in physics, 12(6):620–631, 1998.
[2] P.A. Davidson. An introduction to magnetohydrodynamics, volume 25. Cambridge university
press, 2001.
[3] U. Müller and L. Bühler. Magnetofluiddynamics in channels and containers. Springer Science
& Business Media, 2013.

[4] J.A. Shercliff. Steady motion of conducting fluids in pipes under transverse magnetic fields. In
Mathematical Proceedings of the Cambridge Philosophical Society, volume 49, pages 136–144.
Cambridge University Press, 1953.
[5] J.C.R. Hunt. Magnetohydrodynamic flow in rectangular ducts. Journal of Fluid Mechanics,
21(04):577–590, 1965.
[6] S. Smolentsev et al. An approach to verification and validation of MHD codes for fusion
applications. Fusion Engineering and Design, 100:65–72, 2015.
[7] C. Mistrangelo. Simulation of magneto-hydrodynamic (MHD) flows in OpenFOAM.
Presentation at NUMAP-FOAM Summer School University of Zagreb, available online
at: http://powerlab.fsb.hr/ped/kturbo/OpenFOAM/SummerSchool2010/Chiara.pdf, Septem-
ber 2010.
[8] E.M. de les Valls. Development of a simulation tool for MHD flows under nuclear fusion
conditions. PhD thesis, Dept. of Physics and Nuclear Engineering, Universitat Politecnica de
Catalunya, 2011.

[9] Vincent Dousset. Numerical simulations of MHD flows past obstacles in a duct under externally
applied magnetic field. PhD thesis, Coventry University, 2009.
[10] J.M. Ni et al. A current density conservative scheme for incompressible MHD flows at a low
magnetic reynolds number. Part I: On a rectangular collocated grid system. Journal of Com-
putational Physics, 227(1):174–204, 2007.

[11] J.M. Ni et al. A current density conservative scheme for incompressible MHD flows at a low
magnetic reynolds number. Part II: On an arbitrary collocated mesh. Journal of Computational
Physics, 227(1):205–228, 2007.
[12] C. Mistrangelo and L. Bühler. Development of a numerical tool to simulate magnetohydro-
dynamic interactions of liquid metals with strong applied magnetic fields. Fusion Science and
Technology, 60(2):798–803, 2011.
[13] J. Feng, H. Chen, Q. He, and M. Ye. Further validation of liquid metal MHD code for unstruc-
tured grid based on OpenFOAM. Fusion Engineering and Design, 100:260–264, 2015.

50
BIBLIOGRAPHY BIBLIOGRAPHY

[14] E.M. de les Valls and L. Batet. OpenFOAM capabilities for MHD simulation under nuclear
fusion technology conditions. Presentation at 3rd OpenFOAM workshop at Milan, Italy ,
available online at: http://www.woodruffscientific.com/files/ElisabetMasDeLesValls.pdf, July
2008.

51
Study questions

Theoretical background
1. When the inductionless approximation can be employed to simplify the MHD govering equa-
tions?
2. What is the difference between the B-formulation and the phi-formulation?

3. What is the physical meaning of the Hartmann number (M)?


The mhdFoam solver
1. What method is employed in the mhdFoam solver to ensure the divergence-free condition of the
magnetic field?

2. The file magneticFieldErr.H is included into mhdFoam.C and used to evaluate the magnetic
field divergence error. However, the variable actually solved in the file is not the magnetic
field. Explain the reason.
3. What is the meaning of the parameter L? Which conditions should be satisfied in order to
have a stable and monotone convergent numerical scheme for a 2D MHD flow?

4. What is the value of the wall conductance ratio (c) for the Hartmann problem?
The epotFoam solver
1. Describe the advantages and drawbacks of an electric potential solver compared with a mag-
netic induction-based one.

2. How it is defined the applied magnetic field in epotFoam?


3. How is calculated the Lorentz force in the epotFoam algorithm?
Tutorials for laminar 2D MHD flow

1. Why high velocity jets are generated close to the side walls in the Hunt case?
2. A critical mesh requirement for a MHD flow is the proper resolution of the Hartmann layer.
Explain why and how many nodes are required.
3. What is the influence of the magnetic field and the wall conductance ration on the pressure
drops in the channel? Try to simulate various Shercliff and Hunt cases for different values of
M.

52
Appendix

epotFoam.C
*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 Original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it


under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT


ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Application
epotFoam

Description
Transient solver for incompressible, laminar MHD flow of Newtonian fluids
employing the electric potential formulation. The Lorentz force term is
treated in a NON-CONSERVATIVE way, but a consistent and conservative scheme
for the computation of the current density according to Ni et al. is used to
ensure conservation of momentum and current density.

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
#include "pisoControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])

53
BIBLIOGRAPHY BIBLIOGRAPHY

{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"

pisoControl piso(mesh);

#include "createFields.H"
#include "initContinuityErrs.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting time loop\n" << endl;

//Lorentz force term initialization


volVectorField lorentz = sigma * (-fvc::grad(PotE) ^ B0) + sigma * ((U ^ B0) ^ B0);

while (runTime.loop())
{
Info<< "Time = " << runTime.timeName() << nl << endl;

#include "CourantNo.H"

// Momentum predictor

fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
- (1.0/rho) * lorentz //Lorentz term
);

if (piso.momentumPredictor())
{
solve(UEqn == -fvc::grad(p));
}

// --- PISO loop


while (piso.correct())
{
volScalarField rAU(1.0/UEqn.A());
volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p));
surfaceScalarField phiHbyA
(
"phiHbyA",
fvc::flux(HbyA)
+ fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)
);

//field must satisfy continuity equation


adjustPhi(phiHbyA, U, p);

// Update the pressure BCs to ensure flux consistency

54
BIBLIOGRAPHY BIBLIOGRAPHY

constrainPressure(p, U, phiHbyA, rAU);

// Non-orthogonal pressure corrector loop


while (piso.correctNonOrthogonal())
{
// Pressure corrector

fvScalarMatrix pEqn //Pressure equation coefficient matrix


(
fvm::laplacian(rAU, p) == fvc::div(phiHbyA)
);

//reference value of pressure


pEqn.setReference(pRefCell, pRefValue);

//solve pressure equation according to solution dictionary, check if final iteration


pEqn.solve(mesh.solver(p.select(piso.finalInnerIter())));

if (piso.finalNonOrthogonalIter())
{
phi = phiHbyA - pEqn.flux();
}
}

#include "continuityErrs.H"

//momentum eq and BCs corrections


U = HbyA - rAU*fvc::grad(p);
U.correctBoundaryConditions();
}

//Interpolating cross product u x B over mesh faces


surfaceScalarField psiub = fvc::interpolate(U ^ B0) & mesh.Sf();

//Poisson equation for electric potential


fvScalarMatrix PotEEqn
(
fvm::laplacian(PotE)
==
fvc::div(psiub)
);

//Reference potential
PotEEqn.setReference(PotERefCell, PotERefValue);

//Solving Poisson equation


PotEEqn.solve();

//Computation of current density at cell faces


surfaceScalarField jn = -(fvc::snGrad(PotE) * mesh.magSf()) + psiub;

//Current density at face center


surfaceVectorField jnv = jn * mesh.Cf();

55
BIBLIOGRAPHY BIBLIOGRAPHY

//Interpolation of current density at cell center


volVectorField jfinal = fvc::surfaceIntegrate(jnv) - (fvc::surfaceIntegrate(jn) * mesh.C());

//Update current density distribution and boundary condition


jfinal.correctBoundaryConditions();

//Lorentz force computation


lorentz = sigma* (jfinal ^ B0);

runTime.write(); //ensure writing of all IObjects with AUTO.WRITE

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"


<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
} //end of time loop

Info<< "End\n" << endl;

return 0;
}
// ************************************************************************* //

createFields.H
Info<< "Reading transportProperties\n" << endl;

IOdictionary transportProperties
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);

Info<< "Reading electromagneticProperties\n" << endl;

//Additional dictionary for magnetic field definition


IOdictionary electromagneticProperties
(
IOobject
(
"electromagneticProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);

56
BIBLIOGRAPHY BIBLIOGRAPHY

//Kinematic viscosity
dimensionedScalar nu
(
"nu",
dimViscosity,
transportProperties.lookup("nu")
);

//Density
dimensionedScalar rho
(
"rho",
dimDensity,
transportProperties.lookup("rho")
);

//Electrical conductivity
dimensionedScalar sigma
(
"sigma",
dimensionSet(-1, -3, 3, 0, 0, 2, 0),
transportProperties.lookup("sigma")
);

//Magnetic field
dimensionedVector B0
(
"B0",
dimensionSet(1, 0, -2, 0, 0, -1, 0),
electromagneticProperties.lookup("B0")
);

//Pressure field
Info<< "Reading field p\n" << endl;
volScalarField p
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

//Velocity field
Info<< "Reading field U\n" << endl;
volVectorField U
(
IOobject
(

57
BIBLIOGRAPHY BIBLIOGRAPHY

"U",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

#include "createPhi.H"

//Electric potential field


Info<< "Reading field PotE\n" << endl;
volScalarField PotE
(
IOobject
(
"PotE",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

//Pressure reference point


label pRefCell = 0;
scalar pRefValue = 0.0;
setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
mesh.setFluxRequired(p.name());

//Electric potential reference point


label PotERefCell = 0;
scalar PotERefValue = 0.0;
setRefCell(PotE, mesh.solutionDict().subDict("PotE"), PotERefCell, PotERefValue);
mesh.setFluxRequired(PotE.name());

Analytical solutions for Shercliff and Hunt flows


The analytical solutions originally presented by Shercliff [4] and Hunt [5] have been reformulated to
be directly applied for computer calculations at high Hartmann numbers by Ni et al. [11]. The side
walls are non-conducting with lenghts 2a, whereas the Hartmann walls with lenghts 2b have arbitrary
conductivity represented by the wall conductance ratio dB . The aspect ratio of the duct is l = b/a
and the magnetic field is applied in the y-direction. The scaled coordinates ξ = x/a ∈ [−l, l] and
η = y/b ∈ [−l, l] are also defined. The velocity expression is given as a series in ξ with coefficients
in η

X 2(−1)k cos(αk ξ)
V = (1 − V2 − V3 )
lαk3
k=0

58
BIBLIOGRAPHY BIBLIOGRAPHY

 
1−exp(−2r2k ) exp(−r1k (1−η))+exp(−r1k (1+η))
dB r2k + 1+exp(−2r2k ) 2
V2 = 1+exp(−2r1k ) 1+exp(−2(r1k +r2k ))
2 dB N + 1+exp(−2r2k )
 
1−exp(−2r1k ) exp(−r2k (1−η))+exp(−r2k (1+η))
dB r1k + 1+exp(−2r1k ) 2
V3 = 1+exp(−2r2k ) 1+exp(−2(r2k +r1k ))
2 dB N + 1+exp(−2r1k )

A similar expression can be given for the magnetic field



X 2(−1)k cos(αk ξ)
H= (1 − H2 − H3 )
lαk3
k=0
 
1−exp(−2r2k ) exp(−r1k (1−η))−exp(−r1k (1+η))
dB r2k + 1+exp(−2r2k ) 2
H2 = 1+exp(−2r1k ) 1+exp(−2(r1k +r2k ))
2 dB N + 1+exp(−2r2k )
 
1−exp(−2r1k ) exp(−r2k (1−η))−exp(−r2k (1+η))
dB r1k + 1+exp(−2r1k ) 2
H3 = 1+exp(−2r2k ) 1+exp(−2(r2k +r1k ))
2 dB N + 1+exp(−2r1k )

In the formulas above

N = (M 2 + 4αk2 )1/2

1
r1k , r2k = (±M + N )
2
 
1 π
αk = k +
2 l
The velocity profile at the center of the duct for the Hartmann walls can be obtained by imposing
ξ = 0, whereas for the side walls with η = 0. Of course, if dB = 0 the profile would be the one
referring to the Shercliff case whereas for dB = ∞ to the Hunt case. Once V is known it is possible
to obtain the fully developed velocity distribution through the relation
 
−1 ∂p
Vz = (ρν) V − a2
∂z
For the Shercliff case, a relation for the mean velocity is also given as

2a2 dp X 1
V0 = − V4
l2 η dz αk4
k=0
 
N 1 + exp(−2N ) 1 + exp(−2M )
V4 = 1 − 2 − exp(M − N )
2αk 1 − exp(−2N ) 1 − exp(−2N )
In turn, the calculated H can be used to determine the current density distribution with the relations
 
−1/2 ∂p
Hz = µ H − a2 σ 1/2
∂z
∂Hz ∂Hz
jx = jy =
∂y ∂x

59

You might also like