36 namespace cellsToCellss
46 bool Foam::cellsToCellss::nearest::findInitialSeeds
48 const polyMesh& srcMesh,
49 const polyMesh& tgtMesh,
52 const label startSeedI,
59 for (
label i = startSeedI; i < srcCellIDs.size(); i++)
61 label srcI = srcCellIDs[i];
65 const point& srcCc = srcCcs[srcI];
67 tgtMesh.cellTree().findNearest(srcCc, great);
72 tgtSeedI = hit.index();
79 <<
"Unable to find nearest target cell"
80 <<
" for source cell " << srcI
81 <<
" with centre " << srcCc
91 Pout<<
"could not find starting seed" <<
endl;
98 Foam::scalar Foam::cellsToCellss::nearest::calculateAddressing
100 const polyMesh& srcMesh,
101 const polyMesh& tgtMesh,
106 const label srcSeedI,
107 const label tgtSeedI,
115 List<DynamicList<label>> srcToTgt(srcMesh.nCells());
116 List<DynamicList<label>> tgtToSrc(tgtMesh.nCells());
121 label srcCelli = srcSeedI;
122 label tgtCelli = tgtSeedI;
127 findNearestCell(srcMesh, tgtMesh, srcCelli, tgtCelli);
130 srcToTgt[srcCelli].append(tgtCelli);
131 tgtToSrc[tgtCelli].append(srcCelli);
134 mapFlag[srcCelli] =
false;
137 V += srcVc[srcCelli];
151 while (srcCelli >= 0);
159 forAll(tgtToSrc, targetCelli)
161 if (tgtToSrc[targetCelli].size() > 1)
163 const vector& tgtC = tgtCc[targetCelli];
165 DynamicList<label>& srcCells = tgtToSrc[targetCelli];
167 label srcCelli = srcCells[0];
168 scalar d =
magSqr(tgtC - srcCc[srcCelli]);
170 for (
label i = 1; i < srcCells.size(); i++)
172 label srcI = srcCells[i];
173 scalar dNew =
magSqr(tgtC - srcCc[srcI]);
182 srcCells.append(srcCelli);
188 forAll(tgtToSrc, tgtCelli)
190 if (tgtToSrc[tgtCelli].empty())
193 findMappedSrcCell(srcMesh, tgtMesh, tgtCelli, tgtToSrc);
195 findNearestCell(tgtMesh, srcMesh, tgtCelli, srcCelli);
197 tgtToSrc[tgtCelli].append(srcCelli);
202 forAll(srcToTgtCellAddr, i)
204 srcToTgtCellWght[i] =
scalarList(srcToTgt[i].size(), scalar(1));
205 srcToTgtCellAddr[i].transfer(srcToTgt[i]);
208 forAll(tgtToSrcCellAddr, i)
210 tgtToSrcCellWght[i] =
scalarList(tgtToSrc[i].size(), scalar(1));
211 tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
218 void Foam::cellsToCellss::nearest::findNearestCell
220 const polyMesh& mesh1,
221 const polyMesh& mesh2,
229 const vector& p1 = Cc1[cell1];
231 DynamicList<label> cells2(10);
232 cells2.append(cell2);
234 DynamicList<label> visitedCells(10);
241 visitedCells.append(
c2);
243 scalar dTest =
magSqr(Cc2[
c2] - p1);
248 appendNbrCells(cell2, mesh2, visitedCells, cells2);
251 }
while (cells2.size() > 0);
255 void Foam::cellsToCellss::nearest::setNextNearestCells
257 const polyMesh& srcMesh,
258 const polyMesh& tgtMesh,
266 const labelList& srcNbr = srcMesh.cellCells()[srcCelli];
271 label celli = srcNbr[i];
279 for (
label i = startSeedI; i < srcCellIDs.size(); i++)
281 label celli = srcCellIDs[i];
302 Foam::label Foam::cellsToCellss::nearest::findMappedSrcCell
304 const polyMesh& srcMesh,
305 const polyMesh& tgtMesh,
306 const label tgtCelli,
307 const List<DynamicList<label>>& tgtToSrc
310 DynamicList<label> testCells(10);
311 DynamicList<label> visitedCells(10);
313 testCells.append(tgtCelli);
318 label tgtI = testCells.remove();
322 visitedCells.append(tgtI);
324 if (tgtToSrc[tgtI].size())
326 return tgtToSrc[tgtI][0];
330 const labelList& nbrCells = tgtMesh.cellCells()[tgtI];
334 if (
findIndex(visitedCells, nbrCells[i]) == -1)
336 testCells.append(nbrCells[i]);
341 }
while (testCells.size());
356 initialise(srcMesh, tgtMesh);
359 const labelList srcCellIDs(maskCells(srcMesh, tgtMesh));
368 label startSeedI = 0;
413 forAll(srcToTgtWght, srcCelli)
415 if (srcToTgtWght[srcCelli].size() > 1)
417 srcToTgtAddr[srcCelli].
resize(1);
418 srcToTgtWght[srcCelli].
resize(1);
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
void resize(const label)
Alias for setSize(const label)
A List with indirect addressing.
Class to calculate interpolative addressing and weights between the cells of two overlapping meshes.
Nearest cells-to-cells interpolation class.
virtual scalar calculate(const polyMesh &srcMesh, const polyMesh &tgtMesh)
Calculate the addressing and weights.
virtual ~nearest()
Destructor.
virtual void normalise(const polyMesh &mesh, labelListList &localOtherCells, scalarListList &weights) const
Normalise the weights for a given mesh.
Mesh consisting of general polyhedral cells.
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
defineTypeNameAndDebug(intersection, 0)
addToRunTimeSelectionTable(cellsToCells, intersection, word)
const dimensionedScalar c2
Second radiation constant: default SI units: [m K].
List< scalarList > scalarListList
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
PointIndexHit< point > pointIndexHit
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
List< bool > boolList
Bool container classes.
List< scalar > scalarList
A List of scalars.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Vector< scalar > vector
A scalar version of the templated Vector.
List< labelList > labelListList
A List of labelList.
Field< vector > vectorField
Specialisation of Field<T> for vector.
prefixOSstream Pout(cout, "Pout")
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)