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-2026 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 "units.H"
28 #include "mathematicalConstants.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace blockEdges
36 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::blockEdges::arcEdge::calc(const point& pA)
46 {
47  const tensor dps(pA - p0_, pA - p1_, (pA - p0_)^(pA - p1_));
48  const tensor pMs((p0_ + pA)/2, (p1_ + pA)/2, pA);
49 
50  if (det(dps) < vSmall)
51  {
53  << "Arc point " << pA << " lies on the line of edge "
54  << edge(start_, end_) << abort(FatalError);
55  }
56 
57  const point c =
58  inv(dps)
59  & vector(dps.x() & pMs.x(), dps.y() & pMs.y(), dps.z() & pMs.z());
60 
61  const vector r0 = p0_ - c, r1 = p1_ - c;
62  const scalar cosT = (r0 & r1)/(mag(r0)*mag(r1));
63  scalar t = acos(max(-1, min(cosT, 1)));
64  if (((r0 ^ r1) & dps.z()) > 0)
65  {
67  }
68 
69  centre_ = c;
70  axis_ = - normalised(dps.z());
71  theta_ = t;
72  length_ = 0;
73 }
74 
75 
76 void Foam::blockEdges::arcEdge::calc(const scalar theta, const vector& axis)
77 {
78  if (0 >= theta || theta >= 360)
79  {
81  << "Arc angle for edge " << edge(start_, end_)
82  << " must take a value between 0 and 360 degrees"
83  << abort(FatalError);
84  }
85 
86  const vector dp = p1_ - p0_;
87 
88  const vector pM = (p0_ + p1_)/2;
89  const vector rM = normalised(dp ^ axis);
90 
91  const scalar l = dp & axis;
92 
93  const vector chord = dp - l*axis;
94  const scalar magChord = mag(chord);
95 
96  centre_ = pM - l*axis/2 - rM*magChord/2/tan(theta/2);
97  axis_ = axis;
98  theta_ = theta;
99  length_ = l;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
106 (
107  const dictionary& dict,
108  const label index,
109  const searchableSurfaceList& geometry,
110  const pointField& points,
111  Istream& is
112 )
113 :
114  blockEdge(dict, index, points, is),
115  p0_(points_[start_]),
116  p1_(points_[end_]),
117  centre_(),
118  axis_(),
119  theta_(),
120  length_()
121 {
122  token firstToken(is);
123  is.putBack(firstToken);
124 
125  if (firstToken == token::BEGIN_LIST)
126  {
127  const point pA(is);
128  calc(pA);
129  }
130  else
131  {
132  const scalar theta = degToRad(readScalar(is));
133  const vector axis(is);
134  calc(theta, normalised(axis));
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
142 {
143  if (lambda < - small || lambda > 1 + small)
144  {
146  << "Parameter out of range, lambda = " << lambda
147  << abort(FatalError);
148  }
149 
150  const scalar t = theta_*lambda;
151  const vector r1 = p0_ - centre_, r2 = axis_ ^ r1;
152 
153  return centre_ + r1*cos(t) + r2*sin(t) + axis_*length_*lambda;
154 }
155 
156 
158 {
159  const vector r1 = p0_ - centre_;
160 
161  // Length of a helical segment
162  return theta_*sqrt(magSqr(r1) + sqr(length_));
163 }
164 
165 
166 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Define a curved edge that is parameterised for 0<lambda<1 between the start and end point.
Definition: blockEdge.H:57
const label end_
Definition: blockEdge.H:65
const label start_
Definition: blockEdge.H:64
An arcEdge between two points on a circle. The arc is defined either by a third point that the arc pa...
Definition: arcEdge.H:60
scalar length() const
Return the length of the curve.
Definition: arcEdge.C:157
point position(const scalar) const
Return the point position corresponding to the curve parameter.
Definition: arcEdge.C:141
arcEdge(const dictionary &dict, const label index, const searchableSurfaceList &geometry, const pointField &points, Istream &)
Construct from Istream setting pointsList.
Definition: arcEdge.C:106
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Container for searchableSurfaces.
A token holds items read from Istream.
Definition: token.H:74
@ BEGIN_LIST
Definition: token.H:110
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
dimensionedScalar lambda(viscosity->lookup("lambda"))
defineTypeNameAndDebug(arcEdge, 0)
addToRunTimeSelectionTable(blockEdge, arcEdge, Istream)
const dimensionedScalar c
Speed of light in a vacuum.
unitSet length_(dimensionSet(0, 1, 0, 0, 0), 0, 0, 1)
Namespace for OpenFOAM.
dimensionedScalar tan(const dimensionedScalar &ds)
scalar degToRad(const scalar deg)
Convert degrees to radians.
Definition: units.C:364
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
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
errorManip< error > abort(error &err)
Definition: errorManip.H:131
dimensionedScalar sin(const dimensionedScalar &ds)
vector point
Point is a vector.
Definition: point.H:41
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:509
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void det(pointPatchField< scalar > &, const pointPatchField< tensor > &)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
error FatalError
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar acos(const dimensionedScalar &ds)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dictionary dict
Useful unit conversions.