FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <sampling/meshToMesh.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 void meshToMesh::calculateInverseDistanceWeights() const
00036 {
00037     if (debug)
00038     {
00039         Info<< "meshToMesh::calculateInverseDistanceWeights() : "
00040             << "calculating inverse distance weighting factors" << endl;
00041     }
00042 
00043     if (inverseDistanceWeightsPtr_)
00044     {
00045         FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
00046             << "weighting factors already calculated"
00047             << exit(FatalError);
00048     }
00049 
00050     inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
00051     scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
00052 
00053     // get reference to source mesh data
00054     const labelListList& cc = fromMesh_.cellCells();
00055     const vectorField& centreFrom = fromMesh_.C().internalField();
00056     const vectorField& centreTo = toMesh_.C().internalField();
00057 
00058     forAll (cellAddressing_, celli)
00059     {
00060         if (cellAddressing_[celli] != -1)
00061         {
00062             const vector& target = centreTo[celli];
00063             scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
00064 
00065             const labelList& neighbours = cc[cellAddressing_[celli]];
00066 
00067             // if the nearest cell is a boundary cell or there is a direct hit,
00068             // pick up the value
00069             if
00070             (
00071                 m < directHitTol                            // Direct hit
00072              || neighbours.empty()
00073             )
00074             {
00075                 invDistCoeffs[celli].setSize(1);
00076                 invDistCoeffs[celli][0] = 1.0;
00077             }
00078             else
00079             {
00080                 invDistCoeffs[celli].setSize(neighbours.size() + 1);
00081 
00082                 // The first coefficient corresponds to the centre cell.
00083                 // The rest is ordered in the same way as the cellCells list.
00084                 scalar invDist = 1.0/m;
00085                 invDistCoeffs[celli][0] = invDist;
00086                 scalar sumInvDist = invDist;
00087 
00088                 // now add the neighbours
00089                 forAll (neighbours, ni)
00090                 {
00091                     invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
00092                     invDistCoeffs[celli][ni + 1] = invDist;
00093                     sumInvDist += invDist;
00094                 }
00095                 
00096                 // divide by the total inverse-distance
00097                 forAll (invDistCoeffs[celli], i)
00098                 {
00099                     invDistCoeffs[celli][i] /= sumInvDist;
00100                 }
00101             }
00102         }
00103     }
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00108 
00109 const scalarListList& meshToMesh::inverseDistanceWeights() const
00110 {
00111     if (!inverseDistanceWeightsPtr_)
00112     {
00113         calculateInverseDistanceWeights();
00114     }
00115     
00116     return *inverseDistanceWeightsPtr_;
00117 }
00118 
00119 
00120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00121 
00122 } // End namespace Foam
00123 
00124 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines