patchAverage.C
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 #include "fvCFD.H"
00034
00035
00036
00037
00038 int main(int argc, char *argv[])
00039 {
00040 timeSelector::addOptions();
00041 argList::validArgs.append("fieldName");
00042 argList::validArgs.append("patchName");
00043 # include "setRootCase.H"
00044 # include "createTime.H"
00045 instantList timeDirs = timeSelector::select0(runTime, args);
00046 # include "createMesh.H"
00047
00048 word fieldName(args.additionalArgs()[0]);
00049 word patchName(args.additionalArgs()[1]);
00050
00051 forAll(timeDirs, timeI)
00052 {
00053 runTime.setTime(timeDirs[timeI], timeI);
00054 Info<< "Time = " << runTime.timeName() << endl;
00055
00056 IOobject fieldHeader
00057 (
00058 fieldName,
00059 runTime.timeName(),
00060 mesh,
00061 IOobject::MUST_READ
00062 );
00063
00064
00065 if (fieldHeader.headerOk())
00066 {
00067 mesh.readUpdate();
00068
00069 label patchi = mesh.boundaryMesh().findPatchID(patchName);
00070 if (patchi < 0)
00071 {
00072 FatalError
00073 << "Unable to find patch " << patchName << nl
00074 << exit(FatalError);
00075 }
00076
00077 if (fieldHeader.headerClassName() == "volScalarField")
00078 {
00079 Info<< " Reading volScalarField " << fieldName << endl;
00080 volScalarField field(fieldHeader, mesh);
00081
00082 scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
00083 scalar sumField = 0;
00084
00085 if (area > 0)
00086 {
00087 sumField = gSum
00088 (
00089 mesh.magSf().boundaryField()[patchi]
00090 * field.boundaryField()[patchi]
00091 ) / area;
00092 }
00093
00094 Info<< " Average of " << fieldName << " over patch "
00095 << patchName << '[' << patchi << ']' << " = "
00096 << sumField << endl;
00097 }
00098 else
00099 {
00100 FatalError
00101 << "Only possible to average volScalarFields "
00102 << nl << exit(FatalError);
00103 }
00104 }
00105 else
00106 {
00107 Info<< " No field " << fieldName << endl;
00108 }
00109
00110 Info<< endl;
00111 }
00112
00113 Info<< "End\n" << endl;
00114
00115 return 0;
00116 }
00117
00118
Copyright © 2000-2009 OpenCFD Ltd