Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / meshToMeshInterpolation / meshToMesh / calculateMeshToMeshWeights.C
blobb7117c8c237d51a1ef4f62cb6c13ca1c9814ce3b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
32     if (debug)
33     {
34         Info<< "meshToMesh::calculateInverseDistanceWeights() : "
35             << "calculating inverse distance weighting factors" << endl;
36     }
38     if (inverseDistanceWeightsPtr_)
39     {
40         FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
41             << "weighting factors already calculated"
42             << exit(FatalError);
43     }
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)
54     {
55         if (cellAddressing_[celli] != -1)
56         {
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,
63             // pick up the value
64             if
65             (
66                 m < directHitTol                            // Direct hit
67              || neighbours.empty()
68             )
69             {
70                 invDistCoeffs[celli].setSize(1);
71                 invDistCoeffs[celli][0] = 1.0;
72             }
73             else
74             {
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)
85                 {
86                     invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
87                     invDistCoeffs[celli][ni + 1] = invDist;
88                     sumInvDist += invDist;
89                 }
91                 // divide by the total inverse-distance
92                 forAll(invDistCoeffs[celli], i)
93                 {
94                     invDistCoeffs[celli][i] /= sumInvDist;
95                 }
96             }
97         }
98     }
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 const Foam::scalarListList& Foam::meshToMesh::inverseDistanceWeights() const
106     if (!inverseDistanceWeightsPtr_)
107     {
108         calculateInverseDistanceWeights();
109     }
111     return *inverseDistanceWeightsPtr_;
115 // ************************************************************************* //