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] +=
165 patchFaceTris[i].tri(patchPoints).mag();
175 void Foam::AMIInterpolation::projectPointsToSurface
183 Info<<
"AMI: projecting points to surface" <<
endl;
209 <<
"Error projecting points to surface: " 210 << nMiss <<
" faces could not be determined" 216 void Foam::AMIInterpolation::sumWeights
227 wghtSum[facei] =
sum(wght[facei]);
232 void Foam::AMIInterpolation::sumWeights
238 wghtSum.
setSize(wghts[0].size());
245 forAll(wghts[wghtsi][facei], i)
247 wghtSum[facei] += wghts[wghtsi][facei][i];
254 void Foam::AMIInterpolation::reportSumWeights
257 const word& patchName,
259 const scalar lowWeightTol
267 label nLowWeight = 0;
270 if (wghtSum[facei] < lowWeightTol)
278 <<
" sum(weights) min/max/average = " <<
gMin(wghtSum) <<
", " 279 <<
gMax(wghtSum) <<
", " 284 Info<<
indent <<
"AMI: Patch " << patchName <<
" identified " 285 << nLowWeight <<
" faces with weights less than " 286 << lowWeightTol <<
endl;
291 void Foam::AMIInterpolation::normaliseWeights
303 w[i] /= wghtSum[facei];
309 void Foam::AMIInterpolation::normaliseWeights
323 w[i] /= wghtSum[facei];
330 void Foam::AMIInterpolation::agglomerate
337 const labelList& sourceRestrictAddressing,
338 const labelList& targetRestrictAddressing,
347 label sourceCoarseSize =
349 sourceRestrictAddressing.
size()
350 ?
max(sourceRestrictAddressing)+1
354 label targetCoarseSize =
356 targetRestrictAddressing.
size()
357 ?
max(targetRestrictAddressing)+1
363 srcMagSf.
setSize(sourceRestrictAddressing.
size(), 0.0);
364 forAll(sourceRestrictAddressing, facei)
366 label coarseFacei = sourceRestrictAddressing[facei];
367 srcMagSf[coarseFacei] += fineSrcMagSf[facei];
373 if (targetMapPtr.
valid())
378 labelList allRestrict(targetRestrictAddressing);
405 labelList oldToNew(targetCoarseSize, -1);
410 label fineElem = elems[i];
411 label coarseElem = allRestrict[fineElem];
412 if (oldToNew[coarseElem] == -1)
414 oldToNew[coarseElem] = newI;
415 newSubMap[newI] = coarseElem;
435 tgtCompactMap = targetRestrictAddressing;
438 label compactI = targetCoarseSize;
450 labelList& newConstructMap = tgtConstructMap[proci];
460 remoteTargetCoarseSize =
max 462 remoteTargetCoarseSize,
463 allRestrict[elems[i]]
466 remoteTargetCoarseSize += 1;
469 labelList oldToNew(remoteTargetCoarseSize, -1);
474 label fineElem = elems[i];
476 label coarseElem = allRestrict[fineElem];
477 if (oldToNew[coarseElem] == -1)
479 oldToNew[coarseElem] = newI;
480 tgtCompactMap[fineElem] = compactI;
481 newConstructMap[newI] = compactI++;
487 label compactI = oldToNew[coarseElem];
488 tgtCompactMap[fineElem] = newConstructMap[compactI];
497 srcAddress.
setSize(sourceCoarseSize);
498 srcWeights.
setSize(sourceCoarseSize);
500 forAll(fineSrcAddress, facei)
504 const labelList& elems = fineSrcAddress[facei];
505 const scalarList& weights = fineSrcWeights[facei];
506 const scalar fineArea = fineSrcMagSf[facei];
508 label coarseFacei = sourceRestrictAddressing[facei];
510 const scalar coarseArea = srcMagSf[coarseFacei];
512 labelList& newElems = srcAddress[coarseFacei];
513 scalarList& newWeights = srcWeights[coarseFacei];
517 label elemI = elems[i];
518 label coarseElemI = tgtCompactMap[elemI];
523 newElems.
append(coarseElemI);
524 newWeights.
append(fineArea/coarseArea*weights[i]);
528 newWeights[index] += fineArea/coarseArea*weights[i];
539 move(tgtConstructMap)
545 srcAddress.
setSize(sourceCoarseSize);
546 srcWeights.
setSize(sourceCoarseSize);
548 forAll(fineSrcAddress, facei)
552 const labelList& elems = fineSrcAddress[facei];
553 const scalarList& weights = fineSrcWeights[facei];
554 const scalar fineArea = fineSrcMagSf[facei];
556 label coarseFacei = sourceRestrictAddressing[facei];
558 const scalar coarseArea = srcMagSf[coarseFacei];
560 labelList& newElems = srcAddress[coarseFacei];
561 scalarList& newWeights = srcWeights[coarseFacei];
565 label elemI = elems[i];
566 label coarseElemI = targetRestrictAddressing[elemI];
571 newElems.
append(coarseElemI);
572 newWeights.
append(fineArea/coarseArea*weights[i]);
576 newWeights[index] += fineArea/coarseArea*weights[i];
584 void Foam::AMIInterpolation::constructFromSurface
639 projectPointsToSurface(surfPtr(), srcPoints);
640 projectPointsToSurface(surfPtr(), tgtPoints);
644 update(srcPatch0, tgtPatch0, report);
648 update(srcPatch, tgtPatch, report);
660 const bool requireMatch,
662 const scalar lowWeightCorrection,
663 const bool reverseTarget,
667 methodName_(interpolationMethodToWord(method)),
668 reverseTarget_(reverseTarget),
669 requireMatch_(requireMatch),
670 singlePatchProc_(-999),
671 lowWeightCorrection_(lowWeightCorrection),
682 update(srcPatch, tgtPatch, report);
691 const bool requireMatch,
692 const word& methodName,
693 const scalar lowWeightCorrection,
694 const bool reverseTarget,
698 methodName_(methodName),
699 reverseTarget_(reverseTarget),
700 requireMatch_(requireMatch),
701 singlePatchProc_(-999),
702 lowWeightCorrection_(lowWeightCorrection),
713 update(srcPatch, tgtPatch, report);
723 const bool requireMatch,
725 const scalar lowWeightCorrection,
726 const bool reverseTarget,
730 methodName_(interpolationMethodToWord(method)),
731 reverseTarget_(reverseTarget),
732 requireMatch_(requireMatch),
733 singlePatchProc_(-999),
734 lowWeightCorrection_(lowWeightCorrection),
745 constructFromSurface(srcPatch, tgtPatch, surfPtr, report);
755 const bool requireMatch,
756 const word& methodName,
757 const scalar lowWeightCorrection,
758 const bool reverseTarget,
762 methodName_(methodName),
763 reverseTarget_(reverseTarget),
764 requireMatch_(requireMatch),
765 singlePatchProc_(-999),
766 lowWeightCorrection_(lowWeightCorrection),
777 constructFromSurface(srcPatch, tgtPatch, surfPtr, report);
784 const labelList& sourceRestrictAddressing,
785 const labelList& targetRestrictAddressing,
789 methodName_(fineAMI.methodName_),
790 reverseTarget_(fineAMI.reverseTarget_),
791 requireMatch_(fineAMI.requireMatch_),
792 singlePatchProc_(fineAMI.singlePatchProc_),
793 lowWeightCorrection_(-1.0),
800 triMode_(fineAMI.triMode_),
804 label sourceCoarseSize =
806 sourceRestrictAddressing.
size()
807 ?
max(sourceRestrictAddressing)+1
811 label neighbourCoarseSize =
813 targetRestrictAddressing.
size()
814 ?
max(targetRestrictAddressing)+1
820 Pout<<
"AMI: Creating addressing and weights as agglomeration of AMI :" 823 <<
" coarse source size:" << sourceCoarseSize
824 <<
" neighbour source size:" << neighbourCoarseSize
835 <<
"Size mismatch." <<
nl 837 <<
"Source agglomeration size:" 838 << sourceRestrictAddressing.
size() <<
nl 840 <<
"Target agglomeration size:" 841 << targetRestrictAddressing.
size()
853 sourceRestrictAddressing,
854 targetRestrictAddressing,
870 targetRestrictAddressing,
871 sourceRestrictAddressing,
884 reportSumWeights(*
this);
888 normaliseWeights(*
this);
911 if (srcTotalSize == 0)
915 Info<<
"AMI: no source faces present - no addressing constructed" 925 <<
"AMI: Creating addressing and weights between " 926 << srcTotalSize <<
" source faces and " 927 << tgtTotalSize <<
" target faces" 932 srcMagSf_ = patchMagSf(srcPatch, triMode_);
933 tgtMagSf_ = patchMagSf(tgtPatch, triMode_);
936 singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
938 if (singlePatchProc_ == -1)
959 distributeAndMergePatches
979 scalarField newTgtMagSf(patchMagSf(newTgtPatch, triMode_));
993 requireMatch_ && (lowWeightCorrection_ < 0)
1020 forAll(addressing, addrI)
1022 addressing[addrI] = tgtFaceIDs[addressing[addrI]];
1029 forAll(addressing, addrI)
1031 addressing[addrI] = globalSrcFaces.toGlobal(addressing[addrI]);
1070 srcMapPtr_.reset(
new mapDistribute(globalSrcFaces, tgtAddress_, cMap));
1071 tgtMapPtr_.reset(
new mapDistribute(globalTgtFaces, srcAddress_, cMap));
1075 writeFaceConnectivity(srcPatch, newTgtPatch, srcAddress_);
1092 requireMatch_ && (lowWeightCorrection_ < 0)
1109 reportSumWeights(*
this);
1113 normaliseWeights(*
this);
1118 Info<<
"AMIIPatchToPatchnterpolation :" 1119 <<
"Constructed addressing and weights" <<
nl 1122 <<
" singlePatchProc:" << singlePatchProc_ <<
nl 1123 <<
" srcMagSf :" <<
gSum(srcMagSf_) <<
nl 1124 <<
" tgtMagSf :" <<
gSum(tgtMagSf_) <<
nl 1132 sumWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
1133 sumWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
1142 srcWeights.set(i, &AMIs[i].srcWeights_);
1145 sumWeights(srcWeights, AMIs[0].srcWeightsSum_);
1147 for (
label i = 1; i < AMIs.
size(); ++ i)
1149 AMIs[i].srcWeightsSum_ = AMIs[0].srcWeightsSum_;
1155 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1158 sumWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1160 for (
label i = 1; i < AMIs.
size(); ++ i)
1162 AMIs[i].tgtWeightsSum_ = AMIs[0].tgtWeightsSum_;
1174 AMI.lowWeightCorrection_
1182 AMI.lowWeightCorrection_
1189 normaliseWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
1190 normaliseWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
1199 srcWeights.set(i, &AMIs[i].srcWeights_);
1202 normaliseWeights(srcWeights, AMIs[0].srcWeightsSum_);
1207 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1210 normaliseWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1219 const label tgtFacei,
1227 const labelList& addr = tgtAddress_[tgtFacei];
1230 label nearestFacei = -1;
1234 const label srcFacei = addr[i];
1235 const face&
f = srcPatch[srcFacei];
1251 nearestFacei = srcFacei;
1258 return nearestFacei;
1270 const label srcFacei,
1278 label nearestFacei = -1;
1281 const labelList& addr = srcAddress_[srcFacei];
1285 const label tgtFacei = addr[i];
1286 const face&
f = tgtPatch[tgtFacei];
1302 nearestFacei = tgtFacei;
1309 return nearestFacei;
1335 label tgtPtI = addr[j];
1341 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.
Tuple2< scalar, label > nearInfo
Private class for finding nearest.
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_
static void triangulate(const face &f, const pointField &points, const triangulationMode &triMode, triFaceList &faceTris)
Triangulate a face using the given triangulation mode.
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...
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...
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.