FreeFOAM The Cross-Platform CFD Toolkit
patchIntegrate.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Application
25  patchIntegrate
26 
27 Description
28  Calculates the integral of the specified field over the specified patch.
29 
30 Usage
31 
32  - patchIntegrate [OPTIONS] <fieldName> <patchName>
33 
34  @param <fieldName> \n
35  @todo Detailed description of argument.
36 
37  @param <patchName> \n
38  @todo Detailed description of argument.
39 
40  @param -noZero \n
41  Ignore timestep 0.
42 
43  @param -constant \n
44  Include the constant directory.
45 
46  @param -time <time>\n
47  Apply only to specific time.
48 
49  @param -latestTime \n
50  Only apply to latest time step.
51 
52  @param -case <dir>\n
53  Case directory.
54 
55  @param -parallel \n
56  Run in parallel.
57 
58  @param -help \n
59  Display help message.
60 
61  @param -doc \n
62  Display Doxygen API documentation page for this application.
63 
64  @param -srcDoc \n
65  Display Doxygen source documentation page for this application.
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #include <finiteVolume/fvCFD.H>
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 // Main program:
74 
75 int main(int argc, char *argv[])
76 {
78  timeSelector::addOptions();
79  argList::validArgs.append("fieldName");
80  argList::validArgs.append("patchName");
81 # include <OpenFOAM/setRootCase.H>
82 # include <OpenFOAM/createTime.H>
83  instantList timeDirs = timeSelector::select0(runTime, args);
85 
86  word fieldName(args.additionalArgs()[0]);
87  word patchName(args.additionalArgs()[1]);
88 
89  forAll(timeDirs, timeI)
90  {
91  runTime.setTime(timeDirs[timeI], timeI);
92  Info<< "Time = " << runTime.timeName() << endl;
93 
94  IOobject fieldHeader
95  (
96  fieldName,
97  runTime.timeName(),
98  mesh,
99  IOobject::MUST_READ
100  );
101 
102  // Check field exists
103  if (fieldHeader.headerOk())
104  {
105  mesh.readUpdate();
106 
107  label patchi = mesh.boundaryMesh().findPatchID(patchName);
108  if (patchi < 0)
109  {
110  FatalError
111  << "Unable to find patch " << patchName << nl
112  << exit(FatalError);
113  }
114 
115  // Give patch area
116  if (isA<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
117  {
118  Info<< " Cyclic patch vector area: " << nl;
119  label nFaces = mesh.boundaryMesh()[patchi].size();
120  vector sum1 = vector::zero;
121  vector sum2 = vector::zero;
122  for (label i=0; i<nFaces/2; i++)
123  {
124  sum1 += mesh.Sf().boundaryField()[patchi][i];
125  sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
126  }
127  reduce(sum1, sumOp<vector>());
128  reduce(sum2, sumOp<vector>());
129  Info<< " - half 1 = " << sum1 << ", " << mag(sum1) << nl
130  << " - half 2 = " << sum2 << ", " << mag(sum2) << nl
131  << " - total = " << (sum1 + sum2) << ", "
132  << mag(sum1 + sum2) << endl;
133  Info<< " Cyclic patch area magnitude = "
134  << gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
135  }
136  else
137  {
138  Info<< " Area vector of patch "
139  << patchName << '[' << patchi << ']' << " = "
140  << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
141  Info<< " Area magnitude of patch "
142  << patchName << '[' << patchi << ']' << " = "
143  << gSum(mesh.magSf().boundaryField()[patchi]) << endl;
144  }
145 
146  // Read field and calc integral
147  if (fieldHeader.headerClassName() == volScalarField::typeName)
148  {
149  Info<< " Reading " << volScalarField::typeName << " "
150  << fieldName << endl;
151 
152  volScalarField field(fieldHeader, mesh);
153 
154  Info<< " Integral of " << fieldName
155  << " over vector area of patch "
156  << patchName << '[' << patchi << ']' << " = "
157  << gSum
158  (
160  *field.boundaryField()[patchi]
161  )
162  << nl;
163 
164  Info<< " Integral of " << fieldName
165  << " over area magnitude of patch "
166  << patchName << '[' << patchi << ']' << " = "
167  << gSum
168  (
170  *field.boundaryField()[patchi]
171  )
172  << nl;
173  }
174  else if
175  (
176  fieldHeader.headerClassName() == surfaceScalarField::typeName
177  )
178  {
179  Info<< " Reading " << surfaceScalarField::typeName << " "
180  << fieldName << endl;
181 
182  surfaceScalarField field(fieldHeader, mesh);
183  scalar sumField = gSum(field.boundaryField()[patchi]);
184 
185  Info<< " Integral of " << fieldName << " over patch "
186  << patchName << '[' << patchi << ']' << " = "
187  << sumField << nl;
188  }
189  else
190  {
191  FatalError
192  << "Only possible to integrate "
193  << volScalarField::typeName << "s "
194  << "and " << surfaceScalarField::typeName << "s"
195  << nl << exit(FatalError);
196  }
197  }
198  else
199  {
200  Info<< " No field " << fieldName << endl;
201  }
202 
203  Info<< endl;
204  }
205 
206  Info<< "End\n" << endl;
207 
208  return 0;
209 }
210 
211 
212 // ************************ vim: set sw=4 sts=4 et: ************************ //