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

cellModel.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 "cellModel.H"
00028 #include "pyramid.H"
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 Foam::vector Foam::cellModel::centre
00033 (
00034     const labelList& pointLabels,
00035     const pointField& points
00036 ) const
00037 {
00038     // Estimate centre of cell
00039     vector cEst = vector::zero;
00040 
00041     // Sum the points idicated by the label list
00042     forAll(pointLabels, i)
00043     {
00044         cEst += points[pointLabels[i]];
00045     }
00046 
00047     // Average by dividing by the number summed over.
00048     cEst /= scalar(pointLabels.size());
00049 
00050 
00051     // Calculate the centre by breaking the cell into pyramids and
00052     // volume-weighted averaging their centres
00053     scalar sumV = 0.0;
00054     vector sumVc = vector::zero;
00055 
00056     const faceList cellFaces = faces(pointLabels);
00057 
00058     forAll(cellFaces, i)
00059     {
00060         const face& curFace = cellFaces[i];
00061 
00062         scalar pyrVol =
00063             pyramid<point, const point&, const face&>
00064             (
00065                 curFace,
00066                 cEst
00067             ).mag(points);
00068 
00069         if (pyrVol > SMALL)
00070         {
00071             WarningIn("cellModel::centre(const labelList&, const pointField&)")
00072                 << "zero or negative pyramid volume: " << -pyrVol
00073                 << " for face " << i
00074                 << endl;
00075         }
00076 
00077         sumVc -=
00078             pyrVol
00079            *pyramid<point, const point&, const face&>(curFace, cEst)
00080            .centre(points);
00081 
00082         sumV -= pyrVol;
00083     }
00084 
00085     return sumVc/(sumV + VSMALL);
00086 }
00087 
00088 
00089 Foam::scalar Foam::cellModel::mag
00090 (
00091     const labelList& pointLabels,
00092     const pointField& points
00093 ) const
00094 {
00095     // Estimate centre of cell
00096     vector cEst = vector::zero;
00097 
00098     // Sum the points idicated by the label list
00099     forAll(pointLabels, i)
00100     {
00101         cEst += points[pointLabels[i]];
00102     }
00103 
00104     // Average by dividing by the number summed over.
00105     cEst /= scalar(pointLabels.size());
00106 
00107 
00108     // Calculate the magnitude by summing the -mags of the pyramids
00109     // The sign change is because the faces point outwards
00110     // and a pyramid is constructed from an inward pointing face
00111     // and the base centre-apex vector
00112     scalar v = 0;
00113 
00114     const faceList cellFaces = faces(pointLabels);
00115 
00116     forAll(cellFaces, i)
00117     {
00118         const face& curFace =cellFaces[i];
00119 
00120         scalar pyrVol =
00121             pyramid<point, const point&, const face&>
00122             (
00123                 curFace,
00124                 cEst
00125             ).mag(points);
00126 
00127         if (pyrVol > SMALL)
00128         {
00129             WarningIn("cellModel::mag(const labelList&, const pointField&)")
00130                 << "zero or negative pyramid volume: " << -pyrVol
00131                 << " for face " << i
00132                 << endl;
00133         }
00134 
00135         v -= pyrVol;
00136     }
00137 
00138     return v;
00139 }
00140 
00141 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd