arcEdge.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "arcEdge.H"
27 #include "unitConversion.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace blockEdges
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 Foam::cylindricalCS Foam::blockEdges::arcEdge::calcAngle()
45 {
46  vector a = p2_ - p1_;
47  vector b = p3_ - p1_;
48 
49  // find centre of arcEdge
50  scalar asqr = a & a;
51  scalar bsqr = b & b;
52  scalar adotb = a & b;
53 
54  scalar denom = asqr*bsqr - adotb*adotb;
55 
56  if (mag(denom) < VSMALL)
57  {
59  << denom
60  << abort(FatalError);
61  }
62 
63  scalar fact = 0.5*(bsqr - adotb)/denom;
64 
65  point centre = 0.5*a + fact*((a ^ b) ^ a);
66 
67  centre += p1_;
68 
69  // find position vectors w.r.t. the arcEdge centre
70  vector r1(p1_ - centre);
71  vector r2(p2_ - centre);
72  vector r3(p3_ - centre);
73 
74  // find angles
75  angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1))));
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  if (angle_ <= 180.0)
86  {
87  tempAxis = r1 ^ r3;
88 
89  if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
90  {
91  tempAxis = r1 ^ r2;
92  }
93  }
94  else
95  {
96  tempAxis = r3 ^ r1;
97  }
98 
99  radius_ = mag(r3);
100 
101  // set up and return the local coordinate system
102  return cylindricalCS("arcEdgeCS", centre, tempAxis, r1);
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
108 Foam::blockEdges::arcEdge::arcEdge
109 (
110  const pointField& points,
111  const label start,
112  const label end,
113  const point& pMid
114 )
115 :
116  blockEdge(points, start, end),
117  p1_(points_[start_]),
118  p2_(pMid),
119  p3_(points_[end_]),
120  cs_(calcAngle())
121 {}
122 
123 
124 Foam::blockEdges::arcEdge::arcEdge
125 (
126  const dictionary& dict,
127  const label index,
128  const searchableSurfaces& geometry,
129  const pointField& points,
130  Istream& is
131 )
132 :
133  blockEdge(dict, index, points, is),
134  p1_(points_[start_]),
135  p2_(is),
136  p3_(points_[end_]),
137  cs_(calcAngle())
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
145  if (lambda < -SMALL || lambda > 1 + SMALL)
146  {
148  << "Parameter out of range, lambda = " << lambda
149  << abort(FatalError);
150  }
151 
152  if (lambda < SMALL)
153  {
154  return p1_;
155  }
156  else if (lambda > 1 - SMALL)
157  {
158  return p3_;
159  }
160  else
161  {
162  return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
163  }
164 }
165 
166 
168 {
169  return degToRad(angle_*radius_);
170 }
171 
172 
173 // ************************************************************************* //
dimensionedScalar acos(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
point position(const scalar) const
Return the point position corresponding to the curve parameter.
Definition: arcEdge.C:143
Unit conversion functions.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Macros for easy insertion into run-time selection tables.
Defines the arcEdge of a circle in terms of 3 points on its circumference.
Definition: arcEdge.H:51
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
Cylindrical coordinate system.
Definition: cylindricalCS.H:48
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Container for searchableSurfaces.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
defineTypeNameAndDebug(arcEdge, 0)
addToRunTimeSelectionTable(blockEdge, arcEdge, Istream)
Define a curved edge that is parameterized for 0<lambda<1 between the start and end point...
Definition: blockEdge.H:56
dimensionedScalar lambda(laminarTransport.lookup("lambda"))
dimensioned< scalar > mag(const dimensioned< Type > &)
scalar length() const
Return the length of the curve.
Definition: arcEdge.C:167
Namespace for OpenFOAM.