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

edgeI.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-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 "IOstreams.H"
00028 
00029 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
00030 
00031 
00032 // return
00033 //  -  0: different
00034 //  - +1: identical
00035 //  - -1: same edge, but different orientation
00036 inline int Foam::edge::compare(const edge& a, const edge& b)
00037 {
00038     if (a[0] == b[0] && a[1] == b[1])
00039     {
00040         return 1;
00041     }
00042     else if (a[0] == b[1] && a[1] == b[0])
00043     {
00044         return -1;
00045     }
00046     else
00047     {
00048         return 0;
00049     }
00050 }
00051 
00052 
00053 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00054 
00055 inline Foam::edge::edge()
00056 {}
00057 
00058 
00059 inline Foam::edge::edge(const label a, const label b)
00060 {
00061     start() = a;
00062     end() = b;
00063 }
00064 
00065 
00066 inline Foam::edge::edge(const FixedList<label, 2>& a)
00067 {
00068     start() = a[0];
00069     end() = a[1];
00070 }
00071 
00072 
00073 inline Foam::edge::edge(Istream& is)
00074 :
00075     FixedList<label, 2>(is)
00076 {}
00077 
00078 
00079 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00080 
00081 inline Foam::label Foam::edge::start() const
00082 {
00083     return operator[](0);
00084 }
00085 
00086 inline Foam::label& Foam::edge::start()
00087 {
00088     return operator[](0);
00089 }
00090 
00091 
00092 inline Foam::label Foam::edge::end() const
00093 {
00094     return operator[](1);
00095 }
00096 
00097 inline Foam::label& Foam::edge::end()
00098 {
00099     return operator[](1);
00100 }
00101 
00102 
00103 inline Foam::label Foam::edge::otherVertex(const label a) const
00104 {
00105     if (a == start())
00106     {
00107         return end();
00108     }
00109     else if (a == end())
00110     {
00111         return start();
00112     }
00113     else
00114     {
00115         // The given vertex is not on the edge in the first place.
00116         return -1;
00117     }
00118 }
00119 
00120 
00121 inline Foam::label Foam::edge::commonVertex(const edge& a) const
00122 {
00123     if (start() == a.start() || start() == a.end())
00124     {
00125         return start();
00126     }
00127     else if (end() == a.start() || end() == a.end())
00128     {
00129         return end();
00130     }
00131     else
00132     {
00133         // No shared vertex.
00134         return -1;
00135     }
00136 }
00137 
00138 
00139 inline Foam::edge Foam::edge::reverseEdge() const
00140 {
00141     return edge(end(), start());
00142 }
00143 
00144 
00145 inline Foam::point Foam::edge::centre(const pointField& p) const
00146 {
00147     return 0.5*(p[start()] + p[end()]);
00148 }
00149 
00150 
00151 inline Foam::vector Foam::edge::vec(const pointField& p) const
00152 {
00153     return p[end()] - p[start()];
00154 }
00155 
00156 
00157 inline Foam::scalar Foam::edge::mag(const pointField& p) const
00158 {
00159     return ::Foam::mag(vec(p));
00160 }
00161 
00162 
00163 inline Foam::linePointRef Foam::edge::line(const pointField& p) const
00164 {
00165     return linePointRef(p[start()], p[end()]);
00166 }
00167 
00168 
00169 // * * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * //
00170 
00171 inline bool Foam::operator==(const edge& a, const edge& b)
00172 {
00173     return edge::compare(a,b) != 0;
00174 }
00175 
00176 
00177 inline bool Foam::operator!=(const edge& a, const edge& b)
00178 {
00179     return edge::compare(a,b) == 0;
00180 }
00181 
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd