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

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-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     patchIntegrate
00027 
00028 Description
00029     Calculates the integral of the specified field over the specified patch.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "fvCFD.H"
00034 #include "cyclicPolyPatch.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 // Main program:
00038 
00039 int main(int argc, char *argv[])
00040 {
00041     timeSelector::addOptions();
00042     argList::validArgs.append("fieldName");
00043     argList::validArgs.append("patchName");
00044 #   include "setRootCase.H"
00045 #   include "createTime.H"
00046     instantList timeDirs = timeSelector::select0(runTime, args);
00047 #   include "createMesh.H"
00048 
00049     word fieldName(args.additionalArgs()[0]);
00050     word patchName(args.additionalArgs()[1]);
00051 
00052     forAll(timeDirs, timeI)
00053     {
00054         runTime.setTime(timeDirs[timeI], timeI);
00055         Info<< "Time = " << runTime.timeName() << endl;
00056 
00057         IOobject fieldHeader
00058         (
00059             fieldName,
00060             runTime.timeName(),
00061             mesh,
00062             IOobject::MUST_READ
00063         );
00064 
00065         // Check field exists
00066         if (fieldHeader.headerOk())
00067         {
00068             mesh.readUpdate();
00069 
00070             label patchi = mesh.boundaryMesh().findPatchID(patchName);
00071             if (patchi < 0)
00072             {
00073                 FatalError
00074                     << "Unable to find patch " << patchName << nl
00075                     << exit(FatalError);
00076             }
00077 
00078             // Give patch area
00079             if (isType<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
00080             {
00081                 Info<< "    Cyclic patch vector area: " << nl;
00082                 label nFaces = mesh.boundaryMesh()[patchi].size();
00083                 vector sum1 = vector::zero;
00084                 vector sum2 = vector::zero;
00085                 for (label i=0; i<nFaces/2; i++)
00086                 {
00087                     sum1 += mesh.Sf().boundaryField()[patchi][i];
00088                     sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
00089                 }
00090                 reduce(sum1, sumOp<vector>());
00091                 reduce(sum2, sumOp<vector>());
00092                 Info<< "    - half 1 = " << sum1 << ", " << mag(sum1) << nl
00093                     << "    - half 2 = " << sum2 << ", " << mag(sum2) << nl
00094                     << "    - total  = " << (sum1 + sum2) << ", "
00095                     << mag(sum1 + sum2) << endl;
00096                 Info<< "    Cyclic patch area magnitude = "
00097                     << gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
00098             }
00099             else
00100             {
00101                 Info<< "    Area vector of patch "
00102                     << patchName << '[' << patchi << ']' << " = "
00103                     << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
00104                 Info<< "    Area magnitude of patch "
00105                     << patchName << '[' << patchi << ']' << " = "
00106                     << gSum(mesh.magSf().boundaryField()[patchi]) << endl;
00107             }
00108 
00109             // Read field and calc integral
00110             if (fieldHeader.headerClassName() == volScalarField::typeName)
00111             {
00112                 Info<< "    Reading " << volScalarField::typeName << " "
00113                     << fieldName << endl;
00114 
00115                 volScalarField field(fieldHeader, mesh);
00116 
00117                 Info<< "    Integral of " << fieldName
00118                     << " over vector area of patch "
00119                     << patchName << '[' << patchi << ']' << " = "
00120                     << gSum
00121                        (
00122                            mesh.Sf().boundaryField()[patchi]
00123                           *field.boundaryField()[patchi]
00124                        )
00125                     << nl;
00126 
00127                 Info<< "    Integral of " << fieldName
00128                     << " over area magnitude of patch "
00129                     << patchName << '[' << patchi << ']' << " = "
00130                     << gSum
00131                        (
00132                            mesh.magSf().boundaryField()[patchi]
00133                           *field.boundaryField()[patchi]
00134                        )
00135                     << nl;
00136             }
00137             else if
00138             (
00139                 fieldHeader.headerClassName() == surfaceScalarField::typeName
00140             )
00141             {
00142                 Info<< "    Reading " << surfaceScalarField::typeName << " "
00143                     << fieldName << endl;
00144 
00145                 surfaceScalarField field(fieldHeader, mesh);
00146                 scalar sumField = gSum(field.boundaryField()[patchi]);
00147 
00148                 Info<< "    Integral of " << fieldName << " over patch "
00149                     << patchName << '[' << patchi << ']' << " = "
00150                     << sumField << nl;
00151             }
00152             else
00153             {
00154                 FatalError
00155                     << "Only possible to integrate "
00156                     << volScalarField::typeName << "s "
00157                     << "and " << surfaceScalarField::typeName << "s"
00158                     << nl << exit(FatalError);
00159             }
00160         }
00161         else
00162         {
00163             Info<< "    No field " << fieldName << endl;
00164         }
00165 
00166         Info<< endl;
00167     }
00168 
00169     Info<< "End\n" << endl;
00170 
00171     return 0;
00172 }
00173 
00174 
00175 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd