89 UPstream::listGatherValues<bool>
91 srcPatch.size() > 0 || tgtPatch.size() > 0
95 const auto nHaveFaces = hasFaces.
count();
101 <<
"AMI local to processor" << proci <<
endl;
103 else if (nHaveFaces > 1)
107 <<
"AMI split across multiple processors" <<
endl;
123 addProfiling(ami,
"AMIInterpolation::projectPointsToSurface");
138 pts[i] = pi.hitPoint();
150 <<
"Error projecting points to surface: "
151 << nMiss <<
" faces could not be determined"
160 const word& patchName,
164 const bool conformal,
166 const scalar lowWeightTol
169 addProfiling(ami,
"AMIInterpolation::normaliseWeights");
173 label nLowWeight = 0;
181 scalar denom = patchAreas[facei];
196 if (t < lowWeightTol)
214 <<
"AMI: Patch " << patchName
216 <<
" min:" <<
gMin(wghtSum)
217 <<
" max:" <<
gMax(wghtSum)
225 <<
"AMI: Patch " << patchName
226 <<
" identified " << nLow
227 <<
" faces with weights less than " << lowWeightTol
242 const labelList& sourceRestrictAddressing,
243 const labelList& targetRestrictAddressing,
254 label sourceCoarseSize =
256 sourceRestrictAddressing.
size()
257 ?
max(sourceRestrictAddressing)+1
261 label targetCoarseSize =
263 targetRestrictAddressing.
size()
264 ?
max(targetRestrictAddressing)+1
270 srcMagSf.
setSize(sourceRestrictAddressing.
size(), 0.0);
271 forAll(sourceRestrictAddressing, facei)
273 label coarseFacei = sourceRestrictAddressing[facei];
274 srcMagSf[coarseFacei] += fineSrcMagSf[facei];
284 labelList allRestrict(targetRestrictAddressing);
338 labelList oldToNew(targetCoarseSize, -1);
341 for (
const label elemi : elems)
343 label fineElem = elemsMap[elemi];
344 label coarseElem = allRestrict[fineElem];
345 if (oldToNew[coarseElem] == -1)
347 oldToNew[coarseElem] = newi;
348 newSubMap[newi] = coarseElem;
377 for (
const label fineElem : elemsMap)
379 label coarseElem = allRestrict[fineElem];
380 tgtCompactMap[fineElem] = coarseElem;
384 label compacti = targetCoarseSize;
396 labelList& newConstructMap = tgtConstructMap[proci];
403 label remoteTargetCoarseSize =
labelMin;
404 for (
const label elemi : elems)
406 remoteTargetCoarseSize =
max
408 remoteTargetCoarseSize,
412 remoteTargetCoarseSize += 1;
415 labelList oldToNew(remoteTargetCoarseSize, -1);
418 for (
const label fineElem : elems)
421 label coarseElem = allRestrict[fineElem];
422 if (oldToNew[coarseElem] == -1)
424 oldToNew[coarseElem] = newi;
425 tgtCompactMap[fineElem] = compacti;
426 newConstructMap[newi] = compacti++;
432 label compacti = oldToNew[coarseElem];
433 tgtCompactMap[fineElem] = newConstructMap[compacti];
441 srcAddress.
setSize(sourceCoarseSize);
442 srcWeights.
setSize(sourceCoarseSize);
444 forAll(fineSrcAddress, facei)
448 const labelList& elems = fineSrcAddress[facei];
449 const scalarList& weights = fineSrcWeights[facei];
450 const scalar fineArea = fineSrcMagSf[facei];
452 label coarseFacei = sourceRestrictAddressing[facei];
454 labelList& newElems = srcAddress[coarseFacei];
455 scalarList& newWeights = srcWeights[coarseFacei];
459 label elemi = elems[i];
460 label coarseElemi = tgtCompactMap[elemi];
462 label index = newElems.
find(coarseElemi);
465 newElems.
append(coarseElemi);
466 newWeights.
append(fineArea*weights[i]);
470 newWeights[index] += fineArea*weights[i];
480 std::move(tgtSubMap),
481 std::move(tgtConstructMap)
487 srcAddress.
setSize(sourceCoarseSize);
488 srcWeights.
setSize(sourceCoarseSize);
490 forAll(fineSrcAddress, facei)
494 const labelList& elems = fineSrcAddress[facei];
495 const scalarList& weights = fineSrcWeights[facei];
496 const scalar fineArea = fineSrcMagSf[facei];
498 label coarseFacei = sourceRestrictAddressing[facei];
500 labelList& newElems = srcAddress[coarseFacei];
501 scalarList& newWeights = srcWeights[coarseFacei];
505 const label elemi = elems[i];
506 const label coarseElemi = targetRestrictAddressing[elemi];
508 const label index = newElems.
find(coarseElemi);
511 newElems.
append(coarseElemi);
512 newWeights.
append(fineArea*weights[i]);
516 newWeights[index] += fineArea*weights[i];
542 const bool reverseTarget
545 requireMatch_(
dict.getOrDefault(
"requireMatch", true)),
546 reverseTarget_(
dict.getOrDefault(
"reverseTarget", reverseTarget)),
547 lowWeightCorrection_(
dict.getOrDefault<scalar>(
"lowWeightCorrection", -1)),
548 singlePatchProc_(-999),
567 const bool requireMatch,
568 const bool reverseTarget,
569 const scalar lowWeightCorrection
572 requireMatch_(requireMatch),
573 reverseTarget_(reverseTarget),
574 lowWeightCorrection_(lowWeightCorrection),
575 singlePatchProc_(-999),
597 const labelList& sourceRestrictAddressing,
598 const labelList& targetRestrictAddressing
601 requireMatch_(fineAMI.requireMatch_),
602 reverseTarget_(fineAMI.reverseTarget_),
603 lowWeightCorrection_(-1.0),
604 singlePatchProc_(fineAMI.singlePatchProc_),
619 label sourceCoarseSize =
621 sourceRestrictAddressing.
size()
622 ?
max(sourceRestrictAddressing)+1
626 label neighbourCoarseSize =
628 targetRestrictAddressing.
size()
629 ?
max(targetRestrictAddressing)+1
635 Pout<<
"AMI: Creating addressing and weights as agglomeration of AMI :"
638 <<
" coarse source size:" << sourceCoarseSize
639 <<
" neighbour source size:" << neighbourCoarseSize
650 <<
"Size mismatch." <<
nl
652 <<
"Source agglomeration size:"
653 << sourceRestrictAddressing.
size() <<
nl
655 <<
"Target agglomeration size:"
656 << targetRestrictAddressing.
size()
670 sourceRestrictAddressing,
671 targetRestrictAddressing,
687 targetRestrictAddressing,
688 sourceRestrictAddressing,
701 requireMatch_(ami.requireMatch_),
702 reverseTarget_(ami.reverseTarget_),
703 lowWeightCorrection_(ami.lowWeightCorrection_),
704 singlePatchProc_(ami.singlePatchProc_),
705 srcMagSf_(ami.srcMagSf_),
706 srcAddress_(ami.srcAddress_),
707 srcWeights_(ami.srcWeights_),
708 srcWeightsSum_(ami.srcWeightsSum_),
709 srcCentroids_(ami.srcCentroids_),
711 tgtMagSf_(ami.tgtMagSf_),
712 tgtAddress_(ami.tgtAddress_),
713 tgtWeights_(ami.tgtWeights_),
714 tgtWeightsSum_(ami.tgtWeightsSum_),
715 tgtCentroids_(ami.tgtCentroids_),
739 srcPatchPts_ = srcPatch.
points();
740 projectPointsToSurface(surfPtr(), srcPatchPts_);
747 tgtPatchPts_ = tgtPatch.
points();
748 projectPointsToSurface(surfPtr(), tgtPatchPts_);
757 tsrcPatch0_.cref(srcPatch);
758 ttgtPatch0_.cref(tgtPatch);
764 if (srcTotalSize == 0)
766 DebugInfo<<
"AMI: no source faces present - no addressing constructed"
773 <<
"AMI: Creating addressing and weights between "
774 << srcTotalSize <<
" source faces and "
775 << tgtTotalSize <<
" target faces"
778 singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
782 Info<<
"AMIInterpolation:" <<
nl
783 <<
" singlePatchProc:" << singlePatchProc_ <<
nl
803 srcAddress_.transfer(srcAddress);
804 srcWeights_.transfer(srcWeights);
805 tgtAddress_.transfer(tgtAddress);
806 tgtWeights_.transfer(tgtWeights);
809 srcWeightsSum_.setSize(srcWeights_.size());
810 forAll(srcWeights_, facei)
812 srcWeightsSum_[facei] =
sum(srcWeights_[facei]);
815 tgtWeightsSum_.setSize(tgtWeights_.size());
816 forAll(tgtWeights_, facei)
818 tgtWeightsSum_[facei] =
sum(tgtWeights_[facei]);
821 srcMapPtr_ = std::move(srcToTgtMap);
822 tgtMapPtr_ = std::move(tgtToSrcMap);
837 auto newPtr = clone();
838 newPtr->calculate(srcPatch, tgtPatch);
850 labelListList& newSrcConstructMap = newPtr->srcMapPtr_->constructMap();
853 labelListList& newTgtConstructMap = newPtr->tgtMapPtr_->constructMap();
864 srcConstructMap[proci].size(),
865 (mapMap.size() + newMapMap.
size())
872 newSrcConstructMap[proci].size(),
873 (mapMap.size() + newMapMap.
size())
880 forAll(srcConstructMap[proci], srci)
882 srcConstructMap[proci][srci] =
883 mapMap[srcConstructMap[proci][srci]];
889 forAll(newSrcConstructMap[proci], srci)
891 newSrcConstructMap[proci][srci] =
892 newMapMap[newSrcConstructMap[proci][srci]];
898 forAll(tgtAddress_[tgti], tgtj)
900 tgtAddress_[tgti][tgtj] = mapMap[tgtAddress_[tgti][tgtj]];
904 forAll(newPtr->tgtAddress_, tgti)
906 forAll(newPtr->tgtAddress_[tgti], tgtj)
908 newPtr->tgtAddress_[tgti][tgtj] =
909 newMapMap[newPtr->tgtAddress_[tgti][tgtj]];
923 tgtConstructMap[proci].size(),
924 (mapMap.size() + newMapMap.
size())
931 newTgtConstructMap[proci].size(),
932 (mapMap.size() + newMapMap.
size())
939 forAll(tgtConstructMap[proci], tgti)
941 tgtConstructMap[proci][tgti] =
942 mapMap[tgtConstructMap[proci][tgti]];
948 forAll(newTgtConstructMap[proci], tgti)
950 newTgtConstructMap[proci][tgti] =
951 newMapMap[newTgtConstructMap[proci][tgti]];
957 forAll(srcAddress_[srci], srcj)
959 srcAddress_[srci][srcj] =
960 mapMap[srcAddress_[srci][srcj]];
964 forAll(newPtr->srcAddress_, srci)
966 forAll(newPtr->srcAddress_[srci], srcj)
968 newPtr->srcAddress_[srci][srcj] =
969 newMapMap[newPtr->srcAddress_[srci][srcj]];
975 srcMapPtr_->constructSize() += newPtr->srcMapPtr_->constructSize();
976 tgtMapPtr_->constructSize() += newPtr->tgtMapPtr_->constructSize();
981 srcSubMap[proci].
append(newSrcSubMap[proci]);
982 srcConstructMap[proci].
append(newSrcConstructMap[proci]);
984 tgtSubMap[proci].
append(newTgtSubMap[proci]);
985 tgtConstructMap[proci].
append(newTgtConstructMap[proci]);
990 forAll(srcMagSf_, srcFacei)
992 srcAddress_[srcFacei].append(newPtr->srcAddress()[srcFacei]);
993 srcWeights_[srcFacei].append(newPtr->srcWeights()[srcFacei]);
994 srcWeightsSum_[srcFacei] += newPtr->srcWeightsSum()[srcFacei];
998 forAll(tgtMagSf_, tgtFacei)
1000 tgtAddress_[tgtFacei].append(newPtr->tgtAddress()[tgtFacei]);
1001 tgtWeights_[tgtFacei].append(newPtr->tgtWeights()[tgtFacei]);
1002 tgtWeightsSum_[tgtFacei] += newPtr->tgtWeightsSum()[tgtFacei];
1009 const bool conformal,
1022 lowWeightCorrection_
1034 lowWeightCorrection_
1044 const label tgtFacei,
1052 const labelList& addr = tgtAddress_[tgtFacei];
1056 label nearestFacei = -1;
1058 for (
const label srcFacei : addr)
1060 const face&
f = srcPatch[srcFacei];
1074 nearestFacei = srcFacei;
1081 return nearestFacei;
1093 const label srcFacei,
1102 label nearestFacei = -1;
1105 const labelList& addr = srcAddress_[srcFacei];
1107 for (
const label tgtFacei : addr)
1109 const face&
f = tgtPatch[tgtFacei];
1119 const pointHit near =
f.nearestPoint(srcPoint, tgtPoints);
1124 nearestFacei = tgtFacei;
1131 return nearestFacei;
1142 Log <<
"Checks only valid for serial running (currently)" <<
endl;
1147 bool symmetricSrc =
true;
1149 Log <<
" Checking for missing src face in tgt lists" <<
nl;
1151 forAll(srcAddress_, srcFacei)
1153 const labelList& tgtIds = srcAddress_[srcFacei];
1154 for (
const label tgtFacei : tgtIds)
1156 if (!tgtAddress_[tgtFacei].
found(srcFacei))
1158 symmetricSrc =
false;
1160 Log <<
" srcFacei:" << srcFacei
1161 <<
" not found in tgtToSrc list for tgtFacei:"
1169 Log <<
" - symmetric" <<
endl;
1172 bool symmetricTgt =
true;
1174 Log <<
" Checking for missing tgt face in src lists" <<
nl;
1176 forAll(tgtAddress_, tgtFacei)
1178 const labelList& srcIds = tgtAddress_[tgtFacei];
1179 for (
const label srcFacei : srcIds)
1181 if (!srcAddress_[srcFacei].
found(tgtFacei))
1183 symmetricTgt =
false;
1185 Log <<
" tgtFacei:" << tgtFacei
1186 <<
" not found in srcToTgt list for srcFacei:"
1194 Log <<
" - symmetric" <<
endl;
1197 return symmetricSrc && symmetricTgt;
1218 for (
const label tgtPti : addr)
1225 os <<
"l " << pti <<
" " << pti + 1 <<
endl;
1247 if (lowWeightCorrection_ > 0)
1249 os.
writeEntry(
"lowWeightCorrection", lowWeightCorrection_);
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
labelListList srcAddress_
Addresses of target faces per source face.
scalarList tgtMagSf_
Target face areas.
const scalarListList & tgtWeights() const
Return const access to target patch weights.
void projectPointsToSurface(const searchableSurface &surf, pointField &pts) const
Project points to surface.
const labelListList & srcAddress() const
Return const access to source patch addressing.
autoPtr< mapDistribute > srcMapPtr_
Source map pointer - parallel running only.
virtual bool calculate(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const autoPtr< searchableSurface > &surfPtr=nullptr)
Update addressing, weights and (optional) centroids.
bool checkSymmetricWeights(const bool log) const
autoPtr< mapDistribute > tgtMapPtr_
Target map pointer - parallel running only.
const scalarListList & srcWeights() const
Return const access to source patch weights.
static void agglomerate(const autoPtr< mapDistribute > &targetMap, const scalarList &fineSrcMagSf, const labelListList &fineSrcAddress, const scalarListList &fineSrcWeights, const labelList &sourceRestrictAddressing, const labelList &targetRestrictAddressing, scalarList &srcMagSf, labelListList &srcAddress, scalarListList &srcWeights, scalarField &srcWeightsSum, autoPtr< mapDistribute > &tgtMap)
static void normaliseWeights(const scalarList &patchAreas, const word &patchName, const labelListList &addr, scalarListList &wght, scalarField &wghtSum, const bool conformal, const bool output, const scalar lowWeightTol)
labelListList tgtAddress_
Addresses of source faces per target face.
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.
label calcDistribution(const primitivePatch &srcPatch, const primitivePatch &tgtPatch) const
Calculate if patches are on multiple processors.
static bool cacheIntersections_
void writeFaceConnectivity(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
scalarField srcWeightsSum_
Sum of weights of target faces per source face.
autoPtr< indexedOctree< treeType > > createTree(const primitivePatch &patch) const
Reset the octree for the patch face search.
scalarListList tgtWeights_
Weights of source faces per target face.
scalarListList srcWeights_
Weights of target faces per source face.
const List< scalar > & srcMagSf() const
Return const access to source patch face areas.
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.
scalarList srcMagSf_
Source face areas.
scalarField tgtWeightsSum_
Sum of weights of source faces per target face.
const List< scalar > & tgtMagSf() const
Return const access to target patch face areas.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
static autoPtr< AMIInterpolation > New(const word &modelName, const dictionary &dict, const bool reverseTarget=false)
Selector for dictionary.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(const label n)
Alias for resize()
void append(const T &val)
Append an element at the end of the list.
Output to file stream, using an OSstream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Describes the interaction of a face and a point. It carries the info of a successful hit and (if succ...
const point_type & rawPoint() const noexcept
The point, no checks.
bool eligibleMiss() const noexcept
Is this an eligible miss.
scalar distance() const noexcept
Return distance to hit.
void setDistance(const scalar d) noexcept
Set the distance.
bool hit() const noexcept
Is there a hit.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
A list of faces which address into the list of points.
const Field< point_type > & points() const noexcept
Return reference to global points.
const Field< point_type > & faceCentres() const
Return face centres for patch.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
A List obtained as a section of another List.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
void size(const label n)
Older name for setAddressableSize.
static bool & parRun() noexcept
Test if this a parallel run.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
unsigned int count(const bool on=true) const
Count number of bits set.
label find_first() const
Locate the first bit that is set.
void inflate(const scalar s)
Inflate box by factor*mag(span) in all dimensions.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
void reset()
Reset to defaults.
A face is a list of labels corresponding to mesh vertices.
virtual bool write()
Write the output fields.
Non-pointer based hierarchical recursive searching.
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
const labelListList & subMap() const noexcept
From subsetted data back to original data.
label constructSize() const noexcept
Constructed data size.
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
int myProcNo() const noexcept
Return processor number.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
Standard boundBox with extra functionality for use in octree.
Encapsulation of data needed to search on PrimitivePatches.
bool append() const noexcept
True if output format uses an append mode.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define DebugInfo
Report an information message using Foam::Info.
#define DebugInFunction
Report an information message using Foam::Info.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & indent(Ostream &os)
Indent stream.
errorManip< error > abort(error &err)
static Ostream & output(Ostream &os, const IntRange< T > &range)
Type gAverage(const FieldField< Field, Type > &f)
Type gMin(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a)
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAll(list, i)
Loop across all elements in list.