File size: 4,559 Bytes
5a600cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2011-2026 OpenFOAM Foundation
     \\/     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 3 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, see <http://www.gnu.org/licenses/>.

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

#include "arcEdge.H"
#include "units.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"

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

namespace Foam
{
namespace blockEdges
{
    defineTypeNameAndDebug(arcEdge, 0);
    addToRunTimeSelectionTable(blockEdge, arcEdge, Istream);
}
}


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

void Foam::blockEdges::arcEdge::calc(const point& pA)
{
    const tensor dps(pA - p0_, pA - p1_, (pA - p0_)^(pA - p1_));
    const tensor pMs((p0_ + pA)/2, (p1_ + pA)/2, pA);

    if (det(dps) < vSmall)
    {
        FatalErrorInFunction
            << "Arc point " << pA << " lies on the line of edge "
            << edge(start_, end_) << abort(FatalError);
    }

    const point c =
        inv(dps)
      & vector(dps.x() & pMs.x(), dps.y() & pMs.y(), dps.z() & pMs.z());

    const vector r0 = p0_ - c, r1 = p1_ - c;
    const scalar cosT = (r0 & r1)/(mag(r0)*mag(r1));
    scalar t = acos(max(-1, min(cosT, 1)));
    if (((r0 ^ r1) & dps.z()) > 0)
    {
        t = 2*constant::mathematical::pi - t;
    }

    centre_ = c;
    axis_ = - normalised(dps.z());
    theta_ = t;
    length_ = 0;
}


void Foam::blockEdges::arcEdge::calc(const scalar theta, const vector& axis)
{
    if (0 >= theta || theta >= 360)
    {
        FatalErrorInFunction
            << "Arc angle for edge " << edge(start_, end_)
            << " must take a value between 0 and 360 degrees"
            << abort(FatalError);
    }

    const vector dp = p1_ - p0_;

    const vector pM = (p0_ + p1_)/2;
    const vector rM = normalised(dp ^ axis);

    const scalar l = dp & axis;

    const vector chord = dp - l*axis;
    const scalar magChord = mag(chord);

    centre_ = pM - l*axis/2 - rM*magChord/2/tan(theta/2);
    axis_ = axis;
    theta_ = theta;
    length_ = l;
}


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

Foam::blockEdges::arcEdge::arcEdge
(
    const dictionary& dict,
    const label index,
    const searchableSurfaceList& geometry,
    const pointField& points,
    Istream& is
)
:
    blockEdge(dict, index, points, is),
    p0_(points_[start_]),
    p1_(points_[end_]),
    centre_(),
    axis_(),
    theta_(),
    length_()
{
    token firstToken(is);
    is.putBack(firstToken);

    if (firstToken == token::BEGIN_LIST)
    {
        const point pA(is);
        calc(pA);
    }
    else
    {
        const scalar theta = degToRad(readScalar(is));
        const vector axis(is);
        calc(theta, normalised(axis));
    }
}


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

Foam::point Foam::blockEdges::arcEdge::position(const scalar lambda) const
{
    if (lambda < - small || lambda > 1 + small)
    {
        FatalErrorInFunction
            << "Parameter out of range, lambda = " << lambda
            << abort(FatalError);
    }

    const scalar t = theta_*lambda;
    const vector r1 = p0_ - centre_, r2 = axis_ ^ r1;

    return centre_ + r1*cos(t) + r2*sin(t) + axis_*length_*lambda;
}


Foam::scalar Foam::blockEdges::arcEdge::length() const
{
    const vector r1 = p0_ - centre_;

    // Length of a helical segment
    return theta_*sqrt(magSqr(r1) + sqr(length_));
}


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