40 template<
class ZoneType,
class MeshType>
50 template<
class ZoneType,
class MeshType>
56 <<
"zone map already calculated" 64 const PtrList<ZoneType>& zones = *
this;
66 for (
const ZoneType& zn : zones)
68 nObjects += zn.size();
71 zoneMapPtr_.reset(
new Map<label>(2*nObjects));
72 auto& zm = *zoneMapPtr_;
79 for (
const ZoneType& zn : zones)
83 for (
const label idx : labels)
85 zm.insert(idx, zonei);
94 template<
class ZoneType,
class MeshType>
100 return !groupIDsPtr_->
empty();
103 const PtrList<ZoneType>& zones = *
this;
105 for (
const ZoneType& zn : zones)
107 if (!zn.inGroups().empty())
117 template<
class ZoneType,
class MeshType>
125 groupIDsPtr_.reset(
new HashTable<labelList>(16));
126 auto& groupLookup = *groupIDsPtr_;
128 const PtrList<ZoneType>& zones = *
this;
132 const wordList& groups = zones[zonei].inGroups();
134 for (
const word& groupName : groups)
136 groupLookup(groupName).
append(zonei);
143 if (groupLookup.erase(zones[zonei].name()))
146 <<
"Removed group '" << zones[zonei].name()
147 <<
"' which clashes with zone " << zonei
148 <<
" of the same name." 155 template<
class ZoneType,
class MeshType>
158 if (isReadRequired() || (isReadOptional() && headerOk()))
161 warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
163 PtrList<ZoneType>& zones = *
this;
166 Istream& is = readStream(typeName);
168 PtrList<entry> patchEntries(is);
169 zones.resize(patchEntries.size());
179 patchEntries[zonei].keyword(),
180 patchEntries[zonei].
dict(),
199 template<
class ZoneType,
class MeshType>
214 template<
class ZoneType,
class MeshType>
218 const MeshType&
mesh,
231 template<
class ZoneType,
class MeshType>
235 const MeshType&
mesh,
251 zones.
set(zonei, pzm[zonei].clone(*
this));
259 template<
class ZoneType,
class MeshType>
268 template<
class ZoneType,
class MeshType>
281 template<
class ZoneType,
class MeshType>
284 const label objectIndex
287 return zoneMap().lookup(objectIndex, -1);
291 template<
class ZoneType,
class MeshType>
298 template<
class ZoneType,
class MeshType>
305 template<
class ZoneType,
class MeshType>
308 return this->groupZoneIDs().sortedToc();
312 template<
class ZoneType,
class MeshType>
322 template<
class ZoneType,
class MeshType>
333 template<
class ZoneType,
class MeshType>
343 template<
class ZoneType,
class MeshType>
356 template<
class ZoneType,
class MeshType>
370 template<
class ZoneType,
class MeshType>
383 const bool checkGroups = (useGroups && this->hasGroupIDs());
389 ids.
resize(2*this->size());
396 const auto& groupLookup = groupZoneIDs();
399 if (matcher.
match(iter.key()))
402 ids.insert(iter.val());
427 else if (checkGroups)
429 const auto iter = groupZoneIDs().cfind(matcher);
434 ids.insert(iter.val());
439 return ids.sortedToc();
443 template<
class ZoneType,
class MeshType>
454 else if (matcher.
size() == 1)
456 return this->indices(matcher.
first(), useGroups);
462 if (useGroups && this->hasGroupIDs())
464 ids.
resize(2*this->size());
466 const auto& groupLookup = groupZoneIDs();
469 if (matcher.
match(iter.key()))
472 ids.insert(iter.val());
486 return ids.sortedToc();
490 template<
class ZoneType,
class MeshType>
504 template<
class ZoneType,
class MeshType>
507 const wordRes& matcher
518 template<
class ZoneType,
class MeshType>
524 if (zoneName.empty())
534 <<
"Zone named " << zoneName <<
" not found. " 535 <<
"List of available zone names: " <<
names() <<
endl;
538 if (disallowGenericZones != 0)
540 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
543 Info<<
"Creating dummy zone " << zoneName <<
endl;
544 zm.append(
new ZoneType(zoneName, zoneId, zm));
552 template<
class ZoneType,
class MeshType>
558 if (zoneName.empty())
563 const PtrList<ZoneType>& zones = *
this;
565 for (
auto iter = zones.begin(); iter != zones.end(); ++iter)
567 const ZoneType* ptr = iter.
get();
569 if (ptr && zoneName == ptr->name())
576 if (disallowGenericZones != 0)
578 auto& zm =
const_cast<ZoneMesh<ZoneType, MeshType>&
>(*this);
580 Info<<
"Creating dummy zone " << zoneName <<
endl;
581 zm.append(
new ZoneType(zoneName, zm.size(), zm));
588 template<
class ZoneType,
class MeshType>
594 return const_cast<ZoneType*
>(this->cfindZone(zoneName));
598 template<
class ZoneType,
class MeshType>
606 for (
const label zonei : zoneIds)
609 if (zonei < 0 || zonei >= this->size())
612 << ZoneType::typeName <<
" " 613 << zonei <<
" out of range [0," << this->size() <<
")" 620 static_cast<const labelList&>(this->
operator[](zonei))
628 template<
class ZoneType,
class MeshType>
636 return this->selection(this->indices(matcher, useGroups));
640 template<
class ZoneType,
class MeshType>
648 return this->selection(this->indices(matcher, useGroups));
652 template<
class ZoneType,
class MeshType>
661 return *groupIDsPtr_;
665 template<
class ZoneType,
class MeshType>
668 const word& groupName,
672 groupIDsPtr_.clear();
679 for (
const label zonei :
zoneIDs)
681 zones[zonei].inGroups().appendUniq(groupName);
682 doneZone[zonei] =
true;
688 if (!doneZone[zonei])
690 wordList& groups = zones[zonei].inGroups();
692 if (groups.found(groupName))
697 if (groups[i] != groupName)
699 groups[newi++] = groups[i];
709 template<
class ZoneType,
class MeshType>
713 groupIDsPtr_.clear();
715 PtrList<ZoneType>& zones = *
this;
717 for (ZoneType& zn : zones)
719 zn.clearAddressing();
724 template<
class ZoneType,
class MeshType>
732 template<
class ZoneType,
class MeshType>
738 bool hasError =
false;
742 for (
const ZoneType& zn : zones)
744 hasError |= zn.checkDefinition(report);
751 template<
class ZoneType,
class MeshType>
757 if (!Pstream::parRun())
762 const PtrList<ZoneType>& zones = *
this;
764 bool hasError =
false;
767 const wordList localTypes(this->types());
774 globalIndex::gatherNonLocal{},
782 for (
const int proci :
procAddr.subProcs())
784 const auto procNames(allNames.slice(
procAddr.range(proci)));
785 const auto procTypes(allTypes.slice(
procAddr.range(proci)));
787 if (procNames != localNames || procTypes != localTypes)
793 Info<<
" ***Inconsistent zones across processors, " 794 "processor 0 has zone names:" << localNames
795 <<
" zone types:" << localTypes
796 <<
" processor " << proci
797 <<
" has zone names:" << procNames
798 <<
" zone types:" << procTypes
804 Pstream::broadcast(hasError);
809 for (
const ZoneType& zn : zones)
811 if (zn.checkParallelSync(
false))
815 if (
debug || (report && Pstream::master()))
817 Info<<
" ***Zone " << zn.name()
818 <<
" of type " << zn.type()
819 <<
" is not correctly synchronised" 820 <<
" across coupled boundaries." 821 <<
" (coupled faces are either not both" 822 <<
" present in set or have same flipmap)" <<
endl;
832 template<
class ZoneType,
class MeshType>
835 PtrList<ZoneType>& zones = *
this;
837 for (ZoneType& zn : zones)
844 template<
class ZoneType,
class MeshType>
848 if (zoneNames.empty())
850 this->removeMetaData();
855 meta.
set(
"names", zoneNames);
860 template<
class ZoneType,
class MeshType>
870 template<
class ZoneType,
class MeshType>
876 const label zonei = findZoneID(zoneName);
881 <<
"Zone named " << zoneName <<
" not found." <<
nl 882 <<
"Available zone names: " <<
names() <<
endl 886 return operator[](zonei);
890 template<
class ZoneType,
class MeshType>
896 const label zonei = findZoneID(zoneName);
901 <<
"Zone named " << zoneName <<
" not found." <<
nl 902 <<
"Available zone names: " <<
names() <<
endl 906 return operator[](zonei);
910 template<
class ZoneType,
class MeshType>
913 const word& zoneName,
917 ZoneType* ptr = findZone(zoneName);
919 const bool existing = bool(ptr);
923 ptr =
new ZoneType(zoneName, this->size(), *
this);
929 Info<< ZoneType::typeName <<
' ' << zoneName
930 <<
" (" << (existing ?
"existing" :
"new")
931 <<
" at index " << ptr->index() <<
')' 941 template<
class ZoneType,
class MeshType>
945 const ZoneMesh<ZoneType, MeshType>& zones
948 const label sz = zones.size();
952 os << sz <<
nl << token::BEGIN_LIST;
954 for (label i=0; i < sz; ++i)
956 zones[i].writeDict(
os);
959 os << token::END_LIST;
963 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.
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.
void append(const T &val)
Append an element at the end of the list.
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.
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 the UList is empty (ie, size() is zero)
T & first()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
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...
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
void resize(const label sz)
Resize the hash table for efficiency.
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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 elements in the list.
A List of wordRe with additional matching capabilities.
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.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
List< word > wordList
A List of words.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
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)
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
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.
bool match(const std::string &text, bool literal=false) const
Smart match as regular expression or as a string.
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.
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)