magnetic induction and electric potential solvers for...

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˚ akan Nilsson Project work: Magnetic induction and electric potential solvers for incompressible MHD flows Developed for OpenFOAM-4.x Author: Alessandro Tassone Sapienza University of Rome [email protected] Peer reviewed by: akan Nilsson Milad Setareh 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

Upload: vudang

Post on 18-Aug-2018

279 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 TechnologyTaught by Hakan Nilsson

Project work:

Magnetic induction and electric potentialsolvers for incompressible MHD flows

Developed for OpenFOAM-4.x

Author:Alessandro TassoneSapienza University of [email protected]

Peer reviewed by:Hakan NilssonMilad Setareh

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 someother 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 detailssimilar 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 thatit 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

Page 2: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Learning outcomes

The main requirements of a tutorial is that it should teach the four points: How to use it, Thetheory of it, How it is implemented, and How to modify it. Therefore the list of learning outcomesis 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

Page 3: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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, Anintroduction to fluid dynamics, 2000, Cambridge University Press.

• Fundamental knowledge about the finite volume method and, in general, computational fluiddynamics codes, which can be acquired reading: H.K. Versteeg & W. Malalasekhara, AnIntroduction to Computational Fluid Dynamics:The finite volume method, 2007, LongmanScientific 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

Page 4: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Contents

1 Introduction 4

2 Theoretical background 52.1 MHD equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Fundamental parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.3 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 The mhdFoam solver 93.1 Code description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2 Hartmann tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.2.1 The blockMeshDict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.2.2 The 0 directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.2.3 The constant directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.2.4 The system directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.2.5 Results for M = 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.2.6 Results for M = 50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4 The epotFoam solver 264.1 Code description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264.2 Code implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.2.1 epotFoam.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.2.2 createFields.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5 Tutorials for laminar 2D MHD flow 325.1 Case directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.2 Shercliff tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.2.1 mhdFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.2.2 epotFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

5.3 Hunt tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.3.1 mhdFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.3.2 epotFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

3

Page 5: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Chapter 1

Introduction

This tutorial describes the theoretical background and the implementation of OpenFOAM solverssuitable for the simulation of incompressible magneto-hydrodynamic (MHD) flows. This class isa topic of interest for many research activities and industrial applications including nuclear fusionreactors, materials engineering and metallurgy. The main purpose of this document is to helpthe reader to get accustomed with the relevant phenomena and peculiar challenges of this kind ofproblems. In order to accomplish this goal it will focus the attention on the 2D MHD flows thatarise in a rectangular duct with walls of arbitrary electrical conductivity when an electric conductivefluid moves in the presence of a transverse magnetic field.

In chapter 2, the equations and the fundamental parameters that govern a MHD flow are brieflypresented. 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 therelevant induction-less approximation which is employed for the treatment of flows characterized bya low value of the magnetic Reynolds number (Rem). Since this assumption is verified for almostall the applications involving liquid metals, an alternative formulation based on it called electricpotential or φ-formulation, will be discussed. Both the formulation can be employed to model the2D MHD flows and, in fact, they have been used.

In chapter 3, the solver available in the OpenFOAM current distribution, called mhdFoam, wouldbe 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: theHartmann problem. This is the MHD flow that occurs in the presence of a transverse appliedmagnetic field, constant and uniform, which is bounded by two plates parallel, infinite, insulatingand orthogonal to the magnetic field. The case directory structure would be described and thenemployed 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 fromthe 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 Shercliffand Hunt case are developed and the results validated against analytical solutions available in theliterature.

4

Page 6: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Chapter 2

Theoretical background

In this chapter, the equations and the parameters governing a laminar and incompressible MHDflow 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-lessapproximation is introduced and the MHD set is reformulated accordingly. A different form of theMHD 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 andboundary conditions of MHD flows are briefly discussed.

2.1 MHD equations

A magneto-hydrodynamic flow occurs whenever the motion of an electric conductive fluid happensin the presence of an imposed magnetic field. Currents are induced and the velocity distributionof the flow is significantly modified by the arising of Lorentz forces which oppose the movement indirections perpendicular to the field lines. However, the influence exerted by the magnetic field isfar from being unidirectional: the same currents generate a secondary field which, abiding to theFaraday’s law, lessen the imposed one. Therefore, the velocity and magnetic field are coupled andthe flow features can no longer be described by the ordinary hydrodynamics laws but a new setof governing equations is needed. A full discussion of the topic summarized in this section can befound in textbooks dedicated to magnetohydrodynamics, such as the one by Davidson [2] or themore recent by Muller and Buhler [3].

For a laminar and incompressible MHD flow, the governing equations are obtained by combiningthe Navier-Stokes and Maxwell equations. Considering an externally applied magnetic field B0, thetotal 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 themomentum and energy equations.

∇ · u = 0 (2.2)

Du

Dt= −∇(p/ρ) + ν∇2u + (J×B)/ρ+ Sm (2.3)

DT

Dt=

k

cp ρ∇T 2 + J2/σ + St (2.4)

The symbols ρ, ν, cp, k and σ represent density, kinematic viscosity, specific heat capacity, thermaland electrical conductivity. The term (J ×B)/ρ in equation (2.3) accounts for the retarding effectof the Lorentz force or electromagnetic drag, whereas the group J2/σ in equation (2.4) representsthe heat generation in the fluid due to the Joule effect. However, the above set lacks equations to

5

Page 7: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

2.2. FUNDAMENTAL PARAMETERS CHAPTER 2. THEORETICAL BACKGROUND

determine J and B. For this purpose, equations are introduced to give closure to the system togetherwith the magnetic permeability µ. From the Ohm’s and Ampere’s law the magnetic inductionequation is deduced

∂B

∂t= ∇× (u×B) +

1

µσ∇2B (2.5)

that can be used to calculate the magnetic field distribution, which must satisfy the Gauss’ law formagnetism

∇ ·B = 0 (2.6)

In turn, the current density distribution is obtained from the Ampere’s law

J =1

µ∇×B (2.7)

The flow considered is described completely by (2.1-5), which is known as the magnetic inductionformulation of the MHD equations. The non-linear and mutual coupling between the velocity andmagnetic 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 ofthe most widely employed is the induction-less approximation. The coupling intensity between thevelocity and magnetic field can be represented by the magnetic Reynolds number, which is definedas

Rem =Momentum advection

Magnetic diffusivity= µσu0L (2.8)

If Rem 1, the magnetic field is not dependent from the flow velocity distribution and determinedexclusively by the boundary conditions. In other terms, the induced field b in (2.1) can be neglectedand we can declare that B ' B0. Therefore, equation (2.5) is simplified accordingly in a purediffusion one

∂B

∂t=

1

µσ∇2B (2.9)

If the induction-less approximation is valid, the MHD equations can be casted in a differentformulation. Employing Ohm’s law and the charge conservation condition (DJ/Dt = 0), a Poissonequation 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 toreasons that would be discussed in section 4.1. In the following, we will always assume that theinduction-less approximation is valid.

2.2 Fundamental parameters

The parameters of interest for a laminar, incompressible and induction-less MHD flow are essentiallythree: the Hartmann number (M), the interaction parameter or Stuart number (N) and the wallconductance ratio (c).

The Hartmann number expresses the relation between electromagnetic and viscous forces actingon the fluid, hence representing the magnetic field intensity and the deviation from the ordinary

6

Page 8: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

2.2. FUNDAMENTAL PARAMETERS CHAPTER 2. THEORETICAL BACKGROUND

hydrodynamic behavior. In a typical fusion reactor blanket, this parameter can reach up to 104. Itis formulated as

M =

(Electromagnetic forces

Viscous forces

)1/2

= BL

√σ

ρν(2.12)

The characteristic length L for a rectangular duct is the half-length in the magnetic field linesdirection.

The boundary layer structure is dependent on the associated wall orientation with the magneticfield. For perpendicular walls an Hartmann layer is formed, whereas for parallel walls a Sherclifflayer occurs. The scaling of these layers depends by the Hartmann number according to the relations

δH = 1/M (2.13a)

δS = 1/M1/2 (2.13b)

Therefore, we define Hartmann walls those where the former condition applies and, conversely, sidewalls 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 anon-null normal component of the magnetic field to the wall.

The interaction parameter measures the relative strength of the electromagnetic and inertialforces. Thus, it is correlated to both the Hartmann and Reynolds number through the relation

N =Electromagnetic forces

Inertial forces=M2

Re=B2 Lσ

ρu0=

L

u0 τ(2.14)

The group ρ/σB2 is called magnetic damping time τ and represents the characteristic time in whichthe magnetic field dissipate the kinetic energy carried by the flow. If N 1, then τ is big and theflow is unaffected by the electromagnetic drag. Otherwise, the flow is dominated by the Lorentzforce and it can be considered as inertia-less. The turbulence structures are largely suppressed andthe existence region of the laminar regime is extended. In a typical fusion reactor blanket, thisparameter can reach up to 104.

The electromagnetic drag caused is not uniformly distributed on the duct cross-section but isdependent on the induced current paths inside the fluid. Mean path resistivity influences the MHDpressure drops severity, whereas the path geometry can create local areas where the Lorentz force isreduced, hence causing the onset of jets. Therefore, the flow features are influenced by the relativeconductivity between the duct wall and the fluid which is expressed by the wall conductance ratio

c =σwσ

t

L(2.15)

A value of c → 0 characterizes a duct with poorly conductive walls, whereas a duct with c > 1is associated to well conducting walls. Even small variations for the value of this parameter candrastically 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 causethe 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 andnumerically, in the past and are considered as relevant benchmarks for the validation of numericalcodes [6]. In chapter 5, these two cases would be developed as tutorials for the solvers discussed inchapters 3 and 4.

7

Page 9: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 boundarycondition at the duct walls (u = 0). Dirichlet boundary conditions are employed at the inlet (meanvelocity) and outlet (zero pressure) surfaces. Electromagnetic boundary conditions should also bespecified 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 astream-function of the current density. Therefore, a simple Dirichlet or Neumann boundary conditioncan be set at the wall depending on the wall conductivity. Assuming uniform conductivity, for aperfectly conducting wall the current density flux is conserved at the fluid/solid interface Γ andthe tangential component JΓ must be zero, hence from the Ampere’s law (2.7) we obtain that themagnetic induction gradient normal to the wall must be equal to zero. Otherwise, for a perfectlyinsulating 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 besummarized as

∂B

∂n= 0 (valid for c =∞) (2.16a)

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)

∂φ

∂n= 0 (valid for c = 0) (2.17b)

A considerable layer of complexity is added to this straightforward problem when the walls havean 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 boththe 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 thecurrents in the wall turns in a quasi bi-dimensional way in the tangential direction. Therefore theJw,t and φw are constant across the wall. The component of Jw normal to the wall can be obtainedby 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), theequation (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

Page 10: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Chapter 3

The mhdFoam solver

In this chapter the mhdFoam solver is presented. It employs the magnetic induction formulation ofthe 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 magneticfield, 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 Huntflow.

3.1 Code description

The mhdFoam application solves the complete set of the MHD governing equations described inchapter 2 and thus takes into consideration the complete coupling between the magnetic and velocityfield. At high Hartmann numbers The most critical aspect is to ensure that the total magnetic fieldB, composed by the sum of the applied B0 and induced b, meets the divergence-free condition statedin equation (2.6) for every timestep. This condition is automatically satisfied in 1D simulations butnot so for multi-dimensional ones: non-null divergence of the magnetic field can lead to inaccurateresults and unstable schemes.

Different methods were proposed in the past to overcome this issue [8]. The Projection methodwas the one chosen for mhdFoam and it consists in the correction at the end of the timestep of thecalculated 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 thenecessary corrections exploiting the analogy with the velocity field highlighted by the continuityequation.

An example of the source code of mhdFoam can be found in the directory reached by typing inthe 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

Page 11: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

3.1. CODE DESCRIPTION CHAPTER 3. THE MHDFOAM SOLVER

It contains the main source files mhdFoam.C and createFields.H; the file associated with theBPISO 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 momentumequation 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

µ(J×B) =

1

ρµ(∇×B×B) = − 1

2ρµ∇B2 +

1

ρµ(B · ∇)B (3.1)

These terms corresponds to fvc::grad(DBU*magSqr(B)) and fvc::div(phiB, 2.0*DBU*B) in themhdFoam code. The definition of the scalar DBU can be found in createFields.H, alongside themagnetic 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 BPISOstarts. Its structure resembles closely the previous hydrodynamic loop. In this case, the momentumpredictor role is fulfilled by the magnetic induction equation (2.5) which calculates the magneticfield 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

Page 12: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 variabledistribution is then employed to correct the φB values. The magnetic field divergence errors areprinted and the loop starts again from the B prediction step, which now will use the updated φBvalues. 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, theBPISO is lacking the boundary conditions updating step. Moreover, B is not actually corrected atthe end of the scheme but just through the flux φB [8]. Even the divergence error is computed fromthe 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 bepossible that for cases where the induced field b plays a greater role (i.e. finite Rem) this inaccuratetreatment 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 thetutorial available in the OpenFOAM-4.x distribution. A description of this tutorial is also available

11

Page 13: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 andinsulated plates which are orthogonal to the magnetic field direction. Since the side walls of thechannel 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 belowhartmann

0

Allclean

Allrun

constant

system

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

3.2.1 The blockMeshDict

The case geometry is defined in the blockMeshDict inside the system directory. Since the flowis bi-dimensional, only a slice of the duct in the xy-plane is modelled whereas just one node isprovided in the z-direction. The mesh is composed of a single block. The full dictionary is shownbelow: please note that the patches upperWall and lowerWall are the Hartmann walls whereas thefrontAndBack 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

Page 14: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 15: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 forM = 20, remembering the scaling law (2.13a) this means that 1 node is present in the Hartmannboundary layer region, which is critical for the resolution of the velocity profile. The length scale ischosen 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 appliedfield 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 andupperWall have a boundary condition of type fixedValue equal to the internal field value. AzeroGradient is employed for inlet and outlet, whereas the patches frontAndBack are specifiedas 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

Page 16: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 boundaryconditions are the same that could be expected in the analogous flow in absence of the magneticfield (inlet-velocity/pressure-outlet, no slip, etc.). An uniform velocity U = (1, 0, 0) is imposed atthe inlet. The files 0/Ux, 0/Uy and 0/Uz are used by the functionObject components to calculatethe velocity vector components from the U field for postprocesing purpose. More interesting is the0/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

Page 17: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 surprisethat it is initialized as zero in the domain. The other boundary conditions are what would beexpected 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 assumedconstant 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 Hartmannnumber is fixed by the magnetic field intensity which is specified in the file 0/B. Therefore, tomodify 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 = 1m andthe mean velocity as U0 = 1ms−1. Recalling (2.8), (2.12), (2.14), (2.15) and the classical definitionof the Reynolds number we obtain the parameters of the tutorial: Rem = 1,M = 20, Re = 2, N = 50and 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 dictionarycontains the general setting for the simulation and the functionObjects executed at runtime. Thecode is reported below with the header and not-solver relevant sections omitted.

(omissis)

application mhdFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

16

Page 18: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 mustbe specified in order to have a stable and monotone numerical scheme. The Courant-Friedrichs-Lewycondition 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 velocityand the magnetic field. In particular, the magnetic damping time, defined in (2.14) must be greaterthan the time step [2].

∆t < τ (3.3)

A Von Neumann stability analysis carried over for a 1D simulation individuated the parameter L,defined as

L =σB2

0∆t

ρ(3.4)

It was found that in order to have a stable numerical scheme L ≤ 2∪L 6= 1, whereas the best accuracywas found for L → 2 and L → 0. A value of L < 0.2 was recommended for the performance of a3D simulation [8]. For increasing values of the Hartmann number, the condition on L is the mostdemanding. Moreover, for a monotone scheme the condition that should be met can be expressedas

C + 2L+ν∆t

(∆x)2≤ 1 (3.5)

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

(header omitted)

ddtSchemes

default Euler;

gradSchemes

default Gauss linear;

17

Page 19: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 thepressure and the pseudo-magnetic pressure fields, a Preconditioned conjugate gradient (PCG) solveris 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 forboth 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

Page 20: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 utilitycalled sample. When run, it will extract the velocity profile at the centre of the duct between theplates for every written time step and store it in the new created postProcessing folder. In thenext part, the results of the tutorial would be validate against a theoretical solution employing thisfile.

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

Page 21: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 inthe 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 helpfulto modify the system/sample dictionary in order to obtain more meaningful data for the resultsvalidation.

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 Figure3.2, 3.3 and 3.4. To validate the tutorial results, we will employ the analytical solution available inthe OpenFOAM Programmer’s Guide and presented also by Weller et al. [1].

Ux = U0coshM − coshM(y/L)

coshM − sinhM/L(3.6)

After the run is completed, to extract the velocity profile data it is necessary to type the commandto 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 andthen plot "<dataFileName>" to generate the image from the desired file. However, the result ofthis 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

Page 22: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 23: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 24: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

ε = max

(|Ux − Ux, theory|

Ux, theory

)· 100 = 1.3% (3.7)

The error is due to the uniform mesh employed which is not able to accurately resolve the intensegradient in the Hartmann layer and therefore underestimates the velocity in the core region. Thisissue becomes critical at higher M . To reduce the error it is necessary to concentrate the meshtoward 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 minormodifications are needed to run the case successfully, nevertheless the author believes that it wouldhelp to highlight some issues typical of the computational MHD.

The parameters and properties used for the previous run are left untouched, unless for themagnitude of the applied magnetic field which is raised from 20 T to 50 T. Since all the propertiesof the fluid considered are equal to the unity, this modification translates in a correspondingly risein 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 insideit, 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

Page 25: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 theparameter 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 comparisonof the velocity profiles obtained for values of M ∈ [0, 50] is available in Figure 3.7.

24

Page 26: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

3.2. HARTMANN TUTORIAL CHAPTER 3. THE MHDFOAM SOLVER

Figure 3.7: Velocity profile for M from 0 to 50

25

Page 27: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Chapter 4

The epotFoam solver

In this chapter the epotFoam solver is presented. It is based on the application originally developedby Vincent Dousset of the Coventry University for a previous version of OpenFOAM and the φ-PISOalgorithm 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 sourcecode is briefly revised and implemented starting from the distribution solver icoFoam. The finalcode, obtained following the instructions contained in this chapter, is available in the accompanyingfiles of this document. Tutorials for the solver can be found in the chapter 5 for the cases of Shercliffand Hunt flow.

4.1 Code description

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

• In order to obtain the J distribution, a scalar equation (2.10) must be solved instead of avectorial (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 isdetermined just by the boundary conditions. The MHD coupling non-linearity is lessened andthe numerically stability is improved [11].

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

For the design of fusion reactor blankets, the inductionless approximation is always applicable andalmost 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 evenunphysical results when employed in numerical codes. In particular, the momentum conservationcould be violated for unstructured meshes and high M values due to the non-conservative formulationof the Lorentz force. This issue is worsened when inconsistent interpolation techniques are used forthe computation of cell center values of current density which can result in a field which does notsatisfy the charge conservation, a critical condition for high M flows.

For a collocated mesh, a conservative and consistent numerical scheme was developed in 2007 byNi et al. for both structured [10] and unstructured [11] grids in order to address these issues. Theauthors demonstrated the capability of the scheme to correctly simulate 2D and 3D MHD flows andsince then it is considered as the state-of-the-art, being employed in the development of codes forfusion reactor blanket design [12] [13].

26

Page 28: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

In the epotFoam implementation that would be described in section 4.2, the Lorentz force isstill treated as a source term but, thanks to the consistent interpolation technic employed for theJ 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 toemploy 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 fieldprediction for the PISO loop

∂u

∂t+∇ · (φu,u)−∇2(ν,u)− (1/ρ)L = −∇(p)

3. Execution of the PISO loop for a fixed number of iterations, a Poisson equation is solved toobtain the pressure field which is therefore employed to correct the velocity field predicted atthe previous step.

4. Continuity equation is solved to estimate errors and boundary conditions for velocity areupdated

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

Jc =1

Ωp

nf∑f=1

jf (rf − rp) · Sf

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 toobtain 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 defaultsolver icoFoam. In order to do so, a vanilla copy of the latter is needed. A good practise to followduring the development of a new solver is to maintain the directory general structure of the OpenFOAMsource code. Abiding to this rule, if they are not present we will first create the necessary directoriesand then copy icoFoam in the bottom one.

27

Page 29: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 ofenvironment would be soon justified. For now, to properly compile the code a few name changes areneeded 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 togenerate 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 needto initialize the Lorentz force field before the time loop start. Just after the IO printing add thefollowing 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 productJ×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. Insidethe 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 consideringthe magnetic field influence. No further modification are needed for the velocity-pressure couplingand we can skip at the PISO loop end.

To calculate the electric potential distribution needed for the computation of the Lorentz forcewe have to solve the Poisson equation (2.10) in which the cross product u×B is present. Employingthe updated velocity values after the conclusion of the PISO loop, the quantity psiub would beestimated 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

Page 30: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 wouldbe 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 calculatedfirst by computing the current density fluxes on the cell faces and then interpolating to obtain thedesired 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 therunTime.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 inthe Appendix as a mean of comparison with the user file redacted following the instructions of thissection.

4.2.2 createFields.H

The standard file valid for the icoFoam solver must be modified in order to account for the newquantities 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 beinga volScalarField object could be modelled starting from the pressure field entry.

29

Page 31: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

4.2. CODE IMPLEMENTATION CHAPTER 4. THE EPOTFOAM SOLVER

After opening createFields.H in a suitable text editor, the first modification would be thereading and the declaration of the new dictionary in the preamble. This can be made by copyingthe 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 thekinematic 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 ina 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, asfollows

//Electric potential field

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

volScalarField PotE

30

Page 32: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 thepotential 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 isavailable in the Appendix as a mean of comparison with the user file redacted following the previousinstructions.

The implementation of the new solver is completed. The last step is the compilation of epotFoamwhich 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

Page 33: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

Chapter 5

Tutorials for laminar 2D MHD flow

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

5.1 Case directory structure

The case directory setup for the tutorials of this chapter is very similar to the one presented in thesection 3.2 for the mhdFoam Hartmann problem case. The main difference are encountered in theinitial and boundary conditions settings, the discretization schemes and time step used. In Figure5.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 filesin order to generate the tutorials from scratch. The final tutorials are available in the accompanyingfiles of this document.

5.2 Shercliff tutorial

Consider the flow of an electric conductive fluid in a square duct where a constant and uniformmagnetic field is applied alongside the y-axis (Figure 5.2). The duct walls (half-length L = 1m)have null electrical conductivity and are therefore assumed as perfectly insulating. The fluid is drivenby a constant pressure gradient ∇p, parallel to the x-axis, and at the inlet its velocity is assumedas uniform on the cross section and equal to u = 1m/s.

If these assumptions are valid, all the flow variables except the pressure are constant in theduct axis direction and the flow is bi-dimensional. The flow cross-section can be divided in threezones. The inviscid core region occupies the duct center and it is characterized by a slug flowwith a uniform velocity where the Lorentz force compensates the pressure gradient. The Hartmannboundary layers of thickness δH = O(M−1) are localized near the walls orthogonal to the magneticfield and experience an exponential decay in the velocity. Finally, the more thick side boundarylayers (δS = O(M−1/2)) are found close to the walls parallel to the magnetic field direction. Sincethe walls are non-conductive, the induced currents in the fluid generated by the interaction betweenthe velocity and magnetic field can not penetrate the solid domain and therefore must close throughthe boundary layers to satisfy the charge conservation condition.

This case was first studied by Shercliff in [4] which formulated the analytical solution to theproblem as a Fourier series dependent by M . This approach was successively extended by Hunt

32

Page 34: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

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

33

Page 35: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 isa particular case. The Hunt-Shercliff formula was re-casted by Ni et al. [11] to suit the need ofcomputer calculations at high M number and in this updated form is employed to validate thenumerical 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 (seesection 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 factorof 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

Page 36: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 37: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 mustbe 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 renamingthe upperWall entry to apply it for the new set of walls. Since we are employing a non-uniformmesh 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

Page 38: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 velocityprofile 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

Page 39: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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, theHartmann at z = 0

Figure 5.4: Residuals for magnetic field

38

Page 40: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 41: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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. Employingthe new sample dictionary and the shercliff.dat file containing the analytical solution ([11]) tovalidate 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 theepotFoam without any issues. However, since the flow presents a symmetry plane at y = 0 forboth the velocity and the electric potential it is possible to simulate just one half of the duct. Thevertices entries must be modified accordingly and the lowerWall patch can be transformed in asymmetryPlane. 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

Page 42: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 Hartmannone, it is of paramount importance to obtain meaningful physical results. This is even more criticalfor 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 zeroGradiententry on all the patches except the symmetryPlane one (see subsection 2.3). The following lines mustbe 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 thename 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 storethe applied magnetic field. Copy the following lines inside the new dictionary

41

Page 43: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 toepotFoam. This solver is more numerically stable than the previous one, therefore is possibly toemploy 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 thesnGradSchemes from corrected to orthogonal. At the end of the fvSolution dictionary, add thefollowing 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 analyticalsolution [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 uniformmagnetic field is applied alongside the y-axis (Figure 5.10). The duct walls (half-length L = 1m)have non-uniform electrical conductivity. The pair of Hartmann walls are assumed to be perfectlyconducting, whereas the side walls are composed of a perfect dielectric material. The fluid is drivenby a constant pressure gradient ∇p, parallel to the x-axis, and at the inlet its velocity is assumedas uniform on the cross section and equal to u = 1m/s.

If these assumptions are valid, all the flow variables except the pressure are constant in the ductaxis direction and the flow is bi-dimensional. The currents induced in the fluid can not enter theinsulating side walls and therefore are forced to flow alongside them to close through the conductiveHartmann walls. In a very similar way to what happen for a Shercliff case, the flow cross-sectioncan be divided in three zones. The core and Hartmann layers region are analog to the one describedfor the Shercliff case (see 5.2). In the side layers, the component of the current density tangentialto the wall becomes dominant over the normal one (i.e. Jt Jn with Jn → 0) and therefore theLorentz force is greatly weakened compared with the other regions. This phenomenon causes theformation of high velocity which can carry a relevant fraction of the flow rate in the thin side layersregion. 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 asa Fourier series dependent by M [5]. The Hunt formula was re-casted by Ni et al. to suit the needof computer calculations at high M number and in this updated form is employed to validate thenumerical results of this document [11]. The full expression is available in the Appendix.

42

Page 44: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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, theHartmann at z = 0

43

Page 45: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 conductiveHartmann walls

44

Page 46: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 Hartmannwalls. In the following it is assumed that the reader has already followed the instructions in subsection5.2.1.

The same mesh and solver control settings can be used for the Hunt tutorial, just the boundaryconditions for the magnetic field must be modified in order to take into consideration the non-uniformwall 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 thesubsection 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. Employingthe hunt.dat file containing the analytical solution ([11]) to validate the numerical results a perfectagreement 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 Hartmannwalls. In the following it is assumed that the reader has already followed the instructions in subsection5.2.2.

45

Page 47: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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, theHartmann at z = 0

Figure 5.12: Residuals for magnetic field

46

Page 48: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 49: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 boundaryconditions 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 the0/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 analyticalsolution ([11]) to validate the numerical results a perfect agreement should be found (see Figure5.16). A plot of the electric potential for y = 0 is also provided in Figure 5.17.

48

Page 50: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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, theHartmann at z = 0

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

49

Page 51: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 universitypress, 2001.

[3] U. Muller and L. Buhler. 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. InMathematical 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 fusionapplications. 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 onlineat: 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 fusionconditions. PhD thesis, Dept. of Physics and Nuclear Engineering, Universitat Politecnica deCatalunya, 2011.

[9] Vincent Dousset. Numerical simulations of MHD flows past obstacles in a duct under externallyapplied magnetic field. PhD thesis, Coventry University, 2009.

[10] J.M. Ni et al. A current density conservative scheme for incompressible MHD flows at a lowmagnetic 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 lowmagnetic reynolds number. Part II: On an arbitrary collocated mesh. Journal of ComputationalPhysics, 227(1):205–228, 2007.

[12] C. Mistrangelo and L. Buhler. Development of a numerical tool to simulate magnetohydro-dynamic interactions of liquid metals with strong applied magnetic fields. Fusion Science andTechnology, 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

Page 52: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

BIBLIOGRAPHY BIBLIOGRAPHY

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

51

Page 53: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 themagnetic field?

2. The file magneticFieldErr.H is included into mhdFoam.C and used to evaluate the magneticfield divergence error. However, the variable actually solved in the file is not the magneticfield. Explain the reason.

3. What is the meaning of the parameter L? Which conditions should be satisfied in order tohave 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 pressuredrops in the channel? Try to simulate various Shercliff and Hunt cases for different values ofM .

52

Page 54: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 55: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 56: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 57: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 58: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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

Page 59: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

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 tobe directly applied for computer calculations at high Hartmann numbers by Ni et al. [11]. The sidewalls are non-conducting with lenghts 2a, whereas the Hartmann walls with lenghts 2b have arbitraryconductivity represented by the wall conductance ratio dB . The aspect ratio of the duct is l = b/aand 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 coefficientsin η

V =

∞∑k=0

2(−1)kcos(αkξ)

lα3k

(1− V2 − V3)

58

Page 60: Magnetic induction and electric potential solvers for ...hani/kurser/OS_CFD_2016/AlessandroTassone/... · Cite as: Tassone, A.: Magnetic induction and electric potential solvers for

BIBLIOGRAPHY BIBLIOGRAPHY

V2 =

(dBr2k + 1−exp(−2r2k)

1+exp(−2r2k)

)exp(−r1k(1−η))+exp(−r1k(1+η))

2

1+exp(−2r1k)2 dBN + 1+exp(−2(r1k+r2k))

1+exp(−2r2k)

V3 =

(dBr1k + 1−exp(−2r1k)

1+exp(−2r1k)

)exp(−r2k(1−η))+exp(−r2k(1+η))

2

1+exp(−2r2k)2 dBN + 1+exp(−2(r2k+r1k))

1+exp(−2r1k)

A similar expression can be given for the magnetic field

H =

∞∑k=0

2(−1)kcos(αkξ)

lα3k

(1−H2 −H3)

H2 =

(dBr2k + 1−exp(−2r2k)

1+exp(−2r2k)

)exp(−r1k(1−η))−exp(−r1k(1+η))

2

1+exp(−2r1k)2 dBN + 1+exp(−2(r1k+r2k))

1+exp(−2r2k)

H3 =

(dBr1k + 1−exp(−2r1k)

1+exp(−2r1k)

)exp(−r2k(1−η))−exp(−r2k(1+η))

2

1+exp(−2r2k)2 dBN + 1+exp(−2(r2k+r1k))

1+exp(−2r1k)

In the formulas above

N = (M2 + 4α2k)1/2

r1k, r2k =1

2(±M +N)

αk =

(k +

1

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 onereferring to the Shercliff case whereas for dB =∞ to the Hunt case. Once V is known it is possibleto obtain the fully developed velocity distribution through the relation

Vz = (ρν)−1V

(−∂p∂z

)a2

For the Shercliff case, a relation for the mean velocity is also given as

V0 = −2a2

l2η

dp

dz

∞∑k=0

1

α4k

V4

V4 = 1− N

2α2k

(1 + exp(−2N)

1− exp(−2N)− exp(M −N)

1 + exp(−2M)

1− exp(−2N)

)In turn, the calculated H can be used to determine the current density distribution with the relations

Hz = µ−1/2H

(−∂p∂z

)a2σ1/2

jx =∂Hz

∂yjy =

∂Hz

∂x

59