1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Calculates the integral of the specified field over the specified patch.
30 \*---------------------------------------------------------------------------*/
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 int main(int argc, char *argv[])
39 # include "addRegionOption.H"
40 timeSelector::addOptions();
41 argList::validArgs.append("fieldName");
42 argList::validArgs.append("patchName");
43 # include "setRootCase.H"
44 # include "createTime.H"
45 instantList timeDirs = timeSelector::select0(runTime, args);
46 # include "createNamedMesh.H"
48 const word fieldName = args[1];
49 const word patchName = args[2];
51 forAll(timeDirs, timeI)
53 runTime.setTime(timeDirs[timeI], timeI);
54 Info<< "Time = " << runTime.timeName() << endl;
65 if (fieldHeader.headerOk())
69 const label patchI = mesh.boundaryMesh().findPatchID(patchName);
73 << "Unable to find patch " << patchName << nl
78 Info<< " Area vector of patch "
79 << patchName << '[' << patchI << ']' << " = "
80 << gSum(mesh.Sf().boundaryField()[patchI]) << endl;
81 Info<< " Area magnitude of patch "
82 << patchName << '[' << patchI << ']' << " = "
83 << gSum(mesh.magSf().boundaryField()[patchI]) << endl;
85 // Read field and calc integral
86 if (fieldHeader.headerClassName() == volScalarField::typeName)
88 Info<< " Reading " << volScalarField::typeName << " "
91 volScalarField field(fieldHeader, mesh);
93 Info<< " Integral of " << fieldName
94 << " over vector area of patch "
95 << patchName << '[' << patchI << ']' << " = "
98 mesh.Sf().boundaryField()[patchI]
99 *field.boundaryField()[patchI]
103 Info<< " Integral of " << fieldName
104 << " over area magnitude of patch "
105 << patchName << '[' << patchI << ']' << " = "
108 mesh.magSf().boundaryField()[patchI]
109 *field.boundaryField()[patchI]
115 fieldHeader.headerClassName() == surfaceScalarField::typeName
118 Info<< " Reading " << surfaceScalarField::typeName << " "
119 << fieldName << endl;
121 surfaceScalarField field(fieldHeader, mesh);
122 scalar sumField = gSum(field.boundaryField()[patchI]);
124 Info<< " Integral of " << fieldName << " over patch "
125 << patchName << '[' << patchI << ']' << " = "
131 << "Only possible to integrate "
132 << volScalarField::typeName << "s "
133 << "and " << surfaceScalarField::typeName << "s"
134 << nl << exit(FatalError);
139 Info<< " No field " << fieldName << endl;
145 Info<< "End\n" << endl;
151 // ************************************************************************* //