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 | Copyright (C) 2011-2016 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 "coordSet.H"
27 
28 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  template<>
33  const char* Foam::NamedEnum
34  <
36  5
37  >::names[] =
38  {
39  "xyz",
40  "x",
41  "y",
42  "z",
43  "distance"
44  };
45 }
46 
47 
49  Foam::coordSet::coordFormatNames_;
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const word& name,
57  const word& axis
58 )
59 :
60  pointField(0),
61  name_(name),
62  axis_(coordFormatNames_[axis]),
63  curveDist_(0)
64 {}
65 
66 
68 (
69  const word& name,
70  const word& axis,
71  const List<point>& points,
72  const scalarList& curveDist
73 )
74 :
75  pointField(points),
76  name_(name),
77  axis_(coordFormatNames_[axis]),
78  curveDist_(curveDist)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 {
86  return axis_ == XYZ;
87 }
88 
89 
90 Foam::scalar Foam::coordSet::scalarCoord
91 (
92  const label index
93 ) const
94 {
95  const point& p = operator[](index);
96 
97  if (axis_ == X)
98  {
99  return p.x();
100  }
101  else if (axis_ == Y)
102  {
103  return p.y();
104  }
105  else if (axis_ == Z)
106  {
107  return p.z();
108  }
109  else if (axis_ == DISTANCE)
110  {
111  // Use distance to reference point
112  return curveDist_[index];
113  }
114  else
115  {
117  << "Illegal axis specification " << axis_
118  << " for sampling line " << name_
119  << exit(FatalError);
120 
121  return 0;
122  }
123 }
124 
125 
127 {
128  const point& p = operator[](index);
129 
130  return p;
131 }
132 
133 
135 {
136  os << "name:" << name_ << " axis:" << axis_
137  << endl
138  << endl << "\t(coord)"
139  << endl;
140 
141  forAll(*this, sampleI)
142  {
143  os << '\t' << operator[](sampleI) << endl;
144  }
145 
146  return os;
147 }
148 
149 
150 // ************************************************************************* //
const Cmpt & z() const
Definition: VectorI.H:87
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const Cmpt & x() const
Definition: VectorI.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:91
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:84
Ostream & write(Ostream &os) const
Definition: coordSet.C:134
A class for handling words, derived from string.
Definition: word.H:59
const Cmpt & y() const
Definition: VectorI.H:81
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
coordSet(const word &name, const word &axis)
Construct from components.
Definition: coordSet.C:55
PtrList< volScalarField > & Y
vector vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:126
volScalarField & p
Namespace for OpenFOAM.