kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
DimensionSizes.h
Go to the documentation of this file.
1 /**
2  * @file DimensionSizes.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the structure with 3D dimension sizes.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 09 August 2011, 12:34 (created) \n
14  * 04 September 2017, 11:16 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 
33 #ifndef DIMENSION_SIZES_H
34 #define DIMENSION_SIZES_H
35 
36 #include <cstdlib>
37 
38 #ifdef __AVX2__
39 /**
40  * @var kDataAlignment
41  * @brief memory alignment for AVX2 (32B)
42  */
43 constexpr int kDataAlignment = 32;
44 #elif __AVX__
45 /**
46  * @var kDataAlignment
47  * @brief memory alignment for AVX (32B)
48  */
49 constexpr int kDataAlignment = 32;
50 #else
51 
52 /**
53  * @var kDataAlignment
54  * @brief memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
55  */
56 constexpr int kDataAlignment = 16;
57 #endif
58 
59 /**
60  * @struct DimensionSizes
61  * @brief Structure with 4D dimension sizes (3 in space and 1 in time).
62  * @details Structure with 4D dimension sizes (3 in space and 1 in time).
63  * The structure can be used for 3D (the time is then set to 1). \n
64  * The structure contains only POD, so no C++ stuff is necessary.
65  */
67 {
68  /// Default constructor.
69  DimensionSizes() : nx(0), ny(0), nz(0), nt(0) {};
70 
71  /**
72  * @brief Constructor.
73  * @details Constructor.
74  * @param [in] x, y, z, t - Three spatial dimensions and time.
75  */
76  DimensionSizes(size_t x, size_t y, size_t z, size_t t = 0)
77  : nx(x), ny(y), nz(z), nt(t)
78  {};
79 
80 
81  /**
82  * @brief Get the number of elements, in 3D only spatial domain, in 4D with time.
83  * @details Get element count, in 3D only spatial domain, in 4D with time.
84  * @return the number of elements the domain holds.
85  */
86  inline size_t nElements() const
87  {
88  return (is3D()) ? nx * ny * nz : nx * ny * nz * nt;
89  };
90 
91  /**
92  * @brief Does the object include spatial dimensions only?
93  * @return true if the dimensions are 3D.
94  */
95  inline bool is3D() const
96  {
97  return (nt == 0);
98  };
99 
100  /**
101  * @brief Does the object include spatial and temporal dimensions?
102  * @return true if the dimensions are 4D.
103  */
104  inline bool is4D() const
105  {
106  return (nt > 0);
107  };
108 
109 /**
110  * @brief Operator ==
111  * @param [in] other - The second operand to compare with.
112  * @return true if the dimension sizes are equal.
113  */
114  inline bool operator==(const DimensionSizes& other) const
115  {
116  return ((nx == other.nx) && (ny == other.ny) && (nz == other.nz) && (nt == other.nt));
117  };
118 
119  /**
120  * @brief Operator !=
121  * @param [in] other - the second operand to compare with.
122  * @return true if !=
123  */
124  inline bool operator!=(const DimensionSizes& other) const
125  {
126  return ((nx != other.nx) || (ny != other.ny) || (nz != other.nz) || (nt != other.nt));
127  };
128 
129  /**
130  * @brief Operator -
131  *
132  * Get the size of the cube defined by two corners.
133  *
134  * @param [in] op1 - Usually bottom right corner.
135  * @param [in] op2 - Usually top left corner.
136  * @return the size of the inner cuboid
137  */
138  inline friend DimensionSizes operator-(const DimensionSizes& op1,
139  const DimensionSizes& op2)
140  {
141  // +1 because of planes (10.10.1 - 60.40.1)
142  if (op1.is3D() && op2.is3D())
143  {
144  return DimensionSizes(op1.nx - op2.nx + 1, op1.ny - op2.ny + 1, op1.nz - op2.nz + 1);
145  }
146  else
147  {
148  return DimensionSizes(op1.nx - op2.nx + 1, op1.ny - op2.ny + 1,
149  op1.nz - op2.nz + 1, op1.nt - op2.nt + 1);
150  }
151  };
152 
153 
154  /// Number of elements in the x direction.
155  size_t nx;
156  /// Number of elements in the y direction.
157  size_t ny;
158  /// Number of elements in the z direction.
159  size_t nz;
160  /// Number of time steps (for time series datasets).
161  size_t nt;
162 }; // end of DimensionSizes
163 //----------------------------------------------------------------------------------------------------------------------
164 #endif /* DIMENSION_SIZES_H */
size_t nz
Number of elements in the z direction.
bool operator==(const DimensionSizes &other) const
Operator ==.
constexpr int kDataAlignment
memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
size_t nt
Number of time steps (for time series datasets).
bool operator!=(const DimensionSizes &other) const
Operator !=.
bool is3D() const
Does the object include spatial dimensions only?
Structure with 4D dimension sizes (3 in space and 1 in time).
bool is4D() const
Does the object include spatial and temporal dimensions?
DimensionSizes()
Default constructor.
size_t ny
Number of elements in the y direction.
size_t nElements() const
Get the number of elements, in 3D only spatial domain, in 4D with time.
DimensionSizes(size_t x, size_t y, size_t z, size_t t=0)
Constructor.
size_t nx
Number of elements in the x direction.
friend DimensionSizes operator-(const DimensionSizes &op1, const DimensionSizes &op2)
Operator -.