ijkAddressing.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::ijkAddressing
28 
29 Description
30  A simple i-j-k (row-major order) to linear addressing.
31 
32 SourceFiles
33  ijkAddressingI.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef ijkAddressing_H
38 #define ijkAddressing_H
39 
40 #include "labelVector.H"
41 #include "vector.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class ijkAddressing Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class ijkAddressing
53 {
54  // Private Data
55 
56  //- The number of items in the i,j,k directions.
57  labelVector sizes_;
58 
59 
60 public:
61 
62  // Constructors
63 
64  //- Construct zero-size addressing
65  inline ijkAddressing();
66 
67  //- Construct with addressing
68  inline explicit ijkAddressing(const labelVector& ijk);
69 
70  //- Construct with addressing components
71  inline ijkAddressing(const label ni, const label nj, const label nk);
72 
73 
74  // Member Functions
75 
76  // Access
77 
78  //- Addressing is considered empty if any component is zero
79  inline bool empty() const;
80 
81  //- The (i,j,k) addressing dimensions
82  inline const labelVector& sizes() const;
83 
84  //- Return the (i,j,k) dimensions for modification
85  inline labelVector& sizes();
86 
87  //- Return the total i*j*k size
88  inline label size() const;
89 
90  //- The addressing dimension in the given direction
91  inline const label& size(const vector::components cmpt) const;
92 
93  //- Reset to (0,0,0) sizing
94  inline void clear();
95 
96  //- Change the sizing parameters
97  inline void reset(const label ni, const label nj, const label nk);
98 
99  //- Change the sizing parameters
100  inline void reset(const labelVector& newSizes);
101 
102  //- Linear addressing index (offset) for an (i,j,k) position.
103  inline label index(const label i, const label j, const label k) const;
104 
105  //- Linear addressing index (offset) for an (i,j,k) position.
106  inline label index(const labelVector& ijk) const;
107 
108  //- The (i,j,k) indexing from linear addressing.
109  inline labelVector index(const label idx) const;
110 
111 
112  // Checks
113 
114  //- Check indices are within ni,nj,nk range.
115  // Optionally allow an extra index for point addressing
116  inline void checkIndex
117  (
118  const label i,
119  const label j,
120  const label k,
121  const bool allowExtra = false
122  ) const;
123 
124  //- Check indices are within ni,nj,nk range.
125  // Optionally allow an extra index for point addressing
126  inline void checkIndex
127  (
128  const labelVector& ijk,
129  const bool allowExtra = false
130  ) const;
131 
132  //- Check that all components of sizes() are non-negative
133  inline void checkSizes() const;
134 
135  //- Check that all components of sizes() match
136  inline void checkSizes(const labelVector& other) const;
137 
138  //- Check that the total size matches
139  inline void checkSizes(const label nTotal) const;
140 
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #include "ijkAddressingI.H"
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #endif
155 
156 // ************************************************************************* //
labelVector.H
ijkAddressingI.H
Foam::ijkAddressing::sizes
const labelVector & sizes() const
The (i,j,k) addressing dimensions.
Definition: ijkAddressingI.H:69
Foam::ijkAddressing::checkIndex
void checkIndex(const label i, const label j, const label k, const bool allowExtra=false) const
Check indices are within ni,nj,nk range.
Definition: ijkAddressingI.H:169
Foam::ijkAddressing::clear
void clear()
Reset to (0,0,0) sizing.
Definition: ijkAddressingI.H:97
Foam::Vector< scalar >::components
components
Component labeling enumeration.
Definition: Vector.H:81
Foam::ijkAddressing::ijkAddressing
ijkAddressing()
Construct zero-size addressing.
Definition: ijkAddressingI.H:30
Foam::ijkAddressing::reset
void reset(const label ni, const label nj, const label nk)
Change the sizing parameters.
Definition: ijkAddressingI.H:104
Foam::ijkAddressing::size
label size() const
Return the total i*j*k size.
Definition: ijkAddressingI.H:81
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ijkAddressing::empty
bool empty() const
Addressing is considered empty if any component is zero.
Definition: ijkAddressingI.H:63
Foam::Vector< label >
Foam::ijkAddressing::index
label index(const label i, const label j, const label k) const
Linear addressing index (offset) for an (i,j,k) position.
Definition: ijkAddressingI.H:131
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
vector.H
Foam::ijkAddressing
A simple i-j-k (row-major order) to linear addressing.
Definition: ijkAddressing.H:51
Foam::ijkAddressing::checkSizes
void checkSizes() const
Check that all components of sizes() are non-negative.
Definition: ijkAddressingI.H:212