47 word method =
"unknown-interpolationMethod";
58 method =
"mapNearestAMI";
61 case imFaceAreaWeight:
63 method =
"faceAreaWeightAMI";
66 case imPartialFaceAreaWeight:
68 method =
"partialFaceAreaWeightAMI";
71 case imSweptFaceAreaWeight:
73 method =
"sweptFaceAreaWeightAMI";
79 <<
"Unhandled interpolationMethod enumeration " << method
101 "partialFaceAreaWeightAMI " 102 "sweptFaceAreaWeightAMI" 107 if (im ==
"directAMI")
111 else if (im ==
"mapNearestAMI")
113 method = imMapNearest;
115 else if (im ==
"faceAreaWeightAMI")
117 method = imFaceAreaWeight;
119 else if (im ==
"partialFaceAreaWeightAMI")
121 method = imPartialFaceAreaWeight;
123 else if (im ==
"sweptFaceAreaWeightAMI")
125 method = imSweptFaceAreaWeight;
130 <<
"Invalid interpolationMethod " << im
131 <<
". Valid methods are:" << methods
152 forAll(result, patchFacei)
164 result[patchFacei] +=
167 patchPoints[patchFaceTris[i][0]],
168 patchPoints[patchFaceTris[i][1]],
169 patchPoints[patchFaceTris[i][2]]
180 void Foam::AMIInterpolation::projectPointsToSurface
188 Info<<
"AMI: projecting points to surface" <<
endl;
214 <<
"Error projecting points to surface: " 215 << nMiss <<
" faces could not be determined" 221 void Foam::AMIInterpolation::sumWeights
232 wghtSum[facei] =
sum(wght[facei]);
237 void Foam::AMIInterpolation::sumWeights
243 wghtSum.
setSize(wghts[0].size());
250 forAll(wghts[wghtsi][facei], i)
252 wghtSum[facei] += wghts[wghtsi][facei][i];
259 void Foam::AMIInterpolation::reportSumWeights
262 const word& patchName,
264 const scalar lowWeightTol
272 label nLowWeight = 0;
275 if (wghtSum[facei] < lowWeightTol)
283 <<
" sum(weights) min/max/average = " <<
gMin(wghtSum) <<
", " 284 <<
gMax(wghtSum) <<
", " 289 Info<<
indent <<
"AMI: Patch " << patchName <<
" identified " 290 << nLowWeight <<
" faces with weights less than " 291 << lowWeightTol <<
endl;
296 void Foam::AMIInterpolation::normaliseWeights
308 w[i] /= wghtSum[facei];
314 void Foam::AMIInterpolation::normaliseWeights
328 w[i] /= wghtSum[facei];
335 void Foam::AMIInterpolation::agglomerate
342 const labelList& sourceRestrictAddressing,
343 const labelList& targetRestrictAddressing,
352 label sourceCoarseSize =
354 sourceRestrictAddressing.
size()
355 ?
max(sourceRestrictAddressing)+1
359 label targetCoarseSize =
361 targetRestrictAddressing.
size()
362 ?
max(targetRestrictAddressing)+1
368 srcMagSf.
setSize(sourceRestrictAddressing.
size(), 0.0);
369 forAll(sourceRestrictAddressing, facei)
371 label coarseFacei = sourceRestrictAddressing[facei];
372 srcMagSf[coarseFacei] += fineSrcMagSf[facei];
378 if (targetMapPtr.
valid())
383 labelList allRestrict(targetRestrictAddressing);
410 labelList oldToNew(targetCoarseSize, -1);
415 label fineElem = elems[i];
416 label coarseElem = allRestrict[fineElem];
417 if (oldToNew[coarseElem] == -1)
419 oldToNew[coarseElem] = newI;
420 newSubMap[newI] = coarseElem;
440 tgtCompactMap = targetRestrictAddressing;
443 label compactI = targetCoarseSize;
455 labelList& newConstructMap = tgtConstructMap[proci];
465 remoteTargetCoarseSize =
max 467 remoteTargetCoarseSize,
468 allRestrict[elems[i]]
471 remoteTargetCoarseSize += 1;
474 labelList oldToNew(remoteTargetCoarseSize, -1);
479 label fineElem = elems[i];
481 label coarseElem = allRestrict[fineElem];
482 if (oldToNew[coarseElem] == -1)
484 oldToNew[coarseElem] = newI;
485 tgtCompactMap[fineElem] = compactI;
486 newConstructMap[newI] = compactI++;
492 label compactI = oldToNew[coarseElem];
493 tgtCompactMap[fineElem] = newConstructMap[compactI];
502 srcAddress.
setSize(sourceCoarseSize);
503 srcWeights.
setSize(sourceCoarseSize);
505 forAll(fineSrcAddress, facei)
509 const labelList& elems = fineSrcAddress[facei];
510 const scalarList& weights = fineSrcWeights[facei];
511 const scalar fineArea = fineSrcMagSf[facei];
513 label coarseFacei = sourceRestrictAddressing[facei];
515 const scalar coarseArea = srcMagSf[coarseFacei];
517 labelList& newElems = srcAddress[coarseFacei];
518 scalarList& newWeights = srcWeights[coarseFacei];
522 label elemI = elems[i];
523 label coarseElemI = tgtCompactMap[elemI];
528 newElems.
append(coarseElemI);
529 newWeights.
append(fineArea/coarseArea*weights[i]);
533 newWeights[index] += fineArea/coarseArea*weights[i];
544 move(tgtConstructMap)
550 srcAddress.
setSize(sourceCoarseSize);
551 srcWeights.
setSize(sourceCoarseSize);
553 forAll(fineSrcAddress, facei)
557 const labelList& elems = fineSrcAddress[facei];
558 const scalarList& weights = fineSrcWeights[facei];
559 const scalar fineArea = fineSrcMagSf[facei];
561 label coarseFacei = sourceRestrictAddressing[facei];
563 const scalar coarseArea = srcMagSf[coarseFacei];
565 labelList& newElems = srcAddress[coarseFacei];
566 scalarList& newWeights = srcWeights[coarseFacei];
570 label elemI = elems[i];
571 label coarseElemI = targetRestrictAddressing[elemI];
576 newElems.
append(coarseElemI);
577 newWeights.
append(fineArea/coarseArea*weights[i]);
581 newWeights[index] += fineArea/coarseArea*weights[i];
589 void Foam::AMIInterpolation::constructFromSurface
644 projectPointsToSurface(surfPtr(), srcPoints);
645 projectPointsToSurface(surfPtr(), tgtPoints);
649 update(srcPatch0, tgtPatch0, report);
653 update(srcPatch, tgtPatch, report);
665 const bool requireMatch,
667 const scalar lowWeightCorrection,
668 const bool reverseTarget,
672 methodName_(interpolationMethodToWord(method)),
673 reverseTarget_(reverseTarget),
674 requireMatch_(requireMatch),
675 singlePatchProc_(-999),
676 lowWeightCorrection_(lowWeightCorrection),
687 update(srcPatch, tgtPatch, report);
696 const bool requireMatch,
697 const word& methodName,
698 const scalar lowWeightCorrection,
699 const bool reverseTarget,
703 methodName_(methodName),
704 reverseTarget_(reverseTarget),
705 requireMatch_(requireMatch),
706 singlePatchProc_(-999),
707 lowWeightCorrection_(lowWeightCorrection),
718 update(srcPatch, tgtPatch, report);
728 const bool requireMatch,
730 const scalar lowWeightCorrection,
731 const bool reverseTarget,
735 methodName_(interpolationMethodToWord(method)),
736 reverseTarget_(reverseTarget),
737 requireMatch_(requireMatch),
738 singlePatchProc_(-999),
739 lowWeightCorrection_(lowWeightCorrection),
750 constructFromSurface(srcPatch, tgtPatch, surfPtr, report);
760 const bool requireMatch,
761 const word& methodName,
762 const scalar lowWeightCorrection,
763 const bool reverseTarget,
767 methodName_(methodName),
768 reverseTarget_(reverseTarget),
769 requireMatch_(requireMatch),
770 singlePatchProc_(-999),
771 lowWeightCorrection_(lowWeightCorrection),
782 constructFromSurface(srcPatch, tgtPatch, surfPtr, report);
789 const labelList& sourceRestrictAddressing,
790 const labelList& targetRestrictAddressing,
794 methodName_(fineAMI.methodName_),
795 reverseTarget_(fineAMI.reverseTarget_),
796 requireMatch_(fineAMI.requireMatch_),
797 singlePatchProc_(fineAMI.singlePatchProc_),
798 lowWeightCorrection_(-1.0),
805 triMode_(fineAMI.triMode_),
809 label sourceCoarseSize =
811 sourceRestrictAddressing.
size()
812 ?
max(sourceRestrictAddressing)+1
816 label neighbourCoarseSize =
818 targetRestrictAddressing.
size()
819 ?
max(targetRestrictAddressing)+1
825 Pout<<
"AMI: Creating addressing and weights as agglomeration of AMI :" 828 <<
" coarse source size:" << sourceCoarseSize
829 <<
" neighbour source size:" << neighbourCoarseSize
840 <<
"Size mismatch." <<
nl 842 <<
"Source agglomeration size:" 843 << sourceRestrictAddressing.
size() <<
nl 845 <<
"Target agglomeration size:" 846 << targetRestrictAddressing.
size()
858 sourceRestrictAddressing,
859 targetRestrictAddressing,
875 targetRestrictAddressing,
876 sourceRestrictAddressing,
889 reportSumWeights(*
this);
893 normaliseWeights(*
this);
916 if (srcTotalSize == 0)
920 Info<<
"AMI: no source faces present - no addressing constructed" 930 <<
"AMI: Creating addressing and weights between " 931 << srcTotalSize <<
" source faces and " 932 << tgtTotalSize <<
" target faces" 937 srcMagSf_ = patchMagSf(srcPatch, triMode_);
938 tgtMagSf_ = patchMagSf(tgtPatch, triMode_);
941 singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
943 if (singlePatchProc_ == -1)
964 distributeAndMergePatches
984 scalarField newTgtMagSf(patchMagSf(newTgtPatch, triMode_));
998 requireMatch_ && (lowWeightCorrection_ < 0)
1025 forAll(addressing, addrI)
1027 addressing[addrI] = tgtFaceIDs[addressing[addrI]];
1034 forAll(addressing, addrI)
1036 addressing[addrI] = globalSrcFaces.toGlobal(addressing[addrI]);
1075 srcMapPtr_.reset(
new mapDistribute(globalSrcFaces, tgtAddress_, cMap));
1076 tgtMapPtr_.reset(
new mapDistribute(globalTgtFaces, srcAddress_, cMap));
1080 writeFaceConnectivity(srcPatch, newTgtPatch, srcAddress_);
1097 requireMatch_ && (lowWeightCorrection_ < 0)
1114 reportSumWeights(*
this);
1118 normaliseWeights(*
this);
1123 Info<<
"AMIIPatchToPatchnterpolation :" 1124 <<
"Constructed addressing and weights" <<
nl 1127 <<
" singlePatchProc:" << singlePatchProc_ <<
nl 1128 <<
" srcMagSf :" <<
gSum(srcMagSf_) <<
nl 1129 <<
" tgtMagSf :" <<
gSum(tgtMagSf_) <<
nl 1137 sumWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
1138 sumWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
1147 srcWeights.set(i, &AMIs[i].srcWeights_);
1150 sumWeights(srcWeights, AMIs[0].srcWeightsSum_);
1152 for (
label i = 1; i < AMIs.
size(); ++ i)
1154 AMIs[i].srcWeightsSum_ = AMIs[0].srcWeightsSum_;
1160 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1163 sumWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1165 for (
label i = 1; i < AMIs.
size(); ++ i)
1167 AMIs[i].tgtWeightsSum_ = AMIs[0].tgtWeightsSum_;
1179 AMI.lowWeightCorrection_
1187 AMI.lowWeightCorrection_
1194 normaliseWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
1195 normaliseWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
1204 srcWeights.set(i, &AMIs[i].srcWeights_);
1207 normaliseWeights(srcWeights, AMIs[0].srcWeightsSum_);
1212 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1215 normaliseWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1224 const label tgtFacei,
1232 const labelList& addr = tgtAddress_[tgtFacei];
1235 label nearestFacei = -1;
1239 const label srcFacei = addr[i];
1240 const face&
f = srcPatch[srcFacei];
1256 nearestFacei = srcFacei;
1263 return nearestFacei;
1275 const label srcFacei,
1283 label nearestFacei = -1;
1286 const labelList& addr = srcAddress_[srcFacei];
1290 const label tgtFacei = addr[i];
1291 const face&
f = tgtPatch[tgtFacei];
1307 nearestFacei = tgtFacei;
1314 return nearestFacei;
1340 label tgtPtI = addr[j];
1346 os <<
"l " << ptI <<
" " << ptI + 1 <<
endl;
static word interpolationMethodToWord(const interpolationMethod &method)
Convert interpolationMethod to word representation.
Class containing functor to negate primitives. Dummy for all other types.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & indent(Ostream &os)
Indent stream.
void update(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const bool report)
Update addressing and weights.
label tgtPointFace(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const vector &n, const label srcFacei, point &srcPoint) const
Return target patch face index of point on source patch face.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
A face is a list of labels corresponding to mesh vertices.
const scalarListList & tgtWeights() const
Return const access to target patch weights.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const Field< PointType > & faceCentres() const
Return face centres for patch.
Type gMin(const FieldField< Field, Type > &f)
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
void writeFaceConnectivity(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
T & ref() const
Return non-const reference or generate a fatal error.
label srcPointFace(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const vector &n, const label tgtFacei, point &tgtPoint) const
Return source patch face index of point on target patch face.
const labelListList & subMap() const
From subsetted data back to original data.
void size(const label)
Override size to be inconsistent with allocated storage.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
pointHit ray(const point &p, const vector &n, const pointField &, const intersection::algorithm alg=intersection::algorithm::fullRay, const intersection::direction dir=intersection::direction::vector) const
Return potential intersection with face with a ray starting.
static tmp< scalarField > patchMagSf(const primitivePatch &patch, const faceAreaIntersect::triangulationMode triMode)
Calculate the patch face magnitudes for the given tri-mode.
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
virtual void calculate(labelListList &srcAddress, scalarListList &srcWeights, labelListList &tgtAddress, scalarListList &tgtWeights, label srcFacei=-1, label tgtFacei=-1)=0
Update addressing and weights.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
static const NamedEnum< triangulationMode, 2 > triangulationModeNames_
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
interpolationMethod
Enumeration specifying interpolation method.
static autoPtr< AMIMethod > New(const word &methodName, const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const scalarField &srcMagSf, const scalarField &tgtMagSf, const faceAreaIntersect::triangulationMode &triMode, const bool reverseTarget, const bool requireMatch)
Selector.
const scalarField & srcMagSf() const
Return const access to source patch face areas.
A list of faces which address into the list of points.
const Point & hitPoint() const
Return hit point.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
A List obtained as a section of another List.
Type gSum(const FieldField< Field, Type > &f)
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
AMIInterpolation(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const faceAreaIntersect::triangulationMode &triMode, const bool requireMatch=true, const interpolationMethod &method=imFaceAreaWeight, const scalar lowWeightCorrection=-1, const bool reverseTarget=false, const bool report=true)
Construct from components.
A class for handling words, derived from string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void append(const T &)
Append an element at the end of the list.
List< scalar > scalarList
A List of scalars.
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &, const negateOp &negOp, const int tag=UPstream::msgType())
Distribute data. Note:schedule only used for.
bool hit() const
Is there a hit.
const Field< PointType > & points() const
Return reference to global points.
bool hit() const
Is there a hit.
List< label > labelList
A List of labels.
virtual ~AMIInterpolation()
Destructor.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
errorManip< error > abort(error &err)
const Point & rawPoint() const
Return point with no checking.
const scalarListList & srcWeights() const
Return const access to source patch weights.
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
label size() const
Return the number of elements in the UPtrList.
label constructSize() const
Constructed data size.
void setSize(const label)
Reset size of List.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Class containing processor-to-processor mapping information.
pointHit nearestPoint(const point &p, const pointField &) const
Return nearest point to face.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
triangle< point, const point & > triPointRef
const labelListList & constructMap() const
From subsetted data to new reconstructed data.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Helper class for list to append y onto the end of x.
static interpolationMethod wordTointerpolationMethod(const word &method)
Convert word to interpolationMethod.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static void triangulate(const face &f, const pointField &points, const triangulationMode &triMode, faceList &faceTris)
Triangulate a face using the given triangulation mode.
scalar distance() const
Return distance to hit.
A class for managing temporary objects.
bool eligibleMiss() const
Is this an eligible miss.
const labelListList & srcAddress() const
Return const access to source patch addressing.
static const label labelMin
const scalarField & tgtMagSf() const
Return const access to target patch face areas.