40 template<
class ZoneType,
class MeshType>
50template<
class ZoneType,
class MeshType>
51Foam::label Foam::ZoneMesh<ZoneType, MeshType>::totalSize()
const
54 const PtrList<ZoneType>& zones = *
this;
57 for (
const ZoneType& zn : zones)
66template<
class ZoneType,
class MeshType>
67void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap()
const
72 <<
"zone map already calculated"
77 zoneMapPtr_.reset(
new Map<label>());
78 auto& map = *zoneMapPtr_;
83 map.reserve(this->totalSize());
85 const PtrList<ZoneType>& zones = *
this;
89 for (
const ZoneType& zn : zones)
91 for (
const label
id :
static_cast<const labelList&
>(zn))
94 const auto fnd = map.cfind(
id);
97 map.insert(
id, zonei);
99 else if (fnd.val() != zonei)
103 if (!additionalMapPtr_)
107 for (
const ZoneType& zn : zones)
120 auto& additionalMap = *additionalMapPtr_;
121 additionalMap[id].push_uniq(zonei);
129 if (additionalMapPtr_)
131 auto& additionalMap = *additionalMapPtr_;
139 const label zonei = map[id];
140 const label index =
findLower(zones, zonei);
147 map.set(
id, zones[0]);
148 for (label i = 0; i < zones.size() && i <= index; i++)
150 zones[i] = zones[i+1];
152 zones[index+1] = zonei;
161template<
class ZoneType,
class MeshType>
162bool Foam::ZoneMesh<ZoneType, MeshType>::hasGroupIDs()
const
167 return !groupIDsPtr_->empty();
170 const PtrList<ZoneType>& zones = *
this;
172 for (
const ZoneType& zn : zones)
174 if (!zn.inGroups().empty())
184template<
class ZoneType,
class MeshType>
185void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs()
const
192 groupIDsPtr_.reset(
new HashTable<labelList>(16));
193 auto& groupLookup = *groupIDsPtr_;
195 const PtrList<ZoneType>& zones = *
this;
199 for (
const word& groupName : zones[zonei].inGroups())
201 groupLookup(groupName).push_back(zonei);
208 if (groupLookup.empty())
212 else if (groupLookup.erase(zones[zonei].name()))
215 <<
"Removed group '" << zones[zonei].name()
216 <<
"' which clashes with zone " << zonei
217 <<
" of the same name."
224template<
class ZoneType,
class MeshType>
225void Foam::ZoneMesh<ZoneType, MeshType>::populate
227 PtrList<entry>&& entries
230 clearLocalAddressing();
232 PtrList<ZoneType>& zones = *
this;
234 zones.resize_null(entries.size());
252 entries[zonei].keyword(),
253 entries[zonei].
dict(),
264template<
class ZoneType,
class MeshType>
265bool Foam::ZoneMesh<ZoneType, MeshType>::readIOcontents
267 const bool allowOptionalRead
270 bool updated =
false;
271 PtrList<entry> entries;
276 || (allowOptionalRead && isReadOptional() && headerOk())
280 warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
283 Istream& is = readStream(typeName);
296 populate(std::move(entries));
305template<
class ZoneType,
class MeshType>
318 readIOcontents(
true);
322template<
class ZoneType,
class MeshType>
326 const MeshType&
mesh,
336template<
class ZoneType,
class MeshType>
340 const MeshType&
mesh,
350 readIOcontents(
true);
354template<
class ZoneType,
class MeshType>
358 const MeshType&
mesh,
366 if (!readIOcontents(
true))
380template<
class ZoneType,
class MeshType>
384 const MeshType&
mesh,
392 if (!readIOcontents(
true))
394 populate(std::move(entries));
402template<
class ZoneType,
class MeshType>
415template<
class ZoneType,
class MeshType>
418 const label objectIndex
421 return zoneMap().lookup(objectIndex, -1);
425template<
class ZoneType,
class MeshType>
428 const label objectIndex,
433 const auto fnd = zoneMap().cfind(objectIndex);
438 if (additionalMapPtr_)
440 const auto& additionalMap = *additionalMapPtr_;
441 if (objectIndex < additionalMap.size())
443 for (
const label zonei : additionalMap[objectIndex])
454template<
class ZoneType,
class MeshType>
462template<
class ZoneType,
class MeshType>
469template<
class ZoneType,
class MeshType>
476template<
class ZoneType,
class MeshType>
483template<
class ZoneType,
class MeshType>
493template<
class ZoneType,
class MeshType>
504template<
class ZoneType,
class MeshType>
514template<
class ZoneType,
class MeshType>
527template<
class ZoneType,
class MeshType>
541template<
class ZoneType,
class MeshType>
546 bool changed =
false;
551 if (zones[zonei].index() != zonei)
553 zones[zonei].index() = zonei;
560 this->clearLocalAddressing();
567template<
class ZoneType,
class MeshType>
570 const wordRe& matcher,
580 const bool checkGroups = (useGroups && this->hasGroupIDs());
586 ids.reserve(this->size());
589 if (matcher.isPattern())
593 const auto& groupLookup = groupZoneIDs();
596 if (matcher(iter.key()))
599 ids.insert(iter.val());
624 else if (checkGroups)
626 const auto iter = groupZoneIDs().cfind(matcher);
631 ids.insert(iter.val());
636 return ids.sortedToc();
640template<
class ZoneType,
class MeshType>
643 const wordRes& matcher,
651 else if (matcher.size() == 1)
653 return this->indices(matcher.front(), useGroups);
659 if (useGroups && this->hasGroupIDs())
661 ids.reserve(this->size());
663 const auto& groupLookup = groupZoneIDs();
666 if (matcher(iter.key()))
669 ids.insert(iter.val());
683 return ids.sortedToc();
687template<
class ZoneType,
class MeshType>
690 const wordRes& allow,
695 if (allow.empty() && deny.empty())
706 if (useGroups && this->hasGroupIDs())
708 ids.reserve(this->size());
710 const auto& groupLookup = groupZoneIDs();
713 if (matcher(iter.key()))
716 ids.insert(iter.val());
730 return ids.sortedToc();
734template<
class ZoneType,
class MeshType>
748template<
class ZoneType,
class MeshType>
751 const wordRes& matcher
762template<
class ZoneType,
class MeshType>
768 if (zoneName.empty())
778 <<
"Zone named " << zoneName <<
" not found. "
779 <<
"List of available zone names: " <<
names() <<
endl;
782 if (disallowGenericZones != 0)
784 Info<<
"Creating dummy zone " << zoneName <<
endl;
794template<
class ZoneType,
class MeshType>
800 if (zoneName.empty())
807 for (
auto iter = zones.begin(); iter != zones.end(); ++iter)
809 const ZoneType* ptr = iter.get();
811 if (ptr && zoneName == ptr->name())
818 if (disallowGenericZones != 0)
820 Info<<
"Creating dummy zone " << zoneName <<
endl;
829template<
class ZoneType,
class MeshType>
835 return const_cast<ZoneType*
>(this->
cfindZone(zoneName));
839template<
class ZoneType,
class MeshType>
847 for (
const label zonei : zoneIds)
850 if (zonei < 0 || zonei >= this->size())
853 << ZoneType::typeName <<
" "
854 << zonei <<
" out of range [0," << this->size() <<
")"
861 static_cast<const labelList&
>(this->
operator[](zonei))
869template<
class ZoneType,
class MeshType>
872 const wordRe& matcher,
881template<
class ZoneType,
class MeshType>
893template<
class ZoneType,
class MeshType>
902 return *groupIDsPtr_;
906template<
class ZoneType,
class MeshType>
909 const word& groupName,
913 groupIDsPtr_.reset(
nullptr);
915 PtrList<ZoneType>& zones = *
this;
917 boolList pending(zones.size(),
true);
920 for (
const label zonei :
zoneIDs)
922 if (pending.test(zonei))
924 pending.unset(zonei);
925 zones[zonei].addGroup(groupName);
932 if (pending.test(zonei))
934 zones[zonei].removeGroup(groupName);
941template<
class ZoneType,
class MeshType>
942void Foam::ZoneMesh<ZoneType, MeshType>::clearLocalAddressing()
944 zoneMapPtr_.reset(
nullptr);
945 additionalMapPtr_.reset(
nullptr);
946 groupIDsPtr_.reset(
nullptr);
950template<
class ZoneType,
class MeshType>
953 clearLocalAddressing();
957 for (ZoneType& zn : zones)
959 zn.clearAddressing();
964template<
class ZoneType,
class MeshType>
967 PtrList<ZoneType>& zones = *
this;
969 for (ZoneType& zn : zones)
971 zn.clearPrimitives();
976template<
class ZoneType,
class MeshType>
984template<
class ZoneType,
class MeshType>
990 bool hasError =
false;
994 for (
const ZoneType& zn : zones)
996 hasError |= zn.checkDefinition(report);
1003template<
class ZoneType,
class MeshType>
1016 bool hasError =
false;
1019 const wordList localTypes(this->types());
1030 const wordList allNames(procAddr.gather(localNames));
1031 const wordList allTypes(procAddr.gather(localTypes));
1034 for (
const int proci : procAddr.subProcs())
1036 const auto procNames(allNames.slice(procAddr.range(proci)));
1037 const auto procTypes(allTypes.slice(procAddr.range(proci)));
1039 if (procNames != localNames || procTypes != localTypes)
1043 if (
debug || report)
1045 Info<<
" ***Inconsistent zones across processors, "
1046 "processor 0 has zone names:" << localNames
1047 <<
" zone types:" << localTypes
1048 <<
" processor " << proci
1049 <<
" has zone names:" << procNames
1050 <<
" zone types:" << procTypes
1061 for (
const ZoneType& zn : zones)
1063 if (zn.checkParallelSync(
false))
1069 Info<<
" ***Zone " << zn.name()
1070 <<
" of type " << zn.type()
1071 <<
" is not correctly synchronised"
1072 <<
" across coupled boundaries."
1073 <<
" (coupled faces are either not both"
1074 <<
" present in set or have same flipmap)" <<
endl;
1084template<
class ZoneType,
class MeshType>
1087 PtrList<ZoneType>& zones = *
this;
1089 for (ZoneType& zn : zones)
1096template<
class ZoneType,
class MeshType>
1100 if (zoneNames.empty())
1102 this->removeMetaData();
1109 auto iter = toks.begin();
1111 iter = std::move(zoneNames.begin(), zoneNames.end(), ++iter);
1114 this->getMetaData().set(
"names", std::move(toks));
1121template<
class ZoneType,
class MeshType>
1124 const PtrList<ZoneType>& entries = *
this;
1126 os << entries.size();
1128 if (entries.empty())
1137 for (
const auto& zn : entries)
1148template<
class ZoneType,
class MeshType>
1151 const word& keyword,
1157 if (!keyword.empty())
1160 if (entries.empty())
1168 if (!keyword.empty())
os.endEntry();
1172template<
class ZoneType,
class MeshType>
1182template<
class ZoneType,
class MeshType>
1185 const word& zoneName
1188 const label zonei = findZoneID(zoneName);
1193 <<
"Zone named " << zoneName <<
" not found." <<
nl
1194 <<
"Available zone names: " <<
names() <<
endl
1198 return operator[](zonei);
1202template<
class ZoneType,
class MeshType>
1205 const word& zoneName
1208 const label zonei = findZoneID(zoneName);
1213 <<
"Zone named " << zoneName <<
" not found." <<
nl
1214 <<
"Available zone names: " <<
names() <<
endl
1218 return operator[](zonei);
1222template<
class ZoneType,
class MeshType>
1225 const word& zoneName,
1229 ZoneType* ptr = findZone(zoneName);
1231 const bool existing = bool(ptr);
1235 ptr =
new ZoneType(zoneName, this->size(), *
this);
1236 this->push_back(ptr);
1241 Info<< ZoneType::typeName <<
' ' << zoneName
1242 <<
" (" << (existing ?
"existing" :
"new")
1243 <<
" at index " << ptr->index() <<
')'
1253template<
class ZoneType,
class MeshType>
1254Foam::Ostream& Foam::operator<<
1260 zones.writeEntry(
os);
Functions to operate on Pointer Lists.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
label push_uniq(const T &val)
Append an element if not already in the list.
void push_back(const T &val)
Copy append an element to the end of this list.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
bool empty() const noexcept
True if the hash table is empty.
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
autoPtr< IOobject > clone() const
Clone.
A HashTable to objects of type <T> with a label key.
virtual Ostream & write(const char c) override
Write character.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & endBlock()
Write end block group.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
void push_back(ZoneType *ptr)
T & emplace_back(Args &&... args)
Construct and append an element to the end of the list, return reference to the new list element.
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
constexpr PtrList() noexcept
void resize(const label newLen)
Adjust size of PtrList.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
bool test(const label i) const
Test bool value at specified position, always false for out-of-range access.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
iterator end() noexcept
Return an iterator to end traversing the UList.
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
T & front()
Access first element of the list, position [0].
bool unset(const label i)
Unset the bool entry at specified position, always false for out-of-range access.
void size(const label n)
Older name for setAddressableSize.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
@ broadcast
broadcast [MPI]
static bool & parRun() noexcept
Test if this a parallel run.
iterator begin()
Return iterator to begin traversal of non-nullptr entries.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
label size() const noexcept
iterator end() noexcept
Return iterator beyond end of UPtrList traversal.
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
friend Ostream & operator(Ostream &os, const ZoneMesh< ZoneType, MeshType > &zones)
wordList sortedNames() const
Sorted list of the zone names.
void setGroup(const word &groupName, const labelUList &zoneIDs)
Set/add group with zones.
wordList types() const
Return a list of zone types.
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
bool reindex()
Adjust the index of zone entries to be consistent with their position in the list.
void clearPrimitives()
Clear primitive addressing.
const MeshType & mesh() const noexcept
Return the mesh reference.
void updateMetaData()
Update internal meta-data (eg, prior to writing).
labelList zoneSizes() const
Return a list of zone sizes.
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
label whichZones(const label objectIndex, DynamicList< label > &zones) const
Given a global object index, return (in argument) its zones.
void clearAddressing()
Clear addressing.
bitSet selection(const labelUList &zoneIds) const
Return all elements (cells, faces, points) contained in the listed zones.
void writeEntry(Ostream &os) const
Write as a plain list of entries.
const ZoneType & operator[](const word &zoneName) const
Return const reference to zone by name.
ZoneMesh(const ZoneMesh &)=delete
No copy construct.
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
void clear()
Clear the zones.
wordList groupNames() const
A list of the zone group names (if any).
const HashTable< labelList > & groupZoneIDs() const
The zone indices per zone group.
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
wordList names() const
A list of the zone names.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
The (sorted) patch indices for all matches, optionally matching zone groups.
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
void set(const bitSet &bitset)
Set specified bits from another bitset.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
static void gather(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &fld, UList< Type > &allFld, const int tag=UPstream::msgType(), UPstream::commsTypes commsType=UPstream::commsTypes::nonBlocking)
Collect data in processor order on master (== procIDs[0]).
labelRange range(label proci) const noexcept
Return start/size range of proci data.
labelRange subProcs() const noexcept
Range of process indices for addressed sub-offsets (processes).
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
void removeMetaData()
Remove meta-data.
dictionary & getMetaData() noexcept
Get or create meta-data.
@ BEGIN_LIST
Begin list [isseparator].
@ END_LIST
End list [isseparator].
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
bool isPattern() const noexcept
The wordRe is a pattern, not a literal string.
A List of wordRe with additional matching capabilities.
A class for handling words, derived from Foam::string.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
const labelIOList & zoneIDs
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
label firstMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Find first list item with 'name()' that matches, -1 on failure.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
Namespace for handling debugging switches.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
List< word > wordList
List of word.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
messageStream Info
Information stream (stdout output on master, null elsewhere).
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value.
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
void sort(UList< T > &list)
Sort the list.
errorManip< error > abort(error &err)
List< bool > boolList
A List of bools.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
List< token > tokenList
List of token, used for dictionary primitive entry (for example).
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
void stableSort(UList< T > &list)
Stable sort the list.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Dispatch tag: Construct 'one-sided' from the non-master local sizes using gather but no broadcast.
Extract name (as a word) from an object, typically using its name() method.
Extract type (as a word) from an object, typically using its type() method.
Functor wrapper of allow/deny lists of wordRe for filtering.