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-2012 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 
54 //- Construct from components
56 (
57  const word& name,
58  const word& axis
59 )
60 :
61  pointField(0),
62  name_(name),
63  axis_(coordFormatNames_[axis]),
64  curveDist_(0)
65 {}
66 
67 
68 //- Construct from components
70 (
71  const word& name,
72  const word& axis,
73  const List<point>& points,
74  const scalarList& curveDist
75 )
76 :
77  pointField(points),
78  name_(name),
79  axis_(coordFormatNames_[axis]),
80  curveDist_(curveDist)
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
87 {
88  return axis_ == XYZ;
89 }
90 
91 
92 Foam::scalar Foam::coordSet::scalarCoord
93 (
94  const label index
95 ) const
96 {
97  const point& p = operator[](index);
98 
99  if (axis_ == X)
100  {
101  return p.x();
102  }
103  else if (axis_ == Y)
104  {
105  return p.y();
106  }
107  else if (axis_ == Z)
108  {
109  return p.z();
110  }
111  else if (axis_ == DISTANCE)
112  {
113  // Use distance to reference point
114  return curveDist_[index];
115  }
116  else
117  {
119  (
120  "coordSet::scalarCoord(const label)"
121  ) << "Illegal axis specification " << axis_
122  << " for sampling line " << name_
123  << exit(FatalError);
124 
125  return 0;
126  }
127 }
128 
129 
131 {
132  const point& p = operator[](index);
133 
134  return p;
135 }
136 
137 
139 {
140  os << "name:" << name_ << " axis:" << axis_
141  << endl
142  << endl << "\t(coord)"
143  << endl;
144 
145  forAll(*this, sampleI)
146  {
147  os << '\t' << operator[](sampleI) << endl;
148  }
149 
150  return os;
151 }
152 
153 
154 // ************************************************************************* //
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:59
A class for handling words, derived from string.
Definition: word.H:59
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
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Namespace for OpenFOAM.
vector vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:130
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
const Cmpt & y() const
Definition: VectorI.H:71
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
volScalarField & p
Definition: createFields.H:51
coordSet(const word &name, const word &axis)
Construct from components.
Definition: coordSet.C:56
PtrList< volScalarField > & Y
Definition: createFields.H:36
#define forAll(list, i)
Definition: UList.H:421
const Cmpt & x() const
Definition: VectorI.H:65
const Cmpt & z() const
Definition: VectorI.H:77
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Ostream & write(Ostream &os) const
Definition: coordSet.C:138
error FatalError
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:86
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:93