initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / generation / blockMesh / curvedEdges / arcEdge.C
blobca36ab1b5141717a24dca62a9195698683e8672b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     arcEdge class : defines the arcEdge of a circle in terms of 3 points on its
27     circumference
29 \*---------------------------------------------------------------------------*/
31 #include "arcEdge.H"
32 #include "mathematicalConstants.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
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()
52     vector a = p2_ - p1_;
53     vector b = p3_ - p1_;
55     // find centre of arcEdge
56     scalar asqr = a & a;
57     scalar bsqr = b & b;
58     scalar adotb = a & b;
60     scalar denom = asqr*bsqr - adotb*adotb;
62     if (mag(denom) < VSMALL)
63     {
64         FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
65             << "Invalid arc definition - are the points co-linear?  Denom ="
66             << denom
67             << abort(FatalError);
68     }
70     scalar fact = 0.5*(bsqr - adotb)/denom;
72     vector centre = 0.5*a + fact*((a ^ b) ^ a);
74     centre += p1_;
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);
81     // find angles
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);
90     if (angle_ <= 180.0)
91     {
92         tempAxis = r1 ^ r3;
94         if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) tempAxis = r1 ^ r2;
95     }
96     else
97     {
98         tempAxis = r3 ^ r1;
99     }
101     radius_ = mag(r3);
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,
114     const label start,
115     const label end,
116     const vector& P2
119     curvedEdge(points, start, end),
120     p1_(points_[start_]),
121     p2_(P2),
122     p3_(points_[end_]),
123     cs_(calcAngle())
127 // Construct from Istream
128 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
130     curvedEdge(points, is),
131     p1_(points_[start_]),
132     p2_(is),
133     p3_(points_[end_]),
134     cs_(calcAngle())
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 Foam::vector Foam::arcEdge::position(const scalar lambda) const
142     if (lambda < 0 || lambda > 1)
143     {
144         FatalErrorIn("arcEdge::position(const scalar lambda) const")
145             << "Parameter out of range, lambda = " << lambda
146             << abort(FatalError);
147     }
149     if (lambda < SMALL)
150     {
151         return p1_;
152     }
153     else if (lambda > 1-SMALL)
154     {
155         return p3_;
156     }
157     else
158     {
159         return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
160     }
164 //- Return the length of the curve
165 Foam::scalar Foam::arcEdge::length() const
167     return angle_*radius_*mathematicalConstant::pi/180.0;
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 // ************************************************************************* //