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

arcEdge.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 Description
00026     arcEdge class : defines the arcEdge of a circle in terms of 3 points on its
00027     circumference
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "arcEdge.H"
00032 #include "mathematicalConstants.H"
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039     defineTypeNameAndDebug(arcEdge, 0);
00040 
00041     // Add the curvedEdge constructor functions to the hash tables
00042     addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
00043 }
00044 
00045 
00046 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00047 
00048 Foam::cylindricalCS Foam::arcEdge::calcAngle()
00049 {
00050     vector a = p2_ - p1_;
00051     vector b = p3_ - p1_;
00052 
00053     // find centre of arcEdge
00054     scalar asqr = a & a;
00055     scalar bsqr = b & b;
00056     scalar adotb = a & b;
00057 
00058     scalar denom = asqr*bsqr - adotb*adotb;
00059 
00060     if (mag(denom) < VSMALL)
00061     {
00062         FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
00063             << "Invalid arc definition - are the points co-linear?  Denom ="
00064             << denom
00065             << abort(FatalError);
00066     }
00067 
00068     scalar fact = 0.5*(bsqr - adotb)/denom;
00069 
00070     vector centre = 0.5*a + fact*((a ^ b) ^ a);
00071 
00072     centre += p1_;
00073 
00074     // find position vectors w.r.t. the arcEdge centre
00075     vector r1(p1_ - centre);
00076     vector r2(p2_ - centre);
00077     vector r3(p3_ - centre);
00078 
00079     // find angles
00080     scalar tmp = (r3&r1)/(mag(r3)*mag(r1));
00081     angle_ = acos(tmp)*180.0/mathematicalConstant::pi;
00082 
00083     // check if the vectors define an exterior or an interior arcEdge
00084     if (((r1  ^ r2)&(r1 ^ r3)) < 0.0) angle_ = 360 - angle_;
00085 
00086     vector tempAxis(0.0,0.0,0.0);
00087 
00088     if (angle_ <= 180.0)
00089     {
00090         tempAxis = r1 ^ r3;
00091 
00092         if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) tempAxis = r1 ^ r2;
00093     }
00094     else
00095     {
00096         tempAxis = r3 ^ r1;
00097     }
00098 
00099     radius_ = mag(r3);
00100 
00101     // set up and return the local coordinate system
00102     return cylindricalCS("tmpCS", centre, tempAxis, r1);
00103 }
00104 
00105 
00106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00107 
00108 // Construct from components
00109 Foam::arcEdge::arcEdge
00110 (
00111     const pointField& points,
00112     const label start,
00113     const label end,
00114     const vector& P2
00115 )
00116 :
00117     curvedEdge(points, start, end),
00118     p1_(points_[start_]),
00119     p2_(P2),
00120     p3_(points_[end_]),
00121     cs_(calcAngle())
00122 {}
00123 
00124 
00125 // Construct from Istream
00126 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
00127 :
00128     curvedEdge(points, is),
00129     p1_(points_[start_]),
00130     p2_(is),
00131     p3_(points_[end_]),
00132     cs_(calcAngle())
00133 {}
00134 
00135 
00136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00137 
00138 Foam::vector Foam::arcEdge::position(const scalar lambda) const
00139 {
00140     if (lambda < 0 || lambda > 1)
00141     {
00142         FatalErrorIn("arcEdge::position(const scalar lambda) const")
00143             << "Parameter out of range, lambda = " << lambda
00144             << abort(FatalError);
00145     }
00146 
00147     if (lambda < SMALL)
00148     {
00149         return p1_;
00150     }
00151     else if (lambda > 1-SMALL)
00152     {
00153         return p3_;
00154     }
00155     else
00156     {
00157         return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
00158     }
00159 }
00160 
00161 
00162 //- Return the length of the curve
00163 Foam::scalar Foam::arcEdge::length() const
00164 {
00165     return angle_*radius_*mathematicalConstant::pi/180.0;
00166 }
00167 
00168 
00169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00170 
00171 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd