49 const label startSeedI,
56 for (label i = startSeedI; i < srcCellIDs.
size(); i++)
58 label srcI = srcCellIDs[i];
62 const point& srcCc = srcCcs[srcI];
69 tgtSeedI = hit.
index();
76 <<
"Unable to find nearest target cell"
77 <<
" for source cell " << srcI
78 <<
" with centre " << srcCc
101 const label srcSeedI,
102 const label tgtSeedI,
108 List<DynamicList<label>> srcToTgt(src_.nCells());
109 List<DynamicList<label>> tgtToSrc(tgt_.nCells());
115 label srcCelli = srcSeedI;
116 label tgtCelli = tgtSeedI;
121 findNearestCell(src_, tgt_, srcCelli, tgtCelli);
124 srcToTgt[srcCelli].append(tgtCelli);
125 tgtToSrc[tgtCelli].append(srcCelli);
128 mapFlag[srcCelli] =
false;
131 V_ += srcVc[srcCelli];
143 while (srcCelli >= 0);
151 forAll(tgtToSrc, targetCelli)
153 if (tgtToSrc[targetCelli].size() > 1)
155 const vector& tgtC = tgtCc[targetCelli];
159 label srcCelli = srcCells[0];
160 scalar d =
magSqr(tgtC - srcCc[srcCelli]);
162 for (label i = 1; i < srcCells.size(); i++)
164 label srcI = srcCells[i];
165 scalar dNew =
magSqr(tgtC - srcCc[srcI]);
174 srcCells.append(srcCelli);
180 forAll(tgtToSrc, tgtCelli)
182 if (tgtToSrc[tgtCelli].empty())
184 label srcCelli = findMappedSrcCell(tgtCelli, tgtToSrc);
186 findNearestCell(tgt_, src_, tgtCelli, srcCelli);
188 tgtToSrc[tgtCelli].append(srcCelli);
193 forAll(srcToTgtCellAddr, i)
195 srcToTgtCellWght[i] =
scalarList(srcToTgt[i].size(), srcVc[i]);
196 srcToTgtCellAddr[i].transfer(srcToTgt[i]);
199 forAll(tgtToSrcCellAddr, i)
201 tgtToSrcCellWght[i] =
scalarList(tgtToSrc[i].size(), tgtVc[i]);
202 tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
209 const polyMesh& mesh1,
210 const polyMesh& mesh2,
218 const vector& p1 = Cc1[cell1];
220 DynamicList<label> queuedCells(10);
221 DynamicList<label> visitedCells(10);
223 queuedCells.push_back(cell2);
227 while (!queuedCells.empty())
230 const label currCelli = queuedCells.back();
231 queuedCells.pop_back();
232 visitedCells.push_back(currCelli);
234 scalar dTest = p1.distSqr(Cc2[currCelli]);
255 const labelList& srcNbr = src_.cellCells()[srcCelli];
260 label celli = srcNbr[i];
268 for (label i = startSeedI; i < srcCellIDs.size(); i++)
270 label celli = srcCellIDs[i];
278 (void)findInitialSeeds
291 const label tgtCelli,
300 while (!queuedCells.
empty())
303 const label tgtI = queuedCells.
back();
308 if (!visitedCells.
found(tgtI))
312 if (tgtToSrc[tgtI].size())
314 return tgtToSrc[tgtI][0];
318 const labelList& nbrCells = tgt_.cellCells()[tgtI];
320 for (
const label nbrCelli : nbrCells)
322 if (!visitedCells.
found(nbrCelli))
344 meshToMeshMethod(
src,
tgt)
383 boolList mapFlag(src_.nCells(),
false);
389 label startSeedI = 0;
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
void append(const T &val)
Copy append an element to the end of this list.
void push_back(const T &val)
Copy append an element to the end of this list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
void append(const T &val)
Append an element at the end of the list.
label index() const noexcept
Return the hit index.
bool hit() const noexcept
Is there a hit?
bool found(const T &val, label pos=0) const
Same as contains().
bool empty() const noexcept
True if List is empty (ie, size() is zero).
T & back()
Access last element of the list, position [size()-1].
void size(const label n)
Older name for setAddressableSize.
scalar distSqr(const Vector< Cmpt > &v2) const
The L2-norm distance squared from another vector. The magSqr() of the difference.
Map nearest mesh-to-mesh interpolation class.
virtual bool findInitialSeeds(const labelList &srcCellIDs, const boolList &mapFlag, const label startSeedI, label &srcSeedI, label &tgtSeedI) const
Find indices of overlapping cells in src and tgt meshes - returns.
virtual void findNearestCell(const polyMesh &mesh1, const polyMesh &mesh2, const label cell1, label &cell2) const
Find the nearest cell on mesh2 for cell1 on mesh1.
virtual void setNextNearestCells(label &startSeedI, label &srcCelli, label &tgtCelli, boolList &mapFlag, const labelList &srcCellIDs) const
Set the next cells for the marching front algorithm.
virtual label findMappedSrcCell(const label tgtCelli, const List< DynamicList< label > > &tgtToSrc) const
Find a source cell mapped to target cell tgtCelli.
mapNearestMethod(const mapNearestMethod &)=delete
No copy construct.
virtual void calculateAddressing(labelListList &srcToTgtCellAddr, scalarListList &srcToTgtCellWght, labelListList &tgtToSrcCellAddr, scalarListList &tgtToSrcCellWght, const label srcSeedI, const label tgtSeedI, const labelList &srcCellIDs, boolList &mapFlag, label &startSeedI)
Calculate the mesh-to-mesh addressing and weights.
virtual void calculate(labelListList &srcToTgtAddr, scalarListList &srcToTgtWght, pointListList &srcToTgtVec, labelListList &tgtToSrcAddr, scalarListList &tgtToSrcWght, pointListList &tgtToSrcVec)
Calculate addressing and weights and optionally offset vectors.
virtual ~mapNearestMethod()
Destructor.
Base class for mesh-to-mesh calculation methods.
const polyMesh & tgt_
Reference to the target mesh.
const polyMesh & src() const
Return const access to the source mesh.
const polyMesh & src_
Reference to the source mesh.
const polyMesh & tgt() const
Return const access to the target mesh.
labelList maskCells() const
Return src cell IDs for the overlap region.
scalar V_
Cell total volume in overlap region [m3].
virtual bool initialise(labelListList &srcToTgtAddr, scalarListList &srcToTgtWght, labelListList &tgtToTgtAddr, scalarListList &tgtToTgtWght) const
virtual void appendNbrCells(const label tgtCelli, const polyMesh &mesh, const labelUList &visitedTgtCells, DynamicList< label > &nbrTgtCellIDs) const
Append target cell neighbour cells to cellIDs list.
Mesh consisting of general polyhedral cells.
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
const vectorField & cellCentres() const
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Namespace for handling debugging switches.
List< scalarList > scalarListList
List of scalarList.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
List< bool > boolList
A List of bools.
UIndirectList< bool > boolUIndList
UIndirectList of bools.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
List< scalar > scalarList
List of scalar.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
List< pointList > pointListList
List of pointList.
#define forAll(list, i)
Loop across all elements in list.