From 9cf1ef5f18415ca405eaa1d7fc1ac8f62828a029 Mon Sep 17 00:00:00 2001 From: Henrik Rusche Date: Mon, 15 Nov 2010 20:33:47 +0100 Subject: [PATCH] added postFixedSubRegistry --- etc/controlDict | 1 + src/OpenFOAM/Make/files | 2 +- src/OpenFOAM/db/IOobject/IOobject.C | 32 +++- src/OpenFOAM/db/IOobject/IOobject.H | 9 ++ .../db/objectRegistry/objectRegistry.C | 28 +++- .../db/objectRegistry/objectRegistry.H | 20 ++- .../postfixedSubRegistry.C | 144 ++++++++++++++++++ .../postfixedSubRegistry.H | 136 +++++++++++++++++ .../hCombustionThermo/hCombustionThermo.C | 2 +- .../hCombustionThermo/hCombustionThermo.H | 13 +- 10 files changed, 374 insertions(+), 13 deletions(-) create mode 100644 src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.C create mode 100644 src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.H diff --git a/etc/controlDict b/etc/controlDict index b3dac7260..bdb3675d6 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -629,6 +629,7 @@ DebugSwitches nutWallFunction 0; obj 0; objectRegistry 0; + postfixedSubRegistry 0; octree 0; octreeDataEdges 0; octreeDataFace 0; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 435ad8c6b..26516e713 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -169,6 +169,7 @@ $(regIOobject)/regIOobjectWrite.C db/IOobjectList/IOobjectList.C db/objectRegistry/objectRegistry.C +db/postfixedSubRegistry/postfixedSubRegistry.C db/CallbackRegistry/CallbackRegistryName.C db/dlLibraryTable/dlLibraryTable.C @@ -176,7 +177,6 @@ db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObjectList/functionObjectList.C db/functionObjects/outputFilterOutputControl/outputFilterOutputControl.C - Time = db/Time $(Time)/TimePaths.C $(Time)/TimeState.C diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 6cce7f3dc..904f6f383 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -113,6 +113,34 @@ bool Foam::IOobject::IOobject::fileNameComponents // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::IOobject::IOobject +( + const word& name, + const Time& time, + readOption ro, + writeOption wo +) +: + name_(name), + headerClassName_(typeName), + note_(), + instance_(""), + local_(), + db_(time), + rOpt_(ro), + wOpt_(wo), + registerObject_(false), + objState_(GOOD) +{ + if (objectRegistry::debug) + { + Info<< "Constructing IOobject called " << name_ + << " of type " << headerClassName_ + << endl; + } +} + + Foam::IOobject::IOobject ( const word& name, @@ -123,7 +151,7 @@ Foam::IOobject::IOobject bool registerObject ) : - name_(name), + name_(registry.mangleFileName(name)), headerClassName_(typeName), note_(), instance_(instance), @@ -154,7 +182,7 @@ Foam::IOobject::IOobject bool registerObject ) : - name_(name), + name_(registry.mangleFileName(name)), headerClassName_(typeName), note_(), instance_(instance), diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index c9fcfe29c..cefcd19d3 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -179,6 +179,15 @@ public: // Constructors + //- Construct from name, instance, registry, io options + IOobject + ( + const word& name, + const Time& registry, + readOption r = NO_READ, + writeOption w = NO_WRITE + ); + //- Construct from name, instance, registry, io options IOobject ( diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 1db25d912..3664f27a8 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -45,11 +45,9 @@ Foam::objectRegistry::objectRegistry IOobject ( string::validate(t.caseName()), - "", t, IOobject::NO_READ, - IOobject::AUTO_WRITE, - false + IOobject::AUTO_WRITE ), true // to flag that this is the top-level regIOobject ), @@ -78,6 +76,24 @@ Foam::objectRegistry::objectRegistry } +Foam::objectRegistry::objectRegistry +( + const IOobject& io, + const fileName& dbDir, + const label nIoObjects +) +: + regIOobject(io), + HashTable(nIoObjects), + time_(io.time()), + parent_(io.db()), + dbDir_(dbDir), + event_(1) +{ + writeOpt() = IOobject::AUTO_WRITE; +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::objectRegistry::~objectRegistry() @@ -135,6 +151,12 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const } +Foam::fileName Foam::objectRegistry::mangleFileName(const fileName& fName) const +{ + return fName; +} + + const Foam::objectRegistry& Foam::objectRegistry::subRegistry ( const word& name diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index d11d0c429..d8b78b25d 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -105,6 +105,14 @@ public: const label nIoObjects = 128 ); + //- Construct a sub-registry given an IObject to describe the registry + // and an initial estimate for the number of entries + explicit objectRegistry + ( + const IOobject& io, + const fileName& dbDir, + const label nIoObjects = 128 + ); // Destructor @@ -133,6 +141,14 @@ public: return dbDir_; } + fileName& dbDir() + { + return dbDir_; + } + + //- Return mangled fileName + virtual fileName mangleFileName (const fileName&) const; + //- Return the list of names of the IOobjects wordList names() const; @@ -168,10 +184,10 @@ public: virtual void rename(const word& newName); //- Add an regIOobject to registry - bool checkIn(regIOobject&) const; + virtual bool checkIn(regIOobject&) const; //- Remove an regIOobject from registry - bool checkOut(regIOobject&) const; + virtual bool checkOut(regIOobject&) const; // Reading diff --git a/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.C b/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.C new file mode 100644 index 000000000..b563fec09 --- /dev/null +++ b/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.C @@ -0,0 +1,144 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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 "postfixedSubRegistry.H" +#include "Pstream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(postfixedSubRegistry, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::postfixedSubRegistry::postfixedSubRegistry +( + const IOobject& io, + const label nIoObjects +) +: + objectRegistry(io, io.db().dbDir(), nIoObjects) +{ + writeOpt() = IOobject::NO_WRITE; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::postfixedSubRegistry::~postfixedSubRegistry() +{ + objectRegistry::clear(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::fileName Foam::postfixedSubRegistry::mangleFileName(const fileName& fName) const +{ + return fileName(fName+name()); +} + + +bool Foam::postfixedSubRegistry::checkIn(regIOobject& io) const +{ + if (postfixedSubRegistry::debug) + { + Pout<< "postfixedSubRegistry::checkIn(regIOobject&) : " + << name() << " : checking in " << io.name() + << endl; + } + + word demangledName = io.name(); + demangledName = demangledName(io.name().size() - name().size()); + + // Check into Mesh-Registry under full name + const_cast(parent()).insert(io.name(), &io); + + // Check into Mesh-Registry under short name + return const_cast(*this).insert(demangledName, &io);; +} + + +bool Foam::postfixedSubRegistry::checkOut(regIOobject& io) const +{ + word demangledName = io.name(); + demangledName = demangledName(io.name().size() - name().size()); + iterator iter = const_cast(*this).find(demangledName); + iterator iterPar = const_cast(parent()).find(io.name()); + + if (iter != end() && iterPar != end()) + { + if (postfixedSubRegistry::debug) + { + Pout<< "postfixedSubRegistry::checkOut(regIOobject&) : " + << name() << " : checking out " << io.name() + << endl; + } + + if (iter() != &io || iterPar() != &io) + { + if (postfixedSubRegistry::debug) + { + WarningIn("postfixedSubRegistry::checkOut(regIOobject&)") + << name() << " : attempt to checkOut copy of " << io.name() + << endl; + } + + return false; + } + else + { + bool hasErased = + const_cast(*this).erase(iter) + && const_cast(parent()).erase(iterPar); + + if (io.ownedByRegistry()) + { + delete iter(); + } + + return hasErased; + } + } + else + { + if (postfixedSubRegistry::debug) + { + Pout<< "postfixedSubRegistry::checkOut(regIOobject&) : " + << name() << " : could not find " << io.name() + << " in registry " << name() + << endl; + } + + return false; + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.H b/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.H new file mode 100644 index 000000000..5ec0c968b --- /dev/null +++ b/src/OpenFOAM/db/postfixedSubRegistry/postfixedSubRegistry.H @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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::postfixedSubRegistry + +Description + Registry of regIOobjects + +SourceFiles + postfixedSubRegistry.C + +\*---------------------------------------------------------------------------*/ + +#ifndef postfixedSubRegistry_H +#define postfixedSubRegistry_H + +#include "objectRegistry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class postfixedSubRegistry Declaration +\*---------------------------------------------------------------------------*/ + +class postfixedSubRegistry +: + public objectRegistry +{ + // Private Member Functions + + //- Disallow Copy constructor + postfixedSubRegistry(const postfixedSubRegistry&); + + //- Disallow default bitwise copy construct and assignment + void operator=(const postfixedSubRegistry&); + + +public: + + //- Declare type name for this IOobject + TypeName("postfixedSubRegistry"); + + + // Constructors + + //- Construct a sub-registry given an IObject to describe the registry + // and an initial estimate for the number of entries + explicit postfixedSubRegistry + ( + const IOobject& io, + const label nIoObjects = 128 + ); + + + // Destructor + + virtual ~postfixedSubRegistry(); + + + // Member functions + + // Access + + //- Return mangled fileName + virtual fileName mangleFileName (const fileName&) const; + + // Edit + + //- Add an regIOobject to registry + virtual bool checkIn(regIOobject&) const; + + //- Remove an regIOobject from registry + virtual bool checkOut(regIOobject&) const; + + // Reading + + //- Return true if any of the object's files have been modified + virtual bool modified() const + { + return false; + } + + //- Read object if modified + virtual bool readIfModified() + { + return true; + } + + // Writing + + virtual bool writeObject + ( + IOstream::streamFormat fmt, + IOstream::versionNumber ver, + IOstream::compressionType cmp + ) const + { + return true; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.C b/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.C index f13d686d6..3d86a0fb2 100644 --- a/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.C +++ b/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.C @@ -47,7 +47,7 @@ Foam::hCombustionThermo::hCombustionThermo(const fvMesh& mesh) ( "h", mesh.time().timeName(), - mesh, + obj, IOobject::NO_READ, IOobject::NO_WRITE ), diff --git a/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.H b/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.H index 1e63cc883..29bf3134f 100644 --- a/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.H +++ b/src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.H @@ -75,21 +75,26 @@ public: autoPtr, hCombustionThermo, fvMesh, - (const fvMesh& mesh), - (mesh) + (const fvMesh& mesh, const objectRegistry& obj), + (mesh, obj) ); // Constructors //- Construct from dictionary and mesh - hCombustionThermo(const fvMesh&); + hCombustionThermo(const fvMesh&, const objectRegistry&); // Selectors //- Standard selection based on fvMesh - static autoPtr New(const fvMesh&); + static autoPtr New(const fvMesh&, const objectRegistry&); + + static autoPtr New(const fvMesh& mesh) + { + return New(mesh, mesh) + } //- Select and check that package contains 'thermoType' static autoPtr NewType