1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Solver for magnetohydrodynamics (MHD): incompressible, laminar flow of a
30 conducting fluid under the influence of a magnetic field.
32 An applied magnetic field H acts as a driving force,
33 at present boundary conditions cannot be set via the
34 electric field E or current density J. The fluid viscosity nu,
35 conductivity sigma and permeability mu are read in as uniform
38 A fictitous magnetic flux pressure pH is introduced in order to
39 compensate for discretisation errors and create a magnetic face flux
40 field which is divergence free as required by Maxwell's equations.
42 However, in this formulation discretisation error prevents the normal
43 stresses in UB from cancelling with those from BU, but it is unknown
44 whether this is a serious error. A correction could be introduced
45 whereby the normal stresses in the discretised BU term are replaced
46 by those from the UB term, but this would violate the boundedness
47 constraint presently observed in the present numerics which
48 guarantees div(U) and div(H) are zero.
50 \*---------------------------------------------------------------------------*/
53 #include "OSspecific.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 int main(int argc, char *argv[])
59 #include "setRootCase.H"
61 #include "createTime.H"
62 #include "createMesh.H"
63 #include "createFields.H"
64 #include "initContinuityErrs.H"
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 Info<< nl << "Starting time loop" << endl;
70 while (runTime.loop())
72 #include "readPISOControls.H"
73 #include "readBPISOControls.H"
75 Info<< "Time = " << runTime.timeName() << nl << endl;
77 #include "CourantNo.H"
84 - fvc::div(phiB, 2.0*DBU*B)
85 - fvm::laplacian(nu, U)
86 + fvc::grad(DBU*magSqr(B))
89 solve(UEqn == -fvc::grad(p));
94 for (int corr=0; corr<nCorr; corr++)
96 volScalarField rUA = 1.0/UEqn.A();
100 phi = (fvc::interpolate(U) & mesh.Sf())
101 + fvc::ddtPhiCorr(rUA, U, phi);
103 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
107 fvm::laplacian(rUA, p) == fvc::div(phi)
110 pEqn.setReference(pRefCell, pRefValue);
113 if (nonOrth == nNonOrthCorr)
119 #include "continuityErrs.H"
121 U -= rUA*fvc::grad(p);
122 U.correctBoundaryConditions();
128 for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
135 - fvm::laplacian(DB, B)
140 volScalarField rBA = 1.0/BEqn.A();
142 phiB = (fvc::interpolate(B) & mesh.Sf())
143 + fvc::ddtPhiCorr(rBA, B, phiB);
147 fvm::laplacian(rBA, pB) == fvc::div(phiB)
151 phiB -= pBEqn.flux();
153 #include "magneticFieldErr.H"
159 Info<< "End\n" << endl;
165 // ************************************************************************* //