46 template<
class MatchPredicate>
50 const MatchPredicate& nameMatcher
61 lookupName =
"cellTable_" +
Foam::name(iter.key());
64 if (nameMatcher(lookupName))
66 output.emplace(iter.key(), std::move(lookupName));
78 void Foam::cellTable::addDefaults()
82 if (!iter().
found(
"MaterialType"))
90 void Foam::cellTable::setEntry
100 iterator iter =
find(
id);
116 const objectRegistry& obr,
118 const fileName& instance
121 readDict(obr,
name, instance);
132 if (maxId < iter.key())
144 label maxId = this->maxIndex();
167 const auto iter = cfind(
id);
170 iter.val().readIfPresent(
"Label", lookupName);
173 if (lookupName.empty() &&
id >= 0)
191 const auto&
dict = iter.val();
217 output.emplace(iter.key(), std::move(lookupType));
242 lookupName =
"cellTable_" +
Foam::name(iter.key());
245 output.emplace(iter.key(), std::move(lookupName));
255 return selectType(
"fluid");
261 return selectType(
"solid");
267 return selectType(
"shell");
273 setEntry(
id,
"MaterialType", matlType);
279 setEntry(
id,
"Label",
name);
285 iterator iter =
find(
id);
287 if (!iter.good() || !iter().found(
"Label"))
296 const objectRegistry& obr,
298 const fileName& instance
304 IOMap<dictionary> ioObj
317 if (ioObj.headerOk())
324 Info<<
"no constant/cellTable information available" <<
endl;
331 const objectRegistry& obr,
333 const fileName& instance
337 IOMap<dictionary> ioObj
351 "persistent data for third-party mesh <-> OpenFOAM translation";
353 Info<<
"Writing " << ioObj.name() <<
" to " 354 << ioObj.objectRelPath() <<
endl;
356 OFstream
os(ioObj.objectPath());
357 ioObj.writeHeader(
os);
385 label nZoneCells = 0;
388 label unZonedType = zoneNames.
size() + 1;
394 nZoneCells += cZone.
size();
397 dict.
add(
"Label", zoneNames[zoneI]);
446 for (
const label
id : namesLookup.
sortedToc())
448 typeToZone(
id) = zonei;
449 zoneNames[zonei] = namesLookup[id];
455 List<DynamicList<label>> zoneCells(zoneNames.
size());
459 label zonei = typeToZone.
lookup(tableIds[celli], -1);
462 zoneCells[zonei].push_back(celli);
467 DynamicList<label> zoneUsed(zoneCells.size());
471 zoneCells[zonei].shrink();
472 if (!zoneCells[zonei].empty())
474 zoneUsed.push_back(zonei);
478 const label nZonesUsed = zoneUsed.size();
485 Info<<
"cellZones not used" <<
endl;
488 czMesh.resize(nZonesUsed);
492 const label origZonei = zoneUsed[zonei];
494 Info<<
"cellZone " << zonei
495 <<
" (size: " << zoneCells[origZonei].size()
496 <<
") name: " << zoneNames[origZonei] <<
endl;
503 zoneNames[origZonei],
504 zoneCells[origZonei],
521 Map<word> origNames(this->
names());
525 for (
const entry& dEntry : mapDict)
527 wordRes patterns(dEntry.stream());
533 if (patterns.match(namesIter()))
535 matches.insert(namesIter.key(), namesIter());
541 label targetId = this->
findIndex(dEntry.keyword());
543 Info<<
"combine cellTable: " << dEntry.keyword();
547 targetId =
min(matches.toc());
548 operator[](targetId).set(
"Label", dEntry.keyword());
559 matches.erase(targetId);
560 origNames.erase(targetId);
563 this->
erase(matches);
564 origNames.erase(matches);
568 mapping[matchIter.key()] = targetId;
569 Info<<
" " << matchIter();
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
void size(const label n)
Older name for setAddressableSize.
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.
Map< word > shells() const
Return a Map of (id => name) for shells.
void resize(const label len)
Adjust allocated size of list.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
static const char *const defaultMaterial_
bool found(const Key &key) const
Same as contains()
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
void setName(const label, const word &)
Assign name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Map< word > solids() const
Return a Map of (id => name) for solids.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Ignore writing from objectRegistry::writeObject()
void setMaterial(const label, const word &)
Assign material Type.
void operator=(const cellTable &)
Assignment.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
void writeDict(const objectRegistry &, const word &name="cellTable", const fileName &instance="constant") const
Write constant/cellTable for later reuse.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
Unary and binary predicates that always return true, useful for templating.
void readDict(const objectRegistry &, const word &name="cellTable", const fileName &instance="constant")
Read constant/cellTable.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
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...
A class for handling words, derived from Foam::string.
void clear()
Remove all entries from table.
static Istream & input(Istream &is, IntRange< T > &range)
Map< word > names() const
Return the extracted Map of (id => name)
Map< word > materialTypes() const
Return a Map of (id => fluid|solid|shell)
Reading is optional [identical to LAZY_READ].
#define forAllIters(container, iter)
Iterate across all elements in the container object.
label maxIndex() const
The max table index, -1 if empty.
A List of wordRe with additional matching capabilities.
Map< word > fluids() const
Return a Map of (id => name) for fluids.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
The cellTable persistent data saved as a Map<dictionary>.
label push_back(const dictionary &dict)
Add to the end, return index.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
word name(const label id) const
The 'Label' name corresponding to id, or cellTable_ID if not otherwise defined.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
static Map< word > names_impl(const Map< dictionary > &input, const MatchPredicate &nameMatcher)
OBJstream os(runTime.globalPath()/outputName)
cellTable() noexcept=default
Default construct.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
const T & lookup(const Key &key, const T &deflt) const
Return hashed entry if it exists, or return the given default.
label nCells() const noexcept
Number of mesh cells.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
List< label > sortedToc() const
The table of contents (the keys) in sorted order.
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
Automatically write from objectRegistry::writeObject()
void combine(const dictionary &mapDict, labelList &tableIds)
Combine tableIds together.
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
wordList names() const
A list of the zone names.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static Ostream & output(Ostream &os, const IntRange< T > &range)
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Mesh consisting of general polyhedral cells.
label findIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Deprecated(2017-10) search for first occurrence of the given element.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
List< label > labelList
A List of labels.
label findIndex(const word &name) const
The index corresponding to entry with 'Label' of given name, or -1 if not found.
void operator=(const this_type &rhs)
Copy assignment.
Map< word > selectType(const word &materialType) const
Return the extracted Map of (id => name) for materialType (fluid | solid | shell) ...
Do not request registration (bool: false)
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
forAllConstIters(mixture.phases(), phase)
A HashTable to objects of type <T> with a label key.