Vector.H
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-2013 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 Class
25  Foam::Vector
26 
27 Description
28  Templated 3D Vector derived from VectorSpace adding construction from
29  3 components, element access using x(), y() and z() member functions and
30  the inner-product (dot-product) and cross product operators.
31 
32  A centre() member function which returns the Vector for which it is called
33  is defined so that point which is a typedef to Vector<scalar> behaves as
34  other shapes in the shape hierachy.
35 
36 SourceFiles
37  VectorI.H
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Vector_H
42 #define Vector_H
43 
44 #include "VectorSpace.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 template<class T> class List;
52 
53 /*---------------------------------------------------------------------------*\
54  Class Vector Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Cmpt>
58 class Vector
59 :
60  public VectorSpace<Vector<Cmpt>, Cmpt, 3>
61 {
62 
63 public:
64 
65  //- Equivalent type of labels used for valid component indexing
66  typedef Vector<label> labelType;
67 
68 
69  // Member constants
70 
71  enum
72  {
73  rank = 1 // Rank of Vector is 1
74  };
75 
76 
77  // Static data members
78 
79  static const char* const typeName;
80  static const char* componentNames[];
81  static const Vector zero;
82  static const Vector one;
83  static const Vector max;
84  static const Vector min;
85  static const Vector rootMax;
86  static const Vector rootMin;
87 
88 
89  //- Component labeling enumeration
90  enum components { X, Y, Z };
91 
92 
93  // Constructors
94 
95  //- Construct null
96  inline Vector();
97 
98  //- Construct given VectorSpace of the same rank
99  template<class Cmpt2>
100  inline Vector(const VectorSpace<Vector<Cmpt2>, Cmpt2, 3>&);
101 
102  //- Construct given three components
103  inline Vector(const Cmpt& vx, const Cmpt& vy, const Cmpt& vz);
104 
105  //- Construct from Istream
106  inline Vector(Istream&);
107 
108 
109  // Member Functions
110 
111  // Access
112 
113  inline const Cmpt& x() const;
114  inline const Cmpt& y() const;
115  inline const Cmpt& z() const;
116 
117  inline Cmpt& x();
118  inline Cmpt& y();
119  inline Cmpt& z();
120 
121  //- Return *this (used for point which is a typedef to Vector<scalar>.
122  inline const Vector<Cmpt>& centre
123  (
124  const Foam::List<Vector<Cmpt> >&
125  ) const;
126 };
127 
128 
129 template<class Cmpt>
130 class typeOfRank<Cmpt, 1>
131 {
132 public:
133 
134  typedef Vector<Cmpt> type;
135 };
136 
137 
138 template<class Cmpt>
139 class symmTypeOfRank<Cmpt, 1>
140 {
141 public:
142 
143  typedef Vector<Cmpt> type;
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #include "VectorI.H"
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
Foam::Vector::typeName
static const char *const typeName
Definition: Vector.H:78
VectorSpace.H
Foam::Vector::rank
@ rank
Definition: Vector.H:72
Foam::Vector::min
static const Vector min
Definition: Vector.H:83
Foam::Vector::Z
@ Z
Definition: Vector.H:89
Foam::Vector::zero
static const Vector zero
Definition: Vector.H:80
Foam::Vector::Y
@ Y
Definition: Vector.H:89
Foam::Vector::max
static const Vector max
Definition: Vector.H:82
Foam::Vector::componentNames
static const char * componentNames[]
Definition: Vector.H:79
Foam::Vector< vector >::components
components
Component labeling enumeration.
Definition: Vector.H:89
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::symmTypeOfRank< Cmpt, 1 >::type
Vector< Cmpt > type
Definition: Vector.H:142
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Vector::one
static const Vector one
Definition: Vector.H:81
Foam::Vector::X
@ X
Definition: Vector.H:89
Foam::Vector::centre
const Vector< Cmpt > & centre(const Foam::List< Vector< Cmpt > > &) const
Return *this (used for point which is a typedef to Vector<scalar>.
Definition: VectorI.H:106
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::symmTypeOfRank
Definition: products.H:50
Foam::typeOfRank
Definition: products.H:45
Foam::typeOfRank< Cmpt, 1 >::type
Vector< Cmpt > type
Definition: Vector.H:133
Foam::Vector::rootMin
static const Vector rootMin
Definition: Vector.H:85
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:57
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
Foam::Vector::rootMax
static const Vector rootMax
Definition: Vector.H:84
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
List
Definition: Test.C:19
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::Vector::Vector
Vector()
Construct null.
Definition: VectorI.H:34
VectorI.H
Foam::Vector::labelType
Vector< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Vector.H:65