1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Calculates the integral of the specified field over the specified patch.
31 \*---------------------------------------------------------------------------*/
34 #include "cyclicPolyPatch.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 int main(int argc, char *argv[])
41 # include "addRegionOption.H"
42 timeSelector::addOptions();
43 argList::validArgs.append("fieldName");
44 argList::validArgs.append("patchName");
45 # include "setRootCase.H"
46 # include "createTime.H"
47 instantList timeDirs = timeSelector::select0(runTime, args);
48 # include "createNamedMesh.H"
50 word fieldName(args.additionalArgs()[0]);
51 word patchName(args.additionalArgs()[1]);
53 forAll(timeDirs, timeI)
55 runTime.setTime(timeDirs[timeI], timeI);
56 Info<< "Time = " << runTime.timeName() << endl;
67 if (fieldHeader.headerOk())
71 label patchi = mesh.boundaryMesh().findPatchID(patchName);
75 << "Unable to find patch " << patchName << nl
80 if (isA<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
82 Info<< " Cyclic patch vector area: " << nl;
83 label nFaces = mesh.boundaryMesh()[patchi].size();
84 vector sum1 = vector::zero;
85 vector sum2 = vector::zero;
86 for (label i=0; i<nFaces/2; i++)
88 sum1 += mesh.Sf().boundaryField()[patchi][i];
89 sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
91 reduce(sum1, sumOp<vector>());
92 reduce(sum2, sumOp<vector>());
93 Info<< " - half 1 = " << sum1 << ", " << mag(sum1) << nl
94 << " - half 2 = " << sum2 << ", " << mag(sum2) << nl
95 << " - total = " << (sum1 + sum2) << ", "
96 << mag(sum1 + sum2) << endl;
97 Info<< " Cyclic patch area magnitude = "
98 << gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
102 Info<< " Area vector of patch "
103 << patchName << '[' << patchi << ']' << " = "
104 << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
105 Info<< " Area magnitude of patch "
106 << patchName << '[' << patchi << ']' << " = "
107 << gSum(mesh.magSf().boundaryField()[patchi]) << endl;
110 // Read field and calc integral
111 if (fieldHeader.headerClassName() == volScalarField::typeName)
113 Info<< " Reading " << volScalarField::typeName << " "
114 << fieldName << endl;
116 volScalarField field(fieldHeader, mesh);
118 Info<< " Integral of " << fieldName
119 << " over vector area of patch "
120 << patchName << '[' << patchi << ']' << " = "
123 mesh.Sf().boundaryField()[patchi]
124 *field.boundaryField()[patchi]
128 Info<< " Integral of " << fieldName
129 << " over area magnitude of patch "
130 << patchName << '[' << patchi << ']' << " = "
133 mesh.magSf().boundaryField()[patchi]
134 *field.boundaryField()[patchi]
140 fieldHeader.headerClassName() == surfaceScalarField::typeName
143 Info<< " Reading " << surfaceScalarField::typeName << " "
144 << fieldName << endl;
146 surfaceScalarField field(fieldHeader, mesh);
147 scalar sumField = gSum(field.boundaryField()[patchi]);
149 Info<< " Integral of " << fieldName << " over patch "
150 << patchName << '[' << patchi << ']' << " = "
156 << "Only possible to integrate "
157 << volScalarField::typeName << "s "
158 << "and " << surfaceScalarField::typeName << "s"
159 << nl << exit(FatalError);
164 Info<< " No field " << fieldName << endl;
170 Info<< "End\n" << endl;
176 // ************************************************************************* //