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-2015 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  defineTypeNameAndDebug(arcEdge, 0);
35  addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 Foam::cylindricalCS Foam::arcEdge::calcAngle()
42 {
43  vector a = p2_ - p1_;
44  vector b = p3_ - p1_;
45 
46  // find centre of arcEdge
47  scalar asqr = a & a;
48  scalar bsqr = b & b;
49  scalar adotb = a & b;
50 
51  scalar denom = asqr*bsqr - adotb*adotb;
52 
53  if (mag(denom) < VSMALL)
54  {
56  << denom
57  << abort(FatalError);
58  }
59 
60  scalar fact = 0.5*(bsqr - adotb)/denom;
61 
62  point centre = 0.5*a + fact*((a ^ b) ^ a);
63 
64  centre += p1_;
65 
66  // find position vectors w.r.t. the arcEdge centre
67  vector r1(p1_ - centre);
68  vector r2(p2_ - centre);
69  vector r3(p3_ - centre);
70 
71  // find angles
72  angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1))));
73 
74  // check if the vectors define an exterior or an interior arcEdge
75  if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
76  {
77  angle_ = 360.0 - angle_;
78  }
79 
80  vector tempAxis;
81 
82  if (angle_ <= 180.0)
83  {
84  tempAxis = r1 ^ r3;
85 
86  if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
87  {
88  tempAxis = r1 ^ r2;
89  }
90  }
91  else
92  {
93  tempAxis = r3 ^ r1;
94  }
95 
96  radius_ = mag(r3);
97 
98  // set up and return the local coordinate system
99  return cylindricalCS("arcEdgeCS", centre, tempAxis, r1);
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
105 Foam::arcEdge::arcEdge
106 (
107  const pointField& points,
108  const label start,
109  const label end,
110  const point& pMid
111 )
112 :
113  curvedEdge(points, start, end),
114  p1_(points_[start_]),
115  p2_(pMid),
116  p3_(points_[end_]),
117  cs_(calcAngle())
118 {}
119 
120 
121 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
122 :
123  curvedEdge(points, is),
124  p1_(points_[start_]),
125  p2_(is),
126  p3_(points_[end_]),
127  cs_(calcAngle())
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 {
135  if (lambda < -SMALL || lambda > 1 + SMALL)
136  {
138  << "Parameter out of range, lambda = " << lambda
139  << abort(FatalError);
140  }
141 
142  if (lambda < SMALL)
143  {
144  return p1_;
145  }
146  else if (lambda > 1 - SMALL)
147  {
148  return p3_;
149  }
150  else
151  {
152  return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
153  }
154 }
155 
156 
157 Foam::scalar Foam::arcEdge::length() const
158 {
159  return degToRad(angle_*radius_);
160 }
161 
162 
163 // ************************************************************************* //
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
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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
point globalPosition(const point &local) const
Convert from position in local coordinate system to global.
Macros for easy insertion into run-time selection tables.
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
Cylindrical coordinate system.
Definition: cylindricalCS.H:48
point position(const scalar) const
Return the point position corresponding to the curve parameter.
Definition: arcEdge.C:133
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
errorManip< error > abort(error &err)
Definition: errorManip.H:131
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Definition: point.H:41
dimensionedScalar lambda(laminarTransport.lookup("lambda"))
dimensioned< scalar > mag(const dimensioned< Type > &)
Define a curved edge that is parameterized for 0<lambda<1 between the start and end point...
Definition: curvedEdge.H:60
scalar length() const
Return the length of the curve.
Definition: arcEdge.C:157
Namespace for OpenFOAM.