Go to the documentation of this file.
39 template<
class ZoneType,
class MeshType>
49 template<
class ZoneType,
class MeshType>
55 <<
"zone map already calculated"
63 const PtrList<ZoneType>& zones = *
this;
65 for (
const ZoneType& zn : zones)
67 nObjects += zn.size();
70 zoneMapPtr_.reset(
new Map<label>(2*nObjects));
71 auto& zm = *zoneMapPtr_;
78 for (
const ZoneType& zn : zones)
82 for (
const label idx : labels)
84 zm.insert(idx, zonei);
93 template<
class ZoneType,
class MeshType>
99 return !groupIDsPtr_->empty();
102 const PtrList<ZoneType>& zones = *
this;
104 for (
const ZoneType& zn : zones)
106 if (!zn.inGroups().empty())
116 template<
class ZoneType,
class MeshType>
124 groupIDsPtr_.reset(
new HashTable<labelList>(16));
125 auto& groupLookup = *groupIDsPtr_;
127 const PtrList<ZoneType>& zones = *
this;
131 const wordList& groups = zones[zonei].inGroups();
133 for (
const word& groupName : groups)
135 groupLookup(groupName).
append(zonei);
142 if (groupLookup.erase(zones[zonei].name()))
145 <<
"Removed group '" << zones[zonei].name()
146 <<
"' which clashes with zone " << zonei
147 <<
" of the same name."
154 template<
class ZoneType,
class MeshType>
159 readOpt() == IOobject::MUST_READ
160 || readOpt() == IOobject::MUST_READ_IF_MODIFIED
161 || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
165 warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
167 PtrList<ZoneType>& zones = *
this;
170 Istream& is = readStream(typeName);
172 PtrList<entry> patchEntries(is);
173 zones.resize(patchEntries.size());
182 patchEntries[zonei].keyword(),
183 patchEntries[zonei].
dict(),
205 template<
class ZoneType,
class MeshType>
220 template<
class ZoneType,
class MeshType>
224 const MeshType&
mesh,
237 template<
class ZoneType,
class MeshType>
241 const MeshType&
mesh,
257 zones.
set(zonei, pzm[zonei].clone(*this).ptr());
265 template<
class ZoneType,
class MeshType>
274 template<
class ZoneType,
class MeshType>
287 template<
class ZoneType,
class MeshType>
290 const label objectIndex
293 return zoneMap().lookup(objectIndex, -1);
297 template<
class ZoneType,
class MeshType>
304 template<
class ZoneType,
class MeshType>
311 template<
class ZoneType,
class MeshType>
321 template<
class ZoneType,
class MeshType>
332 template<
class ZoneType,
class MeshType>
342 template<
class ZoneType,
class MeshType>
355 template<
class ZoneType,
class MeshType>
369 template<
class ZoneType,
class MeshType>
382 const bool checkGroups = (useGroups && this->hasGroupIDs());
388 ids.resize(2*this->size());
395 const auto& groupLookup = groupZoneIDs();
398 if (matcher.
match(iter.key()))
426 else if (checkGroups)
428 const auto iter = groupZoneIDs().cfind(matcher);
438 return ids.sortedToc();
442 template<
class ZoneType,
class MeshType>
453 else if (matcher.size() == 1)
455 return this->indices(matcher.first(), useGroups);
461 if (useGroups && this->hasGroupIDs())
463 ids.resize(2*this->size());
465 const auto& groupLookup = groupZoneIDs();
468 if (matcher.
match(iter.key()))
485 return ids.sortedToc();
489 template<
class ZoneType,
class MeshType>
503 template<
class ZoneType,
class MeshType>
517 template<
class ZoneType,
class MeshType>
523 if (zoneName.empty())
533 <<
"Zone named " << zoneName <<
" not found. "
534 <<
"List of available zone names: " <<
names() <<
endl;
537 if (disallowGenericZones != 0)
542 Info<<
"Creating dummy zone " << zoneName <<
endl;
543 zm.append(
new ZoneType(zoneName, zoneId, zm));
551 template<
class ZoneType,
class MeshType>
557 if (zoneName.empty())
564 for (
auto iter = zones.begin(); iter != zones.end(); ++iter)
566 const ZoneType* ptr = iter.get();
568 if (ptr && zoneName == ptr->name())
575 if (disallowGenericZones != 0)
579 Info<<
"Creating dummy zone " << zoneName <<
endl;
580 zm.append(
new ZoneType(zoneName, zm.size(), zm));
587 template<
class ZoneType,
class MeshType>
593 return const_cast<ZoneType*
>(this->cfindZone(zoneName));
597 template<
class ZoneType,
class MeshType>
605 for (
const label zonei : zoneIds)
608 if (zonei < 0 || zonei >= this->size())
611 << ZoneType::typeName <<
" "
612 << zonei <<
" out of range [0," << this->size() <<
")"
619 static_cast<const labelList&
>(this->
operator[](zonei))
627 template<
class ZoneType,
class MeshType>
635 return this->selection(this->indices(matcher, useGroups));
639 template<
class ZoneType,
class MeshType>
647 return this->selection(this->indices(matcher, useGroups));
651 template<
class ZoneType,
class MeshType>
660 return *groupIDsPtr_;
664 template<
class ZoneType,
class MeshType>
667 const word& groupName,
671 groupIDsPtr_.clear();
675 boolList doneZone(zones.size(),
false);
678 for (
const label zonei :
zoneIDs)
680 zones[zonei].inGroups().appendUniq(groupName);
681 doneZone[zonei] =
true;
687 if (!doneZone[zonei])
689 wordList& groups = zones[zonei].inGroups();
691 if (groups.found(groupName))
696 if (groups[i] != groupName)
698 groups[newi++] = groups[i];
708 template<
class ZoneType,
class MeshType>
712 groupIDsPtr_.clear();
716 for (ZoneType& zn : zones)
718 zn.clearAddressing();
723 template<
class ZoneType,
class MeshType>
731 template<
class ZoneType,
class MeshType>
737 bool hasError =
false;
741 for (
const ZoneType& zn : zones)
743 hasError |= zn.checkDefinition(report);
750 template<
class ZoneType,
class MeshType>
756 if (!Pstream::parRun())
763 bool hasError =
false;
767 allNames[Pstream::myProcNo()] = this->
names();
768 Pstream::gatherList(allNames);
769 Pstream::scatterList(allNames);
772 allTypes[Pstream::myProcNo()] = this->types();
773 Pstream::gatherList(allTypes);
774 Pstream::scatterList(allTypes);
778 for (label proci = 1; proci < allNames.size(); ++proci)
782 (allNames[proci] != allNames[0])
783 || (allTypes[proci] != allTypes[0])
788 if (
debug || (report && Pstream::master()))
790 Info<<
" ***Inconsistent zones across processors, "
791 "processor 0 has zone names:" << allNames[0]
792 <<
" zone types:" << allTypes[0]
793 <<
" processor " << proci <<
" has zone names:"
795 <<
" zone types:" << allTypes[proci]
804 for (
const ZoneType& zn : zones)
806 if (zn.checkParallelSync(
false))
810 if (
debug || (report && Pstream::master()))
812 Info<<
" ***Zone " << zn.name()
813 <<
" of type " << zn.type()
814 <<
" is not correctly synchronised"
815 <<
" across coupled boundaries."
816 <<
" (coupled faces are either not both"
817 <<
" present in set or have same flipmap)" <<
endl;
827 template<
class ZoneType,
class MeshType>
832 for (ZoneType& zn : zones)
839 template<
class ZoneType,
class MeshType>
843 if (zoneNames.empty())
845 this->removeMetaData();
850 meta.
set(
"names", zoneNames);
855 template<
class ZoneType,
class MeshType>
865 template<
class ZoneType,
class MeshType>
871 const label zonei = findZoneID(zoneName);
876 <<
"Zone named " << zoneName <<
" not found." <<
nl
877 <<
"Available zone names: " <<
names() <<
endl
881 return operator[](zonei);
885 template<
class ZoneType,
class MeshType>
891 const label zonei = findZoneID(zoneName);
896 <<
"Zone named " << zoneName <<
" not found." <<
nl
897 <<
"Available zone names: " <<
names() <<
endl
901 return operator[](zonei);
905 template<
class ZoneType,
class MeshType>
908 const word& zoneName,
912 ZoneType* ptr = findZone(zoneName);
914 const bool existing =
bool(ptr);
918 ptr =
new ZoneType(zoneName, this->size(), *
this);
924 Info<< ZoneType::typeName <<
' ' << zoneName
925 <<
" (" << (existing ?
"existing" :
"new")
926 <<
" at index " << ptr->index() <<
')'
936 template<
class ZoneType,
class MeshType>
943 const label sz = zones.size();
947 os << sz <<
nl << token::BEGIN_LIST;
949 for (label i=0; i < sz; ++i)
951 zones[i].writeDict(
os);
954 os << token::END_LIST;
958 os << sz << token::BEGIN_LIST << token::END_LIST;
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
int debug
Static debugging option.
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
List< label > labelList
A List of labels.
void clear()
Clear the zones.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
bool isPattern() const noexcept
The wordRe is treated as a pattern, not as literal string.
A class for handling words, derived from Foam::string.
bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
void resize(const label len)
Adjust allocated size of list.
const HashTable< labelList > & groupZoneIDs() const
The zone indices per zone group.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
void set(const bitSet &bitset)
Set specified bits from another bitset.
A HashTable to objects of type <T> with a label key.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
void append(const T &val)
Append an element at the end of the list.
Functions to operate on Pointer Lists.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
bitSet bitset(const labelHashSet &locations)
Transform the on locations to a bitSet.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
const labelIOList & zoneIDs
#define forAll(list, i)
Loop across all elements in list.
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
List< word > wordList
A List of words.
void setGroup(const word &groupName, const labelUList &zoneIDs)
Set/add group with zones.
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
messageStream Info
Information stream (stdout output on master, null elsewhere)
#define DebugInFunction
Report an information message using Foam::Info.
Extract name (as a word) from an object, typically using its name() method.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
OBJstream os(runTime.globalPath()/outputName)
errorManip< error > abort(error &err)
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
friend Ostream & operator(Ostream &os, const ZoneMesh< ZoneType, MeshType > &zones)
wordList names() const
A list of the zone names.
void resize(const label newLen)
Adjust size of PtrList.
A HashTable similar to std::unordered_map.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
wordList sortedNames() const
Sorted list of the zone names.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
forAllConstIters(mixture.phases(), phase)
A List of wordRe with additional matching capabilities.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
label firstMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Find first list item with 'name()' that matches, -1 on failure.
void updateMetaData()
Update internal meta-data (eg, prior to writing)
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
bitSet selection(const labelUList &zoneIds) const
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void clearAddressing()
Clear addressing.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
Extract type (as a word) from an object, typically using its type() method.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
#define WarningInFunction
Report a warning using Foam::Warning.
bool match(const std::string &text, bool literal=false) const
Smart match as regular expression or as a string.
wordList types() const
Return a list of zone types.