arcEdge.C 4.13 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*---------------------------------------------------------------------------*/

#include "arcEdge.H"
28
#include "unitConversion.H"
mattijs's avatar
mattijs committed
29
#include "addToRunTimeSelectionTable.H"
30
31
32
33
34
35

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineTypeNameAndDebug(arcEdge, 0);
mattijs's avatar
mattijs committed
36
    addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
}


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

Foam::cylindricalCS Foam::arcEdge::calcAngle()
{
    vector a = p2_ - p1_;
    vector b = p3_ - p1_;

    // find centre of arcEdge
    scalar asqr = a & a;
    scalar bsqr = b & b;
    scalar adotb = a & b;

    scalar denom = asqr*bsqr - adotb*adotb;

    if (mag(denom) < VSMALL)
    {
        FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
            << "Invalid arc definition - are the points co-linear?  Denom ="
            << denom
            << abort(FatalError);
    }

    scalar fact = 0.5*(bsqr - adotb)/denom;

64
    point centre = 0.5*a + fact*((a ^ b) ^ a);
65
66
67
68
69
70
71
72
73
74

    centre += p1_;

    // find position vectors w.r.t. the arcEdge centre
    vector r1(p1_ - centre);
    vector r2(p2_ - centre);
    vector r3(p3_ - centre);

    // find angles
    scalar tmp = (r3&r1)/(mag(r3)*mag(r1));
75
    angle_ = radToDeg(acos(tmp));
76
77

    // check if the vectors define an exterior or an interior arcEdge
78
    if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
79
    {
80
        angle_ = 360.0 - angle_;
81
    }
82

83
    vector tempAxis;
84
85
86
87
88

    if (angle_ <= 180.0)
    {
        tempAxis = r1 ^ r3;

89
90
91
92
        if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
        {
            tempAxis = r1 ^ r2;
        }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    }
    else
    {
        tempAxis = r3 ^ r1;
    }

    radius_ = mag(r3);

    // set up and return the local coordinate system
    return cylindricalCS("tmpCS", centre, tempAxis, r1);
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::arcEdge::arcEdge
(
    const pointField& points,
    const label start,
    const label end,
113
    const vector& pMid
114
115
116
117
)
:
    curvedEdge(points, start, end),
    p1_(points_[start_]),
118
    p2_(pMid),
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    p3_(points_[end_]),
    cs_(calcAngle())
{}


Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
:
    curvedEdge(points, is),
    p1_(points_[start_]),
    p2_(is),
    p3_(points_[end_]),
    cs_(calcAngle())
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

136
Foam::point Foam::arcEdge::position(const scalar lambda) const
137
138
139
140
141
142
143
144
145
146
147
148
{
    if (lambda < 0 || lambda > 1)
    {
        FatalErrorIn("arcEdge::position(const scalar lambda) const")
            << "Parameter out of range, lambda = " << lambda
            << abort(FatalError);
    }

    if (lambda < SMALL)
    {
        return p1_;
    }
149
    else if (lambda > 1 - SMALL)
150
151
152
153
154
155
156
157
158
159
160
161
    {
        return p3_;
    }
    else
    {
        return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
    }
}


Foam::scalar Foam::arcEdge::length() const
{
162
    return degToRad(angle_*radius_);
163
164
165
166
}


// ************************************************************************* //