1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 arcEdge class : defines the arcEdge of a circle in terms of 3 points on its
29 \*---------------------------------------------------------------------------*/
32 #include "mathematicalConstants.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(arcEdge, 0);
42 // Add the curvedEdge constructor functions to the hash tables
43 curvedEdge::addIstreamConstructorToTable<arcEdge>
44 addArcEdgeIstreamConstructorToTable_;
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 Foam::cylindricalCS Foam::arcEdge::calcAngle()
55 // find centre of arcEdge
60 scalar denom = asqr*bsqr - adotb*adotb;
62 if (mag(denom) < VSMALL)
64 FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
65 << "Invalid arc definition - are the points co-linear? Denom ="
70 scalar fact = 0.5*(bsqr - adotb)/denom;
72 vector centre = 0.5*a + fact*((a ^ b) ^ a);
76 // find position vectors w.r.t. the arcEdge centre
77 vector r1(p1_ - centre);
78 vector r2(p2_ - centre);
79 vector r3(p3_ - centre);
82 scalar tmp = (r3&r1)/(mag(r3)*mag(r1));
83 angle_ = acos(tmp)*180.0/mathematicalConstant::pi;
85 // check if the vectors define an exterior or an interior arcEdge
86 if (((r1 ^ r2)&(r1 ^ r3)) < 0.0) angle_ = 360 - angle_;
88 vector tempAxis(0.0,0.0,0.0);
94 if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) tempAxis = r1 ^ r2;
103 // set up and return the local coordinate system
104 return cylindricalCS("tmpCS", centre, tempAxis, r1);
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 // Construct from components
111 Foam::arcEdge::arcEdge
113 const pointField& points,
119 curvedEdge(points, start, end),
120 p1_(points_[start_]),
127 // Construct from Istream
128 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
130 curvedEdge(points, is),
131 p1_(points_[start_]),
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 Foam::vector Foam::arcEdge::position(const scalar lambda) const
142 if (lambda < 0 || lambda > 1)
144 FatalErrorIn("arcEdge::position(const scalar lambda) const")
145 << "Parameter out of range, lambda = " << lambda
146 << abort(FatalError);
153 else if (lambda > 1-SMALL)
159 return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
164 //- Return the length of the curve
165 Foam::scalar Foam::arcEdge::length() const
167 return angle_*radius_*mathematicalConstant::pi/180.0;
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 // ************************************************************************* //