kspaceFirstOrder3D-CUDA  1.1
The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 3.4
12  *
13  * @date 09 August 2011, 12:34 (created) \n
14  * 25 July 2016, 09:49 (revised)
15  *
16  * @section License
17  * This file is part of the C++ extension of the k-Wave Toolbox
18  * (http://www.k-wave.org).\n Copyright (C) 2016 Jiri Jaros and Bradley Treeby.
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU Lesser General Public License as published by the Free Software
22  * Foundation, either version 3 of the 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
25  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
26  * General Public License for 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/.
30  */
31 
32 
33 #ifndef DIMENSION_SIZES_H
34 #define DIMENSION_SIZES_H
35 
36 #include <cstdlib>
37 
38 
39 #ifdef __AVX2__
40 /**
41  * @var DATA_ALIGNMENT
42  * @brief memory alignment for AVX2 (32B)
43  */
44 const int DATA_ALIGNMENT = 32;
45 #elif __AVX__
46 /**
47  * @var DATA_ALIGNMENT
48  * @brief memory alignment for AVX(32B)
49  */
50 const int DATA_ALIGNMENT = 32;
51 #else
52 
53 /**
54  * @var DATA_ALIGNMENT
55  * @brief memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
56  */const int DATA_ALIGNMENT = 16;
57 #endif
58 
59 /**
60  * @struct TDimensionSizes
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  TDimensionSizes() : 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  TDimensionSizes(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  * @brief Get element count, in 3D only spatial domain, in 4D with time.
82  * @details Get element count, in 3D only spatial domain, in 4D with time.
83  * @return spatial element count or number of elements over time.
84  */
85  inline size_t GetElementCount() const
86  {
87  return (Is3D()) ? nx * ny * nz : nx * ny * nz * nt;
88  };
89 
90  /// Does the object include spatial dimensions only?
91  inline bool Is3D() const
92  {
93  return (nt == 0);
94  }
95 
96  /// Does the object include spatial and temporal dimensions?
97  inline bool Is4D() const
98  {
99  return (nt > 0);
100  }
101 
102  /**
103  * @brief Operator ==
104  * @param [in] other - The second operand to compare with
105  * @return true if the dimension sizes are equal
106  */
107  inline bool operator==(const TDimensionSizes& other) const
108  {
109  return ((nx == other.nx) && (ny == other.ny) && (nz == other.nz) && (nt == other.nt));
110  }
111 
112  /**
113  * @brief Operator !=
114  * @param [in] other - the second operand to compare with
115  * @return true if !=
116  */
117  inline bool operator!=(const TDimensionSizes& other) const
118  {
119  return ((nx != other.nx) || (ny != other.ny) || (nz != other.nz) || (nt != other.nt));
120  }
121 
122  /**
123  * Operator -
124  * Get the size of the cube defined by two corners
125  * @param [in] op1 - Usually bottom right corner
126  * @param [in] op2 - Usually top left corner
127  * @return the size of the inner cuboid
128  */
129  inline friend TDimensionSizes operator-(const TDimensionSizes& op1,
130  const TDimensionSizes& op2)
131  {
132  // +1 because of planes (10.10.1 - 60.40.1)
133  if (op1.Is3D() && op2.Is3D())
134  {
135  return TDimensionSizes(op1.nx - op2.nx + 1, op1.ny - op2.ny + 1, op1.nz - op2.nz + 1);
136  }
137  else
138  {
139  return TDimensionSizes(op1.nx - op2.nx + 1, op1.ny - op2.ny + 1,
140  op1.nz - op2.nz + 1, op1.nt - op2.nt + 1);
141  }
142  }
143 
144  /// number of elements in the x direction
145  size_t nx;
146  /// number of elements in the y direction
147  size_t ny;
148  /// number of elements in the z direction
149  size_t nz;
150  /// Number of time steps (for time series datasets).
151  size_t nt;
152 }; // end of TDimensionSizes
153 //--------------------------------------------------------------------------------------------------
154 
155 #endif /* #define DIMENSION_SIZES_H */
size_t nx
number of elements in the x direction
bool operator!=(const TDimensionSizes &other) const
Operator !=.
size_t nt
Number of time steps (for time series datasets).
friend TDimensionSizes operator-(const TDimensionSizes &op1, const TDimensionSizes &op2)
TDimensionSizes(size_t x, size_t y, size_t z, size_t t=0)
Constructor.
bool Is4D() const
Does the object include spatial and temporal dimensions?
size_t GetElementCount() const
Get element count, in 3D only spatial domain, in 4D with time.
size_t ny
number of elements in the y direction
bool operator==(const TDimensionSizes &other) const
Operator ==.
TDimensionSizes()
Default constructor.
const int DATA_ALIGNMENT
memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
size_t nz
number of elements in the z direction
Structure with 4D dimension sizes (3 in space and 1 in time).
bool Is3D() const
Does the object include spatial dimensions only?