1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "unitConversion.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(arcEdge, 0);
35 addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 Foam::cylindricalCS Foam::arcEdge::calcAngle()
46 // find centre of arcEdge
51 scalar denom = asqr*bsqr - adotb*adotb;
53 if (mag(denom) < VSMALL)
55 FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
56 << "Invalid arc definition - are the points co-linear? Denom ="
61 scalar fact = 0.5*(bsqr - adotb)/denom;
63 point centre = 0.5*a + fact*((a ^ b) ^ a);
67 // find position vectors w.r.t. the arcEdge centre
68 vector r1(p1_ - centre);
69 vector r2(p2_ - centre);
70 vector r3(p3_ - centre);
73 angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1))));
75 // check if the vectors define an exterior or an interior arcEdge
76 if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
78 angle_ = 360.0 - angle_;
87 if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
99 // set up and return the local coordinate system
100 return cylindricalCS("arcEdgeCS", centre, tempAxis, r1);
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 Foam::arcEdge::arcEdge
108 const pointField& points,
114 curvedEdge(points, start, end),
115 p1_(points_[start_]),
122 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
124 curvedEdge(points, is),
125 p1_(points_[start_]),
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 Foam::point Foam::arcEdge::position(const scalar lambda) const
136 if (lambda < 0 || lambda > 1)
138 FatalErrorIn("arcEdge::position(const scalar lambda) const")
139 << "Parameter out of range, lambda = " << lambda
140 << abort(FatalError);
147 else if (lambda > 1 - SMALL)
153 return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
158 Foam::scalar Foam::arcEdge::length() const
160 return degToRad(angle_*radius_);
164 // ************************************************************************* //