arcEdge.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  const scalar cosAngle = (r3 & r1)/(mag(r3) * mag(r1));
76  angle_ = radToDeg(acos(max(-1, min(cosAngle, 1))));
77 
78  // check if the vectors define an exterior or an interior arcEdge
79  if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
80  {
81  angle_ = 360.0 - angle_;
82  }
83 
84  vector tempAxis;
85 
86  if (angle_ <= 180.0)
87  {
88  tempAxis = r1 ^ r3;
89 
90  if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
91  {
92  tempAxis = r1 ^ r2;
93  }
94  }
95  else
96  {
97  tempAxis = r3 ^ r1;
98  }
99 
100  radius_ = mag(r3);
101 
102  // set up and return the local coordinate system
103  return cylindricalCS("arcEdgeCS", centre, tempAxis, r1);
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108 
110 (
111  const pointField& points,
112  const label start,
113  const label end,
114  const point& pMid
115 )
116 :
117  blockEdge(points, start, end),
118  p1_(points_[start_]),
119  p2_(pMid),
120  p3_(points_[end_]),
121  cs_(calcAngle())
122 {}
123 
124 
126 (
127  const dictionary& dict,
128  const label index,
129  const searchableSurfaces& geometry,
130  const pointField& points,
131  Istream& is
132 )
133 :
134  blockEdge(dict, index, points, is),
135  p1_(points_[start_]),
136  p2_(is),
137  p3_(points_[end_]),
138  cs_(calcAngle())
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 {
146  if (lambda < -small || lambda > 1 + small)
147  {
149  << "Parameter out of range, lambda = " << lambda
150  << abort(FatalError);
151  }
152 
153  if (lambda < small)
154  {
155  return p1_;
156  }
157  else if (lambda > 1 - small)
158  {
159  return p3_;
160  }
161  else
162  {
163  return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
164  }
165 }
166 
167 
169 {
170  return degToRad(angle_*radius_);
171 }
172 
173 
174 // ************************************************************************* //
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:158
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#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:144
Unit conversion functions.
arcEdge(const pointField &points, const label start, const label end, const point &pMid)
Construct from components.
Definition: arcEdge.C:110
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
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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:168
Namespace for OpenFOAM.