coordSet.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "coordSet.H"
30 
31 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
32 
33 const Foam::Enum
34 <
36 >
38 ({
39  { coordFormat::XYZ, "xyz" },
40  { coordFormat::X, "x" },
41  { coordFormat::Y, "y" },
42  { coordFormat::Z, "z" },
43  { coordFormat::DISTANCE, "distance" },
44 });
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::coordSet::checkDimensions() const
50 {
51  if (size() != curveDist_.size())
52  {
54  << "Size of points and curve distance must be the same" << nl
55  << " points size : " << size()
56  << " curve size : " << curveDist_.size()
57  << abort(FatalError);
58  }
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
65 (
66  const word& name,
67  const coordFormat axisType
68 )
69 :
70  pointField(),
71  name_(name),
72  axis_(axisType),
73  curveDist_()
74 {}
75 
76 
78 (
79  const word& name,
80  const word& axis
81 )
82 :
83  pointField(),
84  name_(name),
85  axis_(coordFormatNames[axis]),
86  curveDist_()
87 {}
88 
89 
91 (
92  const word& name,
93  const word& axis,
94  const List<point>& points,
95  const scalarList& curveDist
96 )
97 :
99  name_(name),
100  axis_(coordFormatNames[axis]),
101  curveDist_(curveDist)
102 {
103  checkDimensions();
104 }
105 
106 
108 (
109  const word& name,
110  const word& axis,
112  scalarList&& curveDist
113 )
114 :
115  pointField(std::move(points)),
116  name_(name),
117  axis_(coordFormatNames[axis]),
118  curveDist_(std::move(curveDist))
119 {
120  checkDimensions();
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  return axis_ == coordFormat::XYZ;
129 }
130 
131 
132 Foam::scalar Foam::coordSet::scalarCoord(const label index) const
133 {
134  const point& p = operator[](index);
135 
136  switch (axis_)
137  {
138  case coordFormat::X:
139  {
140  return p.x();
141  }
142  case coordFormat::Y:
143  {
144  return p.y();
145  }
146  case coordFormat::Z:
147  {
148  return p.z();
149  }
150  case coordFormat::DISTANCE:
151  {
152  // Note: If this has been constructed from the 'name' and 'axis'
153  // constructor the curveDist list will not have been set
154 
155  if (curveDist_.empty())
156  {
158  << "Axis type '" << coordFormatNames[axis_]
159  << "' requested but curve distance has not been set"
160  << abort(FatalError);
161  }
162 
163  return curveDist_[index];
164  }
165  default:
166  {
168  << "Illegal axis specification '" << coordFormatNames[axis_]
169  << "' for sampling line " << name_
170  << exit(FatalError);
171 
172  return 0;
173  }
174  }
175 }
176 
177 
178 Foam::point Foam::coordSet::vectorCoord(const label index) const
179 {
180  const point& p = operator[](index);
181 
182  return p;
183 }
184 
185 
187 {
188  os << "name:" << name_ << " axis:" << coordFormatNames[axis_]
189  << nl
190  << nl << "\t(coord)"
191  << endl;
192 
193  for (const point& pt : *this)
194  {
195  os << '\t' << pt << endl;
196  }
197 
198  return os;
199 }
200 
201 
202 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
coordSet.H
Foam::coordSet::coordFormat
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:62
Foam::coordSet::scalarCoord
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:132
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::coordSet::coordSet
coordSet(const word &name, const coordFormat axisType)
Construct from components.
Definition: coordSet.C:65
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::coordSet::curveDist_
scalarList curveDist_
Cumulative distance "distance" write specifier.
Definition: coordSet.H:89
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::coordSet::coordFormatNames
static const Enum< coordFormat > coordFormatNames
String representation of coordFormat enum.
Definition: coordSet.H:72
Foam::Vector< scalar >
Foam::coordSet::write
Ostream & write(Ostream &os) const
Write to stream.
Definition: coordSet.C:186
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::coordSet::vectorCoord
vector vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:178
Foam::coordSet::hasVectorAxis
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:126
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56