40 const bool validBoundary
46 <<
"boundary already exists"
50 globalMeshDataPtr_.reset(
nullptr);
54 setPrimitiveMeshData();
66 const bool validBoundary
72 addFaPatches(plist, validBoundary);
78 const word& patchName,
83 if (!patchName.empty())
85 onePatchDict.
add(
"name", patchName);
87 if (!patchType.empty())
89 onePatchDict.
add(
"type", patchType);
92 return createPatchList
103 const dictionary& bndDict,
104 const word& emptyPatchName,
105 const dictionary* defaultPatchDefinition
111 DynamicList<faPatchData> faPatchDefs(bndDict.size() + 8);
112 for (
const entry& dEntry : bndDict)
114 if (!dEntry.isDict())
117 <<
"Not a dictionary entry: " << dEntry.name() <<
nl;
120 const dictionary& patchDict = dEntry.dict();
123 faPatchDefs.append(faPatchData());
125 auto& patchDef = faPatchDefs.last();
126 patchDef.name_ = dEntry.keyword();
127 patchDef.type_ = patchDict.get<word>(
"type");
132 if (patchDict.readIfPresent(
"ownerPolyPatch", patchName))
134 patchDef.ownerPolyPatchId_ = pbm.findPatchID(patchName);
135 if (patchDef.ownerPolyPatchId_ < 0)
138 <<
"ownerPolyPatch " << patchName <<
" not found"
144 patchDict.readEntry(
"neighbourPolyPatch", patchName);
146 patchDef.neighPolyPatchId_ = pbm.findPatchID(patchName);
147 if (patchDef.neighPolyPatchId_ < 0)
150 <<
"neighbourPolyPatch " << patchName <<
" not found"
157 if (!emptyPatchName.empty())
159 faPatchDefs.append(faPatchData());
161 auto& patchDef = faPatchDefs.last();
162 patchDef.name_ = emptyPatchName;
163 patchDef.type_ =
"empty";
166 label nWarnUndefinedPatch(5);
169 const label undefPatchIndex = faPatchDefs.size();
171 faPatchDefs.append(faPatchData());
173 auto& patchDef = faPatchDefs.last();
174 patchDef.name_ =
"undefined";
175 patchDef.type_ =
"patch";
177 if (defaultPatchDefinition)
181 (*defaultPatchDefinition).readIfPresent(
"name", patchDef.name_)
186 nWarnUndefinedPatch = 0;
188 (*defaultPatchDefinition).readIfPresent(
"type", patchDef.type_);
195 List<Pair<patchTuple>> bndEdgeConnections
197 this->getBoundaryEdgeConnections()
201 this->setBoundaryConnections(bndEdgeConnections);
205 labelList patchDefLookup(bndEdgeConnections.size(), -1);
207 Map<labelHashSet> procConnections;
213 forAll(bndEdgeConnections, connecti)
215 const Pair<patchTuple>& connection = bndEdgeConnections[connecti];
216 const auto& a = connection.first();
217 const auto&
b = connection.second();
221 if (a.is_finiteArea())
223 if (
b.is_finiteArea())
226 if (a.procNo() ==
b.procNo())
229 <<
"Processor-processor addressing error:" <<
nl
230 <<
"Both connections have the same processor: "
234 else if (a.is_localProc())
236 procConnections(
b.procNo()).insert(connecti);
240 procConnections(a.procNo()).insert(connecti);
245 else if (a.is_localProc())
247 patchPair.first() = a.realPatchi();
248 patchPair.second() =
b.realPatchi();
251 else if (
b.is_finiteArea() &&
b.is_localProc())
253 patchPair.
first() =
b.realPatchi();
254 patchPair.second() = a.realPatchi();
261 label bestPatchDefi = -1;
263 const label nPatchDefs = (patchPair.valid() ? faPatchDefs.size() : 0);
265 for (label patchDefi = 0; patchDefi < nPatchDefs; ++patchDefi)
267 const int match = faPatchDefs[patchDefi].matchPatchPair(patchPair);
271 bestPatchDefi = patchDefi;
274 else if (match == 2 && bestPatchDefi < 0)
277 bestPatchDefi = patchDefi;
281 if (bestPatchDefi < 0)
283 bestPatchDefi = undefPatchIndex;
286 patchDefLookup[connecti] = bestPatchDefi;
287 patchDefsUsed.insert(bestPatchDefi);
291 if (!
returnReduce(patchDefsUsed.found(undefPatchIndex), orOp<bool>()))
293 faPatchDefs.remove(undefPatchIndex);
297 patchDefsUsed.insert(undefPatchIndex);
302 forAll(patchDefLookup, connecti)
304 if (patchDefLookup[connecti] == undefPatchIndex)
306 const auto& connection = bndEdgeConnections[connecti];
308 const auto& a = connection.first();
309 const auto&
b = connection.second();
311 if (a.is_localProc() && a.is_finiteArea())
313 badEdges.insert(a.patchEdgei());
315 else if (
b.is_localProc() &&
b.is_finiteArea())
317 badEdges.insert(
b.patchEdgei());
320 if (badEdges.size() <= nWarnUndefinedPatch)
322 Pout<<
"Undefined connection: "
323 <<
"(patch:" << a.realPatchi()
324 <<
" face:" << a.meshFacei()
325 <<
") and (patch:" <<
b.realPatchi()
326 <<
" face:" <<
b.meshFacei() <<
") connects: "
327 << pbm[a.realPatchi()].
name() <<
" to "
328 << pbm[
b.realPatchi()].name() <<
nl;
333 if ((nBadEdges =
returnReduce(badEdges.size(), sumOp<label>())) > 0)
338 Info<<
"Had " << nBadEdges <<
'/'
340 <<
" undefined edge connections, added to defaultPatch: "
341 << faPatchDefs[undefPatchIndex].name_ <<
nl;
343 if (nWarnUndefinedPatch)
349 patch().localPoints(),
353 mesh().time().globalPath()
354 / (
"faMesh-construct.undefEdges")
371 Map<label> procToDefLookup(2*procConnections.size());
373 faPatchDefs.reserve(faPatchDefs.size() + procConnections.size());
375 for (
const label otherProci : procConnections.sortedToc())
377 const label patchDefi = faPatchDefs.size();
378 procToDefLookup.insert(otherProci, patchDefi);
381 faPatchDefs.append(faPatchData());
382 auto& patchDef = faPatchDefs.last();
392 DynamicList<label> selectEdges(bndEdgeConnections.size());
393 label nOffProcessorEdges = 0;
395 for (
const label patchDefi : patchDefsUsed.sortedToc())
397 auto& patchDef = faPatchDefs[patchDefi];
403 forAll(patchDefLookup, connecti)
405 if (patchDefLookup[connecti] == patchDefi)
407 const auto& a = bndEdgeConnections[connecti].first();
408 const auto&
b = bndEdgeConnections[connecti].second();
410 if (a.is_localProc() && a.is_finiteArea())
412 selectEdges.
append(a.patchEdgei());
414 else if (
b.is_localProc() &&
b.is_finiteArea())
416 selectEdges.append(
b.patchEdgei());
421 <<
"Error in programming logic" <<
nl
425 if (a.is_localProc() !=
b.is_localProc())
427 ++nOffProcessorEdges;
430 patchDefLookup[connecti] = -2;
438 patchDef.edgeLabels_ = selectEdges;
443 Pout<<
"Had " << nOffProcessorEdges
444 <<
" patch edges connected off-processor" <<
endl;
449 <<
" patch edges connected off-processor" <<
endl;
454 for (
const label otherProci : procToDefLookup.sortedToc())
456 const label patchDefi = procToDefLookup[otherProci];
458 auto& patchDef = faPatchDefs[patchDefi];
464 for (
const label connecti : procConnections(otherProci).
sortedToc())
466 const auto& connection = bndEdgeConnections[connecti];
467 const auto& a = connection.first();
468 const auto&
b = connection.second();
470 if (a.is_localProc())
472 selectEdges.
append(a.patchEdgei());
474 else if (
b.is_localProc())
476 selectEdges.append(
b.patchEdgei());
481 <<
"Error in programming logic" <<
nl
485 patchDefLookup[connecti] = -2;
491 patchDef.edgeLabels_ = selectEdges;
500 for (faPatchData& patchDef : faPatchDefs)
508 patchDef.dict(
false),
515 newPatches[
nPatches].resetEdges(std::move(patchDef.edgeLabels_));
523 Pout<<
"Created new finiteArea patches:" <<
nl;
524 for (
const faPatch&
p : newPatches)
527 <<
" name:" <<
p.
name()
528 <<
" type:" <<
p.type() <<
nl;
532 Pout<<
"addressed: " << nTotal
533 <<
'/' <<
patch().nBoundaryEdges() <<
" edges" <<
endl;
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
const word & name() const noexcept
Return the object name.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void append(const T &val)
Append an element at the end of the list.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
T & first()
Return the first element of the list.
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
bool checkDefinition(const bool report=false) const
Check boundary definition.
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
void addFaPatches(faPatchList &plist, const bool validBoundary=true)
Add boundary patches. Constructor helper.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
int myProcNo() const noexcept
Return processor number.
const fileName & output() const noexcept
The current output file name.
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
virtual bool writeGeometry()
Write mesh topology.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
const std::string patch
OpenFOAM patch number as a std::string.
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
void sort(UList< T > &list)
Sort the list.
errorManip< error > abort(error &err)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
List< edge > edgeList
A List of edges.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
PtrList< faPatch > faPatchList
Store lists of faPatch as a PtrList.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.