Skip to content
Snippets Groups Projects
Commit 18b632e7 authored by Henry Weller's avatar Henry Weller
Browse files

Utilities patchAverage and patchIntegrate replaced by postProcess

e.g.
    postProcess -func 'patchAverage(name=inlet,p)'
    postProcess -func 'patchIntegrate(name=inlet,p)'
parent 6656aff3
No related branches found
No related tags found
No related merge requests found
Showing
with 106 additions and 441 deletions
patchAverage.C
EXE = $(FOAM_APPBIN)/patchAverage
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lgenericPatchFields \
-lfiniteVolume \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
patchAverage
Description
Calculates the average of the specified field over the specified patch.
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class FieldType>
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 =
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;
}
}
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 "createNamedMesh.H"
const word fieldName = args[1];
const word patchName = args[2];
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
IOobject io
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ
);
// Check field exists
if (io.headerOk())
{
mesh.readUpdate();
const label patchi = mesh.boundaryMesh().findPatchID(patchName);
if (patchi < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
<< exit(FatalError);
}
scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
bool done = false;
printAverage<volScalarField>(mesh, io, area, patchi, done);
printAverage<volVectorField>(mesh, io, area, patchi, done);
printAverage<volSphericalTensorField>(mesh, io, area, patchi, done);
printAverage<volSymmTensorField>(mesh, io, area, patchi, done);
printAverage<volTensorField>(mesh, io, area, patchi, done);
if (!done)
{
FatalError
<< "Only possible to average volFields."
<< " Field " << fieldName << " is of type "
<< io.headerClassName()
<< nl << exit(FatalError);
}
}
else
{
Info<< " No field " << fieldName << endl;
}
Info<< endl;
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
patchIntegrate.C
EXE = $(FOAM_APPBIN)/patchIntegrate
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lgenericPatchFields \
-lfiniteVolume \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
patchIntegrate
Description
Calculates the integral of the specified field over the specified patch.
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class FieldType>
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<class FieldType>
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;
}
}
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 "createNamedMesh.H"
const word fieldName = args[1];
const word patchName = args[2];
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
IOobject fieldHeader
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ
);
// Check field exists
if (fieldHeader.headerOk())
{
mesh.readUpdate();
const label patchi = mesh.boundaryMesh().findPatchID(patchName);
if (patchi < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
<< exit(FatalError);
}
// Give patch area
Info<< " Area vector of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.Sf().boundaryField()[patchi]) << endl;
Info<< " Area magnitude of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.magSf().boundaryField()[patchi]) << endl;
// Read field and calc integral
bool done = false;
printIntegrate<volScalarField>
(
mesh,
fieldHeader,
patchi,
done
);
printIntegrate<volVectorField>
(
mesh,
fieldHeader,
patchi,
done
);
//- No tensor integrations
//printIntegrate<volSphericalTensorField>
//(
// mesh,
// fieldHeader,
// patchi,
// done
//);
//printIntegrate<volSymmTensorField>
//(
// mesh,
// fieldHeader,
// patchi,
// done
//);
//printIntegrate<volTensorField>
//(
// mesh,
// fieldHeader,
// patchi,
// done
//);
printSum<surfaceScalarField>
(
mesh,
fieldHeader,
patchi,
done
);
printSum<surfaceVectorField>
(
mesh,
fieldHeader,
patchi,
done
);
printSum<volSphericalTensorField>
(
mesh,
fieldHeader,
patchi,
done
);
printSum<volSymmTensorField>
(
mesh,
fieldHeader,
patchi,
done
);
printSum<volTensorField>
(
mesh,
fieldHeader,
patchi,
done
);
if (!done)
{
FatalError
<< "Only possible to integrate "
<< "volFields and surfaceFields."
<< " Field " << fieldName << " is of type "
<< fieldHeader.headerClassName()
<< nl << exit(FatalError);
}
}
else
{
Info<< " No field " << fieldName << endl;
}
Info<< endl;
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
...@@ -128,6 +128,9 @@ int main(int argc, char *argv[]) ...@@ -128,6 +128,9 @@ int main(int argc, char *argv[])
#include "addRegionOption.H" #include "addRegionOption.H"
#include "addFunctionObjectOptions.H" #include "addFunctionObjectOptions.H"
// Set functionObject post-processing mode
functionObject::postProcess = true;
#include "setRootCase.H" #include "setRootCase.H"
if (args.optionFound("list")) if (args.optionFound("list"))
......
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# patchAverage
#
# Description
# Script to suggest using the new "postProcess" utility.
#
#------------------------------------------------------------------------------
Script=${0##*/}
echo $Script "has been superceded by the postProcess utility:"
echo "postProcess -func '"$Script"(name=inlet,p)'"
#------------------------------------------------------------------------------
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# patchIntegrate
#
# Description
# Script to suggest using the new "postProcess" utility.
#
#------------------------------------------------------------------------------
Script=${0##*/}
echo $Script "has been superceded by the postProcess utility:"
echo "postProcess -func '"$Script"(name=inlet,p)'"
#------------------------------------------------------------------------------
...@@ -17,8 +17,6 @@ patchAverage ...@@ -17,8 +17,6 @@ patchAverage
operation average; operation average;
#includeEtc "caseDicts/postProcessing/surfaceRegion/patch.cfg" #includeEtc "caseDicts/postProcessing/surfaceRegion/patch.cfg"
log true;
} }
......
...@@ -17,8 +17,6 @@ patchIntegrate ...@@ -17,8 +17,6 @@ patchIntegrate
operation areaIntegrate; operation areaIntegrate;
#includeEtc "caseDicts/postProcessing/surfaceRegion/patch.cfg" #includeEtc "caseDicts/postProcessing/surfaceRegion/patch.cfg"
log true;
} }
......
...@@ -36,12 +36,15 @@ namespace Foam ...@@ -36,12 +36,15 @@ namespace Foam
defineRunTimeSelectionTable(functionObject, dictionary); defineRunTimeSelectionTable(functionObject, dictionary);
} }
bool Foam::functionObject::postProcess(false);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObject::functionObject(const word& name) Foam::functionObject::functionObject(const word& name)
: :
name_(name) name_(name),
log(postProcess)
{} {}
...@@ -120,6 +123,17 @@ const Foam::word& Foam::functionObject::name() const ...@@ -120,6 +123,17 @@ const Foam::word& Foam::functionObject::name() const
} }
bool Foam::functionObject::read(const dictionary& dict)
{
if (!postProcess)
{
log = dict.lookupOrDefault<Switch>("log", true);
}
return true;
}
bool Foam::functionObject::end() bool Foam::functionObject::end()
{ {
return execute() && write(); return execute() && write();
......
...@@ -112,6 +112,7 @@ SourceFiles ...@@ -112,6 +112,7 @@ SourceFiles
#include "typeInfo.H" #include "typeInfo.H"
#include "autoPtr.H" #include "autoPtr.H"
#include "Switch.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -152,6 +153,12 @@ public: ...@@ -152,6 +153,12 @@ public:
static int debug; static int debug;
//- Global post-processing mode switch
static bool postProcess;
//- Switch write log to Info
Switch log;
// Declare run-time constructor selection tables // Declare run-time constructor selection tables
...@@ -199,7 +206,7 @@ public: ...@@ -199,7 +206,7 @@ public:
const word& name() const; const word& name() const;
//- Read and set the function object if its data have changed //- Read and set the function object if its data have changed
virtual bool read(const dictionary&) = 0; virtual bool read(const dictionary&);
//- Called at each ++ or += of the time-loop. //- Called at each ++ or += of the time-loop.
// postProcess overrides the usual executeControl behaviour and // postProcess overrides the usual executeControl behaviour and
......
...@@ -73,6 +73,9 @@ if (argList::postProcess(argc, argv)) ...@@ -73,6 +73,9 @@ if (argList::postProcess(argc, argv))
#include "addRegionOption.H" #include "addRegionOption.H"
#include "addFunctionObjectOptions.H" #include "addFunctionObjectOptions.H"
// Set functionObject post-processing mode
functionObject::postProcess = true;
#include "setRootCase.H" #include "setRootCase.H"
if (args.optionFound("list")) if (args.optionFound("list"))
......
...@@ -105,8 +105,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject ...@@ -105,8 +105,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
( (
dict.lookupOrDefault("region", polyMesh::defaultRegion) dict.lookupOrDefault("region", polyMesh::defaultRegion)
) )
), )
log(true)
{} {}
...@@ -119,8 +118,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject ...@@ -119,8 +118,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
: :
functionObject(name), functionObject(name),
time_(obr.time()), time_(obr.time()),
obr_(obr), obr_(obr)
log(true)
{} {}
...@@ -134,9 +132,7 @@ Foam::functionObjects::regionFunctionObject::~regionFunctionObject() ...@@ -134,9 +132,7 @@ Foam::functionObjects::regionFunctionObject::~regionFunctionObject()
bool Foam::functionObjects::regionFunctionObject::read(const dictionary& dict) bool Foam::functionObjects::regionFunctionObject::read(const dictionary& dict)
{ {
log = dict.lookupOrDefault<Switch>("log", true); return functionObject::read(dict);
return true;
} }
......
...@@ -40,7 +40,6 @@ SourceFiles ...@@ -40,7 +40,6 @@ SourceFiles
#define functionObjects_regionFunctionObject_H #define functionObjects_regionFunctionObject_H
#include "functionObject.H" #include "functionObject.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -115,9 +114,6 @@ public: ...@@ -115,9 +114,6 @@ public:
//- Runtime type information //- Runtime type information
TypeName("regionFunctionObject"); TypeName("regionFunctionObject");
//- Switch write log to Info
Switch log;
// Constructors // Constructors
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment