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

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