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

volPointInterpolation.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 "volPointInterpolation.H"
00028 #include "fvMesh.H"
00029 #include "volFields.H"
00030 #include "pointFields.H"
00031 #include "demandDrivenData.H"
00032 #include "coupledPointPatchFields.H"
00033 #include "pointConstraint.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00041 
00042 defineTypeNameAndDebug(volPointInterpolation, 0);
00043 
00044 
00045 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00046 
00047 void volPointInterpolation::makeWeights()
00048 {
00049     if (debug)
00050     {
00051         Info<< "volPointInterpolation::makeWeights() : "
00052             << "constructing weighting factors"
00053             << endl;
00054     }
00055 
00056     const pointField& points = mesh().points();
00057     const labelListList& pointCells = mesh().pointCells();
00058     const vectorField& cellCentres = mesh().cellCentres();
00059 
00060     // Allocate storage for weighting factors
00061     pointWeights_.clear();
00062     pointWeights_.setSize(points.size());
00063 
00064     forAll(pointWeights_, pointi)
00065     {
00066         pointWeights_[pointi].setSize(pointCells[pointi].size());
00067     }
00068 
00069     pointScalarField sumWeights
00070     (
00071         IOobject
00072         (
00073             "volPointSumWeights",
00074             mesh().polyMesh::instance(),
00075             mesh()
00076         ),
00077         pointMesh::New(mesh()),
00078         dimensionedScalar("zero", dimless, 0)
00079     );
00080 
00081     // Calculate inverse distances between cell centres and points
00082     // and store in weighting factor array
00083     forAll(points, pointi)
00084     {
00085         scalarList& pw = pointWeights_[pointi];
00086         const labelList& pcp = pointCells[pointi];
00087 
00088         forAll(pcp, pointCelli)
00089         {
00090             pw[pointCelli] = 
00091                 1.0/mag(points[pointi] - cellCentres[pcp[pointCelli]]);
00092 
00093             sumWeights[pointi] += pw[pointCelli];
00094         }
00095     }
00096 
00097     forAll(sumWeights.boundaryField(), patchi)
00098     {
00099         if (sumWeights.boundaryField()[patchi].coupled())
00100         {
00101             refCast<coupledPointPatchScalarField>
00102                 (sumWeights.boundaryField()[patchi]).initSwapAdd
00103                 (
00104                     sumWeights.internalField()
00105                 );
00106         }
00107     }
00108 
00109     forAll(sumWeights.boundaryField(), patchi)
00110     {
00111         if (sumWeights.boundaryField()[patchi].coupled())
00112         {
00113             refCast<coupledPointPatchScalarField>
00114             (sumWeights.boundaryField()[patchi]).swapAdd
00115             (
00116                 sumWeights.internalField()
00117             );
00118         }
00119     }
00120 
00121     forAll(points, pointi)
00122     {
00123         scalarList& pw = pointWeights_[pointi];
00124 
00125         forAll(pw, pointCelli)
00126         {
00127             pw[pointCelli] /= sumWeights[pointi];
00128         }
00129     }
00130 
00131     if (debug)
00132     {
00133         Info<< "volPointInterpolation::makeWeights() : "
00134             << "finished constructing weighting factors"
00135             << endl;
00136     }
00137 }
00138 
00139 
00140 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
00141 
00142 volPointInterpolation::volPointInterpolation(const fvMesh& vm)
00143 :
00144     MeshObject<fvMesh, volPointInterpolation>(vm),
00145     boundaryInterpolator_(vm)
00146 {
00147     updateMesh();
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * * //
00152 
00153 volPointInterpolation::~volPointInterpolation()
00154 {}
00155 
00156 
00157 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00158 
00159 void volPointInterpolation::updateMesh()
00160 {
00161     makeWeights();
00162     boundaryInterpolator_.updateMesh();
00163 }
00164 
00165 
00166 bool volPointInterpolation::movePoints()
00167 {
00168     makeWeights();
00169     boundaryInterpolator_.movePoints();
00170 
00171     return true;
00172 }
00173 
00174 
00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00176 
00177 } // End namespace Foam
00178 
00179 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd