curveTools.C
Go to the documentation of this file.
1 #include "scalar.H"
2 #include "vector.H"
3 #include "curveTools.H"
4 
5 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
6 
7 namespace Foam
8 {
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 scalar distance(const vector& p1, const vector& p2)
13 {
14  return mag(p2 - p1);
15 }
16 
17 
19 (
20  const vector& o,
21  vector& n,
22  label& i,
23  label& ip1,
24  scalar l,
25  const curve& Curve
26 )
27 {
28  label ip1n = ip1-1;
29  while (++ip1n < Curve.size() && distance(o, Curve[ip1n]) < l);
30  label in = ip1n - 1;
31 
32  bool eoc = true;
33 
34  if (ip1n < Curve.size() && in >= 0)
35  {
36  eoc = interpolate(Curve[in], Curve[ip1n], o, n, l);
37 
38  i = in;
39  ip1 = ip1n;
40  }
41 
42  return eoc;
43 }
44 
45 
47 (
48  const vector& o,
49  vector& n,
50  label& i,
51  label& ip1,
52  scalar l,
53  const curve& Curve
54 )
55 {
56  label ip1n = ip1+1;
57  while (--ip1n >= 0 && distance(o, Curve[ip1n]) < l);
58  label in = ip1n + 1;
59 
60  bool eoc = true;
61 
62  if (ip1n >= 0 && in < Curve.size())
63  {
64  eoc = interpolate(Curve[in], Curve[ip1n], o, n, l);
65 
66  i = in;
67  ip1 = ip1n;
68  }
69 
70  return eoc;
71 }
72 
73 
74 bool interpolate
75 (
76  const vector& p1,
77  const vector& p2,
78  const vector& o,
79  vector& n,
80  scalar l
81 )
82 {
83  vector D = p1 - p2;
84  scalar a = magSqr(D);
85  scalar b = 2.0*(D&(p2 - o));
86  scalar c = magSqr(p2) + (o&(o - 2.0*p2)) - l*l;
87 
88  scalar b2m4ac = b*b - 4.0*a*c;
89 
90  if (b2m4ac >= 0.0)
91  {
92  scalar srb2m4ac = sqrt(b2m4ac);
93 
94  scalar lamda = (-b - srb2m4ac)/(2.0*a);
95 
96  if (lamda > 1.0+curveSmall || lamda < -curveSmall)
97  {
98  lamda = (-b + srb2m4ac)/(2.0*a);
99  }
100 
101  if (lamda < 1.0+curveSmall && lamda > -curveSmall)
102  {
103  n = p2 + lamda*(p1 - p2);
104 
105  return false;
106  }
107  else
108  {
109  return true;
110  }
111  }
112 
113  return true;
114 }
115 
116 
117 
119 (
120  const vector& o,
121  vector& n,
122  label& i,
123  label& ip1,
124  scalar l,
125  const curve& Curve
126 )
127 {
128  label ip1n = ip1-1;
129  while (++ip1n < Curve.size() && mag(o.x() - Curve[ip1n].x()) < l);
130  label in = ip1n - 1;
131 
132  bool eoc = true;
133 
134  if (ip1n < Curve.size() && in >= 0)
135  {
136  eoc = Xinterpolate(Curve[in], Curve[ip1n], o, n, l);
137 
138  i = in;
139  ip1 = ip1n;
140  }
141 
142  return eoc;
143 }
144 
145 
146 
147 bool Xinterpolate
148 (
149  const vector& p1,
150  const vector& p2,
151  const vector& o,
152  vector& n,
153  scalar l
154 )
155 {
156  n.x() = o.x() + l;
157 
158  if (p2.x() < o.x() + l - curveSmall && p2.x() > o.x() - l + curveSmall)
159  {
160  return true;
161  }
162 
163  if (p2.x() < o.x() + l)
164  {
165  n.x() = o.x() - l;
166  }
167 
168  vector D = p2 - p1;
169  scalar lamda = (n.x() - p1.x())/D.x();
170  n.y() = p1.y() + lamda*D.y();
171 
172  return false;
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // ************************************************************************* //
Foam::Xinterpolate
bool Xinterpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:148
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
curveTools.H
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::interpolate
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
Foam::stepBackwardsToNextPoint
bool stepBackwardsToNextPoint(const vector &o, vector &n, label &i, label &ip1, scalar l, const curve &Curve)
Definition: curveTools.C:47
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::XstepForwardsToNextPoint
bool XstepForwardsToNextPoint(const vector &o, vector &n, label &i, label &ip1, scalar l, const curve &Curve)
Definition: curveTools.C:119
scalar.H
Foam::stepForwardsToNextPoint
bool stepForwardsToNextPoint(const vector &o, vector &n, label &i, label &ip1, scalar l, const curve &Curve)
Definition: curveTools.C:19
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distance
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
curveSmall
#define curveSmall
Definition: curveTools.H:15
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
D
const dimensionedScalar & D
Definition: solveBulkSurfactant.H:4
vector.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::curve
A single curve in a graph.
Definition: curve.H:58