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;
88 for (
const ZoneType& zn : zones)
90 for (
const label
id : static_cast<const labelList&>(zn))
92 map.insert(
id, zonei);
101 template<
class ZoneType,
class MeshType>
107 return !groupIDsPtr_->
empty();
110 const PtrList<ZoneType>& zones = *
this;
112 for (
const ZoneType& zn : zones)
114 if (!zn.inGroups().empty())
124 template<
class ZoneType,
class MeshType>
132 groupIDsPtr_.reset(
new HashTable<labelList>(16));
133 auto& groupLookup = *groupIDsPtr_;
135 const PtrList<ZoneType>& zones = *
this;
139 for (
const word& groupName : zones[zonei].inGroups())
141 groupLookup(groupName).push_back(zonei);
148 if (groupLookup.erase(zones[zonei].name()))
151 <<
"Removed group '" << zones[zonei].name()
152 <<
"' which clashes with zone " << zonei
153 <<
" of the same name." 160 template<
class ZoneType,
class MeshType>
163 PtrList<entry>&& entries
166 clearLocalAddressing();
168 PtrList<ZoneType>& zones = *
this;
170 zones.resize_null(entries.size());
188 entries[zonei].keyword(),
189 entries[zonei].
dict(),
200 template<
class ZoneType,
class MeshType>
203 const bool allowOptionalRead
206 bool updated =
false;
207 PtrList<entry> entries;
212 || (allowOptionalRead && isReadOptional() && headerOk())
216 warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
219 Istream& is = readStream(typeName);
232 populate(std::move(entries));
241 template<
class ZoneType,
class MeshType>
258 template<
class ZoneType,
class MeshType>
262 const MeshType&
mesh,
272 template<
class ZoneType,
class MeshType>
276 const MeshType&
mesh,
290 template<
class ZoneType,
class MeshType>
294 const MeshType&
mesh,
302 if (!readContents(
true))
310 zones.
set(zonei, list[zonei].clone(*
this));
316 template<
class ZoneType,
class MeshType>
320 const MeshType&
mesh,
321 PtrList<entry>&& entries
328 if (!readContents(
true))
330 populate(std::move(entries));
338 template<
class ZoneType,
class MeshType>
351 template<
class ZoneType,
class MeshType>
354 const label objectIndex
357 return zoneMap().lookup(objectIndex, -1);
361 template<
class ZoneType,
class MeshType>
368 template<
class ZoneType,
class MeshType>
375 template<
class ZoneType,
class MeshType>
378 return this->groupZoneIDs().sortedToc();
382 template<
class ZoneType,
class MeshType>
392 template<
class ZoneType,
class MeshType>
403 template<
class ZoneType,
class MeshType>
413 template<
class ZoneType,
class MeshType>
426 template<
class ZoneType,
class MeshType>
440 template<
class ZoneType,
class MeshType>
453 const bool checkGroups = (useGroups && this->hasGroupIDs());
459 ids.reserve(this->size());
466 const auto& groupLookup = groupZoneIDs();
469 if (matcher(iter.key()))
472 ids.insert(iter.val());
497 else if (checkGroups)
499 const auto iter = groupZoneIDs().cfind(matcher);
504 ids.insert(iter.val());
509 return ids.sortedToc();
513 template<
class ZoneType,
class MeshType>
524 else if (matcher.
size() == 1)
526 return this->indices(matcher.
front(), useGroups);
532 if (useGroups && this->hasGroupIDs())
534 ids.reserve(this->size());
536 const auto& groupLookup = groupZoneIDs();
539 if (matcher(iter.key()))
542 ids.insert(iter.val());
556 return ids.sortedToc();
560 template<
class ZoneType,
class MeshType>
570 return this->indices(
select, useGroups);
573 const wordRes::filter matcher(
select, ignore);
578 if (useGroups && this->hasGroupIDs())
580 ids.reserve(this->size());
582 const auto& groupLookup = groupZoneIDs();
585 if (matcher(iter.key()))
588 ids.insert(iter.val());
602 return ids.sortedToc();
606 template<
class ZoneType,
class MeshType>
620 template<
class ZoneType,
class MeshType>
623 const wordRes& matcher
634 template<
class ZoneType,
class MeshType>
640 if (zoneName.empty())
650 <<
"Zone named " << zoneName <<
" not found. " 651 <<
"List of available zone names: " <<
names() <<
endl;
654 if (disallowGenericZones != 0)
656 Info<<
"Creating dummy zone " << zoneName <<
endl;
657 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
658 zm.emplace_back(zoneName, zm.size(), zm);
666 template<
class ZoneType,
class MeshType>
672 if (zoneName.empty())
677 const PtrList<ZoneType>& zones = *
this;
679 for (
auto iter = zones.begin(); iter != zones.end(); ++iter)
681 const ZoneType* ptr = iter.
get();
683 if (ptr && zoneName == ptr->name())
690 if (disallowGenericZones != 0)
692 Info<<
"Creating dummy zone " << zoneName <<
endl;
693 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
694 zm.emplace_back(zoneName, zm.size(), zm);
701 template<
class ZoneType,
class MeshType>
707 return const_cast<ZoneType*
>(this->cfindZone(zoneName));
711 template<
class ZoneType,
class MeshType>
719 for (
const label zonei : zoneIds)
722 if (zonei < 0 || zonei >= this->size())
725 << ZoneType::typeName <<
" " 726 << zonei <<
" out of range [0," << this->size() <<
")" 733 static_cast<const labelList&>(this->
operator[](zonei))
741 template<
class ZoneType,
class MeshType>
749 return this->selection(this->indices(matcher, useGroups));
753 template<
class ZoneType,
class MeshType>
761 return this->selection(this->indices(matcher, useGroups));
765 template<
class ZoneType,
class MeshType>
774 return *groupIDsPtr_;
778 template<
class ZoneType,
class MeshType>
781 const word& groupName,
785 groupIDsPtr_.reset(
nullptr);
792 for (
const label zonei :
zoneIDs)
794 if (pending.test(zonei))
796 pending.
unset(zonei);
797 zones[zonei].addGroup(groupName);
804 if (pending.test(zonei))
806 zones[zonei].removeGroup(groupName);
813 template<
class ZoneType,
class MeshType>
816 zoneMapPtr_.reset(
nullptr);
817 groupIDsPtr_.reset(
nullptr);
821 template<
class ZoneType,
class MeshType>
824 clearLocalAddressing();
828 for (ZoneType& zn : zones)
830 zn.clearAddressing();
835 template<
class ZoneType,
class MeshType>
838 PtrList<ZoneType>& zones = *
this;
840 for (ZoneType& zn : zones)
842 zn.clearPrimitives();
847 template<
class ZoneType,
class MeshType>
855 template<
class ZoneType,
class MeshType>
861 bool hasError =
false;
865 for (
const ZoneType& zn : zones)
867 hasError |= zn.checkDefinition(report);
874 template<
class ZoneType,
class MeshType>
880 if (!Pstream::parRun())
885 const PtrList<ZoneType>& zones = *
this;
887 bool hasError =
false;
890 const wordList localTypes(this->types());
897 globalIndex::gatherNonLocal{},
905 for (
const int proci :
procAddr.subProcs())
907 const auto procNames(allNames.slice(
procAddr.range(proci)));
908 const auto procTypes(allTypes.slice(
procAddr.range(proci)));
910 if (procNames != localNames || procTypes != localTypes)
916 Info<<
" ***Inconsistent zones across processors, " 917 "processor 0 has zone names:" << localNames
918 <<
" zone types:" << localTypes
919 <<
" processor " << proci
920 <<
" has zone names:" << procNames
921 <<
" zone types:" << procTypes
927 Pstream::broadcast(hasError);
932 for (
const ZoneType& zn : zones)
934 if (zn.checkParallelSync(
false))
938 if (
debug || (report && Pstream::master()))
940 Info<<
" ***Zone " << zn.name()
941 <<
" of type " << zn.type()
942 <<
" is not correctly synchronised" 943 <<
" across coupled boundaries." 944 <<
" (coupled faces are either not both" 945 <<
" present in set or have same flipmap)" <<
endl;
955 template<
class ZoneType,
class MeshType>
958 PtrList<ZoneType>& zones = *
this;
960 for (ZoneType& zn : zones)
967 template<
class ZoneType,
class MeshType>
971 if (zoneNames.empty())
973 this->removeMetaData();
978 meta.
set(
"names", zoneNames);
983 template<
class ZoneType,
class MeshType>
993 template<
class ZoneType,
class MeshType>
999 const label zonei = findZoneID(zoneName);
1004 <<
"Zone named " << zoneName <<
" not found." <<
nl 1005 <<
"Available zone names: " <<
names() <<
endl 1009 return operator[](zonei);
1013 template<
class ZoneType,
class MeshType>
1016 const word& zoneName
1019 const label zonei = findZoneID(zoneName);
1024 <<
"Zone named " << zoneName <<
" not found." <<
nl 1025 <<
"Available zone names: " <<
names() <<
endl 1029 return operator[](zonei);
1033 template<
class ZoneType,
class MeshType>
1036 const word& zoneName,
1040 ZoneType* ptr = findZone(zoneName);
1042 const bool existing = bool(ptr);
1046 ptr =
new ZoneType(zoneName, this->size(), *
this);
1047 this->push_back(ptr);
1052 Info<< ZoneType::typeName <<
' ' << zoneName
1053 <<
" (" << (existing ?
"existing" :
"new")
1054 <<
" at index " << ptr->index() <<
')' 1064 template<
class ZoneType,
class MeshType>
1068 const ZoneMesh<ZoneType, MeshType>& zones
1071 const label sz = zones.size();
1075 os << sz <<
nl << token::BEGIN_LIST;
1077 for (label i=0; i < sz; ++i)
1079 zones[i].writeDict(
os);
1082 os << token::END_LIST;
1086 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.
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.
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.
Functions to operate on Pointer Lists.
const T * get(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
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 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.
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)
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)