52 directMappedPatchBase::sampleModeNames_;
58 void Foam::directMappedPatchBase::collectSamples
85 samples = ListListOps::combine<pointField>
88 accessOp<pointField>()
90 patchFaces = ListListOps::combine<labelList>
95 patchFc = ListListOps::combine<pointField>
98 accessOp<pointField>()
101 patchFaceProcs.setSize(patchFaces.size());
107 accessOp<labelList>()
113 for (label i = 0; i < nPerProc[procI]; i++)
115 patchFaceProcs[sampleI++] = procI;
123 void Foam::directMappedPatchBase::findSamples
132 const polyMesh&
mesh = sampleMesh();
135 List<nearInfo> nearest(samples.size());
141 if (samplePatch_.size() && samplePatch_ !=
"none")
145 "directMappedPatchBase::findSamples(const pointField&,"
146 " labelList&, labelList&, pointField&) const"
147 ) <<
"No need to supply a patch name when in "
152 meshSearch meshSearchEngine(mesh,
false);
156 const point& sample = samples[sampleI];
158 label cellI = meshSearchEngine.findCell(sample);
162 nearest[sampleI].second().first() =
Foam::sqr(GREAT);
167 const point& cc = mesh.cellCentres()[cellI];
175 nearest[sampleI].second().first() =
magSqr(cc-sample);
182 case NEARESTPATCHFACE:
184 Random rndGen(123456);
186 const polyPatch& pp = samplePolyPatch();
192 nearest[sampleI].second().first() =
Foam::sqr(GREAT);
203 treeBoundBox(pp.points(), pp.meshPoints()).extend
209 patchBb.min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
210 patchBb.max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
212 indexedOctree<treeDataFace> boundaryTree
228 const point& sample = samples[sampleI];
231 nearInfo = boundaryTree.findNearest
239 nearest[sampleI].second().first() =
Foam::sqr(GREAT);
240 nearest[sampleI].second().second() =
245 point fc(pp[nearInfo.index()].centre(pp.points()));
246 nearInfo.setPoint(fc);
247 nearest[sampleI].second().first() =
magSqr(fc-sample);
248 nearest[sampleI].second().second() =
258 if (samplePatch_.size() && samplePatch_ !=
"none")
262 "directMappedPatchBase::findSamples(const pointField&,"
263 " labelList&, labelList&, pointField&) const"
264 ) <<
"No need to supply a patch name when in "
269 meshSearch meshSearchEngine(mesh,
false);
273 const point& sample = samples[sampleI];
275 label faceI = meshSearchEngine.findNearestFace(sample);
279 nearest[sampleI].second().first() =
Foam::sqr(GREAT);
284 const point& fc = mesh.faceCentres()[faceI];
292 nearest[sampleI].second().first() =
magSqr(fc-sample);
313 Info<<
"directMappedPatchBase::findSamples on mesh " << sampleRegion_
317 label procI = nearest[sampleI].second().second();
318 label localI = nearest[sampleI].first().index();
320 Info<<
" " << sampleI <<
" coord:"<< samples[sampleI]
321 <<
" found on processor:" << procI
322 <<
" in local cell/face:" << localI
323 <<
" with cc:" << nearest[sampleI].first().rawPoint() <<
endl;
330 if (!nearest[sampleI].first().hit())
334 "directMappedPatchBase::findSamples"
335 "(const pointField&, labelList&"
336 ", labelList&, pointField&)"
337 ) <<
"Did not find sample " << samples[sampleI]
338 <<
" on any processor of region " << sampleRegion_
345 sampleProcs.setSize(samples.size());
346 sampleIndices.setSize(samples.size());
347 sampleLocations.setSize(samples.size());
351 sampleProcs[sampleI] = nearest[sampleI].second().second();
352 sampleIndices[sampleI] = nearest[sampleI].first().index();
353 sampleLocations[sampleI] = nearest[sampleI].first().hitPoint();
358 void Foam::directMappedPatchBase::calcMapping()
const
362 FatalErrorIn(
"directMappedPatchBase::calcMapping() const")
369 && mode_ == NEARESTPATCHFACE
370 && sampleRegion_ == patch_.boundaryMesh().mesh().name()
371 && samplePatch_ == patch_.name()
374 WarningIn(
"directMappedPatchBase::calcMapping() const")
375 <<
"Invalid offset " << offsets_ << endl
376 <<
"Offset is the vector added to the patch face centres to"
377 <<
" find the patch face supplying the data." << endl
378 <<
"Setting it to " << offsets_
379 <<
" on the same patch, on the same region"
380 <<
" will find the faces themselves which does not make sense"
381 <<
" for anything but testing." << endl
382 <<
"patch_:" << patch_.name() << endl
383 <<
"sampleRegion_:" << sampleRegion_ << endl
384 <<
"mode_:" << sampleModeNames_[mode_] << endl
385 <<
"samplePatch_:" << samplePatch_ << endl
386 <<
"offsets_:" << offsets_ <<
endl;
395 collectSamples(samples, patchFaceProcs, patchFaces, patchFc);
401 findSamples(samples, sampleProcs, sampleIndices, sampleLocations);
430 patch_.boundaryMesh().mesh().time().path()
432 +
"_directMapped.obj"
434 Pout<<
"Dumping mapping as lines from patch faceCentres to"
435 <<
" sampled cell/faceCentres to file " << str.
name() <<
endl;
445 str <<
"l " << vertI-1 <<
' ' << vertI <<
nl;
485 mapPtr_.reset(
new mapDistribute(sampleProcs, patchFaceProcs));
495 subMap[procI] = UIndirectList<label>
500 constructMap[procI] = UIndirectList<label>
508 Pout<<
"To proc:" << procI <<
" sending values of cells/faces:"
509 << subMap[procI] <<
endl;
510 Pout<<
"From proc:" << procI <<
" receiving values of patch faces:"
511 << constructMap[procI] <<
endl;
516 mapPtr_().constructSize() = patch_.size();
522 forAll(constructMap, procI)
524 const labelList& map = constructMap[procI];
528 label faceI = map[i];
530 if (used[faceI] == 0)
536 FatalErrorIn(
"directMappedPatchBase::calcMapping() const")
537 <<
"On patch " << patch_.name()
538 <<
" patchface " << faceI
539 <<
" is assigned to more than once."
546 if (used[faceI] == 0)
548 FatalErrorIn(
"directMappedPatchBase::calcMapping() const")
549 <<
"On patch " << patch_.name()
550 <<
" patchface " << faceI
551 <<
" is never assigned to."
567 sampleRegion_(patch_.boundaryMesh().mesh().name()),
568 mode_(NEARESTPATCHFACE),
569 samplePatch_(
"none"),
570 uniformOffset_(
true),
572 offsets_(pp.size(), offset_),
573 sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
581 const word& sampleRegion,
583 const word& samplePatch,
588 sampleRegion_(sampleRegion),
590 samplePatch_(samplePatch),
591 uniformOffset_(
false),
593 sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
601 const word& sampleRegion,
603 const word& samplePatch,
608 sampleRegion_(sampleRegion),
610 samplePatch_(samplePatch),
611 uniformOffset_(
true),
613 offsets_(pp.size(), offset_),
614 sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
631 patch_.boundaryMesh().mesh().name()
634 mode_(sampleModeNames_.read(dict.
lookup(
"sampleMode"))),
635 samplePatch_(dict.
lookup(
"samplePatch")),
636 uniformOffset_(dict.
found(
"offset")),
649 sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
661 sampleRegion_(dmp.sampleRegion_),
663 samplePatch_(dmp.samplePatch_),
664 uniformOffset_(dmp.uniformOffset_),
665 offset_(dmp.offset_),
666 offsets_(dmp.offsets_),
667 sameRegion_(dmp.sameRegion_),
699 const polyMesh& nbrMesh = sampleMesh();
705 FatalErrorIn(
"directMappedPatchBase::samplePolyPatch() ")
706 <<
"Cannot find patch " << samplePatch_
707 <<
" in region " << sampleRegion_ << endl
718 os.
writeKeyword(
"sampleMode") << sampleModeNames_[mode_]