Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #include <finiteVolume/fvCFD.H>
00070
00071
00072
00073
00074 int main(int argc, char *argv[])
00075 {
00076 timeSelector::addOptions();
00077 argList::validArgs.append("fieldName");
00078 argList::validArgs.append("patchName");
00079 # include <OpenFOAM/setRootCase.H>
00080 # include <OpenFOAM/createTime.H>
00081 instantList timeDirs = timeSelector::select0(runTime, args);
00082 # include <OpenFOAM/createMesh.H>
00083
00084 word fieldName(args.additionalArgs()[0]);
00085 word patchName(args.additionalArgs()[1]);
00086
00087 forAll(timeDirs, timeI)
00088 {
00089 runTime.setTime(timeDirs[timeI], timeI);
00090 Info<< "Time = " << runTime.timeName() << endl;
00091
00092 IOobject fieldHeader
00093 (
00094 fieldName,
00095 runTime.timeName(),
00096 mesh,
00097 IOobject::MUST_READ
00098 );
00099
00100
00101 if (fieldHeader.headerOk())
00102 {
00103 mesh.readUpdate();
00104
00105 label patchi = mesh.boundaryMesh().findPatchID(patchName);
00106 if (patchi < 0)
00107 {
00108 FatalError
00109 << "Unable to find patch " << patchName << nl
00110 << exit(FatalError);
00111 }
00112
00113 if (fieldHeader.headerClassName() == "volScalarField")
00114 {
00115 Info<< " Reading volScalarField " << fieldName << endl;
00116 volScalarField field(fieldHeader, mesh);
00117
00118 scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
00119 scalar sumField = 0;
00120
00121 if (area > 0)
00122 {
00123 sumField = gSum
00124 (
00125 mesh.magSf().boundaryField()[patchi]
00126 * field.boundaryField()[patchi]
00127 ) / area;
00128 }
00129
00130 Info<< " Average of " << fieldName << " over patch "
00131 << patchName << '[' << patchi << ']' << " = "
00132 << sumField << endl;
00133 }
00134 else
00135 {
00136 FatalError
00137 << "Only possible to average volScalarFields "
00138 << nl << exit(FatalError);
00139 }
00140 }
00141 else
00142 {
00143 Info<< " No field " << fieldName << endl;
00144 }
00145
00146 Info<< endl;
00147 }
00148
00149 Info<< "End\n" << endl;
00150
00151 return 0;
00152 }
00153
00154