patchIntegrate.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 #include "cyclicPolyPatch.H"
00035
00036
00037
00038
00039 int main(int argc, char *argv[])
00040 {
00041 timeSelector::addOptions();
00042 argList::validArgs.append("fieldName");
00043 argList::validArgs.append("patchName");
00044 # include "setRootCase.H"
00045 # include "createTime.H"
00046 instantList timeDirs = timeSelector::select0(runTime, args);
00047 # include "createMesh.H"
00048
00049 word fieldName(args.additionalArgs()[0]);
00050 word patchName(args.additionalArgs()[1]);
00051
00052 forAll(timeDirs, timeI)
00053 {
00054 runTime.setTime(timeDirs[timeI], timeI);
00055 Info<< "Time = " << runTime.timeName() << endl;
00056
00057 IOobject fieldHeader
00058 (
00059 fieldName,
00060 runTime.timeName(),
00061 mesh,
00062 IOobject::MUST_READ
00063 );
00064
00065
00066 if (fieldHeader.headerOk())
00067 {
00068 mesh.readUpdate();
00069
00070 label patchi = mesh.boundaryMesh().findPatchID(patchName);
00071 if (patchi < 0)
00072 {
00073 FatalError
00074 << "Unable to find patch " << patchName << nl
00075 << exit(FatalError);
00076 }
00077
00078
00079 if (isType<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
00080 {
00081 Info<< " Cyclic patch vector area: " << nl;
00082 label nFaces = mesh.boundaryMesh()[patchi].size();
00083 vector sum1 = vector::zero;
00084 vector sum2 = vector::zero;
00085 for (label i=0; i<nFaces/2; i++)
00086 {
00087 sum1 += mesh.Sf().boundaryField()[patchi][i];
00088 sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
00089 }
00090 reduce(sum1, sumOp<vector>());
00091 reduce(sum2, sumOp<vector>());
00092 Info<< " - half 1 = " << sum1 << ", " << mag(sum1) << nl
00093 << " - half 2 = " << sum2 << ", " << mag(sum2) << nl
00094 << " - total = " << (sum1 + sum2) << ", "
00095 << mag(sum1 + sum2) << endl;
00096 Info<< " Cyclic patch area magnitude = "
00097 << gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
00098 }
00099 else
00100 {
00101 Info<< " Area vector of patch "
00102 << patchName << '[' << patchi << ']' << " = "
00103 << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
00104 Info<< " Area magnitude of patch "
00105 << patchName << '[' << patchi << ']' << " = "
00106 << gSum(mesh.magSf().boundaryField()[patchi]) << endl;
00107 }
00108
00109
00110 if (fieldHeader.headerClassName() == volScalarField::typeName)
00111 {
00112 Info<< " Reading " << volScalarField::typeName << " "
00113 << fieldName << endl;
00114
00115 volScalarField field(fieldHeader, mesh);
00116
00117 Info<< " Integral of " << fieldName
00118 << " over vector area of patch "
00119 << patchName << '[' << patchi << ']' << " = "
00120 << gSum
00121 (
00122 mesh.Sf().boundaryField()[patchi]
00123 *field.boundaryField()[patchi]
00124 )
00125 << nl;
00126
00127 Info<< " Integral of " << fieldName
00128 << " over area magnitude of patch "
00129 << patchName << '[' << patchi << ']' << " = "
00130 << gSum
00131 (
00132 mesh.magSf().boundaryField()[patchi]
00133 *field.boundaryField()[patchi]
00134 )
00135 << nl;
00136 }
00137 else if
00138 (
00139 fieldHeader.headerClassName() == surfaceScalarField::typeName
00140 )
00141 {
00142 Info<< " Reading " << surfaceScalarField::typeName << " "
00143 << fieldName << endl;
00144
00145 surfaceScalarField field(fieldHeader, mesh);
00146 scalar sumField = gSum(field.boundaryField()[patchi]);
00147
00148 Info<< " Integral of " << fieldName << " over patch "
00149 << patchName << '[' << patchi << ']' << " = "
00150 << sumField << nl;
00151 }
00152 else
00153 {
00154 FatalError
00155 << "Only possible to integrate "
00156 << volScalarField::typeName << "s "
00157 << "and " << surfaceScalarField::typeName << "s"
00158 << nl << exit(FatalError);
00159 }
00160 }
00161 else
00162 {
00163 Info<< " No field " << fieldName << endl;
00164 }
00165
00166 Info<< endl;
00167 }
00168
00169 Info<< "End\n" << endl;
00170
00171 return 0;
00172 }
00173
00174
00175
Copyright © 2000-2009 OpenCFD Ltd