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

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