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

shallowWaterFoam.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     shallowWaterFoam
00027 
00028 Description
00029     Transient solver for inviscid shallow-water equations with rotation.
00030 
00031     If the geometry is 3D then it is assumed to be one layers of cells and the
00032     component of the velocity normal to gravity is removed.
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #include "fvCFD.H"
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 int main(int argc, char *argv[])
00041 {
00042     #include "setRootCase.H"
00043     #include "createTime.H"
00044     #include "createMesh.H"
00045     #include "readGravitationalAcceleration.H"
00046     #include "createFields.H"
00047 
00048     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050     Info<< "\nStarting time loop\n" << endl;
00051 
00052     while (runTime.loop())
00053     {
00054         Info<< "\n Time = " << runTime.timeName() << nl << endl;
00055 
00056         #include "readPISOControls.H"
00057         #include "CourantNo.H"
00058 
00059         for (int ucorr=0; ucorr<nOuterCorr; ucorr++)
00060         {
00061             surfaceScalarField phiv("phiv", phi/fvc::interpolate(h));
00062 
00063             fvVectorMatrix hUEqn
00064             (
00065                 fvm::ddt(hU)
00066               + fvm::div(phiv, hU)
00067             );
00068 
00069             hUEqn.relax();
00070 
00071             if (momentumPredictor)
00072             {
00073                 if (rotating)
00074                 {
00075                     solve(hUEqn + (F ^ hU) == -magg*h*fvc::grad(h + h0));
00076                 }
00077                 else
00078                 {
00079                     solve(hUEqn == -magg*h*fvc::grad(h + h0));
00080                 }
00081 
00082                 // Constrain the momentum to be in the geometry if 3D geometry
00083                 if (mesh.nGeometricD() == 3)
00084                 {
00085                     hU -= (gHat & hU)*gHat;
00086                     hU.correctBoundaryConditions();
00087                 }
00088             }
00089 
00090             // --- PISO loop
00091             for (int corr=0; corr<nCorr; corr++)
00092             {
00093                 surfaceScalarField hf = fvc::interpolate(h);
00094                 volScalarField rUA = 1.0/hUEqn.A();
00095                 surfaceScalarField ghrUAf = magg*fvc::interpolate(h*rUA);
00096 
00097                 surfaceScalarField phih0 = ghrUAf*mesh.magSf()*fvc::snGrad(h0);
00098 
00099                 if (rotating)
00100                 {
00101                     hU = rUA*(hUEqn.H() - (F ^ hU));
00102                 }
00103                 else
00104                 {
00105                     hU = rUA*hUEqn.H();
00106                 }
00107 
00108                 phi = (fvc::interpolate(hU) & mesh.Sf())
00109                     + fvc::ddtPhiCorr(rUA, h, hU, phi)
00110                     - phih0;
00111 
00112                 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
00113                 {
00114                     fvScalarMatrix hEqn
00115                     (
00116                         fvm::ddt(h)
00117                       + fvc::div(phi)
00118                       - fvm::laplacian(ghrUAf, h)
00119                     );
00120 
00121                     if (ucorr < nOuterCorr-1 || corr < nCorr-1)
00122                     {
00123                         hEqn.solve();
00124                     }
00125                     else
00126                     {
00127                         hEqn.solve(mesh.solver(h.name() + "Final"));
00128                     }
00129 
00130                     if (nonOrth == nNonOrthCorr)
00131                     {
00132                         phi += hEqn.flux();
00133                     }
00134                 }
00135 
00136                 hU -= rUA*h*magg*fvc::grad(h + h0);
00137 
00138                 // Constrain the momentum to be in the geometry if 3D geometry
00139                 if (mesh.nGeometricD() == 3)
00140                 {
00141                     hU -= (gHat & hU)*gHat;
00142                 }
00143 
00144                 hU.correctBoundaryConditions();
00145             }
00146         }
00147 
00148         U == hU/h;
00149         hTotal == h + h0;
00150 
00151         runTime.write();
00152 
00153         Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
00154             << "  ClockTime = " << runTime.elapsedClockTime() << " s"
00155             << nl << endl;
00156     }
00157 
00158     Info<< "End\n" << endl;
00159 
00160     return 0;
00161 }
00162 
00163 
00164 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd