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-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 "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 
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 :
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  << "Illegal axis specification " << axis_
120  << " for sampling line " << name_
121  << exit(FatalError);
122 
123  return 0;
124  }
125 }
126 
127 
129 {
130  const point& p = operator[](index);
131 
132  return p;
133 }
134 
135 
137 {
138  os << "name:" << name_ << " axis:" << axis_
139  << endl
140  << endl << "\t(coord)"
141  << endl;
142 
143  forAll(*this, sampleI)
144  {
145  os << '\t' << operator[](sampleI) << endl;
146  }
147 
148  return os;
149 }
150 
151 
152 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
coordSet.H
Foam::coordSet::coordFormat
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:59
Foam::coordSet::scalarCoord
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:93
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::coordSet::coordSet
coordSet(const word &name, const word &axis)
Construct from components.
Definition: coordSet.C:56
Foam::label
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
Foam::coordSet::coordFormatNames_
static const NamedEnum< coordFormat, 5 > coordFormatNames_
String representation of coordFormat enums.
Definition: coordSet.H:72
Foam::coordSet::axis_
const coordFormat axis_
Axis write type.
Definition: coordSet.H:81
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Vector< scalar >
Foam::coordSet::write
Ostream & write(Ostream &os) const
Definition: coordSet.C:136
Foam::List
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
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:128
Foam::coordSet::hasVectorAxis
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:86
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::coordSet::XYZ
@ XYZ
Definition: coordSet.H:61
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Y
PtrList< volScalarField > & Y
Definition: createFields.H:36
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52