40 template<
class ZoneType,
class MeshType>
50 template<
class ZoneType,
class MeshType>
54 const PtrList<ZoneType>& zones = *
this;
57 for (
const ZoneType& zn : zones)
66 template<
class ZoneType,
class MeshType>
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)
112 : static_cast<const labelList&>(zn)
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;
161 template<
class ZoneType,
class MeshType>
167 return !groupIDsPtr_->
empty();
170 const PtrList<ZoneType>& zones = *
this;
172 for (
const ZoneType& zn : zones)
174 if (!zn.inGroups().empty())
184 template<
class ZoneType,
class MeshType>
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.erase(zones[zonei].name()))
211 <<
"Removed group '" << zones[zonei].name()
212 <<
"' which clashes with zone " << zonei
213 <<
" of the same name." 220 template<
class ZoneType,
class MeshType>
223 PtrList<entry>&& entries
226 clearLocalAddressing();
228 PtrList<ZoneType>& zones = *
this;
230 zones.resize_null(entries.size());
248 entries[zonei].keyword(),
249 entries[zonei].
dict(),
260 template<
class ZoneType,
class MeshType>
263 const bool allowOptionalRead
266 bool updated =
false;
267 PtrList<entry> entries;
272 || (allowOptionalRead && isReadOptional() && headerOk())
276 warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
279 Istream& is = readStream(typeName);
292 populate(std::move(entries));
301 template<
class ZoneType,
class MeshType>
314 readIOcontents(
true);
318 template<
class ZoneType,
class MeshType>
322 const MeshType&
mesh,
332 template<
class ZoneType,
class MeshType>
336 const MeshType&
mesh,
346 readIOcontents(
true);
350 template<
class ZoneType,
class MeshType>
354 const MeshType&
mesh,
362 if (!readIOcontents(
true))
370 zones.
set(zonei, list[zonei].clone(*
this));
376 template<
class ZoneType,
class MeshType>
380 const MeshType&
mesh,
381 PtrList<entry>&& entries
388 if (!readIOcontents(
true))
390 populate(std::move(entries));
398 template<
class ZoneType,
class MeshType>
411 template<
class ZoneType,
class MeshType>
414 const label objectIndex
417 return zoneMap().lookup(objectIndex, -1);
421 template<
class ZoneType,
class MeshType>
424 const label objectIndex,
429 const auto fnd = zoneMap().cfind(objectIndex);
434 if (additionalMapPtr_)
436 const auto& additionalMap = *additionalMapPtr_;
437 if (objectIndex < additionalMap.size())
439 for (
const label zonei : additionalMap[objectIndex])
450 template<
class ZoneType,
class MeshType>
457 template<
class ZoneType,
class MeshType>
464 template<
class ZoneType,
class MeshType>
467 return this->groupZoneIDs().sortedToc();
471 template<
class ZoneType,
class MeshType>
481 template<
class ZoneType,
class MeshType>
492 template<
class ZoneType,
class MeshType>
502 template<
class ZoneType,
class MeshType>
515 template<
class ZoneType,
class MeshType>
529 template<
class ZoneType,
class MeshType>
542 const bool checkGroups = (useGroups && this->hasGroupIDs());
548 ids.reserve(this->size());
555 const auto& groupLookup = groupZoneIDs();
558 if (matcher(iter.key()))
561 ids.insert(iter.val());
586 else if (checkGroups)
588 const auto iter = groupZoneIDs().cfind(matcher);
593 ids.insert(iter.val());
598 return ids.sortedToc();
602 template<
class ZoneType,
class MeshType>
613 else if (matcher.
size() == 1)
615 return this->indices(matcher.
front(), useGroups);
621 if (useGroups && this->hasGroupIDs())
623 ids.reserve(this->size());
625 const auto& groupLookup = groupZoneIDs();
628 if (matcher(iter.key()))
631 ids.insert(iter.val());
645 return ids.sortedToc();
649 template<
class ZoneType,
class MeshType>
659 return this->indices(
select, useGroups);
662 const wordRes::filter matcher(
select, ignore);
667 if (useGroups && this->hasGroupIDs())
669 ids.reserve(this->size());
671 const auto& groupLookup = groupZoneIDs();
674 if (matcher(iter.key()))
677 ids.insert(iter.val());
691 return ids.sortedToc();
695 template<
class ZoneType,
class MeshType>
709 template<
class ZoneType,
class MeshType>
712 const wordRes& matcher
723 template<
class ZoneType,
class MeshType>
729 if (zoneName.empty())
739 <<
"Zone named " << zoneName <<
" not found. " 740 <<
"List of available zone names: " <<
names() <<
endl;
743 if (disallowGenericZones != 0)
745 Info<<
"Creating dummy zone " << zoneName <<
endl;
746 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
747 zm.emplace_back(zoneName, zm.size(), zm);
755 template<
class ZoneType,
class MeshType>
761 if (zoneName.empty())
766 const PtrList<ZoneType>& zones = *
this;
768 for (
auto iter = zones.begin(); iter != zones.end(); ++iter)
770 const ZoneType* ptr = iter.
get();
772 if (ptr && zoneName == ptr->name())
779 if (disallowGenericZones != 0)
781 Info<<
"Creating dummy zone " << zoneName <<
endl;
782 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
783 zm.emplace_back(zoneName, zm.size(), zm);
790 template<
class ZoneType,
class MeshType>
796 return const_cast<ZoneType*
>(this->cfindZone(zoneName));
800 template<
class ZoneType,
class MeshType>
808 for (
const label zonei : zoneIds)
811 if (zonei < 0 || zonei >= this->size())
814 << ZoneType::typeName <<
" " 815 << zonei <<
" out of range [0," << this->size() <<
")" 822 static_cast<const labelList&>(this->
operator[](zonei))
830 template<
class ZoneType,
class MeshType>
838 return this->selection(this->indices(matcher, useGroups));
842 template<
class ZoneType,
class MeshType>
850 return this->selection(this->indices(matcher, useGroups));
854 template<
class ZoneType,
class MeshType>
863 return *groupIDsPtr_;
867 template<
class ZoneType,
class MeshType>
870 const word& groupName,
874 groupIDsPtr_.reset(
nullptr);
881 for (
const label zonei :
zoneIDs)
883 if (pending.test(zonei))
885 pending.
unset(zonei);
886 zones[zonei].addGroup(groupName);
893 if (pending.test(zonei))
895 zones[zonei].removeGroup(groupName);
902 template<
class ZoneType,
class MeshType>
905 zoneMapPtr_.reset(
nullptr);
906 additionalMapPtr_.reset(
nullptr);
907 groupIDsPtr_.reset(
nullptr);
911 template<
class ZoneType,
class MeshType>
914 clearLocalAddressing();
918 for (ZoneType& zn : zones)
920 zn.clearAddressing();
925 template<
class ZoneType,
class MeshType>
928 PtrList<ZoneType>& zones = *
this;
930 for (ZoneType& zn : zones)
932 zn.clearPrimitives();
937 template<
class ZoneType,
class MeshType>
945 template<
class ZoneType,
class MeshType>
951 bool hasError =
false;
955 for (
const ZoneType& zn : zones)
957 hasError |= zn.checkDefinition(report);
964 template<
class ZoneType,
class MeshType>
970 if (!UPstream::parRun())
975 const PtrList<ZoneType>& zones = *
this;
977 bool hasError =
false;
980 const wordList localTypes(this->types());
987 globalIndex::gatherNonLocal{},
995 for (
const int proci :
procAddr.subProcs())
997 const auto procNames(allNames.slice(
procAddr.range(proci)));
998 const auto procTypes(allTypes.slice(
procAddr.range(proci)));
1000 if (procNames != localNames || procTypes != localTypes)
1004 if (
debug || report)
1006 Info<<
" ***Inconsistent zones across processors, " 1007 "processor 0 has zone names:" << localNames
1008 <<
" zone types:" << localTypes
1009 <<
" processor " << proci
1010 <<
" has zone names:" << procNames
1011 <<
" zone types:" << procTypes
1017 Pstream::broadcast(hasError);
1022 for (
const ZoneType& zn : zones)
1024 if (zn.checkParallelSync(
false))
1028 if (
debug || (report && UPstream::master()))
1030 Info<<
" ***Zone " << zn.name()
1031 <<
" of type " << zn.type()
1032 <<
" is not correctly synchronised" 1033 <<
" across coupled boundaries." 1034 <<
" (coupled faces are either not both" 1035 <<
" present in set or have same flipmap)" <<
endl;
1045 template<
class ZoneType,
class MeshType>
1048 PtrList<ZoneType>& zones = *
this;
1050 for (ZoneType& zn : zones)
1057 template<
class ZoneType,
class MeshType>
1061 if (zoneNames.empty())
1063 this->removeMetaData();
1068 meta.
set(
"names", zoneNames);
1073 template<
class ZoneType,
class MeshType>
1083 template<
class ZoneType,
class MeshType>
1086 const word& zoneName
1089 const label zonei = findZoneID(zoneName);
1094 <<
"Zone named " << zoneName <<
" not found." <<
nl 1095 <<
"Available zone names: " <<
names() <<
endl 1099 return operator[](zonei);
1103 template<
class ZoneType,
class MeshType>
1106 const word& zoneName
1109 const label zonei = findZoneID(zoneName);
1114 <<
"Zone named " << zoneName <<
" not found." <<
nl 1115 <<
"Available zone names: " <<
names() <<
endl 1119 return operator[](zonei);
1123 template<
class ZoneType,
class MeshType>
1126 const word& zoneName,
1130 ZoneType* ptr = findZone(zoneName);
1132 const bool existing = bool(ptr);
1136 ptr =
new ZoneType(zoneName, this->size(), *
this);
1137 this->push_back(ptr);
1142 Info<< ZoneType::typeName <<
' ' << zoneName
1143 <<
" (" << (existing ?
"existing" :
"new")
1144 <<
" at index " << ptr->index() <<
')' 1154 template<
class ZoneType,
class MeshType>
1158 const ZoneMesh<ZoneType, MeshType>& zones
1161 const label sz = zones.size();
1165 os << sz <<
nl << token::BEGIN_LIST;
1167 for (label i=0; i < sz; ++i)
1169 zones[i].writeDict(
os);
1172 os << token::END_LIST;
1176 os << sz << token::BEGIN_LIST << token::END_LIST;
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
void size(const label n)
Older name for setAddressableSize.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type unset(const label i)
Unset the bool entry at specified position, always false for out-of-range access. ...
const labelIOList & zoneIDs
wordList types() const
Return a list of zone types.
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
void clearAddressing()
Clear addressing.
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...
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
void set(const bitSet &bitset)
Set specified bits from another bitset.
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.
void clear()
Clear the zones.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
constexpr char nl
The newline '\n' character (0x0a)
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
bool empty() const noexcept
True if List is empty (ie, size() is zero)
T & front()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type get(const label i) const
Return bool value at specified position, always false for out-of-range access.
void stableSort(UList< T > &list)
Stable sort the list.
Functions to operate on Pointer Lists.
List< labelList > labelListList
List of labelList.
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
Extract name (as a word) from an object, typically using its name() method.
#define forAll(list, i)
Loop across all elements in list.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
vectorField pointField
pointField is a vectorField.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
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)
A class for handling words, derived from Foam::string.
#define DebugInFunction
Report an information message using Foam::Info.
void sort(UList< T > &list)
Sort the list.
void setGroup(const word &groupName, const labelUList &zoneIDs)
Set/add group with zones.
label size() const noexcept
The number of entries in the list.
A List of wordRe with additional matching capabilities.
void clearPrimitives()
Clear primitive addressing.
A HashTable similar to std::unordered_map.
errorManip< error > abort(error &err)
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void push_back(const T &val)
Copy append an element to the end of this list.
void resize(const label newLen)
Adjust size of PtrList.
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
label push_uniq(const T &val)
Append an element if not already in the list.
ZoneMesh(const ZoneMesh &)=delete
No copy construct.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
List< word > wordList
List of word.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
#define WarningInFunction
Report a warning using Foam::Warning.
globalIndex procAddr(aMesh.nFaces())
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
wordList groupNames() const
A list of the zone group names (if any)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
wordList names() const
A list of the zone names.
messageStream Info
Information stream (stdout output on master, null elsewhere)
bitSet selection(const labelUList &zoneIds) const
Return all elements (cells, faces, points) contained in the listed zones.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
wordList sortedNames() const
Sorted list of the zone names.
List< label > labelList
A List of labels.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
label whichZones(const label objectIndex, DynamicList< label > &zones) const
Given a global object index, return (in argument) its zones.
Defines the attributes of an object for which implicit objectRegistry management is supported...
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
bitSet bitset(const labelHashSet &locations)
Transform the on locations to a bitSet.
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
bool isPattern() const noexcept
The wordRe is a pattern, not a literal string.
bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
Extract type (as a word) from an object, typically using its type() method.
forAllConstIters(mixture.phases(), phase)
label firstMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Find first list item with 'name()' that matches, -1 on failure.
A HashTable to objects of type <T> with a label key.
const HashTable< labelList > & groupZoneIDs() const
The zone indices per zone group.
void updateMetaData()
Update internal meta-data (eg, prior to writing)