1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "meshToMesh.H"
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 void meshToMesh::calculateInverseDistanceWeights() const
39 Info<< "meshToMesh::calculateInverseDistanceWeights() : "
40 << "calculating inverse distance weighting factors" << endl;
43 if (inverseDistanceWeightsPtr_)
45 FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
46 << "weighting factors already calculated"
50 inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
51 scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
53 // get reference to source mesh data
54 const labelListList& cc = fromMesh_.cellCells();
55 const vectorField& centreFrom = fromMesh_.C().internalField();
56 const vectorField& centreTo = toMesh_.C().internalField();
58 forAll (cellAddressing_, celli)
60 if (cellAddressing_[celli] != -1)
62 const vector& target = centreTo[celli];
63 scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
65 const labelList& neighbours = cc[cellAddressing_[celli]];
67 // if the nearest cell is a boundary cell or there is a direct hit,
71 m < directHitTol() // Direct hit
75 invDistCoeffs[celli].setSize(1);
76 invDistCoeffs[celli][0] = 1.0;
80 invDistCoeffs[celli].setSize(neighbours.size() + 1);
82 // The first coefficient corresponds to the centre cell.
83 // The rest is ordered in the same way as the cellCells list.
84 scalar invDist = 1.0/m;
85 invDistCoeffs[celli][0] = invDist;
86 scalar sumInvDist = invDist;
88 // now add the neighbours
89 forAll (neighbours, ni)
91 invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
92 invDistCoeffs[celli][ni + 1] = invDist;
93 sumInvDist += invDist;
96 // divide by the total inverse-distance
97 forAll (invDistCoeffs[celli], i)
99 invDistCoeffs[celli][i] /= sumInvDist;
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 const scalarListList& meshToMesh::inverseDistanceWeights() const
111 if (!inverseDistanceWeightsPtr_)
113 calculateInverseDistanceWeights();
116 return *inverseDistanceWeightsPtr_;
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 } // End namespace Foam
124 // ************************************************************************* //