ENH: allow wordHashSet filter for IOobjectList::names

- simplifies usage.
  Support syncPar check on names() to detect inconsistencies.

- simplify readFields, ReadFields and other routines by using these
  new methods.
This commit is contained in:
Mark Olesen
2018-07-26 14:56:52 +02:00
parent a8ef5610d0
commit 02ad76df4f
51 changed files with 1434 additions and 1397 deletions

View File

@ -690,8 +690,6 @@ $(derivedPointPatchFields)/codedFixedValue/codedFixedValuePointPatchFields.C
fields/GeometricFields/pointFields/pointFields.C
fields/ReadFields/ReadFields.C
meshes/bandCompression/bandCompression.C
meshes/preservePatchTypes/preservePatchTypes.C

View File

@ -29,7 +29,7 @@ License
#include "IOList.H"
#include "predicates.H"
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
@ -45,18 +45,48 @@ namespace Foam
forAllConstIters(list, iter)
{
if (matcher(iter.key()))
const word& key = iter.key();
const IOobject* io = iter.object();
if (matcher(key))
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
InfoInFunction << "Found " << key << endl;
}
results.set
(
iter.key(),
new IOobject(*(iter.object()))
);
results.set(key, new IOobject(*io));
}
}
return results;
}
// Templated implementation for lookupClass() - file-scope
template<class UnaryMatchPredicate>
static IOobjectList lookupClassImpl
(
const IOobjectList& list,
const word& clsName,
const UnaryMatchPredicate& matcher
)
{
IOobjectList results(list.size());
forAllConstIters(list, iter)
{
const word& key = iter.key();
const IOobject* io = iter.object();
if (clsName == io->headerClassName() && matcher(key))
{
if (IOobject::debug)
{
InfoInFunction << "Found " << key << endl;
}
results.set(key, new IOobject(*io));
}
}
@ -77,10 +107,13 @@ namespace Foam
// Summary (key,val) = (class-name, object-names)
forAllConstIters(list, iter)
{
if (matcher(iter.key()))
const word& key = iter.key();
const IOobject* io = iter.object();
if (matcher(key))
{
// Create entry (if needed) and insert
summary(iter.object()->headerClassName()).insert(iter.key());
summary(io->headerClassName()).insert(key);
}
}
@ -103,13 +136,17 @@ namespace Foam
label count = 0;
forAllConstIters(list, iter)
{
if (iter()->headerClassName() == clsName && matcher(iter.key()))
const word& key = iter.key();
const IOobject* io = iter.object();
if (clsName == io->headerClassName() && matcher(key))
{
objNames[count++] = iter.key();
objNames[count] = key;
++count;
}
}
objNames.setSize(count);
objNames.resize(count);
if (doSort)
{
@ -118,7 +155,39 @@ namespace Foam
return objNames;
}
}
// With syncPar = true, check that object names are the same on
// all processors. Trigger FatalError if not.
//
// The object names are sorted as a side-effect, since this is
// required for consistent ordering across all processors.
static bool checkNames(wordList& masterNames, const bool syncPar)
{
Foam::sort(masterNames);
if (syncPar && Pstream::parRun())
{
const wordList localNames(masterNames);
Pstream::scatter(masterNames);
if (localNames != masterNames)
{
FatalErrorInFunction
<< "Objects not synchronised across processors." << nl
<< "Master has " << flatOutput(masterNames) << nl
<< "Processor " << Pstream::myProcNo()
<< " has " << flatOutput(localNames)
<< exit(FatalError);
return false;
}
}
return true;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -272,28 +341,15 @@ Foam::IOobjectList Foam::IOobjectList::lookup(const wordRes& matcher) const
}
Foam::IOobjectList Foam::IOobjectList::lookup(const wordHashSet& matcher) const
{
return lookupImpl(*this, matcher);
}
Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
{
IOobjectList results(size());
forAllConstIters(*this, iter)
{
if (iter()->headerClassName() == clsName)
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
}
results.set
(
iter.key(),
new IOobject(*(iter.object()))
);
}
}
return results;
return lookupClassImpl(*this, clsName, predicates::always());
}
@ -317,6 +373,13 @@ Foam::IOobjectList::classes(const wordRes& matcher) const
}
Foam::HashTable<Foam::wordHashSet>
Foam::IOobjectList::classes(const wordHashSet& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::wordList Foam::IOobjectList::names() const
{
return HashPtrTable<IOobject>::toc();
@ -329,6 +392,15 @@ Foam::wordList Foam::IOobjectList::sortedNames() const
}
Foam::wordList Foam::IOobjectList::names(const bool syncPar) const
{
wordList objNames(HashPtrTable<IOobject>::toc());
checkNames(objNames, syncPar);
return objNames;
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName
@ -338,26 +410,6 @@ Foam::wordList Foam::IOobjectList::names
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRe& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRes& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName
@ -367,6 +419,29 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const bool syncPar
) const
{
wordList objNames(namesImpl(*this, clsName, predicates::always(), false));
checkNames(objNames, syncPar);
return objNames;
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRe& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
@ -377,6 +452,30 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRe& matcher,
const bool syncPar
) const
{
wordList objNames(namesImpl(*this, clsName, matcher, false));
checkNames(objNames, syncPar);
return objNames;
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRes& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
@ -387,6 +486,54 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRes& matcher,
const bool syncPar
) const
{
wordList objNames(namesImpl(*this, clsName, matcher, false));
checkNames(objNames, syncPar);
return objNames;
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordHashSet& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
const wordHashSet& matcher
) const
{
return namesImpl(*this, clsName, matcher, true);
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordHashSet& matcher,
const bool syncPar
) const
{
wordList objNames(namesImpl(*this, clsName, matcher, false));
checkNames(objNames, syncPar);
return objNames;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::IOobjectList::operator=(IOobjectList&& list)

View File

@ -118,6 +118,9 @@ public:
//- The list of all IOobjects with matching names
IOobjectList lookup(const wordRes& matcher) const;
//- The list of all IOobjects with matching names
IOobjectList lookup(const wordHashSet& matcher) const;
//- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& clsName) const;
@ -201,6 +204,10 @@ public:
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRes& matcher) const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordHashSet& matcher) const;
// Summary of names
@ -211,13 +218,61 @@ public:
wordList names(const word& clsName) const;
//- The names of IOobjects with the given class name that also
// have a name satisfying the input matcher
//- have a name satisfying the input matcher
wordList names(const word& clsName, const wordRe& matcher) const;
//- The names of IOobjects with the given class name that also
// have a name satisfying the input matcher
//- have a name satisfying the input matcher
wordList names(const word& clsName, const wordRes& matcher) const;
//- The names of IOobjects with the given class name that also
//- have a name satisfying the input matcher
wordList names(const word& clsName, const wordHashSet& matcher) const;
//- A sorted list of names of the IOobjects.
// With syncPar = true, triggers FatalError if the names are
// not consistent on all processors.
wordList names(const bool syncPar) const;
//- A sorted list of names of the IOobjects
// With syncPar = true, triggers FatalError if the names are
// not consistent on all processors.
wordList names(const word& clsName, const bool syncPar) const;
//- The sorted names of IOobjects with the given class name that also
//- have a name satisfying the input matcher
// With syncPar = true, triggers FatalError if the names are
// not consistent on all processors.
wordList names
(
const word& clsName,
const wordRe& matcher,
const bool syncPar
) const;
//- The sorted names of IOobjects with the given class name that also
//- have a name satisfying the input matcher
// With syncPar = true, triggers FatalError if the names are
// not consistent on all processors.
wordList names
(
const word& clsName,
const wordRes& matcher,
const bool syncPar
) const;
//- The sorted names of IOobjects with the given class name that also
//- have a name satisfying the input matcher
// With syncPar = true, triggers FatalError if the names are
// not consistent on all processors.
wordList names
(
const word& cls,
const wordHashSet& matcher,
const bool syncPar
) const;
// Summary of names (sorted)
@ -228,13 +283,21 @@ public:
wordList sortedNames(const word& clsName) const;
//- The sorted names of IOobjects with the given class name that also
// have a name satisfying the input matcher
//- have a name satisfying the input matcher
wordList sortedNames(const word& clsName, const wordRe& matcher) const;
//- The sorted names of IOobjects with the given class name that also
// have a name satisfying the input matcher
//- have a name satisfying the input matcher
wordList sortedNames(const word& clsName, const wordRes& matcher) const;
//- The sorted names of IOobjects with the given class name that also
//- have a name satisfying the input matcher
wordList sortedNames
(
const word& clsName,
const wordHashSet& matcher
) const;
// Member Operators

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -133,6 +133,13 @@ Foam::objectRegistry::classes(const wordRes& matcher) const
}
Foam::HashTable<Foam::wordHashSet>
Foam::objectRegistry::classes(const wordHashSet& matcher) const
{
return classesImpl(*this, matcher);
}
Foam::wordList Foam::objectRegistry::names() const
{
return HashTable<regIOobject*>::toc();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -132,210 +132,223 @@ public:
// Member functions
// Access
// Access
//- Return time
const Time& time() const
{
return time_;
}
//- Return time
const Time& time() const
{
return time_;
}
//- Return the parent objectRegistry
const objectRegistry& parent() const
{
return parent_;
}
//- Return the parent objectRegistry
const objectRegistry& parent() const
{
return parent_;
}
//- Local directory path of this objectRegistry relative to the time
virtual const fileName& dbDir() const
{
return dbDir_;
}
//- Local directory path of this objectRegistry relative to the time
virtual const fileName& dbDir() const
{
return dbDir_;
}
// Summary of classes
// Summary of classes
//- A summary hash of classes used and their associated object names.
// Behaviour and usage as per IOobjectList::classes
HashTable<wordHashSet> classes() const;
//- A summary hash of classes used and their associated object names.
// Behaviour and usage as per IOobjectList::classes
HashTable<wordHashSet> classes() const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRe& matcher) const;
//- A summary hash of classes used and their associated object names
//- restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRe& matcher) const;
//- A summary hash of classes used and their associated object names
// restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRes& matcher) const;
//- A summary hash of classes used and their associated object names
//- restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordRes& matcher) const;
//- A summary hash of classes used and their associated object names
//- restricted to objects with names that satisfy the input matcher
HashTable<wordHashSet> classes(const wordHashSet& matcher) const;
// Summary of names
// Summary of names
//- A list of names of the objects
wordList names() const;
//- A list of names of the objects
wordList names() const;
//- The names of objects with the given class name
wordList names(const word& clsName) const;
//- The names of objects with the given class name
wordList names(const word& clsName) const;
//- The names of objects with the given type
template<class Type>
wordList names() const;
//- The names of objects with the given type
template<class Type>
wordList names() const;
//- The names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList names(const wordRe& matcher) const;
//- The names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList names(const wordRe& matcher) const;
//- The names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList names(const wordRes& matcher) const;
//- The names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList names(const wordRes& matcher) const;
//- The names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList names(const wordHashSet& matcher) const;
// Summary of names (sorted)
// Summary of names (sorted)
//- A sorted list of names of the objects
wordList sortedNames() const;
//- A sorted list of names of the objects
wordList sortedNames() const;
//- The sorted names of objects with the given class name
wordList sortedNames(const word& clsName) const;
//- The sorted names of objects with the given class name
wordList sortedNames(const word& clsName) const;
//- The sorted names of objects with the given type
template<class Type>
wordList sortedNames() const;
//- The sorted names of objects with the given type
template<class Type>
wordList sortedNames() const;
//- The sorted names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRe& matcher) const;
//- The sorted names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRe& matcher) const;
//- The sorted names of objects with the given type that also
// have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRes& matcher) const;
//- The sorted names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRes& matcher) const;
//- The sorted names of objects with the given type that also
//- have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordHashSet& matcher) const;
// Lookup
// Lookup
//- Lookup and return a const sub-objectRegistry.
// Optionally create it if it does not exist.
// If recursive, search parent registries.
const objectRegistry& subRegistry
(
const word& name,
const bool forceCreate = false,
const bool recursive = false
) const;
//- Lookup and return a const sub-objectRegistry.
// Optionally create it if it does not exist.
// If recursive, search parent registries.
const objectRegistry& subRegistry
(
const word& name,
const bool forceCreate = false,
const bool recursive = false
) const;
//- Lookup and return all objects of the given Type
template<class Type>
HashTable<const Type*> lookupClass(const bool strict = false) const;
//- Lookup and return all objects of the given Type
template<class Type>
HashTable<const Type*> lookupClass(const bool strict = false) const;
//- Lookup and return all objects of the given Type
template<class Type>
HashTable<Type*> lookupClass(const bool strict = false);
//- Lookup and return all objects of the given Type
template<class Type>
HashTable<Type*> lookupClass(const bool strict = false);
//- Is the named Type found?
// If recursive, search parent registries.
template<class Type>
bool foundObject
(
const word& name,
const bool recursive = false
) const;
//- Is the named Type found?
// If recursive, search parent registries.
template<class Type>
bool foundObject
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
template<class Type>
const Type& lookupObject
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
template<class Type>
const Type& lookupObject
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
template<class Type>
Type& lookupObjectRef
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
template<class Type>
Type& lookupObjectRef
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return pointer to the object of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
const Type* lookupObjectPtr
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return pointer to the object of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
const Type* lookupObjectPtr
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return non-const pointer to the object
// of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
Type* lookupObjectRefPtr
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return non-const pointer to the object
// of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
Type* lookupObjectRefPtr
(
const word& name,
const bool recursive = false
) const;
// Events
// Events
//- Return new event number.
label getEvent() const;
//- Return new event number.
label getEvent() const;
// Edit
// Edit
//- Rename
virtual void rename(const word& newName);
//- Rename
virtual void rename(const word& newName);
//- Add an regIOobject to registry
bool checkIn(regIOobject& io) const;
//- Add an regIOobject to registry
bool checkIn(regIOobject& io) const;
//- Remove an regIOobject from registry
bool checkOut(regIOobject& io) const;
//- Remove an regIOobject from registry
bool checkOut(regIOobject& io) const;
// Reading
// Reading
//- Return true if any of the object's files have been modified
virtual bool modified() const;
//- Return true if any of the object's files have been modified
virtual bool modified() const;
//- Read the objects that have been modified
void readModifiedObjects();
//- Read the objects that have been modified
void readModifiedObjects();
//- Read object if modified
virtual bool readIfModified();
//- Read object if modified
virtual bool readIfModified();
// Writing
// Writing
//- writeData function required by regIOobject but not used
// for this class, write is used instead
virtual bool writeData(Ostream&) const
{
NotImplemented;
//- writeData function required by regIOobject but not used.
// For this class, write is used instead
virtual bool writeData(Ostream&) const
{
NotImplemented;
return false;
}
return false;
}
//- Write the objects
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
const bool valid
) const;
//- Write the objects
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
const bool valid
) const;
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -69,7 +69,8 @@ Foam::wordList Foam::objectRegistry::namesImpl
{
if (isA<Type>(*iter()) && matcher(iter()->name()))
{
objNames[count++] = iter()->name();
objNames[count] = iter()->name();
++count;
}
}
@ -101,10 +102,14 @@ Foam::wordList Foam::objectRegistry::names(const wordRe& matcher) const
template<class Type>
Foam::wordList Foam::objectRegistry::names
(
const wordRes& matcher
) const
Foam::wordList Foam::objectRegistry::names(const wordRes& matcher) const
{
return namesImpl<Type>(*this, matcher, false);
}
template<class Type>
Foam::wordList Foam::objectRegistry::names(const wordHashSet& matcher) const
{
return namesImpl<Type>(*this, matcher, false);
}
@ -118,10 +123,14 @@ Foam::wordList Foam::objectRegistry::sortedNames() const
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames
(
const wordRe& matcher
) const
Foam::wordList Foam::objectRegistry::sortedNames(const wordRe& matcher) const
{
return namesImpl<Type>(*this, matcher, true);
}
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames(const wordRes& matcher) const
{
return namesImpl<Type>(*this, matcher, true);
}
@ -130,7 +139,7 @@ Foam::wordList Foam::objectRegistry::sortedNames
template<class Type>
Foam::wordList Foam::objectRegistry::sortedNames
(
const wordRes& matcher
const wordHashSet& matcher
) const
{
return namesImpl<Type>(*this, matcher, true);
@ -198,10 +207,8 @@ bool Foam::objectRegistry::foundObject
{
return true;
}
else
{
return false;
}
return false;
}

