OpenFOAM logo
Open Source CFD Toolkit

tetrahedronI.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 "triangle.H"
00030 #include "IOstreams.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00038 
00039 template<class Point, class PointRef>
00040 inline tetrahedron<Point, PointRef>::tetrahedron
00041 (
00042     const Point& a,
00043     const Point& b,
00044     const Point& c,
00045     const Point& d
00046 )
00047 :
00048     a_(a),
00049     b_(b),
00050     c_(c),
00051     d_(d)
00052 {}
00053 
00054 
00055 template<class Point, class PointRef>
00056 inline tetrahedron<Point, PointRef>::tetrahedron(Istream& is)
00057 {
00058     // Read beginning of tetrahedron point pair
00059     is.readBegin("tetrahedron");
00060 
00061     is >> a_ >> b_ >> c_ >> d_;
00062 
00063     // Read end of tetrahedron point pair
00064     is.readEnd("tetrahedron");
00065 
00066     // Check state of Istream
00067     is.check("tetrahedron::tetrahedron(Istream& is)");
00068 }
00069 
00070 
00071 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00072 
00073 template<class Point, class PointRef>
00074 inline const Point& tetrahedron<Point, PointRef>::a() const
00075 {
00076     return a_;
00077 }
00078 
00079 
00080 template<class Point, class PointRef>
00081 inline const Point& tetrahedron<Point, PointRef>::b() const
00082 {
00083     return b_;
00084 }
00085 
00086 
00087 template<class Point, class PointRef>
00088 inline const Point& tetrahedron<Point, PointRef>::c() const
00089 {
00090     return c_;
00091 }
00092 
00093 
00094 template<class Point, class PointRef>
00095 inline const Point& tetrahedron<Point, PointRef>::d() const
00096 {
00097     return d_;
00098 }
00099 
00100 
00101 template<class Point, class PointRef>
00102 inline vector tetrahedron<Point, PointRef>::Sa() const
00103 {
00104     return triangle<Point, PointRef>(b_, c_, d_).normal();
00105 }
00106 
00107 
00108 template<class Point, class PointRef>
00109 inline vector tetrahedron<Point, PointRef>::Sb() const
00110 {
00111     return triangle<Point, PointRef>(a_, d_, c_).normal();
00112 }
00113 
00114 
00115 template<class Point, class PointRef>
00116 inline vector tetrahedron<Point, PointRef>::Sc() const
00117 {
00118     return triangle<Point, PointRef>(a_, b_, d_).normal();
00119 }
00120 
00121 
00122 template<class Point, class PointRef>
00123 inline vector tetrahedron<Point, PointRef>::Sd() const
00124 {
00125     return triangle<Point, PointRef>(a_, c_, b_).normal();
00126 }
00127 
00128 
00129 template<class Point, class PointRef>
00130 inline scalar tetrahedron<Point, PointRef>::mag() const
00131 {
00132     return (1.0/6.0)*(((b_ - a_) ^ (c_ - a_)) & (d_ - a_));
00133 }
00134 
00135 
00136 template<class Point, class PointRef>
00137 inline vector tetrahedron<Point, PointRef>::circumCentre() const
00138 {
00139     vector a = b_ - a_;
00140     vector b = c_ - a_;
00141     vector c = d_ - a_;
00142 
00143     scalar lamda = magSqr(c) - (a&c);
00144     scalar mu = magSqr(b) - (a&b);
00145 
00146     vector ba = b^a;
00147     vector ca = c^a;
00148 
00149     return a_ + 0.5*(a + (lamda*ba - mu*ca)/(c&ba));
00150 }
00151 
00152 
00153 template<class Point, class PointRef>
00154 inline scalar tetrahedron<Point, PointRef>::circumRadius() const
00155 {
00156     return Foam::mag(a_ - circumCentre());
00157 }
00158 
00159 
00160 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00161 
00162 template<class point, class pointRef>
00163 inline Istream& operator>>(Istream& is, tetrahedron<point, pointRef>& t)
00164 {
00165     // Read beginning of tetrahedron point pair
00166     is.readBegin("tetrahedron");
00167 
00168     is >> t.a_ >> t.b_ >> t.c_ >> t.d_;
00169 
00170     // Read end of tetrahedron point pair
00171     is.readEnd("tetrahedron");
00172 
00173     // Check state of Ostream
00174     is.check("Istream& operator>>(Istream&, tetrahedron&)");
00175 
00176     return is;
00177 }
00178 
00179 
00180 template<class Point, class PointRef>
00181 inline Ostream& operator<<(Ostream& os, const tetrahedron<Point, PointRef>& t)
00182 {
00183     os  << nl
00184         << token::BEGIN_LIST
00185         << t.a_ << token::SPACE << t.b_
00186         << token::SPACE << t.c_ << token::SPACE << t.d_
00187         << token::END_LIST;
00188 
00189     return os;
00190 }
00191 
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 
00195 } // End namespace Foam
00196 
00197 // ************************************************************************* //
For further information go to www.openfoam.org