FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     mhdFoam
00026 
00027 Description
00028     Solver for magnetohydrodynamics (MHD): incompressible, laminar flow of a
00029     conducting fluid under the influence of a magnetic field.
00030 
00031     An applied magnetic field H acts as a driving force,
00032     at present boundary conditions cannot be set via the
00033     electric field E or current density J. The fluid viscosity nu,
00034     conductivity sigma and permeability mu are read in as uniform
00035     constants.
00036 
00037     A fictitous magnetic flux pressure pH is introduced in order to
00038     compensate for discretisation errors and create a magnetic face flux
00039     field which is divergence free as required by Maxwell's equations.
00040 
00041     However, in this formulation discretisation error prevents the normal
00042     stresses in UB from cancelling with those from BU, but it is unknown
00043     whether this is a serious error.  A correction could be introduced
00044     whereby the normal stresses in the discretised BU term are replaced
00045     by those from the UB term, but this would violate the boundedness
00046     constraint presently observed in the present numerics which
00047     guarantees div(U) and div(H) are zero.
00048 
00049 Usage
00050     - mhdFoam [OPTION]
00051 
00052     @param -case <dir> \n
00053     Specify the case directory
00054 
00055     @param -parallel \n
00056     Run the case in parallel
00057 
00058     @param -help \n
00059     Display short usage message
00060 
00061     @param -doc \n
00062     Display Doxygen documentation page
00063 
00064     @param -srcDoc \n
00065     Display source code
00066 
00067 \*---------------------------------------------------------------------------*/
00068 
00069 #include <finiteVolume/fvCFD.H>
00070 #include <OpenFOAM/OSspecific.H>
00071 
00072 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00073 
00074 int main(int argc, char *argv[])
00075 {
00076     #include <OpenFOAM/setRootCase.H>
00077 
00078     #include <OpenFOAM/createTime.H>
00079     #include <OpenFOAM/createMesh.H>
00080     #include "createFields.H"
00081     #include <finiteVolume/initContinuityErrs.H>
00082 
00083     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00084 
00085     Info<< nl << "Starting time loop" << endl;
00086 
00087     while (runTime.loop())
00088     {
00089         #include <finiteVolume/readPISOControls.H>
00090         #include "readBPISOControls.H"
00091 
00092         Info<< "Time = " << runTime.timeName() << nl << endl;
00093 
00094         #include <finiteVolume/CourantNo.H>
00095 
00096         {
00097             fvVectorMatrix UEqn
00098             (
00099                 fvm::ddt(U)
00100               + fvm::div(phi, U)
00101               - fvc::div(phiB, 2.0*DBU*B)
00102               - fvm::laplacian(nu, U)
00103               + fvc::grad(DBU*magSqr(B))
00104             );
00105 
00106             solve(UEqn == -fvc::grad(p));
00107 
00108 
00109             // --- PISO loop
00110 
00111             for (int corr=0; corr<nCorr; corr++)
00112             {
00113                 volScalarField rUA = 1.0/UEqn.A();
00114 
00115                 U = rUA*UEqn.H();
00116 
00117                 phi = (fvc::interpolate(U) & mesh.Sf())
00118                     + fvc::ddtPhiCorr(rUA, U, phi);
00119 
00120                 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
00121                 {
00122                     fvScalarMatrix pEqn
00123                     (
00124                         fvm::laplacian(rUA, p) == fvc::div(phi)
00125                     );
00126 
00127                     pEqn.setReference(pRefCell, pRefValue);
00128                     pEqn.solve();
00129 
00130                     if (nonOrth == nNonOrthCorr)
00131                     {
00132                         phi -= pEqn.flux();
00133                     }
00134                 }
00135 
00136                 #include <finiteVolume/continuityErrs.H>
00137 
00138                 U -= rUA*fvc::grad(p);
00139                 U.correctBoundaryConditions();
00140             }
00141         }
00142 
00143         // --- B-PISO loop
00144 
00145         for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
00146         {
00147             fvVectorMatrix BEqn
00148             (
00149                 fvm::ddt(B)
00150               + fvm::div(phi, B)
00151               - fvc::div(phiB, U)
00152               - fvm::laplacian(DB, B)
00153             );
00154 
00155             BEqn.solve();
00156 
00157             volScalarField rBA = 1.0/BEqn.A();
00158 
00159             phiB = (fvc::interpolate(B) & mesh.Sf())
00160                 + fvc::ddtPhiCorr(rBA, B, phiB);
00161 
00162             fvScalarMatrix pBEqn
00163             (
00164                 fvm::laplacian(rBA, pB) == fvc::div(phiB)
00165             );
00166             pBEqn.solve();
00167 
00168             phiB -= pBEqn.flux();
00169 
00170             #include "magneticFieldErr.H"
00171         }
00172 
00173         runTime.write();
00174     }
00175 
00176     Info<< "End\n" << endl;
00177 
00178     return 0;
00179 }
00180 
00181 
00182 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines