diff --git a/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C b/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C index d8f651c968..f7948701cc 100644 --- a/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C +++ b/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,17 +32,59 @@ Description #include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void printAverage +( + const fvMesh& mesh, + const IOobject& fieldHeader, + const scalar area, + const label patchI, + bool& done +) +{ + if (!done && fieldHeader.headerClassName() == FieldType::typeName) + { + Info<< " Reading " << fieldHeader.headerClassName() << " " + << fieldHeader.name() << endl; + + FieldType field(fieldHeader, mesh); + + typename FieldType::value_type sumField = + pTraits::zero; + + if (area > 0) + { + sumField = gSum + ( + mesh.magSf().boundaryField()[patchI] + * field.boundaryField()[patchI] + ) / area; + } + + Info<< " Average of " << fieldHeader.headerClassName() + << " over patch " + << mesh.boundary()[patchI].name() + << '[' << patchI << ']' << " = " + << sumField << endl; + + done = true; + } +} + + // Main program: int main(int argc, char *argv[]) { timeSelector::addOptions(); + #include "addRegionOption.H" argList::validArgs.append("fieldName"); argList::validArgs.append("patchName"); # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); -# include "createMesh.H" +# include "createNamedMesh.H" const word fieldName = args[1]; const word patchName = args[2]; @@ -52,7 +94,7 @@ int main(int argc, char *argv[]) runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; - IOobject fieldHeader + IOobject io ( fieldName, runTime.timeName(), @@ -61,7 +103,7 @@ int main(int argc, char *argv[]) ); // Check field exists - if (fieldHeader.headerOk()) + if (io.headerOk()) { mesh.readUpdate(); @@ -72,32 +114,21 @@ int main(int argc, char *argv[]) << "Unable to find patch " << patchName << nl << exit(FatalError); } + scalar area = gSum(mesh.magSf().boundaryField()[patchI]); - if (fieldHeader.headerClassName() == "volScalarField") - { - Info<< " Reading volScalarField " << fieldName << endl; - volScalarField field(fieldHeader, mesh); + bool done = false; + printAverage(mesh, io, area, patchI, done); + printAverage(mesh, io, area, patchI, done); + printAverage(mesh, io, area, patchI, done); + printAverage(mesh, io, area, patchI, done); + printAverage(mesh, io, area, patchI, done); - scalar area = gSum(mesh.magSf().boundaryField()[patchI]); - scalar sumField = 0; - - if (area > 0) - { - sumField = gSum - ( - mesh.magSf().boundaryField()[patchI] - * field.boundaryField()[patchI] - ) / area; - } - - Info<< " Average of " << fieldName << " over patch " - << patchName << '[' << patchI << ']' << " = " - << sumField << endl; - } - else + if (!done) { FatalError - << "Only possible to average volScalarFields " + << "Only possible to average volFields." + << " Field " << fieldName << " is of type " + << io.headerClassName() << nl << exit(FatalError); } } diff --git a/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C b/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C index 8696c6ffde..5004df4c9e 100644 --- a/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C +++ b/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,12 +32,83 @@ Description #include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void printIntegrate +( + const fvMesh& mesh, + const IOobject& fieldHeader, + const label patchI, + bool& done +) +{ + if (!done && fieldHeader.headerClassName() == FieldType::typeName) + { + Info<< " Reading " << fieldHeader.headerClassName() << " " + << fieldHeader.name() << endl; + + FieldType field(fieldHeader, mesh); + + Info<< " Integral of " << fieldHeader.name() + << " over vector area of patch " + << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = " + << gSum + ( + mesh.Sf().boundaryField()[patchI] + *field.boundaryField()[patchI] + ) + << nl; + + Info<< " Integral of " << fieldHeader.name() + << " over area magnitude of patch " + << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = " + << gSum + ( + mesh.magSf().boundaryField()[patchI] + *field.boundaryField()[patchI] + ) + << nl; + + done = true; + } +} + + +template +void printSum +( + const fvMesh& mesh, + const IOobject& fieldHeader, + const label patchI, + bool& done +) +{ + if (!done && fieldHeader.headerClassName() == FieldType::typeName) + { + Info<< " Reading " << FieldType::typeName << " " + << fieldHeader.name() << endl; + + FieldType field(fieldHeader, mesh); + typename FieldType::value_type sumField = gSum + ( + field.boundaryField()[patchI] + ); + + Info<< " Integral of " << fieldHeader.name() << " over patch " + << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = " + << sumField << nl; + + done = true; + } +} + + // Main program: int main(int argc, char *argv[]) { -# include "addRegionOption.H" timeSelector::addOptions(); +# include "addRegionOption.H" argList::validArgs.append("fieldName"); argList::validArgs.append("patchName"); # include "setRootCase.H" @@ -83,54 +154,88 @@ int main(int argc, char *argv[]) << gSum(mesh.magSf().boundaryField()[patchI]) << endl; // Read field and calc integral - if (fieldHeader.headerClassName() == volScalarField::typeName) - { - Info<< " Reading " << volScalarField::typeName << " " - << fieldName << endl; - - volScalarField field(fieldHeader, mesh); - - Info<< " Integral of " << fieldName - << " over vector area of patch " - << patchName << '[' << patchI << ']' << " = " - << gSum - ( - mesh.Sf().boundaryField()[patchI] - *field.boundaryField()[patchI] - ) - << nl; - - Info<< " Integral of " << fieldName - << " over area magnitude of patch " - << patchName << '[' << patchI << ']' << " = " - << gSum - ( - mesh.magSf().boundaryField()[patchI] - *field.boundaryField()[patchI] - ) - << nl; - } - else if + bool done = false; + printIntegrate ( - fieldHeader.headerClassName() == surfaceScalarField::typeName - ) - { - Info<< " Reading " << surfaceScalarField::typeName << " " - << fieldName << endl; + mesh, + fieldHeader, + patchI, + done + ); + printIntegrate + ( + mesh, + fieldHeader, + patchI, + done + ); - surfaceScalarField field(fieldHeader, mesh); - scalar sumField = gSum(field.boundaryField()[patchI]); + //- No tensor integrations + //printIntegrate + //( + // mesh, + // fieldHeader, + // patchI, + // done + //); + //printIntegrate + //( + // mesh, + // fieldHeader, + // patchI, + // done + //); + //printIntegrate + //( + // mesh, + // fieldHeader, + // patchI, + // done + //); - Info<< " Integral of " << fieldName << " over patch " - << patchName << '[' << patchI << ']' << " = " - << sumField << nl; - } - else + printSum + ( + mesh, + fieldHeader, + patchI, + done + ); + printSum + ( + mesh, + fieldHeader, + patchI, + done + ); + printSum + ( + mesh, + fieldHeader, + patchI, + done + ); + printSum + ( + mesh, + fieldHeader, + patchI, + done + ); + printSum + ( + mesh, + fieldHeader, + patchI, + done + ); + + if (!done) { FatalError << "Only possible to integrate " - << volScalarField::typeName << "s " - << "and " << surfaceScalarField::typeName << "s" + << "volFields and surfaceFields." + << " Field " << fieldName << " is of type " + << fieldHeader.headerClassName() << nl << exit(FatalError); } }