curve.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 "curve.H"
27 //#include "curveTools.H"
28 #include "Ostream.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 // construct as interpolation
38 /*
39 curve::curve(const curve& Curve, const label nFacets)
40 :
41  Name("Interpolated" + Curve.Name),
42  Style(Curve.Style),
43  X(2*nFacets),
44  Y(2*nFacets)
45 {
46  // Calculate curve length
47  scalar curveLength=0;
48  label i;
49  for (i=0; i<Curve.size()-1; i++)
50  {
51  curveLength += distance(Curve[i], Curve[i+1]);
52  }
53 
54  scalar stepLength = curveLength/nFacets;
55  label nPoints = 0;
56  label previous=0, next=1;
57  bool endOfCurve;
58  vector presentPoint=Curve[0], nextPoint;
59 
60  do
61  {
62  endOfCurve =
63  stepForwardsToNextPoint
64  (
65  presentPoint,
66  nextPoint,
67  previous,
68  next,
69  stepLength,
70  Curve
71  );
72 
73  if (!endOfCurve)
74  {
75  if (nPoints >= size()-1)
76  {
77  setSize(label(1.5*size()));
78  }
79 
80  presentPoint = nextPoint;
81 
82  x()[nPoints] = nextPoint.x();
83  y()[nPoints] = nextPoint.y();
84 
85  nPoints++;
86  }
87 
88  } while (!endOfCurve);
89 
90  setSize(nPoints);
91 }
92 */
93 
94 
95 // construct given name, style and size
97 (
98  const string& name,
99  const curveStyle& style,
100  const label l
101 )
102 :
103  scalarField(l, 0.0),
104  name_(name),
105  style_(style)
106 {}
107 
108 
109 // construct from the bits
111 (
112  const string& name,
113  const curveStyle& style,
114  const scalarField& y
115 )
116 :
117  scalarField(y),
118  name_(name),
119  style_(style)
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
124 
125 // Gradient operation
126 /*
127 curve grad(const curve& Curve)
128 {
129  curve gradCurve(Curve);
130 
131  label i;
132  for (i=1; i<Curve.size()-1; i++)
133  {
134  scalar deltaIm1 = Curve[i].x() - Curve[i-1].x();
135  scalar deltaI = Curve[i+1].x() - Curve[i].x();
136 
137  scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI;
138 
139  gradCurve.y()[i] =
140  (
141  (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
142  + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
143  )/deltaAv;
144  }
145 
146  gradCurve.y()[0] =
147  (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
148 
149  label n = Curve.size()-1;
150 
151  gradCurve.y()[n] =
152  (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
153 
154  return gradCurve;
155 }
156 */
157 
158 
159 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
160 
162 {
163  os << nl
164  << c.name_ << nl
165  << c.style_ << nl
166  << static_cast<const scalarField&>(c);
167 
168  os.check("Ostream& operator>>(Ostream&, const curve&)");
169 
170  return os;
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 } // End namespace Foam
177 
178 // ************************************************************************* //
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
The style (line, symbol, etc) of a curve.
Definition: curve.H:64
A single curve in a graph.
Definition: curve.H:56
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
static const char nl
Definition: Ostream.H:260
scalar y
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
curve(const string &name, const curveStyle &style, const label l)
Construct as interpolation of an existing curve.
Definition: curve.C:97
const dimensionedScalar c
Speed of light in a vacuum.