diff --git a/src/postProcessing/functionObjects/zones/Make/files b/src/postProcessing/functionObjects/zones/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..90e33f75241df48dde2b4749d723aff3fc660b82 --- /dev/null +++ b/src/postProcessing/functionObjects/zones/Make/files @@ -0,0 +1,4 @@ +faceZoneIntegration/faceZonesIntegration.C +faceZoneIntegration/faceZonesIntegrationFunctionObject.C + +LIB = $(FOAM_LIBBIN)/libzoneFunctionObjects diff --git a/src/postProcessing/functionObjects/zones/Make/options b/src/postProcessing/functionObjects/zones/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..5166bcc9e32f547f48a5f87c9c60d7210409967f --- /dev/null +++ b/src/postProcessing/functionObjects/zones/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools \ + -lsampling diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/IOfaceZonesIntegration.H b/src/postProcessing/functionObjects/zones/faceZoneIntegration/IOfaceZonesIntegration.H new file mode 100644 index 0000000000000000000000000000000000000000..ef1ecbf0043aa34d098f0f2db829ee69e9c955fe --- /dev/null +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/IOfaceZonesIntegration.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Typedef + Foam::IOfaceZonesIntegration + +Description + Instance of the generic IOOutputFilter for faceZonesIntegration. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOfaceZonesIntegration_H +#define IOfaceZonesIntegration_H + +#include "faceZonesIntegration.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter<faceZonesIntegration> IOfaceZonesIntegration; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C new file mode 100644 index 0000000000000000000000000000000000000000..0b8314667c728839bc11e72eddc2149e94026fdd --- /dev/null +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C @@ -0,0 +1,322 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "faceZonesIntegration.H" +#include "volFields.H" +#include "dictionary.H" +#include "Time.H" +#include "IOmanip.H" +#include "ListListOps.H" +#include "processorPolyPatch.H" +#include "cyclicPolyPatch.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(faceZonesIntegration, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::faceZonesIntegration::faceZonesIntegration +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + log_(false), + faceZonesSet_(), + fItems_(), + faceZonesIntegrationFilePtr_(NULL) +{ + // Check if the available mesh is an fvMesh otherise deactivate + if (!isA<fvMesh>(obr_)) + { + active_ = false; + WarningIn + ( + "Foam::faceZonesIntegration::faceZonesIntegration" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "No fvMesh available, deactivating." + << endl; + } + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::faceZonesIntegration::~faceZonesIntegration() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::faceZonesIntegration::read(const dictionary& dict) +{ + if (active_) + { + log_ = dict.lookupOrDefault<Switch>("log", false); + + dict.lookup("fields") >> fItems_; + + dict.lookup("faceZones") >> faceZonesSet_; + } +} + + +void Foam::faceZonesIntegration::makeFile() +{ + // Create the face Zone file if not already created + if (faceZonesIntegrationFilePtr_.empty()) + { + if (debug) + { + Info<< "Creating faceZonesIntegration file." << endl; + } + + // File update + if (Pstream::master()) + { + fileName faceZonesIntegrationDir; + if (Pstream::parRun()) + { + // Put in undecomposed case (Note: gives problems for + // distributed data running) + faceZonesIntegrationDir = + obr_.time().path()/".."/name_/obr_.time().timeName(); + } + else + { + faceZonesIntegrationDir = + obr_.time().path()/name_/obr_.time().timeName(); + } + + // Create directory if does not exist. + mkDir(faceZonesIntegrationDir); + + // Open new file at start up + faceZonesIntegrationFilePtr_.resize(fItems_.size()); + + forAll(fItems_, Ifields) + { + const word& fieldName = fItems_[Ifields]; + + OFstream* sPtr = new OFstream + ( + faceZonesIntegrationDir/fieldName + ); + + faceZonesIntegrationFilePtr_.insert(fieldName, sPtr); + } + + // Add headers to output data + writeFileHeader(); + } + } +} + + +void Foam::faceZonesIntegration::writeFileHeader() +{ + forAllIter(HashPtrTable<OFstream>, faceZonesIntegrationFilePtr_, iter) + { + unsigned int w = IOstream::defaultPrecision() + 7; + + OFstream& os = *faceZonesIntegrationFilePtr_[iter.key()]; + + os << "#Time " << setw(w); + + forAll (faceZonesSet_, zoneI) + { + const word name = faceZonesSet_[zoneI]; + os << name << setw(w); + } + + os << nl << endl; + } +} + + +void Foam::faceZonesIntegration::execute() +{ + // Do nothing - only valid on write +} + + +void Foam::faceZonesIntegration::end() +{ + // Do nothing - only valid on write +} + + +void Foam::faceZonesIntegration::write() +{ + if (active_) + { + makeFile(); + scalar dm = 0.0; + forAll(fItems_, fieldI) + { + const word& fieldName = fItems_[fieldI]; + + const surfaceScalarField& fD = + obr_.lookupObject<surfaceScalarField>(fieldName); + + const fvMesh& mesh = fD.mesh(); + + unsigned int w = IOstream::defaultPrecision() + 7; + + if + ( + Pstream::master() + && faceZonesIntegrationFilePtr_.found(fieldName) + ) + { + OFstream& os = *faceZonesIntegrationFilePtr_(fieldName); + + os << obr_.time().value(); + + const faceZoneMesh& faceZoneList = mesh.faceZones(); + + forAll(faceZonesSet_, zoneI) + { + const word name = faceZonesSet_[zoneI]; + + label zoneID = faceZoneList.findZoneID(name); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + dm = calcFaceZonesIntegral(fD, fz); + + reduce(dm, sumOp<scalar>()); + + os << ' ' << setw(w) << dm; + + if (log_) + { + Info<< "faceZonesIntegration output:" << nl + << " Integration" << dm << endl; + } + } + + os << endl; + } + } + } +} + + +Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral +( + const surfaceScalarField& fD, + const faceZone& fz +) const +{ + scalar dm = 0.0; + const fvMesh& mesh = fD.mesh(); + + forAll (fz, i) + { + label faceI = fz[i]; + + if (mesh.isInternalFace(faceI)) + { + if (fz.flipMap()[faceI]) + { + dm -= fD[faceI]; + } + else + { + dm += fD[faceI]; + } + } + else + { + label patchI = mesh.boundaryMesh().whichPatch(faceI); + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + if (isA<processorPolyPatch>(pp)) + { + if (refCast<const processorPolyPatch>(pp).owner()) + { + if (fz.flipMap()[faceI]) + { + dm -= fD.boundaryField()[patchI][pp.whichFace(faceI)]; + } + else + { + dm += fD.boundaryField()[patchI][pp.whichFace(faceI)]; + } + } + } + else if (isA<cyclicPolyPatch>(pp)) + { + label patchFaceI = faceI - pp.start(); + if (patchFaceI < pp.size()/2) + { + if (fz.flipMap()[patchFaceI]) + { + dm -= fD.boundaryField()[patchI][patchFaceI]; + } + else + { + dm += fD.boundaryField()[patchI][patchFaceI]; + } + } + } + else if (!isA<emptyPolyPatch>(pp)) + { + label patchFaceI = faceI - pp.start(); + if (fz.flipMap()[patchFaceI]) + { + dm -= fD.boundaryField()[patchI][patchFaceI]; + } + else + { + dm += fD.boundaryField()[patchI][patchFaceI]; + } + } + } + } + + return dm; +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H new file mode 100644 index 0000000000000000000000000000000000000000..5fc957bba739954dcf3181cd03d5a7f654e6609f --- /dev/null +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H @@ -0,0 +1,178 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::faceZonesIntegration + +Description + Integrates surfaceScalarFields on faceZones + +SourceFiles + faceZonesIntegration.C + IOfaceZonesIntegration.H + +\*---------------------------------------------------------------------------*/ + +#ifndef faceZonesIntegration_H +#define faceZonesIntegration_H + +#include "fvCFD.H" +#include "primitiveFieldsFwd.H" +#include "volFieldsFwd.H" +#include "HashPtrTable.H" +#include "OFstream.H" +#include "Switch.H" +#include "pointFieldFwd.H" +#include "polyMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; + +/*---------------------------------------------------------------------------*\ + Class faceZonesIntegration Declaration +\*---------------------------------------------------------------------------*/ + +class faceZonesIntegration +{ + +protected: + + // Private data + + //- Name of this set of face zone integration, + // Also used as the name of the probes directory. + word name_; + + const objectRegistry& obr_; + + //- on/off switch + bool active_; + + //- Switch to send output to Info as well as to file + Switch log_; + + //- Current open files + HashPtrTable<OFstream> faceZonesIntegrationFilePtr_; + + // Read from dictionary + + //- faceZones to integrate over + wordList faceZonesSet_; + + //- Names of the surface fields + wordList fItems_; + + + // Private Member Functions + + //- If the integration file has not been created create it + void makeFile(); + + scalar calcFaceZonesIntegral + ( + const surfaceScalarField& fD, + const faceZone& fz + ) const; + + + //- Disallow default bitwise copy construct + faceZonesIntegration(const faceZonesIntegration&); + + //- Disallow default bitwise assignment + void operator=(const faceZonesIntegration&); + + //- Output file header information + virtual void writeFileHeader(); + + +public: + + //- Runtime type information + TypeName("faceZonesIntegration"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + faceZonesIntegration + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + // Destructor + + virtual ~faceZonesIntegration(); + + + // Member Functions + + //- Return name of the set of zones + virtual const word& name() const + { + return name_; + }; + + //- Read the zone integration data + virtual void read(const dictionary&); + + //- Execute, currently does nothing + virtual void execute(); + + //- Execute at the final time-loop, currently does nothing + virtual void end(); + + //- Write the integration + virtual void write(); + + //- Update for changes of mesh + virtual void updateMesh(const mapPolyMesh&) + {} + + //- Update for changes of mesh + virtual void movePoints(const pointField&) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.C b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.C new file mode 100644 index 0000000000000000000000000000000000000000..43665119b14aeedf9056ead1a814e32f8518e3cb --- /dev/null +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.C @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "faceZonesIntegrationFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug(faceZonesIntegrationFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + faceZonesIntegrationFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.H b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.H new file mode 100644 index 0000000000000000000000000000000000000000..2cc95e2af21eb19a1e890207447fdfdfa76d47d3 --- /dev/null +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegrationFunctionObject.H @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Typedef + Foam::faceZonesIntegrationFunctionObject + +Description + FunctionObject wrapper around faceZonesIntegration to allow them to be + created via the functions list within controlDict. + +SourceFiles + faceZonesIntegrationFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef faceZonesIntegrationFunctionObject_H +#define faceZonesIntegrationFunctionObject_H + +#include "faceZonesIntegration.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject<faceZonesIntegration> + faceZonesIntegrationFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //