68 patchFaceTris[i].tri(patchPoints).mag();
78 void Foam::AMIInterpolation::projectPointsToSurface
86 Info<<
"AMI: projecting points to surface" <<
endl;
112 <<
"Error projecting points to surface: " 113 << nMiss <<
" faces could not be determined" 119 void Foam::AMIInterpolation::sumWeights
130 wghtSum[facei] =
sum(wght[facei]);
135 void Foam::AMIInterpolation::sumWeights
141 wghtSum.
setSize(wghts[0].size());
148 forAll(wghts[wghtsi][facei], i)
150 wghtSum[facei] += wghts[wghtsi][facei][i];
157 void Foam::AMIInterpolation::reportSumWeights
160 const word& patchName,
162 const scalar lowWeightTol
170 label nLowWeight = 0;
173 if (wghtSum[facei] < lowWeightTol)
181 <<
" sum(weights) min/max/average = " <<
gMin(wghtSum) <<
", " 182 <<
gMax(wghtSum) <<
", " 187 Info<<
indent <<
"AMI: Patch " << patchName <<
" identified " 188 << nLowWeight <<
" faces with weights less than " 189 << lowWeightTol <<
endl;
194 void Foam::AMIInterpolation::normaliseWeights
206 w[i] /= wghtSum[facei];
212 void Foam::AMIInterpolation::normaliseWeights
226 w[i] /= wghtSum[facei];
233 void Foam::AMIInterpolation::agglomerate
240 const labelList& sourceRestrictAddressing,
241 const labelList& targetRestrictAddressing,
250 label sourceCoarseSize =
252 sourceRestrictAddressing.
size()
253 ?
max(sourceRestrictAddressing)+1
257 label targetCoarseSize =
259 targetRestrictAddressing.
size()
260 ?
max(targetRestrictAddressing)+1
266 srcMagSf.
setSize(sourceRestrictAddressing.
size(), 0.0);
267 forAll(sourceRestrictAddressing, facei)
269 label coarseFacei = sourceRestrictAddressing[facei];
270 srcMagSf[coarseFacei] += fineSrcMagSf[facei];
276 if (targetMapPtr.
valid())
281 labelList allRestrict(targetRestrictAddressing);
308 labelList oldToNew(targetCoarseSize, -1);
313 label fineElem = elems[i];
314 label coarseElem = allRestrict[fineElem];
315 if (oldToNew[coarseElem] == -1)
317 oldToNew[coarseElem] = newI;
318 newSubMap[newI] = coarseElem;
338 tgtCompactMap = targetRestrictAddressing;
341 label compactI = targetCoarseSize;
353 labelList& newConstructMap = tgtConstructMap[proci];
363 remoteTargetCoarseSize =
max 365 remoteTargetCoarseSize,
366 allRestrict[elems[i]]
369 remoteTargetCoarseSize += 1;
372 labelList oldToNew(remoteTargetCoarseSize, -1);
377 label fineElem = elems[i];
379 label coarseElem = allRestrict[fineElem];
380 if (oldToNew[coarseElem] == -1)
382 oldToNew[coarseElem] = newI;
383 tgtCompactMap[fineElem] = compactI;
384 newConstructMap[newI] = compactI++;
390 label compactI = oldToNew[coarseElem];
391 tgtCompactMap[fineElem] = newConstructMap[compactI];
400 srcAddress.
setSize(sourceCoarseSize);
401 srcWeights.
setSize(sourceCoarseSize);
403 forAll(fineSrcAddress, facei)
407 const labelList& elems = fineSrcAddress[facei];
408 const scalarList& weights = fineSrcWeights[facei];
409 const scalar fineArea = fineSrcMagSf[facei];
411 label coarseFacei = sourceRestrictAddressing[facei];
413 const scalar coarseArea = srcMagSf[coarseFacei];
415 labelList& newElems = srcAddress[coarseFacei];
416 scalarList& newWeights = srcWeights[coarseFacei];
420 label elemI = elems[i];
421 label coarseElemI = tgtCompactMap[elemI];
426 newElems.
append(coarseElemI);
427 newWeights.
append(fineArea/coarseArea*weights[i]);
431 newWeights[index] += fineArea/coarseArea*weights[i];
442 move(tgtConstructMap)
448 srcAddress.
setSize(sourceCoarseSize);
449 srcWeights.
setSize(sourceCoarseSize);
451 forAll(fineSrcAddress, facei)
455 const labelList& elems = fineSrcAddress[facei];
456 const scalarList& weights = fineSrcWeights[facei];
457 const scalar fineArea = fineSrcMagSf[facei];
459 label coarseFacei = sourceRestrictAddressing[facei];
461 const scalar coarseArea = srcMagSf[coarseFacei];
463 labelList& newElems = srcAddress[coarseFacei];
464 scalarList& newWeights = srcWeights[coarseFacei];
468 label elemI = elems[i];
469 label coarseElemI = targetRestrictAddressing[elemI];
474 newElems.
append(coarseElemI);
475 newWeights.
append(fineArea/coarseArea*weights[i]);
479 newWeights[index] += fineArea/coarseArea*weights[i];
487 void Foam::AMIInterpolation::constructFromSurface
542 projectPointsToSurface(surfPtr(), srcPoints);
543 projectPointsToSurface(surfPtr(), tgtPoints);
547 update(srcPatch0, tgtPatch0, report);
551 update(srcPatch, tgtPatch, report);
563 const bool requireMatch,
564 const word& methodName,
565 const scalar lowWeightCorrection,
566 const bool reverseTarget,
570 methodName_(methodName),
571 reverseTarget_(reverseTarget),
572 requireMatch_(requireMatch),
573 singlePatchProc_(-999),
574 lowWeightCorrection_(lowWeightCorrection),
585 update(srcPatch, tgtPatch, report);
595 const bool requireMatch,
596 const word& methodName,
597 const scalar lowWeightCorrection,
598 const bool reverseTarget,
602 methodName_(methodName),
603 reverseTarget_(reverseTarget),
604 requireMatch_(requireMatch),
605 singlePatchProc_(-999),
606 lowWeightCorrection_(lowWeightCorrection),
617 constructFromSurface(srcPatch, tgtPatch, surfPtr, report);
624 const labelList& sourceRestrictAddressing,
625 const labelList& targetRestrictAddressing,
629 methodName_(fineAMI.methodName_),
630 reverseTarget_(fineAMI.reverseTarget_),
631 requireMatch_(fineAMI.requireMatch_),
632 singlePatchProc_(fineAMI.singlePatchProc_),
633 lowWeightCorrection_(-1.0),
640 triMode_(fineAMI.triMode_),
644 label sourceCoarseSize =
646 sourceRestrictAddressing.
size()
647 ?
max(sourceRestrictAddressing)+1
651 label neighbourCoarseSize =
653 targetRestrictAddressing.
size()
654 ?
max(targetRestrictAddressing)+1
660 Pout<<
"AMI: Creating addressing and weights as agglomeration of AMI :" 663 <<
" coarse source size:" << sourceCoarseSize
664 <<
" neighbour source size:" << neighbourCoarseSize
675 <<
"Size mismatch." <<
nl 677 <<
"Source agglomeration size:" 678 << sourceRestrictAddressing.
size() <<
nl 680 <<
"Target agglomeration size:" 681 << targetRestrictAddressing.
size()
693 sourceRestrictAddressing,
694 targetRestrictAddressing,
710 targetRestrictAddressing,
711 sourceRestrictAddressing,
724 reportSumWeights(*
this);
728 normaliseWeights(*
this);
751 if (srcTotalSize == 0)
755 Info<<
"AMI: no source faces present - no addressing constructed" 765 <<
"AMI: Creating addressing and weights between " 766 << srcTotalSize <<
" source faces and " 767 << tgtTotalSize <<
" target faces" 772 srcMagSf_ = patchMagSf(srcPatch, triMode_);
773 tgtMagSf_ = patchMagSf(tgtPatch, triMode_);
776 singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
778 if (singlePatchProc_ == -1)
799 distributeAndMergePatches
819 scalarField newTgtMagSf(patchMagSf(newTgtPatch, triMode_));
833 requireMatch_ && (lowWeightCorrection_ < 0)
862 addressing[addrI] = tgtFaceIDs[addressing[addrI]];
871 addressing[addrI] = globalSrcFaces.toGlobal(addressing[addrI]);
921 writeFaceConnectivity(srcPatch, newTgtPatch, srcAddress_);
938 requireMatch_ && (lowWeightCorrection_ < 0)
955 reportSumWeights(*
this);
959 normaliseWeights(*
this);
964 Info<<
"AMIIPatchToPatchnterpolation :" 965 <<
"Constructed addressing and weights" <<
nl 968 <<
" singlePatchProc:" << singlePatchProc_ <<
nl 969 <<
" srcMagSf :" <<
gSum(srcMagSf_) <<
nl 970 <<
" tgtMagSf :" <<
gSum(tgtMagSf_) <<
nl 978 sumWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
979 sumWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
988 srcWeights.set(i, &AMIs[i].srcWeights_);
991 sumWeights(srcWeights, AMIs[0].srcWeightsSum_);
995 AMIs[i].srcWeightsSum_ = AMIs[0].srcWeightsSum_;
1001 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1004 sumWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1006 for (
label i = 1; i < AMIs.
size(); ++ i)
1008 AMIs[i].tgtWeightsSum_ = AMIs[0].tgtWeightsSum_;
1020 AMI.lowWeightCorrection_
1028 AMI.lowWeightCorrection_
1035 normaliseWeights(AMI.srcWeights_, AMI.srcWeightsSum_);
1036 normaliseWeights(AMI.tgtWeights_, AMI.tgtWeightsSum_);
1045 srcWeights.set(i, &AMIs[i].srcWeights_);
1048 normaliseWeights(srcWeights, AMIs[0].srcWeightsSum_);
1053 tgtWeights.set(i, &AMIs[i].tgtWeights_);
1056 normaliseWeights(tgtWeights, AMIs[0].tgtWeightsSum_);
1065 const label tgtFacei,
1073 const labelList& addr = tgtAddress_[tgtFacei];
1076 label nearestFacei = -1;
1080 const label srcFacei = addr[i];
1081 const face&
f = srcPatch[srcFacei];
1097 nearestFacei = srcFacei;
1104 return nearestFacei;
1116 const label srcFacei,
1124 label nearestFacei = -1;
1127 const labelList& addr = srcAddress_[srcFacei];
1131 const label tgtFacei = addr[i];
1132 const face&
f = tgtPatch[tgtFacei];
1148 nearestFacei = tgtFacei;
1155 return nearestFacei;
1181 label tgtPtI = addr[j];
1187 os <<
"l " << ptI <<
" " << ptI + 1 <<
endl;
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.
Class containing functor to negate primitives. Dummy for all other types.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
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.
#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 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.
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.
const labelListList & constructMap() const
From subsetted data to new reconstructed data.
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 labelListList & subMap() const
From subsetted data back to original data.
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.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
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
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.
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)
label constructSize() const
Constructed data size.
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.
void setSize(const label)
Reset size of List.
Class containing processor-to-processor mapping information.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
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...
prefixOSstream Pout(cout, "Pout")
AMIInterpolation(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const faceAreaIntersect::triangulationMode &triMode, const bool requireMatch=true, const word &methodName=faceAreaWeightAMI::typeName, const scalar lowWeightCorrection=-1, const bool reverseTarget=false, const bool report=true)
Construct from components.
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...
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
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.
List operator to append one list onto another.