mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add sorted() to objectRegistry and IOobjectList
- returns UPtrList view (read-only or read/write) of the objects
- shorter names for IOobject checks: hasHeaderClass(), isHeaderClass()
- remove unused IOobject::isHeaderClassName(const word&) method.
The typed versions are preferable/recommended, but can still check
directly if needed:
(io.headerClassName() == "foo")
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -39,6 +39,38 @@ Description
|
|||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
|
|
||||||
|
void report(const UPtrList<const IOobject>& objects)
|
||||||
|
{
|
||||||
|
Info<< "name/type:" << nl
|
||||||
|
<< objects.size() << nl << '(' << nl;
|
||||||
|
|
||||||
|
for (const IOobject& io : objects)
|
||||||
|
{
|
||||||
|
Info<< " " << io.name() << " : " << io.headerClassName() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< ')' << nl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void report(const UPtrList<const IOobject>& objects)
|
||||||
|
{
|
||||||
|
Info<< "name/type:" << nl
|
||||||
|
<< objects.size() << nl << '(' << nl;
|
||||||
|
|
||||||
|
for (const IOobject& io : objects)
|
||||||
|
{
|
||||||
|
Info<< " " << io.name() << " : " << io.headerClassName()
|
||||||
|
<< (io.isHeaderClass<Type>() ? " is " : " is not ")
|
||||||
|
<< Type::typeName << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< ')' << nl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void report(const IOobjectList& objects)
|
void report(const IOobjectList& objects)
|
||||||
{
|
{
|
||||||
Info<< "Names: " << flatOutput(objects.sortedNames()) << nl
|
Info<< "Names: " << flatOutput(objects.sortedNames()) << nl
|
||||||
@ -199,7 +231,7 @@ void registryTests(const IOobjectList& objs)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
argList::noParallel();
|
// argList::noParallel();
|
||||||
argList::addOption
|
argList::addOption
|
||||||
(
|
(
|
||||||
"filter",
|
"filter",
|
||||||
@ -269,6 +301,15 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "Time: " << runTime.timeName() << nl;
|
Info<< "Time: " << runTime.timeName() << nl;
|
||||||
|
|
||||||
report(objects);
|
report(objects);
|
||||||
|
report(objects.sorted());
|
||||||
|
|
||||||
|
report(objects.sorted<volScalarField>());
|
||||||
|
report(objects.sorted<volVectorField>());
|
||||||
|
|
||||||
|
// Extra checks
|
||||||
|
report<volScalarField>(objects.sorted<volScalarField>());
|
||||||
|
report<volScalarField>(objects.sorted<volVectorField>());
|
||||||
|
|
||||||
|
|
||||||
findObjectTest(objects);
|
findObjectTest(objects);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -37,6 +37,7 @@ Description
|
|||||||
#include "polyMesh.H"
|
#include "polyMesh.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "FlatOutput.H"
|
#include "FlatOutput.H"
|
||||||
|
#include "PtrListOps.H"
|
||||||
#include "objectRegistry.H"
|
#include "objectRegistry.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -47,6 +48,21 @@ using namespace Foam;
|
|||||||
bool recursive = false;
|
bool recursive = false;
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void report(const UPtrList<const Type>& objects)
|
||||||
|
{
|
||||||
|
Info<< Type::typeName << " name/type:" << nl
|
||||||
|
<< objects.size() << nl << '(' << nl;
|
||||||
|
|
||||||
|
for (const Type& obj : objects)
|
||||||
|
{
|
||||||
|
Info<< " " << obj.name() << " : " << obj.type() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< ')' << nl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void printRegistry
|
void printRegistry
|
||||||
(
|
(
|
||||||
Foam::Ostream& os,
|
Foam::Ostream& os,
|
||||||
@ -62,8 +78,8 @@ void printRegistry
|
|||||||
Foam::label indent
|
Foam::label indent
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
wordList names(obr.sortedNames());
|
UPtrList<const regIOobject> objects(obr.sorted());
|
||||||
wordList regs(obr.sortedNames<objectRegistry>());
|
wordList regNames(obr.sortedNames<objectRegistry>());
|
||||||
|
|
||||||
std::string prefix;
|
std::string prefix;
|
||||||
for (label i=indent; i; --i)
|
for (label i=indent; i; --i)
|
||||||
@ -74,15 +90,17 @@ void printRegistry
|
|||||||
os << '#' << prefix.c_str() << obr.name()
|
os << '#' << prefix.c_str() << obr.name()
|
||||||
<< " parent:" << obr.parent().name() << nl;
|
<< " parent:" << obr.parent().name() << nl;
|
||||||
|
|
||||||
os << ' ' << prefix.c_str() << "objects: " << flatOutput(names) << nl;
|
os << ' ' << prefix.c_str() << "objects: "
|
||||||
os << ' ' << prefix.c_str() << "registries: " << flatOutput(regs) << nl;
|
<< flatOutput(PtrListOps::names(objects)) << nl;
|
||||||
|
os << ' ' << prefix.c_str() << "registries: "
|
||||||
|
<< flatOutput(regNames) << nl;
|
||||||
|
|
||||||
|
|
||||||
// Print, but skip expansion of sub-registries for now
|
// Print without expanding sub-registries
|
||||||
for (const word& name : names)
|
for (const regIOobject& obj : objects)
|
||||||
{
|
{
|
||||||
os << (regs.found(name) ? '-' : ' ')
|
os << (isA<objectRegistry>(obj) ? '-' : ' ')
|
||||||
<< prefix.c_str() << name << " => " << obr[name]->type() << nl;
|
<< prefix.c_str() << obj.name() << " => " << obj.type() << nl;
|
||||||
}
|
}
|
||||||
for (label i=indent; i; --i)
|
for (label i=indent; i; --i)
|
||||||
{
|
{
|
||||||
@ -91,7 +109,7 @@ void printRegistry
|
|||||||
os << '\n';
|
os << '\n';
|
||||||
|
|
||||||
// Now descend into the sub-registries
|
// Now descend into the sub-registries
|
||||||
for (const word& name : regs)
|
for (const word& name : regNames)
|
||||||
{
|
{
|
||||||
const objectRegistry& next = obr.lookupObject<objectRegistry>
|
const objectRegistry& next = obr.lookupObject<objectRegistry>
|
||||||
(
|
(
|
||||||
@ -117,12 +135,15 @@ void printRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main program:
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
argList::noBanner();
|
argList::noBanner();
|
||||||
argList::noParallel();
|
// argList::noParallel();
|
||||||
argList::addBoolOption
|
argList::addBoolOption
|
||||||
(
|
(
|
||||||
"mesh",
|
"mesh",
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018 OpenCFD Ltd.
|
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -36,10 +36,12 @@ Description
|
|||||||
#include "fvCFD.H"
|
#include "fvCFD.H"
|
||||||
#include "fvMesh.H"
|
#include "fvMesh.H"
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "IOobjectList.H"
|
|
||||||
#include "timeSelector.H"
|
#include "timeSelector.H"
|
||||||
#include "ReadFields.H"
|
#include "ReadFields.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include "PtrListOps.H"
|
||||||
|
#include "IOobjectList.H"
|
||||||
|
#include "objectRegistry.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -113,6 +115,21 @@ void loadFields(fvMesh& mesh, const IOobjectList& objects)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void report(const UPtrList<const Type>& objects)
|
||||||
|
{
|
||||||
|
Info<< Type::typeName << " name/type:" << nl
|
||||||
|
<< objects.size() << nl << '(' << nl;
|
||||||
|
|
||||||
|
for (const Type& obj : objects)
|
||||||
|
{
|
||||||
|
Info<< " " << obj.name() << " : " << obj.type() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< ')' << nl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void printRegistry
|
void printRegistry
|
||||||
(
|
(
|
||||||
Foam::Ostream& os,
|
Foam::Ostream& os,
|
||||||
@ -128,8 +145,8 @@ void printRegistry
|
|||||||
Foam::label indent
|
Foam::label indent
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
wordList names(obr.sortedNames());
|
UPtrList<const regIOobject> objects(obr.sorted());
|
||||||
wordList regs(obr.sortedNames<objectRegistry>());
|
wordList regNames(obr.sortedNames<objectRegistry>());
|
||||||
|
|
||||||
std::string prefix;
|
std::string prefix;
|
||||||
for (label i=indent; i; --i)
|
for (label i=indent; i; --i)
|
||||||
@ -140,15 +157,17 @@ void printRegistry
|
|||||||
os << '#' << prefix.c_str() << obr.name()
|
os << '#' << prefix.c_str() << obr.name()
|
||||||
<< " parent:" << obr.parent().name() << nl;
|
<< " parent:" << obr.parent().name() << nl;
|
||||||
|
|
||||||
os << ' ' << prefix.c_str() << "objects: " << flatOutput(names) << nl;
|
os << ' ' << prefix.c_str() << "objects: "
|
||||||
os << ' ' << prefix.c_str() << "registries: " << flatOutput(regs) << nl;
|
<< flatOutput(PtrListOps::names(objects)) << nl;
|
||||||
|
os << ' ' << prefix.c_str() << "registries: "
|
||||||
|
<< flatOutput(regNames) << nl;
|
||||||
|
|
||||||
|
|
||||||
// Print, but skip expansion of sub-registries for now
|
// Print without expanding sub-registries
|
||||||
for (const word& name : names)
|
for (const regIOobject& obj : objects)
|
||||||
{
|
{
|
||||||
os << (regs.found(name) ? '-' : ' ')
|
os << (isA<objectRegistry>(obj) ? '-' : ' ')
|
||||||
<< prefix.c_str() << name << " => " << obr[name]->type() << nl;
|
<< prefix.c_str() << obj.name() << " => " << obj.type() << nl;
|
||||||
}
|
}
|
||||||
for (label i=indent; i; --i)
|
for (label i=indent; i; --i)
|
||||||
{
|
{
|
||||||
@ -157,7 +176,7 @@ void printRegistry
|
|||||||
os << '\n';
|
os << '\n';
|
||||||
|
|
||||||
// Now descend into the sub-registries
|
// Now descend into the sub-registries
|
||||||
for (const word& name : regs)
|
for (const word& name : regNames)
|
||||||
{
|
{
|
||||||
const objectRegistry& next = obr.lookupObject<objectRegistry>
|
const objectRegistry& next = obr.lookupObject<objectRegistry>
|
||||||
(
|
(
|
||||||
@ -251,12 +270,12 @@ void registryTests(const objectRegistry& obr)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Main program:
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
argList::noBanner();
|
argList::noBanner();
|
||||||
argList::noParallel();
|
//argList::noParallel();
|
||||||
// argList::addOption
|
// argList::addOption
|
||||||
// (
|
// (
|
||||||
// "filter",
|
// "filter",
|
||||||
@ -296,6 +315,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
registryTests(mesh);
|
registryTests(mesh);
|
||||||
|
|
||||||
|
report(mesh.sorted<const volScalarField>());
|
||||||
|
report(mesh.csorted<volVectorField>());
|
||||||
|
|
||||||
Info<< nl;
|
Info<< nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -129,7 +129,7 @@ class readFieldsHandler
|
|||||||
const bool ok =
|
const bool ok =
|
||||||
(
|
(
|
||||||
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
||||||
&& io.hasHeaderClassName() // Extra safety
|
&& io.hasHeaderClass() // Extra safety
|
||||||
&&
|
&&
|
||||||
(
|
(
|
||||||
loadField<scalar>(io)
|
loadField<scalar>(io)
|
||||||
|
|||||||
@ -129,7 +129,7 @@ class readFieldsHandler
|
|||||||
const bool ok =
|
const bool ok =
|
||||||
(
|
(
|
||||||
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
||||||
&& io.hasHeaderClassName() // Extra safety
|
&& io.hasHeaderClass() // Extra safety
|
||||||
&&
|
&&
|
||||||
(
|
(
|
||||||
loadField<scalar>(io)
|
loadField<scalar>(io)
|
||||||
|
|||||||
@ -159,20 +159,28 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc
|
|||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Foam::UPtrList<const typename Foam::HashTable<T, Key, Hash>::node_type>
|
Foam::UPtrList<const typename Foam::HashTable<T, Key, Hash>::node_type>
|
||||||
Foam::HashTable<T, Key, Hash>::sorted() const
|
Foam::HashTable<T, Key, Hash>::csorted() const
|
||||||
{
|
{
|
||||||
UPtrList<const node_type> list(size_);
|
UPtrList<const node_type> result(size_);
|
||||||
|
|
||||||
label count = 0;
|
label count = 0;
|
||||||
|
|
||||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||||
{
|
{
|
||||||
list.set(count++, iter.node());
|
result.set(count++, iter.node());
|
||||||
}
|
}
|
||||||
|
|
||||||
Foam::sort(list);
|
Foam::sort(result);
|
||||||
|
|
||||||
return list;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
Foam::UPtrList<const typename Foam::HashTable<T, Key, Hash>::node_type>
|
||||||
|
Foam::HashTable<T, Key, Hash>::sorted() const
|
||||||
|
{
|
||||||
|
return csorted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,18 +188,18 @@ template<class T, class Key, class Hash>
|
|||||||
Foam::UPtrList<typename Foam::HashTable<T, Key, Hash>::node_type>
|
Foam::UPtrList<typename Foam::HashTable<T, Key, Hash>::node_type>
|
||||||
Foam::HashTable<T, Key, Hash>::sorted()
|
Foam::HashTable<T, Key, Hash>::sorted()
|
||||||
{
|
{
|
||||||
UPtrList<node_type> list(size_);
|
UPtrList<node_type> result(size_);
|
||||||
|
|
||||||
label count = 0;
|
label count = 0;
|
||||||
|
|
||||||
for (iterator iter = begin(); iter != end(); ++iter)
|
for (iterator iter = begin(); iter != end(); ++iter)
|
||||||
{
|
{
|
||||||
list.set(count++, iter.node());
|
result.set(count++, iter.node());
|
||||||
}
|
}
|
||||||
|
|
||||||
Foam::sort(list);
|
Foam::sort(result);
|
||||||
|
|
||||||
return list;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -346,10 +346,17 @@ public:
|
|||||||
|
|
||||||
//- Const access to the hash-table contents in sorted order
|
//- Const access to the hash-table contents in sorted order
|
||||||
//- (sorted by keys).
|
//- (sorted by keys).
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<const node_type> csorted() const;
|
||||||
|
|
||||||
|
//- Const access to the hash-table contents in sorted order
|
||||||
|
//- (sorted by keys).
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
UPtrList<const node_type> sorted() const;
|
UPtrList<const node_type> sorted() const;
|
||||||
|
|
||||||
//- Non-const access to the hash-table contents in sorted order
|
//- Non-const access to the hash-table contents in sorted order
|
||||||
//- (sorted by keys).
|
//- (sorted by keys).
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
UPtrList<node_type> sorted();
|
UPtrList<node_type> sorted();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -125,13 +125,6 @@ public:
|
|||||||
|
|
||||||
// Public Data Types
|
// Public Data Types
|
||||||
|
|
||||||
//- Enumeration defining the valid states of an IOobject
|
|
||||||
enum objectState : char
|
|
||||||
{
|
|
||||||
GOOD,
|
|
||||||
BAD
|
|
||||||
};
|
|
||||||
|
|
||||||
//- Enumeration defining the read options
|
//- Enumeration defining the read options
|
||||||
enum readOption : char
|
enum readOption : char
|
||||||
{
|
{
|
||||||
@ -148,6 +141,13 @@ public:
|
|||||||
AUTO_WRITE = 0x10
|
AUTO_WRITE = 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//- Enumeration defining the valid states of an IOobject
|
||||||
|
enum objectState : char
|
||||||
|
{
|
||||||
|
GOOD,
|
||||||
|
BAD
|
||||||
|
};
|
||||||
|
|
||||||
//- Enumeration defining the file checking options
|
//- Enumeration defining the file checking options
|
||||||
enum fileCheckTypes : char
|
enum fileCheckTypes : char
|
||||||
{
|
{
|
||||||
@ -474,14 +474,15 @@ public:
|
|||||||
// Checks
|
// Checks
|
||||||
|
|
||||||
//- True if headerClassName() is non-empty (after reading)
|
//- True if headerClassName() is non-empty (after reading)
|
||||||
inline bool hasHeaderClassName() const noexcept;
|
inline bool hasHeaderClass() const noexcept;
|
||||||
|
|
||||||
//- Test if headerClassName() equals the given class name
|
//- Check if headerClassName() equals Type::typeName
|
||||||
inline bool isHeaderClassName(const word& clsName) const;
|
|
||||||
|
|
||||||
//- Test if headerClassName() equals Type::typeName
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
inline bool isHeaderClassName() const;
|
inline bool isHeaderClass() const;
|
||||||
|
|
||||||
|
//- Same as isHeaderClass()
|
||||||
|
template<class Type>
|
||||||
|
bool isHeaderClassName() const { return isHeaderClass<Type>(); }
|
||||||
|
|
||||||
|
|
||||||
// Meta-data
|
// Meta-data
|
||||||
@ -638,8 +639,7 @@ public:
|
|||||||
|
|
||||||
// Info
|
// Info
|
||||||
|
|
||||||
//- Return info proxy.
|
//- Return info proxy, for printing information to a stream
|
||||||
// Used to print token information to a stream
|
|
||||||
InfoProxy<IOobject> info() const
|
InfoProxy<IOobject> info() const
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
@ -674,7 +674,7 @@ public:
|
|||||||
|
|
||||||
//- Specialization for \c void always returns true (no headerClassName check).
|
//- Specialization for \c void always returns true (no headerClassName check).
|
||||||
template<>
|
template<>
|
||||||
inline bool IOobject::isHeaderClassName<void>() const
|
inline bool IOobject::isHeaderClass<void>() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,20 +146,14 @@ inline unsigned Foam::IOobject::scalarByteSize() const noexcept
|
|||||||
|
|
||||||
// Checks
|
// Checks
|
||||||
|
|
||||||
inline bool Foam::IOobject::hasHeaderClassName() const noexcept
|
inline bool Foam::IOobject::hasHeaderClass() const noexcept
|
||||||
{
|
{
|
||||||
return !headerClassName_.empty();
|
return !headerClassName_.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const
|
|
||||||
{
|
|
||||||
return (clsName == headerClassName_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
inline bool Foam::IOobject::isHeaderClassName() const
|
inline bool Foam::IOobject::isHeaderClass() const
|
||||||
{
|
{
|
||||||
return (Type::typeName == headerClassName_);
|
return (Type::typeName == headerClassName_);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "IOobject.H"
|
#include "IOobject.H"
|
||||||
#include "token.H"
|
#include "Ostream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -36,14 +36,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<IOobject>& ip)
|
|||||||
const IOobject& io = ip.t_;
|
const IOobject& io = ip.t_;
|
||||||
|
|
||||||
os << "IOobject: "
|
os << "IOobject: "
|
||||||
<< io.type() << token::SPACE
|
<< io.type() << ' ' << io.name()
|
||||||
<< io.name()
|
|
||||||
<< " local: " << io.local()
|
<< " local: " << io.local()
|
||||||
<< " readOpt: " << static_cast<int>(io.readOpt())
|
<< " readOpt: " << static_cast<int>(io.readOpt())
|
||||||
<< " writeOpt: " << static_cast<int>(io.writeOpt())
|
<< " writeOpt: " << static_cast<int>(io.writeOpt())
|
||||||
<< " registerObject: " << io.registerObject()
|
<< " registerObject: " << io.registerObject()
|
||||||
<< " globalObject: " << io.globalObject()
|
<< " globalObject: " << io.globalObject()
|
||||||
<< token::SPACE << io.path() << endl;
|
<< ' ' << io.path() << endl;
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -34,31 +34,54 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::IOobjectList::checkNames(wordList& masterNames, const bool syncPar)
|
void Foam::IOobjectList::checkObjectOrder
|
||||||
|
(
|
||||||
|
const UPtrList<const IOobject>& objs,
|
||||||
|
bool syncPar
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Sort for consistent order on all processors.
|
|
||||||
// Even do this for serial runs, for consistent behaviour
|
|
||||||
Foam::sort(masterNames);
|
|
||||||
|
|
||||||
if (syncPar && Pstream::parRun())
|
if (syncPar && Pstream::parRun())
|
||||||
{
|
{
|
||||||
const wordList localNames(masterNames);
|
wordList objectNames(objs.size());
|
||||||
|
|
||||||
|
auto iter = objectNames.begin();
|
||||||
|
|
||||||
|
for (const IOobject& io : objs)
|
||||||
|
{
|
||||||
|
*iter = io.name(); // nameOp<IOobject>()
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNameOrder(objectNames, syncPar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::IOobjectList::checkNameOrder
|
||||||
|
(
|
||||||
|
const wordList& objectNames,
|
||||||
|
bool syncPar
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (syncPar && Pstream::parRun())
|
||||||
|
{
|
||||||
|
wordList masterNames;
|
||||||
|
if (Pstream::master())
|
||||||
|
{
|
||||||
|
masterNames = objectNames;
|
||||||
|
}
|
||||||
Pstream::broadcast(masterNames);
|
Pstream::broadcast(masterNames);
|
||||||
|
|
||||||
if (localNames != masterNames)
|
if (objectNames != masterNames)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Objects not synchronised across processors." << nl
|
<< "Objects not synchronised across processors." << nl
|
||||||
<< "Master has " << flatOutput(masterNames) << nl
|
<< "Master has " << flatOutput(masterNames) << nl
|
||||||
<< "Processor " << Pstream::myProcNo()
|
<< "Processor " << Pstream::myProcNo()
|
||||||
<< " has " << flatOutput(localNames)
|
<< " has " << flatOutput(objectNames) << endl
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +94,7 @@ void Foam::IOobjectList::syncNames(wordList& objNames)
|
|||||||
Pstream::broadcast(objNames);
|
Pstream::broadcast(objNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort for consistent order on all processors
|
// Consistent order on all processors
|
||||||
Foam::sort(objNames);
|
Foam::sort(objNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +219,7 @@ Foam::label Foam::IOobjectList::append(const IOobjectList& other)
|
|||||||
InfoInFunction << "Copy append " << iter.key() << nl;
|
InfoInFunction << "Copy append " << iter.key() << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(iter.key(), new IOobject(*(iter.val())));
|
set(iter.key(), new IOobject(*iter.val()));
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,6 +330,24 @@ Foam::label Foam::IOobjectList::count(const char* clsName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted() const
|
||||||
|
{
|
||||||
|
return sorted<void>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted(const bool syncPar) const
|
||||||
|
{
|
||||||
|
return sorted<void>(syncPar);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::wordList Foam::IOobjectList::names() const
|
Foam::wordList Foam::IOobjectList::names() const
|
||||||
{
|
{
|
||||||
return HashPtrTable<IOobject>::toc();
|
return HashPtrTable<IOobject>::toc();
|
||||||
@ -315,10 +356,7 @@ Foam::wordList Foam::IOobjectList::names() const
|
|||||||
|
|
||||||
Foam::wordList Foam::IOobjectList::names(const bool syncPar) const
|
Foam::wordList Foam::IOobjectList::names(const bool syncPar) const
|
||||||
{
|
{
|
||||||
wordList objNames(HashPtrTable<IOobject>::toc());
|
return sortedNames(syncPar);
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
|
||||||
return objNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -336,7 +374,7 @@ Foam::wordList Foam::IOobjectList::names
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// No nullptr check - only called with string literals
|
// No nullptr check - only called with string literals
|
||||||
return names(static_cast<word>(clsName), syncPar);
|
return sortedNames(static_cast<word>(clsName), syncPar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -352,7 +390,7 @@ Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const
|
|||||||
{
|
{
|
||||||
wordList objNames(HashPtrTable<IOobject>::sortedToc());
|
wordList objNames(HashPtrTable<IOobject>::sortedToc());
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
checkNameOrder(objNames, syncPar);
|
||||||
return objNames;
|
return objNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +409,7 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// No nullptr check - only called with string literals
|
// No nullptr check - only called with string literals
|
||||||
return names(static_cast<word>(clsName), syncPar);
|
return sortedNames(static_cast<word>(clsName), syncPar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -397,16 +435,14 @@ Foam::wordList Foam::IOobjectList::allNames() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::IOobjectList::checkNames(const bool syncPar) const
|
void Foam::IOobjectList::checkNames(const bool syncPar) const
|
||||||
{
|
{
|
||||||
if (syncPar && Pstream::parRun())
|
if (syncPar && Pstream::parRun())
|
||||||
{
|
{
|
||||||
wordList objNames(HashPtrTable<IOobject>::toc());
|
wordList objNames(HashPtrTable<IOobject>::sortedToc());
|
||||||
|
|
||||||
return checkNames(objNames, syncPar);
|
checkNameOrder(objNames, syncPar);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -36,11 +36,12 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef IOobjectList_H
|
#ifndef Foam_IOobjectList_H
|
||||||
#define IOobjectList_H
|
#define Foam_IOobjectList_H
|
||||||
|
|
||||||
#include "HashPtrTable.H"
|
#include "HashPtrTable.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
|
#include "UPtrList.H"
|
||||||
#include "IOobject.H"
|
#include "IOobject.H"
|
||||||
#include "wordRes.H"
|
#include "wordRes.H"
|
||||||
|
|
||||||
@ -59,14 +60,23 @@ class IOobjectList
|
|||||||
{
|
{
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Check name consistency on all processors
|
//- Check consistency of names and their order on all processors
|
||||||
|
//- (the input list is assumed to be pre-sorted).
|
||||||
//
|
//
|
||||||
// With syncPar = true, check that object names are the same on
|
// With syncPar = true, check that object names are identical
|
||||||
// all processors. Trigger FatalError if not.
|
// (content and order) on all processors. FatalError if not.
|
||||||
|
static void checkNameOrder(const wordList& objectNames, bool syncPar);
|
||||||
|
|
||||||
|
//- Check consistency of object names/order on all processors
|
||||||
|
//- (the input list is assumed to be pre-sorted).
|
||||||
//
|
//
|
||||||
// When syncPar is used, the object names are sorted as a side-effect,
|
// With syncPar = true, check that object names are identical
|
||||||
// since this is required for consistent ordering across processors.
|
// (content and order) on all processors. FatalError if not.
|
||||||
static bool checkNames(wordList& masterNames, const bool syncPar);
|
static void checkObjectOrder
|
||||||
|
(
|
||||||
|
const UPtrList<const IOobject>& objs,
|
||||||
|
bool syncPar
|
||||||
|
);
|
||||||
|
|
||||||
//- Combine names from all processors and sort
|
//- Combine names from all processors and sort
|
||||||
static void syncNames(wordList& objNames);
|
static void syncNames(wordList& objNames);
|
||||||
@ -116,6 +126,14 @@ class IOobjectList
|
|||||||
const bool doSort
|
const bool doSort
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Templated implementation for sorted()
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
static UPtrList<const IOobject> objectsTypeImpl
|
||||||
|
(
|
||||||
|
const IOobjectList& list,
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
);
|
||||||
|
|
||||||
//- Templated implementation for lookup()
|
//- Templated implementation for lookup()
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
static IOobjectList lookupImpl
|
static IOobjectList lookupImpl
|
||||||
@ -383,6 +401,54 @@ public:
|
|||||||
HashTable<wordHashSet> classes(const MatchPredicate& matchName) const;
|
HashTable<wordHashSet> classes(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Sorted access
|
||||||
|
|
||||||
|
//- The sorted list of IOobjects
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<const IOobject> sorted() const;
|
||||||
|
|
||||||
|
//- The sorted list of IOobjects with optional check for
|
||||||
|
//- parallel consistency.
|
||||||
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<const IOobject> sorted(const bool syncPar) const;
|
||||||
|
|
||||||
|
//- The sorted list of IOobjects with headerClassName == Type::typeName
|
||||||
|
//
|
||||||
|
// \note If \a Type is \c void, no headerClassName check is used
|
||||||
|
// (always true).
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type>
|
||||||
|
UPtrList<const IOobject> sorted() const;
|
||||||
|
|
||||||
|
//- The sorted names of the IOobjects with optional check for
|
||||||
|
//- parallel consistency.
|
||||||
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type>
|
||||||
|
UPtrList<const IOobject> sorted(const bool syncPar) const;
|
||||||
|
|
||||||
|
//- The sorted list of IOobjects with headerClassName == Type::typeName
|
||||||
|
//- that also have a matching object name.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
UPtrList<const IOobject> sorted(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
|
//- The sorted list of IOobjects with headerClassName == Type::typeName
|
||||||
|
//- that also have a matching object name.
|
||||||
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
UPtrList<const IOobject> sorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName,
|
||||||
|
const bool syncPar
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
// Number of items
|
// Number of items
|
||||||
|
|
||||||
//- The number of objects of the given headerClassName
|
//- The number of objects of the given headerClassName
|
||||||
@ -420,29 +486,36 @@ public:
|
|||||||
|
|
||||||
// Summary of names
|
// Summary of names
|
||||||
|
|
||||||
//- The names of the IOobjects
|
//- The unsorted names of the IOobjects
|
||||||
wordList names() const;
|
wordList names() const;
|
||||||
|
|
||||||
//- The names of the IOobjects.
|
//- The sorted names of the IOobjects with optional check for
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
//- parallel consistency.
|
||||||
// if the names are not consistent on all processors.
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
wordList names(const bool syncPar) const;
|
wordList names(const bool syncPar) const;
|
||||||
|
|
||||||
//- The names of IOobjects with the given headerClassName
|
//- The unsorted names of IOobjects with the given headerClassName
|
||||||
wordList names(const char* clsName) const;
|
wordList names(const char* clsName) const;
|
||||||
|
|
||||||
//- The names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
wordList names(const char* clsName, const bool syncPar) const;
|
wordList names(const char* clsName, const bool syncPar) const;
|
||||||
|
|
||||||
//- The names of IOobjects with the given headerClassName
|
//- The unsorted names of IOobjects with the given headerClassName
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
wordList names(const MatchPredicate& matchClass) const;
|
wordList names(const MatchPredicate& matchClass) const;
|
||||||
|
|
||||||
//- The names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
wordList names
|
wordList names
|
||||||
(
|
(
|
||||||
@ -450,7 +523,7 @@ public:
|
|||||||
const bool syncPar
|
const bool syncPar
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- The names of IOobjects with the given headerClassName
|
//- The unsorted names of IOobjects with the given headerClassName
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
template<class MatchPredicate1, class MatchPredicate2>
|
template<class MatchPredicate1, class MatchPredicate2>
|
||||||
wordList names
|
wordList names
|
||||||
@ -459,10 +532,12 @@ public:
|
|||||||
const MatchPredicate2& matchName
|
const MatchPredicate2& matchName
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- The names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
template<class MatchPredicate1, class MatchPredicate2>
|
template<class MatchPredicate1, class MatchPredicate2>
|
||||||
wordList names
|
wordList names
|
||||||
(
|
(
|
||||||
@ -472,27 +547,31 @@ public:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
//- The names of objects with headerClassName == Type::typeName
|
//- The unsorted names of objects with
|
||||||
|
//- headerClassName == Type::typeName
|
||||||
template<class Type>
|
template<class Type>
|
||||||
wordList names() const;
|
wordList names() const;
|
||||||
|
|
||||||
//- The names of objects with headerClassName == Type::typeName
|
//- The sorted names of objects with
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
//- headerClassName == Type::typeName.
|
||||||
// if the names are not consistent on all processors.
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
template<class Type>
|
template<class Type>
|
||||||
wordList names(bool syncPar) const;
|
wordList names(bool syncPar) const;
|
||||||
|
|
||||||
//- The names of objects with headerClassName == Type::typeName
|
//- The unsorted names of objects with
|
||||||
//- that also have a matching object name.
|
//- headerClassName == Type::typeName and a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
|
||||||
// if the names are not consistent on all processors.
|
|
||||||
template<class Type, class MatchPredicate>
|
template<class Type, class MatchPredicate>
|
||||||
wordList names(const MatchPredicate& matchName) const;
|
wordList names(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
//- The names of objects with headerClassName == Type::typeName
|
//- The sorted names of objects with
|
||||||
//- that also have a matching object name.
|
//- headerClassName == Type::typeName and a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
|
// \note Output is always sorted - for consistent serial/parallel
|
||||||
|
// behaviour.
|
||||||
template<class Type, class MatchPredicate>
|
template<class Type, class MatchPredicate>
|
||||||
wordList names
|
wordList names
|
||||||
(
|
(
|
||||||
@ -506,17 +585,18 @@ public:
|
|||||||
//- The sorted names of the IOobjects
|
//- The sorted names of the IOobjects
|
||||||
wordList sortedNames() const;
|
wordList sortedNames() const;
|
||||||
|
|
||||||
//- The sorted names of the IOobjects.
|
//- The sorted names of the IOobjects with optional check for
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
//- parallel consistency.
|
||||||
// if the names are not consistent on all processors.
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
|
// processors.
|
||||||
wordList sortedNames(const bool syncPar) const;
|
wordList sortedNames(const bool syncPar) const;
|
||||||
|
|
||||||
//- The sorted names of IOobjects with the given headerClassName
|
//- The sorted names of IOobjects with the given headerClassName
|
||||||
wordList sortedNames(const char* clsName) const;
|
wordList sortedNames(const char* clsName) const;
|
||||||
|
|
||||||
//- The sorted names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
wordList sortedNames(const char* clsName, const bool syncPar) const;
|
wordList sortedNames(const char* clsName, const bool syncPar) const;
|
||||||
|
|
||||||
//- The sorted names of IOobjects with the given headerClassName
|
//- The sorted names of IOobjects with the given headerClassName
|
||||||
@ -524,8 +604,8 @@ public:
|
|||||||
wordList sortedNames(const MatchPredicate& matchClass) const;
|
wordList sortedNames(const MatchPredicate& matchClass) const;
|
||||||
|
|
||||||
//- The sorted names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
wordList sortedNames
|
wordList sortedNames
|
||||||
(
|
(
|
||||||
@ -544,8 +624,8 @@ public:
|
|||||||
|
|
||||||
//- The sorted names of the IOobjects with the given headerClassName
|
//- The sorted names of the IOobjects with the given headerClassName
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
template<class MatchPredicate1, class MatchPredicate2>
|
template<class MatchPredicate1, class MatchPredicate2>
|
||||||
wordList sortedNames
|
wordList sortedNames
|
||||||
(
|
(
|
||||||
@ -560,22 +640,20 @@ public:
|
|||||||
wordList sortedNames() const;
|
wordList sortedNames() const;
|
||||||
|
|
||||||
//- The sorted names of objects with headerClassName == Type::typeName
|
//- The sorted names of objects with headerClassName == Type::typeName
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
template<class Type>
|
template<class Type>
|
||||||
wordList sortedNames(bool syncPar) const;
|
wordList sortedNames(bool syncPar) const;
|
||||||
|
|
||||||
//- The sorted names of objects with headerClassName == Type::typeName
|
//- The sorted names of objects with headerClassName == Type::typeName
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
|
||||||
// if the names are not consistent on all processors.
|
|
||||||
template<class Type, class MatchPredicate>
|
template<class Type, class MatchPredicate>
|
||||||
wordList sortedNames(const MatchPredicate& matchName) const;
|
wordList sortedNames(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
//- The sorted names of objects with headerClassName == Type::typeName
|
//- The sorted names of objects with headerClassName == Type::typeName
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
// With syncPar = true, sorts the names and triggers FatalError
|
// FatalError if syncPar = true and names are not consistent on all
|
||||||
// if the names are not consistent on all processors.
|
// processors.
|
||||||
template<class Type, class MatchPredicate>
|
template<class Type, class MatchPredicate>
|
||||||
wordList sortedNames
|
wordList sortedNames
|
||||||
(
|
(
|
||||||
@ -620,9 +698,8 @@ public:
|
|||||||
wordList allNames() const;
|
wordList allNames() const;
|
||||||
|
|
||||||
//- Verify that object names are synchronised across processors
|
//- Verify that object names are synchronised across processors
|
||||||
// Triggers FatalError if the names are not consistent on all
|
// FatalError if the names are not consistent on all processors.
|
||||||
// processors.
|
void checkNames(const bool syncPar = true) const;
|
||||||
bool checkNames(const bool syncPar = true) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -96,7 +96,7 @@ Foam::label Foam::IOobjectList::countTypeImpl
|
|||||||
{
|
{
|
||||||
const IOobject* io = iter.val();
|
const IOobject* io = iter.val();
|
||||||
|
|
||||||
if (io->isHeaderClassName<Type>() && matchName(io->name()))
|
if (io->isHeaderClass<Type>() && matchName(io->name()))
|
||||||
{
|
{
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl
|
|||||||
const word& key = iter.key();
|
const word& key = iter.key();
|
||||||
const IOobject* io = iter.val();
|
const IOobject* io = iter.val();
|
||||||
|
|
||||||
if (io->isHeaderClassName<Type>() && matchName(key))
|
if (io->isHeaderClass<Type>() && matchName(key))
|
||||||
{
|
{
|
||||||
objNames[count] = key;
|
objNames[count] = key;
|
||||||
++count;
|
++count;
|
||||||
@ -177,6 +177,38 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Templated implementation for sorted()
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::objectsTypeImpl
|
||||||
|
(
|
||||||
|
const IOobjectList& list,
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UPtrList<const IOobject> result(list.size());
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
forAllConstIters(list, iter)
|
||||||
|
{
|
||||||
|
const word& key = iter.key();
|
||||||
|
const IOobject* io = iter.val();
|
||||||
|
|
||||||
|
if (io->isHeaderClass<Type>() && matchName(key))
|
||||||
|
{
|
||||||
|
result.set(count, io);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.resize(count);
|
||||||
|
|
||||||
|
Foam::sort(result, nameOp<IOobject>()); // Sort by object name()
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Templated implementation for lookup()
|
// Templated implementation for lookup()
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
Foam::IOobjectList Foam::IOobjectList::lookupImpl
|
Foam::IOobjectList Foam::IOobjectList::lookupImpl
|
||||||
@ -253,7 +285,7 @@ Foam::IOobjectList Foam::IOobjectList::lookupClassTypeImpl
|
|||||||
const word& key = iter.key();
|
const word& key = iter.key();
|
||||||
const IOobject* io = iter.val();
|
const IOobject* io = iter.val();
|
||||||
|
|
||||||
if (io->isHeaderClassName<Type>() && matchName(key))
|
if (io->isHeaderClass<Type>() && matchName(key))
|
||||||
{
|
{
|
||||||
if (IOobject::debug)
|
if (IOobject::debug)
|
||||||
{
|
{
|
||||||
@ -282,7 +314,7 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject
|
|||||||
{
|
{
|
||||||
const IOobject* io = iter.val();
|
const IOobject* io = iter.val();
|
||||||
|
|
||||||
if (io->isHeaderClassName<Type>())
|
if (io->isHeaderClass<Type>())
|
||||||
{
|
{
|
||||||
if (IOobject::debug)
|
if (IOobject::debug)
|
||||||
{
|
{
|
||||||
@ -427,6 +459,62 @@ Foam::label Foam::IOobjectList::count
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted() const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<Type>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted(const bool syncPar) const
|
||||||
|
{
|
||||||
|
UPtrList<const IOobject> list
|
||||||
|
(
|
||||||
|
objectsTypeImpl<Type>(*this, predicates::always())
|
||||||
|
);
|
||||||
|
|
||||||
|
checkObjectOrder(list, syncPar);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<Type>(*this, matchName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<const Foam::IOobject>
|
||||||
|
Foam::IOobjectList::sorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName,
|
||||||
|
const bool syncPar
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
UPtrList<const IOobject> list
|
||||||
|
(
|
||||||
|
objectsTypeImpl<Type>(*this, matchName)
|
||||||
|
);
|
||||||
|
|
||||||
|
checkObjectOrder(list, syncPar);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
@ -446,13 +534,7 @@ Foam::wordList Foam::IOobjectList::names
|
|||||||
const bool syncPar
|
const bool syncPar
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
wordList objNames
|
return sortedNames(matchClass, syncPar);
|
||||||
(
|
|
||||||
namesImpl(*this, matchClass, predicates::always(), false)
|
|
||||||
);
|
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
|
||||||
return objNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -475,10 +557,7 @@ Foam::wordList Foam::IOobjectList::names
|
|||||||
const bool syncPar
|
const bool syncPar
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
wordList objNames(namesImpl(*this, matchClass, matchName, false));
|
return sortedNames(matchClass, matchName, syncPar);
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
|
||||||
return objNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -492,10 +571,7 @@ Foam::wordList Foam::IOobjectList::names() const
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::wordList Foam::IOobjectList::names(const bool syncPar) const
|
Foam::wordList Foam::IOobjectList::names(const bool syncPar) const
|
||||||
{
|
{
|
||||||
wordList objNames(namesTypeImpl<Type>(*this, predicates::always(), false));
|
return sortedNames<Type>(syncPar);
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
|
||||||
return objNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -516,10 +592,7 @@ Foam::wordList Foam::IOobjectList::names
|
|||||||
const bool syncPar
|
const bool syncPar
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
wordList objNames(namesTypeImpl<Type>(*this, matchName, false));
|
return sortedNames<Type>(matchName, syncPar);
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
|
||||||
return objNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -547,7 +620,7 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
|||||||
namesImpl(*this, matchClass, predicates::always(), true)
|
namesImpl(*this, matchClass, predicates::always(), true)
|
||||||
);
|
);
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
checkNameOrder(objNames, syncPar);
|
||||||
return objNames;
|
return objNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,6 +635,7 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
|||||||
return namesImpl(*this, matchClass, matchName, true);
|
return namesImpl(*this, matchClass, matchName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class MatchPredicate1, class MatchPredicate2>
|
template<class MatchPredicate1, class MatchPredicate2>
|
||||||
Foam::wordList Foam::IOobjectList::sortedNames
|
Foam::wordList Foam::IOobjectList::sortedNames
|
||||||
(
|
(
|
||||||
@ -572,7 +646,7 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
|||||||
{
|
{
|
||||||
wordList objNames(namesImpl(*this, matchClass, matchName, true));
|
wordList objNames(namesImpl(*this, matchClass, matchName, true));
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
checkNameOrder(objNames, syncPar);
|
||||||
return objNames;
|
return objNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +663,7 @@ Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const
|
|||||||
{
|
{
|
||||||
wordList objNames(namesTypeImpl<Type>(*this, predicates::always(), true));
|
wordList objNames(namesTypeImpl<Type>(*this, predicates::always(), true));
|
||||||
|
|
||||||
checkNames(objNames, syncPar);
|
checkNameOrder(objNames, syncPar);
|
||||||
return objNames;
|
return objNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +685,10 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
|||||||
const bool syncPar
|
const bool syncPar
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return namesTypeImpl<Type>(*this, matchName, true, syncPar);
|
wordList objNames(namesTypeImpl<Type>(*this, matchName, true));
|
||||||
|
|
||||||
|
checkNameOrder(objNames, syncPar);
|
||||||
|
return objNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -144,6 +144,27 @@ Foam::label Foam::objectRegistry::count(const char* clsName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::UPtrList<const Foam::regIOobject>
|
||||||
|
Foam::objectRegistry::csorted() const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const regIOobject>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::UPtrList<const Foam::regIOobject>
|
||||||
|
Foam::objectRegistry::sorted() const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const regIOobject>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::UPtrList<Foam::regIOobject>
|
||||||
|
Foam::objectRegistry::sorted()
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<regIOobject>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::wordList Foam::objectRegistry::names() const
|
Foam::wordList Foam::objectRegistry::names() const
|
||||||
{
|
{
|
||||||
return HashTable<regIOobject*>::toc();
|
return HashTable<regIOobject*>::toc();
|
||||||
@ -442,7 +463,7 @@ bool Foam::objectRegistry::modified() const
|
|||||||
{
|
{
|
||||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||||
{
|
{
|
||||||
if ((*iter)->modified())
|
if (iter.val()->modified())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -463,7 +484,7 @@ void Foam::objectRegistry::readModifiedObjects()
|
|||||||
<< iter.key() << endl;
|
<< iter.key() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*iter)->readIfModified();
|
iter.val()->readIfModified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,18 +508,19 @@ bool Foam::objectRegistry::writeObject
|
|||||||
{
|
{
|
||||||
if (objectRegistry::debug)
|
if (objectRegistry::debug)
|
||||||
{
|
{
|
||||||
|
const regIOobject& obj = *iter.val();
|
||||||
|
|
||||||
Pout<< "objectRegistry::write() : "
|
Pout<< "objectRegistry::write() : "
|
||||||
<< name() << " : Considering writing object "
|
<< name() << " : Considering writing object "
|
||||||
<< iter.key()
|
<< iter.key() << " of type "
|
||||||
<< " of type " << (*iter)->type()
|
<< obj.type() << " with writeOpt "
|
||||||
<< " with writeOpt " << static_cast<int>((*iter)->writeOpt())
|
<< static_cast<int>(obj.writeOpt())
|
||||||
<< " to file " << (*iter)->objectPath()
|
<< " to file " << obj.objectRelPath() << endl;
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*iter)->writeOpt() != NO_WRITE)
|
if (iter.val()->writeOpt() != NO_WRITE)
|
||||||
{
|
{
|
||||||
ok = (*iter)->writeObject(streamOpt, valid) && ok;
|
ok = iter.val()->writeObject(streamOpt, valid) && ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -36,11 +36,12 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef objectRegistry_H
|
#ifndef Foam_objectRegistry_H
|
||||||
#define objectRegistry_H
|
#define Foam_objectRegistry_H
|
||||||
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
|
#include "UPtrList.H"
|
||||||
#include "regIOobject.H"
|
#include "regIOobject.H"
|
||||||
#include "wordRes.H"
|
#include "wordRes.H"
|
||||||
|
|
||||||
@ -130,6 +131,15 @@ class objectRegistry
|
|||||||
const bool doSort
|
const bool doSort
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Templated implementation for sorted()
|
||||||
|
// Called with 'Type' or 'const Type'
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
static UPtrList<Type> objectsTypeImpl
|
||||||
|
(
|
||||||
|
const objectRegistry& list,
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//- No copy construct
|
//- No copy construct
|
||||||
objectRegistry(const objectRegistry&) = delete;
|
objectRegistry(const objectRegistry&) = delete;
|
||||||
@ -203,6 +213,54 @@ public:
|
|||||||
HashTable<wordHashSet> classes(const MatchPredicate& matchName) const;
|
HashTable<wordHashSet> classes(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Sorted access
|
||||||
|
|
||||||
|
//- Return sorted list of objects
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<const regIOobject> csorted() const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<const regIOobject> sorted() const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
UPtrList<regIOobject> sorted();
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type>
|
||||||
|
UPtrList<const Type> csorted() const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type>
|
||||||
|
UPtrList<const Type> sorted() const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type>
|
||||||
|
UPtrList<Type> sorted();
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
//- that also have a matching object name.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
UPtrList<const Type> csorted(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
//- that also have a matching object name.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
UPtrList<const Type> sorted(const MatchPredicate& matchName) const;
|
||||||
|
|
||||||
|
//- Return sorted list of objects with a class satisfying \c isA\<Type\>
|
||||||
|
//- that also have a matching object name.
|
||||||
|
// The lifetime of the returned content cannot exceed the parent!
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
UPtrList<Type> sorted(const MatchPredicate& matchName);
|
||||||
|
|
||||||
|
|
||||||
// Number of items
|
// Number of items
|
||||||
|
|
||||||
//- The number of objects of the given class name
|
//- The number of objects of the given class name
|
||||||
@ -244,19 +302,19 @@ public:
|
|||||||
|
|
||||||
// Summary of names
|
// Summary of names
|
||||||
|
|
||||||
//- The names of all objects
|
//- The unsorted names of all objects
|
||||||
wordList names() const;
|
wordList names() const;
|
||||||
|
|
||||||
//- The names of objects with the given class name.
|
//- The unsorted names of objects with the given class name.
|
||||||
// \note uses the class type() method
|
// \note uses the class type() method
|
||||||
wordList names(const char* clsName) const;
|
wordList names(const char* clsName) const;
|
||||||
|
|
||||||
//- The names of objects with a matching class name
|
//- The unsorted names of objects with a matching class name
|
||||||
// \note uses the class type() method
|
// \note uses the class type() method
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
wordList names(const MatchPredicate& matchClass) const;
|
wordList names(const MatchPredicate& matchClass) const;
|
||||||
|
|
||||||
//- The names of objects with a matching class name
|
//- The unsorted names of objects with a matching class name
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
// \note uses the class type() method
|
// \note uses the class type() method
|
||||||
template<class MatchPredicate1, class MatchPredicate2>
|
template<class MatchPredicate1, class MatchPredicate2>
|
||||||
@ -266,13 +324,13 @@ public:
|
|||||||
const MatchPredicate2& matchName
|
const MatchPredicate2& matchName
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- The names of objects with a class satisfying \c isA\<Type\>.
|
//- The unsorted names of objects with a class satisfying \c isA\<Type\>.
|
||||||
//
|
//
|
||||||
// \note If \a Type is \c void, no isA check is used (always true).
|
// \note If \a Type is \c void, no isA check is used (always true).
|
||||||
template<class Type>
|
template<class Type>
|
||||||
wordList names() const;
|
wordList names() const;
|
||||||
|
|
||||||
//- The names of objects with a class satisfying \c isA\<Type\>
|
//- The unsorted names of objects with a class satisfying \c isA\<Type\>
|
||||||
//- that also have a matching object name.
|
//- that also have a matching object name.
|
||||||
//
|
//
|
||||||
// \note If \a Type is \c void, no isA check is used (always true).
|
// \note If \a Type is \c void, no isA check is used (always true).
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -99,7 +99,7 @@ Foam::label Foam::objectRegistry::countTypeImpl
|
|||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
(std::is_void<Type>::value || isA<Type>(*obj))
|
(std::is_void<Type>::value || Foam::isA<Type>(*obj))
|
||||||
&& matchName(obj->name())
|
&& matchName(obj->name())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -164,7 +164,7 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl
|
|||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
(std::is_void<Type>::value || isA<Type>(*obj))
|
(std::is_void<Type>::value || Foam::isA<Type>(*obj))
|
||||||
&& matchName(obj->name())
|
&& matchName(obj->name())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -184,6 +184,39 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Templated implementation for sorted()
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<Type>
|
||||||
|
Foam::objectRegistry::objectsTypeImpl
|
||||||
|
(
|
||||||
|
const objectRegistry& list,
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_cv<Type>::type BaseType;
|
||||||
|
|
||||||
|
UPtrList<Type> result(list.size());
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
forAllConstIters(list, iter)
|
||||||
|
{
|
||||||
|
const BaseType* ptr = Foam::isA<BaseType>(*iter.val());
|
||||||
|
|
||||||
|
if (ptr && matchName(ptr->name()))
|
||||||
|
{
|
||||||
|
result.set(count, const_cast<BaseType*>(ptr));
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.resize(count);
|
||||||
|
|
||||||
|
Foam::sort(result, nameOp<Type>()); // Sort by object name()
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
@ -243,7 +276,12 @@ Foam::label Foam::objectRegistry::count
|
|||||||
if
|
if
|
||||||
(
|
(
|
||||||
std::is_void<Type>::value
|
std::is_void<Type>::value
|
||||||
|| (strict ? isType<Type>(*obj) : bool(isA<Type>(*obj)))
|
||
|
||||||
|
(
|
||||||
|
strict
|
||||||
|
? bool(Foam::isType<Type>(*obj))
|
||||||
|
: bool(Foam::isA<Type>(*obj))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
++nObjects;
|
++nObjects;
|
||||||
@ -254,6 +292,66 @@ Foam::label Foam::objectRegistry::count
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::UPtrList<const Type>
|
||||||
|
Foam::objectRegistry::csorted() const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const Type>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::UPtrList<const Type>
|
||||||
|
Foam::objectRegistry::sorted() const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const Type>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::UPtrList<Type>
|
||||||
|
Foam::objectRegistry::sorted()
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<Type>(*this, predicates::always());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<const Type>
|
||||||
|
Foam::objectRegistry::csorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const Type>(*this, matchName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<const Type>
|
||||||
|
Foam::objectRegistry::sorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<const Type>(*this, matchName);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Type, class MatchPredicate>
|
||||||
|
Foam::UPtrList<Type>
|
||||||
|
Foam::objectRegistry::sorted
|
||||||
|
(
|
||||||
|
const MatchPredicate& matchName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return objectsTypeImpl<Type>(*this, matchName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class MatchPredicate>
|
template<class MatchPredicate>
|
||||||
Foam::wordList Foam::objectRegistry::names
|
Foam::wordList Foam::objectRegistry::names
|
||||||
(
|
(
|
||||||
@ -342,7 +440,12 @@ Foam::HashTable<const Type*> Foam::objectRegistry::lookupClass
|
|||||||
{
|
{
|
||||||
const regIOobject* obj = iter.val();
|
const regIOobject* obj = iter.val();
|
||||||
|
|
||||||
if (strict ? isType<Type>(*obj) : bool(isA<Type>(*obj)))
|
if
|
||||||
|
(
|
||||||
|
strict
|
||||||
|
? bool(Foam::isType<Type>(*obj))
|
||||||
|
: bool(Foam::isA<Type>(*obj))
|
||||||
|
)
|
||||||
{
|
{
|
||||||
objectsOfClass.insert(obj->name(), dynamic_cast<const Type*>(obj));
|
objectsOfClass.insert(obj->name(), dynamic_cast<const Type*>(obj));
|
||||||
}
|
}
|
||||||
@ -364,7 +467,12 @@ Foam::HashTable<Type*> Foam::objectRegistry::lookupClass
|
|||||||
{
|
{
|
||||||
regIOobject* obj = iter.val();
|
regIOobject* obj = iter.val();
|
||||||
|
|
||||||
if (strict ? isType<Type>(*obj) : bool(isA<Type>(*obj)))
|
if
|
||||||
|
(
|
||||||
|
strict
|
||||||
|
? bool(Foam::isType<Type>(*obj))
|
||||||
|
: bool(Foam::isA<Type>(*obj))
|
||||||
|
)
|
||||||
{
|
{
|
||||||
objectsOfClass.insert(obj->name(), dynamic_cast<Type*>(obj));
|
objectsOfClass.insert(obj->name(), dynamic_cast<Type*>(obj));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -313,7 +313,7 @@ Foam::polyMesh::polyMesh(const IOobject& io, const bool doInit)
|
|||||||
oldPointsPtr_(nullptr),
|
oldPointsPtr_(nullptr),
|
||||||
oldCellCentresPtr_(nullptr)
|
oldCellCentresPtr_(nullptr)
|
||||||
{
|
{
|
||||||
if (owner_.hasHeaderClassName())
|
if (owner_.hasHeaderClass())
|
||||||
{
|
{
|
||||||
initMesh();
|
initMesh();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -240,7 +240,7 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
|
|||||||
// Boundary is set so can use initMesh now (uses boundary_ to
|
// Boundary is set so can use initMesh now (uses boundary_ to
|
||||||
// determine internal and active faces)
|
// determine internal and active faces)
|
||||||
|
|
||||||
if (owner_.hasHeaderClassName())
|
if (owner_.hasHeaderClass())
|
||||||
{
|
{
|
||||||
initMesh();
|
initMesh();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -40,8 +40,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef word_H
|
#ifndef Foam_word_H
|
||||||
#define word_H
|
#define Foam_word_H
|
||||||
|
|
||||||
#include "string.H"
|
#include "string.H"
|
||||||
|
|
||||||
@ -241,6 +241,12 @@ struct nameOp
|
|||||||
{
|
{
|
||||||
return obj.name();
|
return obj.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Less-compare two objects by their name() method - for sorting
|
||||||
|
bool operator()(const T& a, const T& b) const
|
||||||
|
{
|
||||||
|
return (a.name() < b.name());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -252,6 +258,12 @@ struct typeOp
|
|||||||
{
|
{
|
||||||
return obj.type();
|
return obj.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Less-compare two objects by their type() method - for sorting
|
||||||
|
bool operator()(const T& a, const T& b) const
|
||||||
|
{
|
||||||
|
return (a.type() < b.type());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -192,7 +192,7 @@ Foam::label Foam::functionObjects::fvExpressionField::loadFields
|
|||||||
const bool ok =
|
const bool ok =
|
||||||
(
|
(
|
||||||
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
||||||
&& io.hasHeaderClassName() // Extra safety
|
&& io.hasHeaderClass() // Extra safety
|
||||||
&&
|
&&
|
||||||
(
|
(
|
||||||
loadField<scalar>(io)
|
loadField<scalar>(io)
|
||||||
|
|||||||
@ -104,7 +104,7 @@ bool Foam::functionObjects::readFields::execute()
|
|||||||
const bool ok =
|
const bool ok =
|
||||||
(
|
(
|
||||||
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
io.typeHeaderOk<regIOobject>(false) // Preload header info
|
||||||
&& io.hasHeaderClassName() // Extra safety
|
&& io.hasHeaderClass() // Extra safety
|
||||||
&&
|
&&
|
||||||
(
|
(
|
||||||
loadField<scalar>(io)
|
loadField<scalar>(io)
|
||||||
|
|||||||
Reference in New Issue
Block a user