OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

mhdFoam.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     mhdFoam
00027 
00028 Description
00029     Solver for magnetohydrodynamics (MHD): incompressible, laminar flow of a
00030     conducting fluid under the influence of a magnetic field.
00031 
00032     An applied magnetic field H acts as a driving force,
00033     at present boundary conditions cannot be set via the
00034     electric field E or current density J. The fluid viscosity nu,
00035     conductivity sigma and permeability mu are read in as uniform
00036     constants.
00037 
00038     A fictitous magnetic flux pressure pH is introduced in order to
00039     compensate for discretisation errors and create a magnetic face flux
00040     field which is divergence free as required by Maxwell's equations.
00041 
00042     However, in this formulation discretisation error prevents the normal
00043     stresses in UB from cancelling with those from BU, but it is unknown
00044     whether this is a serious error.  A correction could be introduced
00045     whereby the normal stresses in the discretised BU term are replaced
00046     by those from the UB term, but this would violate the boundedness
00047     constraint presently observed in the present numerics which
00048     guarantees div(U) and div(H) are zero.
00049 
00050 \*---------------------------------------------------------------------------*/
00051 
00052 #include "string.H"
00053 #include "Time.H"
00054 #include "fvCFD.H"
00055 #include "OSspecific.H"
00056 
00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00058 
00059 int main(int argc, char *argv[])
00060 {
00061     #include "setRootCase.H"
00062 
00063     #include "createTime.H"
00064     #include "createMesh.H"
00065     #include "createFields.H"
00066     #include "initContinuityErrs.H"
00067 
00068     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00069 
00070     Info<< nl << "Starting time loop" << endl;
00071 
00072     while (runTime.loop())
00073     {
00074         #include "readPISOControls.H"
00075         #include "readBPISOControls.H"
00076 
00077         Info<< "Time = " << runTime.timeName() << nl << endl;
00078 
00079         #include "CourantNo.H"
00080 
00081         {
00082             fvVectorMatrix UEqn
00083             (
00084                 fvm::ddt(U)
00085               + fvm::div(phi, U)
00086               - fvc::div(phiB, 2.0*DBU*B)
00087               - fvm::laplacian(nu, U)
00088               + fvc::grad(DBU*magSqr(B))
00089             );
00090 
00091             solve(UEqn == -fvc::grad(p));
00092 
00093 
00094             // --- PISO loop
00095 
00096             for (int corr=0; corr<nCorr; corr++)
00097             {
00098                 volScalarField rUA = 1.0/UEqn.A();
00099 
00100                 U = rUA*UEqn.H();
00101 
00102                 phi = (fvc::interpolate(U) & mesh.Sf())
00103                     + fvc::ddtPhiCorr(rUA, U, phi);
00104 
00105                 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
00106                 {
00107                     fvScalarMatrix pEqn
00108                     (
00109                         fvm::laplacian(rUA, p) == fvc::div(phi)
00110                     );
00111 
00112                     pEqn.setReference(pRefCell, pRefValue);
00113                     pEqn.solve();
00114 
00115                     if (nonOrth == nNonOrthCorr)
00116                     {
00117                         phi -= pEqn.flux();
00118                     }
00119                 }
00120 
00121                 #include "continuityErrs.H"
00122 
00123                 U -= rUA*fvc::grad(p);
00124                 U.correctBoundaryConditions();
00125             }
00126         }
00127 
00128         // --- B-PISO loop
00129 
00130         for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
00131         {
00132             fvVectorMatrix BEqn
00133             (
00134                 fvm::ddt(B)
00135               + fvm::div(phi, B)
00136               - fvc::div(phiB, U)
00137               - fvm::laplacian(DB, B)
00138             );
00139 
00140             BEqn.solve();
00141 
00142             volScalarField rBA = 1.0/BEqn.A();
00143 
00144             phiB = (fvc::interpolate(B) & mesh.Sf())
00145                 + fvc::ddtPhiCorr(rBA, B, phiB);
00146 
00147             fvScalarMatrix pBEqn
00148             (
00149                 fvm::laplacian(rBA, pB) == fvc::div(phiB)
00150             );
00151             pBEqn.solve();
00152 
00153             phiB -= pBEqn.flux();
00154 
00155             #include "magneticFieldErr.H"
00156         }
00157 
00158         runTime.write();
00159     }
00160 
00161     Info<< "End\n" << endl;
00162 
00163     return 0;
00164 }
00165 
00166 
00167 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd