1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "meshToMesh.H"
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 void Foam::meshToMesh::calculateInverseDistanceWeights() const
34 Info<< "meshToMesh::calculateInverseDistanceWeights() : "
35 << "calculating inverse distance weighting factors" << endl;
38 if (inverseDistanceWeightsPtr_)
40 FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
41 << "weighting factors already calculated"
45 inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
46 scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
48 // get reference to source mesh data
49 const labelListList& cc = fromMesh_.cellCells();
50 const vectorField& centreFrom = fromMesh_.C().internalField();
51 const vectorField& centreTo = toMesh_.C().internalField();
53 forAll(cellAddressing_, celli)
55 if (cellAddressing_[celli] != -1)
57 const vector& target = centreTo[celli];
58 scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
60 const labelList& neighbours = cc[cellAddressing_[celli]];
62 // if the nearest cell is a boundary cell or there is a direct hit,
66 m < directHitTol // Direct hit
70 invDistCoeffs[celli].setSize(1);
71 invDistCoeffs[celli][0] = 1.0;
75 invDistCoeffs[celli].setSize(neighbours.size() + 1);
77 // The first coefficient corresponds to the centre cell.
78 // The rest is ordered in the same way as the cellCells list.
79 scalar invDist = 1.0/m;
80 invDistCoeffs[celli][0] = invDist;
81 scalar sumInvDist = invDist;
83 // now add the neighbours
84 forAll(neighbours, ni)
86 invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
87 invDistCoeffs[celli][ni + 1] = invDist;
88 sumInvDist += invDist;
91 // divide by the total inverse-distance
92 forAll(invDistCoeffs[celli], i)
94 invDistCoeffs[celli][i] /= sumInvDist;
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 const Foam::scalarListList& Foam::meshToMesh::inverseDistanceWeights() const
106 if (!inverseDistanceWeightsPtr_)
108 calculateInverseDistanceWeights();
111 return *inverseDistanceWeightsPtr_;
115 // ************************************************************************* //