View File

@ -1,87 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
\*---------------------------------------------------------------------------*/
#include "ReadFields.H"
#include "IOobjectList.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Read all fields of type. Returns names of fields read. Guarantees all
// processors to read fields in same order.
Foam::wordList Foam::fieldNames
(
const IOobjectList& fieldObjects,
const bool syncPar
)
{
// Get sorted field names. Sorting needed in parallel since different
// processors (using different file servers) might pick up the files
// in different order.
wordList masterNames(fieldObjects.sortedNames());
if (syncPar && Pstream::parRun())
{
// Check that I have the same fields as the master
const wordList localNames(masterNames);
Pstream::scatter(masterNames);
wordHashSet localNamesSet(localNames);
forAll(masterNames, i)
{
const word& masterFld = masterNames[i];
wordHashSet::iterator iter = localNamesSet.find(masterFld);
if (iter == localNamesSet.end())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
<< "Master has fields " << masterNames
<< " processor " << Pstream::myProcNo()
<< " has fields " << localNames << exit(FatalError);
}
else
{
localNamesSet.erase(iter);
}
}
if (localNamesSet.size())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
<< "Master has fields " << masterNames
<< " processor " << Pstream::myProcNo()
<< " has fields " << localNames << exit(FatalError);
}
}
return masterNames;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,11 +51,9 @@ class regIOobject;
class IOobjectList;
class objectRegistry;
//- Get sorted names of fields of type. If syncPar and running in parallel
// check for identical names
wordList fieldNames(const IOobjectList& objects, const bool syncPar);
//- Read Geometric fields
//- Read Geometric fields of templated type.
// \return sorted names of fields read.
// \note All processors guaranteed to read fields in same order.
template<class Type, template<class> class PatchField, class GeoMesh>
wordList ReadFields
(
@ -66,9 +64,10 @@ wordList ReadFields
const bool readOldTime = false
);
//- Read all fields of the specified type.
// Returns names of fields read.
// Guarantees all processors read fields in same order.
//- Read fields of the templated type.
// \return sorted names of fields read.
// \note All processors guaranteed to read fields in same order.
template<class GeoField, class Mesh>
wordList ReadFields
(
@ -78,7 +77,9 @@ wordList ReadFields
const bool syncPar = true
);
//- Read non-mesh fields, e.g. uniformDimensionedField like 'g'
//- Read non-mesh fields (uniformDimensionedField like 'g').
// \return sorted names of fields read.
// \note All processors guaranteed to read fields in same order.
template<class GeoField>
wordList ReadFields
(
@ -87,8 +88,8 @@ wordList ReadFields
const bool syncPar = true
);
//- Read all GeometricFields of the specified type.
// The fieldsCache is an objectRegistry of all stored fields
//- Read all GeometricFields of the templated type.
// \param fieldsCache is an objectRegistry of all stored fields
template<class GeoField>
static void ReadFields
(
@ -98,8 +99,8 @@ static void ReadFields
objectRegistry& fieldsCache
);
//- Read all GeometricFields of the specified type.
// The fieldsCache is an objectRegistry of all stored fields
//- Read all GeometricFields of the templated type.
// \param fieldsCache is the objectRegistry name where fields are stored
template<class GeoField>
static void ReadFields
(
@ -109,9 +110,9 @@ static void ReadFields
const word& registryName = "fieldsCache"
);
//- Read the selected GeometricFields of the specified type.
//- Read the selected GeometricFields of the templated type.
// The fields are transferred to the objectRegistry and a list of them is
// returned as a stack for later clean-up
// returned as a stack for later cleanup
template<class GeoFieldType>
void readFields
(
@ -122,9 +123,9 @@ void readFields
);
//- Read the selected UniformDimensionedFields of the specified type.
//- Read the selected UniformDimensionedFields of the templated type.
// The fields are transferred to the objectRegistry and a list of them is
// returned as a stack for later clean-up
// returned as a stack for later cleanup
template<class GeoFieldType>
void readUniformFields
(

View File

@ -29,8 +29,6 @@ License
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Read all GeometricFields of type. Returns names of fields read. Guarantees
// all processors to read fields in same order.
template<class Type, template<class> class PatchField, class GeoMesh>
Foam::wordList Foam::ReadFields
(
@ -43,25 +41,27 @@ Foam::wordList Foam::ReadFields
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// Search list of objects for wanted type
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Names of GeoField objects, sorted order.
const wordList fieldNames(objects.names(GeoField::typeName, syncPar));
const wordList masterNames(fieldNames(fieldObjects, syncPar));
// Construct the fields - reading in consistent (master) order.
fields.resize(fieldNames.size());
fields.setSize(masterNames.size());
label nFields = 0;
// Make sure to read in masterNames order.
forAll(masterNames, i)
for (const word& fieldName : fieldNames)
{
Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
<< endl;
if (!nFields)
{
Info<< "Reading " << GeoField::typeName << ':';
}
Info<< ' ' << fieldName;
const IOobject& io = *fieldObjects[masterNames[i]];
const IOobject& io = *objects[fieldName];
fields.set
(
i,
nFields++,
new GeoField
(
IOobject
@ -79,12 +79,13 @@ Foam::wordList Foam::ReadFields
)
);
}
return masterNames;
if (nFields) Info<< endl;
return fieldNames;
}
// Read all fields of type. Returns names of fields read. Guarantees all
// processors to read fields in same order.
template<class GeoField, class Mesh>
Foam::wordList Foam::ReadFields
(
@ -94,25 +95,27 @@ Foam::wordList Foam::ReadFields
const bool syncPar
)
{
// Search list of objects for wanted type
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Names of GeoField objects, sorted order.
const wordList fieldNames(objects.names(GeoField::typeName, syncPar));
const wordList masterNames(fieldNames(fieldObjects, syncPar));
// Construct the fields - reading in consistent (master) order.
fields.resize(fieldNames.size());
fields.setSize(masterNames.size());
label nFields = 0;
// Make sure to read in masterNames order.
forAll(masterNames, i)
for (const word& fieldName : fieldNames)
{
Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
<< endl;
if (!nFields)
{
Info<< "Reading " << GeoField::typeName << ':';
}
Info<< ' ' << fieldName;
const IOobject& io = *fieldObjects[masterNames[i]];
const IOobject& io = *objects[fieldName];
fields.set
(
i,
nFields++,
new GeoField
(
IOobject
@ -129,12 +132,13 @@ Foam::wordList Foam::ReadFields
)
);
}
return masterNames;
if (nFields) Info<< endl;
return fieldNames;
}
// Read all (non-mesh) fields of type. Returns names of fields read. Guarantees
// all processors to read fields in same order.
template<class GeoField>
Foam::wordList Foam::ReadFields
(
@ -143,25 +147,27 @@ Foam::wordList Foam::ReadFields
const bool syncPar
)
{
// Search list of objects for wanted type
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Names of GeoField objects, sorted order.
const wordList fieldNames(objects.names(GeoField::typeName, syncPar));
const wordList masterNames(fieldNames(fieldObjects, syncPar));
// Construct the fields - reading in consistent (master) order.
fields.resize(fieldNames.size());
fields.setSize(masterNames.size());
label nFields = 0;
// Make sure to read in masterNames order.
forAll(masterNames, i)
for (const word& fieldName : fieldNames)
{
Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
<< endl;
if (!nFields)
{
Info<< "Reading " << GeoField::typeName << ':';
}
Info<< ' ' << fieldName;
const IOobject& io = *fieldObjects[masterNames[i]];
const IOobject& io = *objects[fieldName];
fields.set
(
i,
nFields++,
new GeoField
(
IOobject
@ -177,7 +183,10 @@ Foam::wordList Foam::ReadFields
)
);
}
return masterNames;
if (nFields) Info<< endl;
return fieldNames;
}
@ -190,51 +199,38 @@ void Foam::ReadFields
objectRegistry& fieldsCache
)
{
// Collect all times that are no longer used
// Unload times that are no longer used
{
wordHashSet usedTimes(timeNames);
DynamicList<word> unusedTimes(fieldsCache.size());
forAllIter(objectRegistry, fieldsCache, timeIter)
{
const word& tm = timeIter.key();
if (!usedTimes.found(tm))
{
unusedTimes.append(tm);
}
}
wordHashSet unusedTimes(fieldsCache.toc());
unusedTimes.erase(timeNames);
//Info<< "Unloading times " << unusedTimes << endl;
forAll(unusedTimes, i)
for (const word& timeName : unusedTimes)
{
objectRegistry& timeCache = const_cast<objectRegistry&>
(
fieldsCache.lookupObject<objectRegistry>(unusedTimes[i])
);
objectRegistry& timeCache =
fieldsCache.lookupObjectRef<objectRegistry>(timeName);
fieldsCache.checkOut(timeCache);
}
}
// Load any new fields
forAll(timeNames, i)
for (const word& timeName : timeNames)
{
const word& tm = timeNames[i];
// Create if not found
if (!fieldsCache.found(tm))
if (!fieldsCache.found(timeName))
{
//Info<< "Creating registry for time " << tm << endl;
//Info<< "Creating registry for time " << timeName << endl;
// Create objectRegistry if not found
objectRegistry* timeCachePtr = new objectRegistry
(
IOobject
(
tm,
tm,
timeName,
timeName,
fieldsCache,
IOobject::NO_READ,
IOobject::NO_WRITE
@ -245,27 +241,24 @@ void Foam::ReadFields
// Obtain cache for current time
const objectRegistry& timeCache =
fieldsCache.lookupObject<objectRegistry>
(
tm
);
fieldsCache.lookupObject<objectRegistry>(timeName);
// Store field if not found
if (!timeCache.found(fieldName))
{
//Info<< "Loading field " << fieldName
// << " for time " << tm << endl;
// << " for time " << timeName << endl;
GeoField loadedFld
(
IOobject
(
fieldName,
tm,
timeName,
mesh.thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
false // do not register
),
mesh
);
@ -276,7 +269,7 @@ void Foam::ReadFields
IOobject
(
fieldName,
tm,
timeName,
timeCache,
IOobject::NO_READ,
IOobject::NO_WRITE
@ -320,48 +313,48 @@ void Foam::readFields
LIFOStack<regIOobject*>& storedObjects
)
{
IOobjectList fields(objects.lookupClass(GeoFieldType::typeName));
if (!fields.size()) return;
// Names of GeoField objects, sorted order. Not synchronised.
const wordList fieldNames
(
objects.sortedNames
(
GeoFieldType::typeName,
selectedFields // Only permit these
)
);
bool firstField = true;
label nFields = 0;
forAllConstIter(IOobjectList, fields, fieldIter)
for (const word& fieldName : fieldNames)
{
const IOobject& io = *fieldIter();
const word& fieldName = io.name();
const IOobject& io = *objects[fieldName];
if (selectedFields.found(fieldName))
if (!nFields)
{
if (firstField)
{
Info<< " " << GeoFieldType::typeName << "s:";
firstField = false;
}
Info<< " " << fieldName;
GeoFieldType* fieldPtr = new GeoFieldType
(
IOobject
(
fieldName,
io.instance(),
io.local(),
io.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
fieldPtr->store();
storedObjects.push(fieldPtr);
Info<< " " << GeoFieldType::typeName << ':';
}
Info<< ' ' << fieldName;
GeoFieldType* fieldPtr = new GeoFieldType
(
IOobject
(
fieldName,
io.instance(),
io.local(),
io.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
fieldPtr->store();
storedObjects.push(fieldPtr);
++nFields;
}
if (!firstField)
{
Info<< endl;
}
if (nFields) Info<< endl;
}
@ -374,85 +367,48 @@ void Foam::readUniformFields
const bool syncPar
)
{
// Search list of objects for wanted type
IOobjectList fields(objects.lookupClass(UniformFieldType::typeName));
if (!fields.size()) return;
// Names of UniformField objects, sorted order.
const wordList fieldNames
(
objects.names
(
UniformFieldType::typeName,
selectedFields, // Only permit these
syncPar
)
);
wordList masterNames(fields.names());
label nFields = 0;
if (syncPar && Pstream::parRun())
for (const word& fieldName : fieldNames)
{
// Check that I have the same fields as the master
const wordList localNames(masterNames);
Pstream::scatter(masterNames);
const IOobject& io = *objects[fieldName];
wordHashSet localNamesSet(localNames);
forAll(masterNames, i)
if (!nFields)
{
const word& masterFld = masterNames[i];
wordHashSet::iterator iter = localNamesSet.find(masterFld);
if (iter == localNamesSet.end())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
<< "Master has fields " << masterNames
<< " processor " << Pstream::myProcNo()
<< " has fields " << localNames << exit(FatalError);
}
else
{
localNamesSet.erase(iter);
}
Info<< " " << UniformFieldType::typeName << ':';
}
Info<< ' ' << fieldName;
if (localNamesSet.size())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
<< "Master has fields " << masterNames
<< " processor " << Pstream::myProcNo()
<< " has fields " << localNames << exit(FatalError);
}
}
bool firstField = true;
forAll(masterNames, i)
{
const IOobject& io = *fields[masterNames[i]];
const word& fieldName = io.name();
if (selectedFields.found(fieldName))
{
if (firstField)
{
Info<< " " << UniformFieldType::typeName << "s:";
firstField = false;
}
Info<< " " << fieldName;
UniformFieldType* fieldPtr = new UniformFieldType
UniformFieldType* fieldPtr = new UniformFieldType
(
IOobject
(
IOobject
(
fieldName,
io.instance(),
io.local(),
io.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
fieldPtr->store();
storedObjects.push(fieldPtr);
}
fieldName,
io.instance(),
io.local(),
io.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
fieldPtr->store();
storedObjects.push(fieldPtr);
++nFields;
}
Info<< endl;
if (nFields) Info<< endl;
}

View File

@ -28,7 +28,6 @@ License
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "IOobjectList.H"
#include "turbulentFluidThermoModel.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -52,7 +52,7 @@ void Foam::polyMeshFilter::updateSets(const mapPolyMesh& map)
IOobjectList fileSets(Objects.lookupClass(SetType::typeName));
forAllConstIter(IOobjectList, fileSets, iter)
forAllConstIters(fileSets, iter)
{
if (!sets.found(iter.key()))
{

View File

@ -72,7 +72,7 @@ void Foam::setUpdater::updateSets(const mapPolyMesh& morphMap) const
IOobjectList fileSets(Objects.lookupClass(Type::typeName));
forAllConstIter(IOobjectList, fileSets, iter)
forAllConstIters(fileSets, iter)
{
if (!memSets.found(iter.key()))
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,15 +56,12 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
);
}
tmp<DimensionedField<Type, volMesh>> tfield
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
new DimensionedField<Type, volMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField
);
tfield.ref().oriented() = procFields[0].oriented();
@ -106,7 +103,6 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
);
}
return reconstructFvVolumeInternalField
(
IOobject
@ -286,16 +282,13 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
// Now construct and write the field
// setting the internalField and patchFields
tmp<GeometricField<Type, fvPatchField, volMesh>> tfield
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
new GeometricField<Type, fvPatchField, volMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
tfield.ref().oriented() = procFields[0].oriented();
@ -531,16 +524,13 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// Now construct and write the field
// setting the internalField and patchFields
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
new GeometricField<Type, fvsPatchField, surfaceMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
tfield.ref().oriented() = procFields[0].oriented();
@ -604,31 +594,30 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
const wordHashSet& selectedFields
)
{
const word& fieldClassName = DimensionedField<Type, volMesh>::typeName;
const word& clsName = DimensionedField<Type, volMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvVolumeInternalField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructFvVolumeInternalField<Type>(*(objects[fieldName]))().write();
++nReconstructed_;
}
if (fieldNames.size()) Info<< endl;
}
@ -639,32 +628,31 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeFields
const wordHashSet& selectedFields
)
{
const word& fieldClassName =
const word& clsName =
GeometricField<Type, fvPatchField, volMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvVolumeField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructFvVolumeField<Type>(*(objects[fieldName]))().write();
++nReconstructed_;
}
if (fieldNames.size()) Info<< endl;
}
@ -675,32 +663,31 @@ void Foam::fvFieldReconstructor::reconstructFvSurfaceFields
const wordHashSet& selectedFields
)
{
const word& fieldClassName =
const word& clsName =
GeometricField<Type, fvsPatchField, surfaceMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvSurfaceField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructFvSurfaceField<Type>(*(objects[fieldName]))().write();
++nReconstructed_;
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -117,23 +117,20 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
// Construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, pointPatchField, pointMesh>>
return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
new GeometricField<Type, pointPatchField, pointMesh>
IOobject
(
IOobject
(
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
}
@ -146,33 +143,29 @@ void Foam::pointFieldReconstructor::reconstructFields
const wordHashSet& selectedFields
)
{
word fieldClassName
const word& clsName =
GeometricField<Type, pointPatchField, pointMesh>::typeName;
const wordList fieldNames =
(
GeometricField<Type, pointPatchField, pointMesh>::typeName
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
IOobjectList fields = objects.lookupClass(fieldClassName);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
!selectedFields.size()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructField<Type>(*fieldIter())().write();
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,8 +27,8 @@ InClass
Description
SourceFiles
reconstructLagrangianPositions.C
reconstructLagrangianFields.C
reconstructLagrangianPositions.C
\*---------------------------------------------------------------------------*/

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,47 +39,44 @@ Foam::tmp<Foam::IOField<Type>> Foam::reconstructLagrangianField
)
{
// Construct empty field on mesh
tmp<IOField<Type>> tfield
auto tfield = tmp<IOField<Type>>::New
(
new IOField<Type>
IOobject
(
IOobject
(
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Type>(0)
)
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Type>(0)
);
Field<Type>& field = tfield.ref();
auto& field = tfield.ref();
forAll(meshes, i)
for (const fvMesh& localMesh : meshes)
{
// Check object on local mesh
IOobject localIOobject
(
fieldName,
meshes[i].time().timeName(),
localMesh.time().timeName(),
cloud::prefix/cloudName,
meshes[i],
localMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (localIOobject.typeHeaderOk<IOField<Type>>(true))
{
IOField<Type> fieldi(localIOobject);
IOField<Type> localField(localIOobject);
label offset = field.size();
field.setSize(offset + fieldi.size());
const label offset = field.size();
field.setSize(offset + localField.size());
forAll(fieldi, j)
forAll(localField, j)
{
field[offset + j] = fieldi[j];
field[offset + j] = localField[j];
}
}
}
@ -99,33 +96,30 @@ Foam::reconstructLagrangianFieldField
)
{
// Construct empty field on mesh
tmp<CompactIOField<Field<Type>, Type >> tfield
auto tfield = tmp<CompactIOField<Field<Type>, Type>>::New
(
new CompactIOField<Field<Type>, Type>
IOobject
(
IOobject
(
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Field<Type>>(0)
)
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Field<Type>>(0)
);
Field<Field<Type>>& field = tfield.ref();
auto& field = tfield.ref();
forAll(meshes, i)
for (const fvMesh& localMesh : meshes)
{
// Check object on local mesh
IOobject localIOobject
(
fieldName,
meshes[i].time().timeName(),
localMesh.time().timeName(),
cloud::prefix/cloudName,
meshes[i],
localMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
@ -139,14 +133,14 @@ Foam::reconstructLagrangianFieldField
|| localIOobject.typeHeaderOk<IOField<Field<Type>>>(false)
)
{
CompactIOField<Field<Type>, Type> fieldi(localIOobject);
CompactIOField<Field<Type>, Type> localField(localIOobject);
label offset = field.size();
field.setSize(offset + fieldi.size());
const label offset = field.size();
field.setSize(offset + localField.size());
forAll(fieldi, j)
forAll(localField, j)
{
field[offset + j] = fieldi[j];
field[offset + j] = localField[j];
}
}
}
@ -155,7 +149,6 @@ Foam::reconstructLagrangianFieldField
}
template<class Type>
void Foam::reconstructLagrangianFields
(
@ -166,36 +159,34 @@ void Foam::reconstructLagrangianFields
const wordHashSet& selectedFields
)
{
const word fieldClassName(IOField<Type>::typeName);
const word& clsName = IOField<Type>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
if (fieldNames.size()) Info<< endl;
}
@ -210,69 +201,65 @@ void Foam::reconstructLagrangianFieldFields
)
{
{
const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName);
const word& clsName = CompactIOField<Field<Type>,Type>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
if (fieldNames.size()) Info<< endl;
}
{
const word fieldClassName(IOField<Field<Type>>::typeName);
const word& clsName = IOField<Field<Type>>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
if (fieldNames.size()) Info<< endl;
}
}

View File

@ -45,12 +45,12 @@ void Foam::reconstructLagrangianPositions
IDLList<passiveParticle>()
);
forAll(meshes, i)
forAll(meshes, meshi)
{
const labelList& cellMap = cellProcAddressing[i];
const labelList& faceMap = faceProcAddressing[i];
const labelList& cellMap = cellProcAddressing[meshi];
const labelList& faceMap = faceProcAddressing[meshi];
Cloud<passiveParticle> lpi(meshes[i], cloudName, false);
Cloud<passiveParticle> lpi(meshes[meshi], cloudName, false);
forAllConstIter(Cloud<passiveParticle>, lpi, iter)
{