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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::ijkAddressing
28
29Description
30 A simple i-j-k (row-major order) to linear addressing.
31
32SourceFiles
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
45namespace Foam
46{
47
48/*---------------------------------------------------------------------------*\
49 Class ijkAddressing Declaration
50\*---------------------------------------------------------------------------*/
52class ijkAddressing
53{
54 // Private Data
55
56 //- The number of items in the i,j,k directions.
57 labelVector sizes_;
58
59
60public:
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// ************************************************************************* //
label k
Extracts the components of elements of a field and outputs the result into new fields,...
Definition: components.H:188
A simple i-j-k (row-major order) to linear addressing.
Definition: ijkAddressing.H:52
void checkIndex(const label i, const label j, const label k, const bool allowExtra=false) const
Check indices are within ni,nj,nk range.
labelVector & sizes()
Return the (i,j,k) dimensions for modification.
ijkAddressing()
Construct zero-size addressing.
label index(const label i, const label j, const label k) const
Linear addressing index (offset) for an (i,j,k) position.
label size() const
Return the total i*j*k size.
bool empty() const
Addressing is considered empty if any component is zero.
void checkSizes() const
Check that all components of sizes() are non-negative.
void reset(const label ni, const label nj, const label nk)
Change the sizing parameters.
void clear()
Reset to (0,0,0) sizing.
Namespace for OpenFOAM.