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

patchIntegrate.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     patchIntegrate
00026 
00027 Description
00028     Calculates the integral of the specified field over the specified patch.
00029 
00030 Usage
00031 
00032     - patchIntegrate [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 #include <OpenFOAM/cyclicPolyPatch.H>
00071 
00072 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00073 // Main program:
00074 
00075 int main(int argc, char *argv[])
00076 {
00077 #   include <OpenFOAM/addRegionOption.H>
00078     timeSelector::addOptions();
00079     argList::validArgs.append("fieldName");
00080     argList::validArgs.append("patchName");
00081 #   include <OpenFOAM/setRootCase.H>
00082 #   include <OpenFOAM/createTime.H>
00083     instantList timeDirs = timeSelector::select0(runTime, args);
00084 #   include <OpenFOAM/createNamedMesh.H>
00085 
00086     word fieldName(args.additionalArgs()[0]);
00087     word patchName(args.additionalArgs()[1]);
00088 
00089     forAll(timeDirs, timeI)
00090     {
00091         runTime.setTime(timeDirs[timeI], timeI);
00092         Info<< "Time = " << runTime.timeName() << endl;
00093 
00094         IOobject fieldHeader
00095         (
00096             fieldName,
00097             runTime.timeName(),
00098             mesh,
00099             IOobject::MUST_READ
00100         );
00101 
00102         // Check field exists
00103         if (fieldHeader.headerOk())
00104         {
00105             mesh.readUpdate();
00106 
00107             label patchi = mesh.boundaryMesh().findPatchID(patchName);
00108             if (patchi < 0)
00109             {
00110                 FatalError
00111                     << "Unable to find patch " << patchName << nl
00112                     << exit(FatalError);
00113             }
00114 
00115             // Give patch area
00116             if (isA<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
00117             {
00118                 Info<< "    Cyclic patch vector area: " << nl;
00119                 label nFaces = mesh.boundaryMesh()[patchi].size();
00120                 vector sum1 = vector::zero;
00121                 vector sum2 = vector::zero;
00122                 for (label i=0; i<nFaces/2; i++)
00123                 {
00124                     sum1 += mesh.Sf().boundaryField()[patchi][i];
00125                     sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
00126                 }
00127                 reduce(sum1, sumOp<vector>());
00128                 reduce(sum2, sumOp<vector>());
00129                 Info<< "    - half 1 = " << sum1 << ", " << mag(sum1) << nl
00130                     << "    - half 2 = " << sum2 << ", " << mag(sum2) << nl
00131                     << "    - total  = " << (sum1 + sum2) << ", "
00132                     << mag(sum1 + sum2) << endl;
00133                 Info<< "    Cyclic patch area magnitude = "
00134                     << gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
00135             }
00136             else
00137             {
00138                 Info<< "    Area vector of patch "
00139                     << patchName << '[' << patchi << ']' << " = "
00140                     << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
00141                 Info<< "    Area magnitude of patch "
00142                     << patchName << '[' << patchi << ']' << " = "
00143                     << gSum(mesh.magSf().boundaryField()[patchi]) << endl;
00144             }
00145 
00146             // Read field and calc integral
00147             if (fieldHeader.headerClassName() == volScalarField::typeName)
00148             {
00149                 Info<< "    Reading " << volScalarField::typeName << " "
00150                     << fieldName << endl;
00151 
00152                 volScalarField field(fieldHeader, mesh);
00153 
00154                 Info<< "    Integral of " << fieldName
00155                     << " over vector area of patch "
00156                     << patchName << '[' << patchi << ']' << " = "
00157                     << gSum
00158                        (
00159                            mesh.Sf().boundaryField()[patchi]
00160                           *field.boundaryField()[patchi]
00161                        )
00162                     << nl;
00163 
00164                 Info<< "    Integral of " << fieldName
00165                     << " over area magnitude of patch "
00166                     << patchName << '[' << patchi << ']' << " = "
00167                     << gSum
00168                        (
00169                            mesh.magSf().boundaryField()[patchi]
00170                           *field.boundaryField()[patchi]
00171                        )
00172                     << nl;
00173             }
00174             else if
00175             (
00176                 fieldHeader.headerClassName() == surfaceScalarField::typeName
00177             )
00178             {
00179                 Info<< "    Reading " << surfaceScalarField::typeName << " "
00180                     << fieldName << endl;
00181 
00182                 surfaceScalarField field(fieldHeader, mesh);
00183                 scalar sumField = gSum(field.boundaryField()[patchi]);
00184 
00185                 Info<< "    Integral of " << fieldName << " over patch "
00186                     << patchName << '[' << patchi << ']' << " = "
00187                     << sumField << nl;
00188             }
00189             else
00190             {
00191                 FatalError
00192                     << "Only possible to integrate "
00193                     << volScalarField::typeName << "s "
00194                     << "and " << surfaceScalarField::typeName << "s"
00195                     << nl << exit(FatalError);
00196             }
00197         }
00198         else
00199         {
00200             Info<< "    No field " << fieldName << endl;
00201         }
00202 
00203         Info<< endl;
00204     }
00205 
00206     Info<< "End\n" << endl;
00207 
00208     return 0;
00209 }
00210 
00211 
00212 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines