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

patchAverage.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     patchAverage
00026 
00027 Description
00028     Calculates the average of the specified field over the specified patch.
00029 
00030 Usage
00031 
00032     - patchAverage [OPTIONS] <fieldName> <patchName>
00033 
00034     @param <fieldName> \n
00035     @todo Detailed description of argument.
00036 
00037     @param <patchName> \n
00038     @todo Detailed description of argument.
00039 
00040     @param -noZero \n
00041     Ignore timestep 0.
00042 
00043     @param -constant \n
00044     Include the constant directory.
00045 
00046     @param -time <time>\n
00047     Apply only to specific time.
00048 
00049     @param -latestTime \n
00050     Only apply to latest time step.
00051 
00052     @param -case <dir>\n
00053     Case directory.
00054 
00055     @param -parallel \n
00056     Run in parallel.
00057 
00058     @param -help \n
00059     Display help message.
00060 
00061     @param -doc \n
00062     Display Doxygen API documentation page for this application.
00063 
00064     @param -srcDoc \n
00065     Display Doxygen source documentation page for this application.
00066 
00067 \*---------------------------------------------------------------------------*/
00068 
00069 #include <finiteVolume/fvCFD.H>
00070 
00071 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00072 // Main program:
00073 
00074 int main(int argc, char *argv[])
00075 {
00076     timeSelector::addOptions();
00077     argList::validArgs.append("fieldName");
00078     argList::validArgs.append("patchName");
00079 #   include <OpenFOAM/setRootCase.H>
00080 #   include <OpenFOAM/createTime.H>
00081     instantList timeDirs = timeSelector::select0(runTime, args);
00082 #   include <OpenFOAM/createMesh.H>
00083 
00084     word fieldName(args.additionalArgs()[0]);
00085     word patchName(args.additionalArgs()[1]);
00086 
00087     forAll(timeDirs, timeI)
00088     {
00089         runTime.setTime(timeDirs[timeI], timeI);
00090         Info<< "Time = " << runTime.timeName() << endl;
00091 
00092         IOobject fieldHeader
00093         (
00094             fieldName,
00095             runTime.timeName(),
00096             mesh,
00097             IOobject::MUST_READ
00098         );
00099 
00100         // Check field exists
00101         if (fieldHeader.headerOk())
00102         {
00103             mesh.readUpdate();
00104 
00105             label patchi = mesh.boundaryMesh().findPatchID(patchName);
00106             if (patchi < 0)
00107             {
00108                 FatalError
00109                     << "Unable to find patch " << patchName << nl
00110                     << exit(FatalError);
00111             }
00112 
00113             if (fieldHeader.headerClassName() == "volScalarField")
00114             {
00115                 Info<< "    Reading volScalarField " << fieldName << endl;
00116                 volScalarField field(fieldHeader, mesh);
00117 
00118                 scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
00119                 scalar sumField = 0;
00120 
00121                 if (area > 0)
00122                 {
00123                     sumField = gSum
00124                     (
00125                         mesh.magSf().boundaryField()[patchi]
00126                       * field.boundaryField()[patchi]
00127                     ) / area;
00128                 }
00129 
00130                 Info<< "    Average of " << fieldName << " over patch "
00131                     << patchName << '[' << patchi << ']' << " = "
00132                     << sumField << endl;
00133             }
00134             else
00135             {
00136                 FatalError
00137                     << "Only possible to average volScalarFields "
00138                     << nl << exit(FatalError);
00139             }
00140         }
00141         else
00142         {
00143             Info<< "    No field " << fieldName << endl;
00144         }
00145 
00146         Info<< endl;
00147     }
00148 
00149     Info<< "End\n" << endl;
00150 
00151     return 0;
00152 }
00153 
00154 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines