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());
122 label srcCelli = srcSeedI;
123 label tgtCelli = tgtSeedI;
128 findNearestCell(srcMesh, tgtMesh, srcCelli, tgtCelli);
131 srcToTgt[srcCelli].append(tgtCelli);
132 tgtToSrc[tgtCelli].append(srcCelli);
135 mapFlag[srcCelli] =
false;
138 V += srcVc[srcCelli];
152 while (srcCelli >= 0);
160 forAll(tgtToSrc, targetCelli)
162 if (tgtToSrc[targetCelli].size() > 1)
164 const vector& tgtC = tgtCc[targetCelli];
166 DynamicList<label>& srcCells = tgtToSrc[targetCelli];
168 label srcCelli = srcCells[0];
169 scalar d =
magSqr(tgtC - srcCc[srcCelli]);
171 for (
label i = 1; i < srcCells.size(); i++)
173 label srcI = srcCells[i];
174 scalar dNew =
magSqr(tgtC - srcCc[srcI]);
183 srcCells.append(srcCelli);
189 forAll(tgtToSrc, tgtCelli)
191 if (tgtToSrc[tgtCelli].empty())
194 findMappedSrcCell(srcMesh, tgtMesh, tgtCelli, tgtToSrc);
196 findNearestCell(tgtMesh, srcMesh, tgtCelli, srcCelli);
198 tgtToSrc[tgtCelli].append(srcCelli);
203 forAll(srcToTgtCellAddr, i)
205 srcToTgtCellWght[i] =
scalarList(srcToTgt[i].size(), srcVc[i]);
206 srcToTgtCellAddr[i].transfer(srcToTgt[i]);
209 forAll(tgtToSrcCellAddr, i)
211 tgtToSrcCellWght[i] =
scalarList(tgtToSrc[i].size(), tgtVc[i]);
212 tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
219 void Foam::cellsToCellss::nearest::findNearestCell
221 const polyMesh& mesh1,
222 const polyMesh& mesh2,
230 const vector& p1 = Cc1[cell1];
232 DynamicList<label> cells2(10);
233 cells2.append(cell2);
235 DynamicList<label> visitedCells(10);
242 visitedCells.append(
c2);
244 scalar dTest =
magSqr(Cc2[
c2] - p1);
249 appendNbrCells(cell2, mesh2, visitedCells, cells2);
252 }
while (cells2.size() > 0);
256 void Foam::cellsToCellss::nearest::setNextNearestCells
258 const polyMesh& srcMesh,
259 const polyMesh& tgtMesh,
267 const labelList& srcNbr = srcMesh.cellCells()[srcCelli];
272 label celli = srcNbr[i];
280 for (
label i = startSeedI; i < srcCellIDs.size(); i++)
282 label celli = srcCellIDs[i];
303 Foam::label Foam::cellsToCellss::nearest::findMappedSrcCell
305 const polyMesh& srcMesh,
306 const polyMesh& tgtMesh,
307 const label tgtCelli,
308 const List<DynamicList<label>>& tgtToSrc
311 DynamicList<label> testCells(10);
312 DynamicList<label> visitedCells(10);
314 testCells.append(tgtCelli);
319 label tgtI = testCells.remove();
323 visitedCells.append(tgtI);
325 if (tgtToSrc[tgtI].size())
327 return tgtToSrc[tgtI][0];
331 const labelList& nbrCells = tgtMesh.cellCells()[tgtI];
335 if (
findIndex(visitedCells, nbrCells[i]) == -1)
337 testCells.append(nbrCells[i]);
342 }
while (testCells.size());
357 initialise(srcMesh, tgtMesh);
360 const labelList srcCellIDs(maskCells(srcMesh, tgtMesh));
369 label startSeedI = 0;
414 forAll(srcToTgtWght, srcCelli)
416 if (srcToTgtWght[srcCelli].size() > 1)
418 srcToTgtAddr[srcCelli].
resize(1);
419 srcToTgtWght[srcCelli].
resize(1);
420 srcToTgtWght[srcCelli][0] = 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.
vector point
Point is a vector.
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,.
dimensioned< scalar > magSqr(const dimensioned< Type > &)