OpenFOAM logo
Open Source CFD Toolkit

pyramidI.H

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-2005 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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "IOstreams.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 template<class Point, class PointRef, class polygonRef>
00039 inline pyramid<Point, PointRef, polygonRef>::pyramid
00040 (
00041     polygonRef base,
00042     const Point& apex
00043 )
00044 :
00045     base_(base),
00046     apex_(apex)
00047 {}
00048 
00049 
00050 template<class Point, class PointRef, class polygonRef>
00051 inline pyramid<Point, PointRef, polygonRef>::pyramid(Istream& is)
00052 {
00053     is >> base_ >> apex_;
00054     is.check("pyramid::pyramid(Istream& is)");
00055 }
00056 
00057 
00058 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00059 
00060 template<class Point, class PointRef, class polygonRef>
00061 inline const Point& pyramid<Point, PointRef, polygonRef>::apex() const
00062 {
00063     return apex_;
00064 }
00065 
00066 template<class Point, class PointRef, class polygonRef>
00067 inline polygonRef pyramid<Point, PointRef, polygonRef>::base() const
00068 {
00069     return base_;
00070 }
00071 
00072 
00073 template<class Point, class PointRef, class polygonRef>
00074 inline Point pyramid<Point, PointRef, polygonRef>::centre
00075 (
00076     const pointField& points
00077 ) const
00078 {
00079     return (3.0/4.0)*base_.centre(points) + (1.0/4.0)*apex_;
00080 }
00081 
00082 
00083 template<class Point, class PointRef, class polygonRef>
00084 inline vector pyramid<Point, PointRef, polygonRef>::height
00085 (
00086     const pointField& points
00087 ) const
00088 {
00089     // Height = apex - baseCentroid
00090     return (apex_ - base_.centre(points));
00091 }
00092 
00093 
00094 template<class Point, class PointRef, class polygonRef>
00095 inline scalar pyramid<Point, PointRef, polygonRef>::mag
00096 (
00097     const pointField& points
00098 ) const
00099 {
00100     return (1.0/3.0)*(base_.normal(points)&(height(points)));
00101 }
00102 
00103 
00104 // * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * * //
00105 
00106 template<class Point, class PointRef, class polygonRef>
00107 inline Istream& operator>>
00108 (
00109     Istream& is,
00110     pyramid<Point, PointRef, polygonRef>& p
00111 )
00112 {
00113     is >> p.base_ >> p.apex_;
00114     is.check("Istream& operator>>(Istream&, pyramid&)");
00115     return is;
00116 }
00117 
00118 
00119 template<class Point, class PointRef, class polygonRef>
00120 inline Ostream& operator<<
00121 (
00122     Ostream& os,
00123     const pyramid<Point, PointRef, polygonRef>& p
00124 )
00125 {
00126     os << p.base_ << tab << p.apex_ << nl;
00127     return os;
00128 }
00129 
00130 
00131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00132 
00133 } // End namespace Foam
00134 
00135 // ************************************************************************* //
For further information go to www.openfoam.org