34 template<
class SourcePatch,
class TargetPatch>
41 word method =
"unknown-interpolationMethod";
52 method =
"mapNearestAMI";
55 case imFaceAreaWeight:
57 method =
"faceAreaWeightAMI";
60 case imPartialFaceAreaWeight:
62 method =
"partialFaceAreaWeightAMI";
68 <<
"Unhandled interpolationMethod enumeration " << method
77 template<
class SourcePatch,
class TargetPatch>
94 "partialFaceAreaWeightAMI"
99 if (im ==
"directAMI")
103 else if (im ==
"mapNearestAMI")
105 method = imMapNearest;
107 else if (im ==
"faceAreaWeightAMI")
109 method = imFaceAreaWeight;
111 else if (im ==
"partialFaceAreaWeightAMI")
113 method = imPartialFaceAreaWeight;
118 <<
"Invalid interpolationMethod " << im
119 <<
". Valid methods are:" << methods
129 template<
class SourcePatch,
class TargetPatch>
138 Info<<
"AMI: projecting points to surface" <<
endl;
152 pts[i] =
pi.hitPoint();
164 <<
"Error projecting points to surface: "
165 << nMiss <<
" faces could not be determined"
171 template<
class SourcePatch,
class TargetPatch>
175 const word& patchName,
179 const bool conformal,
181 const scalar lowWeightTol
185 wghtSum.setSize(wght.
size(), 0.0);
186 label nLowWeight = 0;
194 scalar denom = patchAreas[faceI];
211 if (t < lowWeightTol)
230 <<
"AMI: Patch " << patchName
231 <<
" sum(weights) min/max/average = "
232 <<
gMin(wghtSum) <<
", "
233 <<
gMax(wghtSum) <<
", "
241 <<
"AMI: Patch " << patchName
242 <<
" identified " << nLow
243 <<
" faces with weights less than " << lowWeightTol
251 template<
class SourcePatch,
class TargetPatch>
259 const labelList& sourceRestrictAddressing,
260 const labelList& targetRestrictAddressing,
269 label sourceCoarseSize =
271 sourceRestrictAddressing.
size()
272 ?
max(sourceRestrictAddressing)+1
276 label targetCoarseSize =
278 targetRestrictAddressing.
size()
279 ?
max(targetRestrictAddressing)+1
285 srcMagSf.setSize(sourceRestrictAddressing.
size(), 0.0);
286 forAll(sourceRestrictAddressing, faceI)
288 label coarseFaceI = sourceRestrictAddressing[faceI];
289 srcMagSf[coarseFaceI] += fineSrcMagSf[faceI];
295 if (targetMapPtr.
valid())
300 labelList allRestrict(targetRestrictAddressing);
333 tgtSubMap[Pstream::myProcNo()] =
identity(targetCoarseSize);
338 if (procI != Pstream::myProcNo())
354 labelList oldToNew(targetCoarseSize, -1);
359 label fineElem = elemsMap[elems[i]];
360 label coarseElem = allRestrict[fineElem];
361 if (oldToNew[coarseElem] == -1)
363 oldToNew[coarseElem] = newI;
364 newSubMap[newI] = coarseElem;
380 tgtConstructMap[Pstream::myProcNo()] =
396 label fineElem = elemsMap[i];
397 label coarseElem = allRestrict[fineElem];
398 tgtCompactMap[fineElem] = coarseElem;
402 label compactI = targetCoarseSize;
407 if (procI != Pstream::myProcNo())
414 labelList& newConstructMap = tgtConstructMap[procI];
424 remoteTargetCoarseSize =
max
426 remoteTargetCoarseSize,
427 allRestrict[elems[i]]
430 remoteTargetCoarseSize += 1;
433 labelList oldToNew(remoteTargetCoarseSize, -1);
438 label fineElem = elems[i];
440 label coarseElem = allRestrict[fineElem];
441 if (oldToNew[coarseElem] == -1)
443 oldToNew[coarseElem] = newI;
444 tgtCompactMap[fineElem] = compactI;
445 newConstructMap[newI] = compactI++;
451 label compactI = oldToNew[coarseElem];
452 tgtCompactMap[fineElem] = newConstructMap[compactI];
460 srcAddress.
setSize(sourceCoarseSize);
461 srcWeights.
setSize(sourceCoarseSize);
463 forAll(fineSrcAddress, faceI)
467 const labelList& elems = fineSrcAddress[faceI];
468 const scalarList& weights = fineSrcWeights[faceI];
469 const scalar fineArea = fineSrcMagSf[faceI];
471 label coarseFaceI = sourceRestrictAddressing[faceI];
473 labelList& newElems = srcAddress[coarseFaceI];
474 scalarList& newWeights = srcWeights[coarseFaceI];
478 label elemI = elems[i];
479 label coarseElemI = tgtCompactMap[elemI];
484 newElems.
append(coarseElemI);
485 newWeights.
append(fineArea*weights[i]);
489 newWeights[index] += fineArea*weights[i];
500 tgtConstructMap.
xfer()
506 srcAddress.
setSize(sourceCoarseSize);
507 srcWeights.
setSize(sourceCoarseSize);
509 forAll(fineSrcAddress, faceI)
513 const labelList& elems = fineSrcAddress[faceI];
514 const scalarList& weights = fineSrcWeights[faceI];
515 const scalar fineArea = fineSrcMagSf[faceI];
517 label coarseFaceI = sourceRestrictAddressing[faceI];
519 labelList& newElems = srcAddress[coarseFaceI];
520 scalarList& newWeights = srcWeights[coarseFaceI];
524 label elemI = elems[i];
525 label coarseElemI = targetRestrictAddressing[elemI];
530 newElems.
append(coarseElemI);
531 newWeights.
append(fineArea*weights[i]);
535 newWeights[index] += fineArea*weights[i];
556 template<
class SourcePatch,
class TargetPatch>
559 const SourcePatch& srcPatch,
560 const TargetPatch& tgtPatch,
568 SourcePatch srcPatch0
589 TargetPatch tgtPatch0
611 projectPointsToSurface(surfPtr(), srcPoints);
612 projectPointsToSurface(surfPtr(), tgtPoints);
616 update(srcPatch0, tgtPatch0);
620 update(srcPatch, tgtPatch);
626 template<
class SourcePatch,
class TargetPatch>
629 const SourcePatch& srcPatch,
630 const TargetPatch& tgtPatch,
632 const bool requireMatch,
634 const scalar lowWeightCorrection,
635 const bool reverseTarget
638 methodName_(interpolationMethodToWord(method)),
639 reverseTarget_(reverseTarget),
640 requireMatch_(requireMatch),
641 singlePatchProc_(-999),
642 lowWeightCorrection_(lowWeightCorrection),
653 update(srcPatch, tgtPatch);
657 template<
class SourcePatch,
class TargetPatch>
660 const SourcePatch& srcPatch,
661 const TargetPatch& tgtPatch,
663 const bool requireMatch,
664 const word& methodName,
665 const scalar lowWeightCorrection,
666 const bool reverseTarget
669 methodName_(methodName),
670 reverseTarget_(reverseTarget),
671 requireMatch_(requireMatch),
672 singlePatchProc_(-999),
673 lowWeightCorrection_(lowWeightCorrection),
684 update(srcPatch, tgtPatch);
688 template<
class SourcePatch,
class TargetPatch>
691 const SourcePatch& srcPatch,
692 const TargetPatch& tgtPatch,
695 const bool requireMatch,
697 const scalar lowWeightCorrection,
698 const bool reverseTarget
701 methodName_(interpolationMethodToWord(method)),
702 reverseTarget_(reverseTarget),
703 requireMatch_(requireMatch),
704 singlePatchProc_(-999),
705 lowWeightCorrection_(lowWeightCorrection),
716 constructFromSurface(srcPatch, tgtPatch, surfPtr);
720 template<
class SourcePatch,
class TargetPatch>
723 const SourcePatch& srcPatch,
724 const TargetPatch& tgtPatch,
727 const bool requireMatch,
728 const word& methodName,
729 const scalar lowWeightCorrection,
730 const bool reverseTarget
733 methodName_(methodName),
734 reverseTarget_(reverseTarget),
735 requireMatch_(requireMatch),
736 singlePatchProc_(-999),
737 lowWeightCorrection_(lowWeightCorrection),
748 constructFromSurface(srcPatch, tgtPatch, surfPtr);
752 template<
class SourcePatch,
class TargetPatch>
756 const labelList& sourceRestrictAddressing,
757 const labelList& targetRestrictAddressing
764 lowWeightCorrection_(-1.0),
775 label sourceCoarseSize =
777 sourceRestrictAddressing.
size()
778 ?
max(sourceRestrictAddressing)+1
782 label neighbourCoarseSize =
784 targetRestrictAddressing.
size()
785 ?
max(targetRestrictAddressing)+1
791 Pout<<
"AMI: Creating addressing and weights as agglomeration of AMI :"
794 <<
" coarse source size:" << sourceCoarseSize
795 <<
" neighbour source size:" << neighbourCoarseSize
806 <<
"Size mismatch." <<
nl
807 <<
"Source patch size:" << fineAMI.
srcAddress().size() <<
nl
808 <<
"Source agglomeration size:"
809 << sourceRestrictAddressing.
size() <<
nl
810 <<
"Target patch size:" << fineAMI.
tgtAddress().size() <<
nl
811 <<
"Target agglomeration size:"
812 << targetRestrictAddressing.
size()
826 sourceRestrictAddressing,
827 targetRestrictAddressing,
852 targetRestrictAddressing,
853 sourceRestrictAddressing,
875 template<
class SourcePatch,
class TargetPatch>
882 template<
class SourcePatch,
class TargetPatch>
885 const SourcePatch& srcPatch,
886 const TargetPatch& tgtPatch
892 if (srcTotalSize == 0)
896 Info<<
"AMI: no source faces present - no addressing constructed"
904 <<
"AMI: Creating addressing and weights between "
905 << srcTotalSize <<
" source faces and "
906 << tgtTotalSize <<
" target faces"
910 srcMagSf_.setSize(srcPatch.size());
913 srcMagSf_[faceI] = srcPatch[faceI].mag(srcPatch.points());
915 tgtMagSf_.setSize(tgtPatch.size());
918 tgtMagSf_[faceI] = tgtPatch[faceI].mag(tgtPatch.points());
922 singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
924 if (singlePatchProc_ == -1)
944 distributeAndMergePatches
977 requireMatch_ && (lowWeightCorrection_ < 0)
1004 forAll(addressing, addrI)
1006 addressing[addrI] = tgtFaceIDs[addressing[addrI]];
1013 forAll(addressing, addrI)
1015 addressing[addrI] = globalSrcFaces.
toGlobal(addressing[addrI]);
1022 mapDistributeBase::distribute
1024 Pstream::nonBlocking,
1037 mapDistributeBase::distribute
1039 Pstream::nonBlocking,
1053 normaliseWeights(AMIPtr->conformal(),
true);
1057 srcMapPtr_.reset(
new mapDistribute(globalSrcFaces, tgtAddress_, cMap));
1058 tgtMapPtr_.reset(
new mapDistribute(globalTgtFaces, srcAddress_, cMap));
1062 writeFaceConnectivity(srcPatch, newTgtPatch, srcAddress_);
1079 requireMatch_ && (lowWeightCorrection_ < 0)
1091 normaliseWeights(AMIPtr->conformal(),
true);
1096 Info<<
"AMIInterpolation : Constructed addressing and weights" <<
nl
1098 << faceAreaIntersect::triangulationModeNames_[triMode_] <<
nl
1099 <<
" singlePatchProc:" << singlePatchProc_ <<
nl
1100 <<
" srcMagSf :" <<
gSum(srcMagSf_) <<
nl
1101 <<
" tgtMagSf :" <<
gSum(tgtMagSf_) <<
nl
1107 template<
class SourcePatch,
class TargetPatch>
1110 const SourcePatch& srcPatch,
1111 const TargetPatch& tgtPatch
1124 lowWeightCorrection_,
1130 if (singlePatchProc_ == -1)
1133 labelListList& srcConstructMap = srcMapPtr_->constructMap();
1136 labelListList& tgtConstructMap = tgtMapPtr_->constructMap();
1139 labelListList& newSrcConstructMap = newPtr->srcMapPtr_->constructMap();
1142 labelListList& newTgtConstructMap = newPtr->tgtMapPtr_->constructMap();
1151 identity(srcConstructMap[procI].size())
1156 identity(newSrcConstructMap[procI].size())
1163 forAll(srcConstructMap[procI], srcI)
1165 srcConstructMap[procI][srcI] =
1166 mapMap[srcConstructMap[procI][srcI]];
1172 forAll(newSrcConstructMap[procI], srcI)
1174 newSrcConstructMap[procI][srcI] =
1175 newMapMap[newSrcConstructMap[procI][srcI]];
1179 forAll(tgtAddress_, tgtI)
1181 forAll(tgtAddress_[tgtI], tgtJ)
1183 tgtAddress_[tgtI][tgtJ] =
1184 mapMap[tgtAddress_[tgtI][tgtJ]];
1188 forAll(newPtr->tgtAddress_, tgtI)
1190 forAll(newPtr->tgtAddress_[tgtI], tgtJ)
1192 newPtr->tgtAddress_[tgtI][tgtJ] =
1193 newMapMap[newPtr->tgtAddress_[tgtI][tgtJ]];
1205 identity(tgtConstructMap[procI].size())
1210 identity(newTgtConstructMap[procI].size())
1217 forAll(tgtConstructMap[procI], tgtI)
1219 tgtConstructMap[procI][tgtI] =
1220 mapMap[tgtConstructMap[procI][tgtI]];
1226 forAll(newTgtConstructMap[procI], tgtI)
1228 newTgtConstructMap[procI][tgtI] =
1229 newMapMap[newTgtConstructMap[procI][tgtI]];
1233 forAll(srcAddress_, srcI)
1235 forAll(srcAddress_[srcI], srcJ)
1237 srcAddress_[srcI][srcJ] =
1238 mapMap[srcAddress_[srcI][srcJ]];
1242 forAll(newPtr->srcAddress_, srcI)
1244 forAll(newPtr->srcAddress_[srcI], srcJ)
1246 newPtr->srcAddress_[srcI][srcJ] =
1247 newMapMap[newPtr->srcAddress_[srcI][srcJ]];
1253 srcMapPtr_->constructSize() += newPtr->srcMapPtr_->constructSize();
1254 tgtMapPtr_->constructSize() += newPtr->tgtMapPtr_->constructSize();
1259 srcSubMap[procI].
append(newSrcSubMap[procI]);
1260 srcConstructMap[procI].
append(newSrcConstructMap[procI]);
1262 tgtSubMap[procI].
append(newTgtSubMap[procI]);
1263 tgtConstructMap[procI].
append(newTgtConstructMap[procI]);
1268 forAll(srcMagSf_, srcFaceI)
1270 srcAddress_[srcFaceI].append(newPtr->srcAddress()[srcFaceI]);
1271 srcWeights_[srcFaceI].append(newPtr->srcWeights()[srcFaceI]);
1272 srcWeightsSum_[srcFaceI] += newPtr->srcWeightsSum()[srcFaceI];
1276 forAll(tgtMagSf_, tgtFaceI)
1278 tgtAddress_[tgtFaceI].append(newPtr->tgtAddress()[tgtFaceI]);
1279 tgtWeights_[tgtFaceI].append(newPtr->tgtWeights()[tgtFaceI]);
1280 tgtWeightsSum_[tgtFaceI] += newPtr->tgtWeightsSum()[tgtFaceI];
1285 template<
class SourcePatch,
class TargetPatch>
1288 const bool conformal,
1301 lowWeightCorrection_
1313 lowWeightCorrection_
1318 template<
class SourcePatch,
class TargetPatch>
1319 template<
class Type,
class CombineOp>
1323 const CombineOp& cop,
1328 if (
fld.size() != srcAddress_.size())
1331 <<
"Supplied field size is not equal to source patch size" <<
nl
1332 <<
" source patch = " << srcAddress_.size() <<
nl
1333 <<
" target patch = " << tgtAddress_.size() <<
nl
1334 <<
" supplied field = " <<
fld.size()
1338 if (lowWeightCorrection_ > 0)
1340 if (defaultValues.
size() != tgtAddress_.size())
1343 <<
"Employing default values when sum of weights falls below "
1344 << lowWeightCorrection_
1345 <<
" but supplied default field size is not equal to target "
1346 <<
"patch size" <<
nl
1347 <<
" default values = " << defaultValues.
size() <<
nl
1348 <<
" target patch = " << tgtAddress_.size() <<
nl
1353 result.
setSize(tgtAddress_.size());
1355 if (singlePatchProc_ == -1)
1364 if (tgtWeightsSum_[faceI] < lowWeightCorrection_)
1366 result[faceI] = defaultValues[faceI];
1370 const labelList& faces = tgtAddress_[faceI];
1371 const scalarList& weights = tgtWeights_[faceI];
1375 cop(result[faceI], faceI, work[faces[i]], weights[i]);
1384 if (tgtWeightsSum_[faceI] < lowWeightCorrection_)
1386 result[faceI] = defaultValues[faceI];
1390 const labelList& faces = tgtAddress_[faceI];
1391 const scalarList& weights = tgtWeights_[faceI];
1395 cop(result[faceI], faceI,
fld[faces[i]], weights[i]);
1403 template<
class SourcePatch,
class TargetPatch>
1404 template<
class Type,
class CombineOp>
1408 const CombineOp& cop,
1413 if (
fld.size() != tgtAddress_.size())
1416 <<
"Supplied field size is not equal to target patch size" <<
nl
1417 <<
" source patch = " << srcAddress_.size() <<
nl
1418 <<
" target patch = " << tgtAddress_.size() <<
nl
1419 <<
" supplied field = " <<
fld.size()
1423 if (lowWeightCorrection_ > 0)
1425 if (defaultValues.
size() != srcAddress_.size())
1428 <<
"Employing default values when sum of weights falls below "
1429 << lowWeightCorrection_
1430 <<
" but supplied default field size is not equal to target "
1431 <<
"patch size" <<
nl
1432 <<
" default values = " << defaultValues.
size() <<
nl
1433 <<
" source patch = " << srcAddress_.size() <<
nl
1438 result.
setSize(srcAddress_.size());
1440 if (singlePatchProc_ == -1)
1449 if (srcWeightsSum_[faceI] < lowWeightCorrection_)
1451 result[faceI] = defaultValues[faceI];
1455 const labelList& faces = srcAddress_[faceI];
1456 const scalarList& weights = srcWeights_[faceI];
1460 cop(result[faceI], faceI, work[faces[i]], weights[i]);
1469 if (srcWeightsSum_[faceI] < lowWeightCorrection_)
1471 result[faceI] = defaultValues[faceI];
1475 const labelList& faces = srcAddress_[faceI];
1476 const scalarList& weights = srcWeights_[faceI];
1480 cop(result[faceI], faceI,
fld[faces[i]], weights[i]);
1488 template<
class SourcePatch,
class TargetPatch>
1489 template<
class Type,
class CombineOp>
1494 const CombineOp& cop,
1519 template<
class SourcePatch,
class TargetPatch>
1520 template<
class Type,
class CombineOp>
1525 const CombineOp& cop,
1529 return interpolateToSource(tFld(), cop, defaultValues);
1533 template<
class SourcePatch,
class TargetPatch>
1534 template<
class Type,
class CombineOp>
1539 const CombineOp& cop,
1564 template<
class SourcePatch,
class TargetPatch>
1565 template<
class Type,
class CombineOp>
1570 const CombineOp& cop,
1574 return interpolateToTarget(tFld(), cop, defaultValues);
1578 template<
class SourcePatch,
class TargetPatch>
1579 template<
class Type>
1591 template<
class SourcePatch,
class TargetPatch>
1592 template<
class Type>
1600 return interpolateToSource(tFld(),
plusEqOp<Type>(), defaultValues);
1604 template<
class SourcePatch,
class TargetPatch>
1605 template<
class Type>
1617 template<
class SourcePatch,
class TargetPatch>
1618 template<
class Type>
1626 return interpolateToTarget(tFld(),
plusEqOp<Type>(), defaultValues);
1630 template<
class SourcePatch,
class TargetPatch>
1633 const SourcePatch& srcPatch,
1634 const TargetPatch& tgtPatch,
1636 const label tgtFaceI,
1641 const pointField& srcPoints = srcPatch.points();
1644 const labelList& addr = tgtAddress_[tgtFaceI];
1648 label srcFaceI = addr[i];
1649 const face&
f = srcPatch[srcFaceI];
1651 pointHit ray =
f.ray(tgtPoint,
n, srcPoints);
1664 label srcFaceI = addr[i];
1665 const face&
f = srcPatch[srcFaceI];
1667 vector nFace(-srcPatch.faceNormals()[srcFaceI]);
1668 nFace += tgtPatch.faceNormals()[tgtFaceI];
1670 pointHit ray =
f.ray(tgtPoint, nFace, srcPoints);
1684 template<
class SourcePatch,
class TargetPatch>
1687 const SourcePatch& srcPatch,
1688 const TargetPatch& tgtPatch,
1690 const label srcFaceI,
1695 const pointField& tgtPoints = tgtPatch.points();
1698 const labelList& addr = srcAddress_[srcFaceI];
1702 label tgtFaceI = addr[i];
1703 const face&
f = tgtPatch[tgtFaceI];
1705 pointHit ray =
f.ray(srcPoint,
n, tgtPoints);
1718 label tgtFaceI = addr[i];
1719 const face&
f = tgtPatch[tgtFaceI];
1721 vector nFace(-srcPatch.faceNormals()[srcFaceI]);
1722 nFace += tgtPatch.faceNormals()[tgtFaceI];
1724 pointHit ray =
f.ray(srcPoint,
n, tgtPoints);
1738 template<
class SourcePatch,
class TargetPatch>
1741 const SourcePatch& srcPatch,
1742 const TargetPatch& tgtPatch,
1754 const point& srcPt = srcPatch.faceCentres()[i];
1757 label tgtPtI = addr[j];
1758 const point& tgtPt = tgtPatch.faceCentres()[tgtPtI];
1763 os <<
"l " << ptI <<
" " << ptI + 1 <<
endl;