OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

calculateMeshToMeshWeights.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "meshToMesh.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00035 
00036 void meshToMesh::calculateInverseDistanceWeights() const
00037 {
00038     if (debug)
00039     {
00040         Info<< "meshToMesh::calculateInverseDistanceWeights() : "
00041             << "calculating inverse distance weighting factors" << endl;
00042     }
00043 
00044     if (inverseDistanceWeightsPtr_)
00045     {
00046         FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
00047             << "weighting factors already calculated"
00048             << exit(FatalError);
00049     }
00050 
00051     inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
00052     scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
00053 
00054     // get reference to source mesh data
00055     const labelListList& cc = fromMesh_.cellCells();
00056     const vectorField& centreFrom = fromMesh_.C().internalField();
00057     const vectorField& centreTo = toMesh_.C().internalField();
00058 
00059     forAll (cellAddressing_, celli)
00060     {
00061         if (cellAddressing_[celli] != -1)
00062         {
00063             const vector& target = centreTo[celli];
00064             scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
00065 
00066             const labelList& neighbours = cc[cellAddressing_[celli]];
00067 
00068             // if the nearest cell is a boundary cell or there is a direct hit,
00069             // pick up the value
00070             if
00071             (
00072                 m < directHitTol                            // Direct hit
00073              || neighbours.empty()
00074             )
00075             {
00076                 invDistCoeffs[celli].setSize(1);
00077                 invDistCoeffs[celli][0] = 1.0;
00078             }
00079             else
00080             {
00081                 invDistCoeffs[celli].setSize(neighbours.size() + 1);
00082 
00083                 // The first coefficient corresponds to the centre cell.
00084                 // The rest is ordered in the same way as the cellCells list.
00085                 scalar invDist = 1.0/m;
00086                 invDistCoeffs[celli][0] = invDist;
00087                 scalar sumInvDist = invDist;
00088 
00089                 // now add the neighbours
00090                 forAll (neighbours, ni)
00091                 {
00092                     invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
00093                     invDistCoeffs[celli][ni + 1] = invDist;
00094                     sumInvDist += invDist;
00095                 }
00096                 
00097                 // divide by the total inverse-distance
00098                 forAll (invDistCoeffs[celli], i)
00099                 {
00100                     invDistCoeffs[celli][i] /= sumInvDist;
00101                 }
00102             }
00103         }
00104     }
00105 }
00106 
00107 
00108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00109 
00110 const scalarListList& meshToMesh::inverseDistanceWeights() const
00111 {
00112     if (!inverseDistanceWeightsPtr_)
00113     {
00114         calculateInverseDistanceWeights();
00115     }
00116     
00117     return *inverseDistanceWeightsPtr_;
00118 }
00119 
00120 
00121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00122 
00123 } // End namespace Foam
00124 
00125 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd