Gradient Augmented Levelset Implementation in CPU & GPU
grid.h (Latest change: Author:Lakshman Anumolu <acrlakshman@yahoo.co.in>, 2019-07-26 23:58:51 -0500, [commit: 5e5cd8b])
Go to the documentation of this file.
1 // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 #pragma once
33 
34 #include <string>
35 #include <vector>
36 
37 #include "gals/input-fields/grid.h"
39 #include "mat3.h"
40 #include "vec3.h"
41 
42 namespace GALS
43 {
44 namespace CPU
45 {
46 constexpr int num_mixed_derivatives(const int dim)
47 {
48  switch (dim) {
49  case 1:
50  return 0;
51  break;
52  case 2:
53  return 1;
54  break;
55  case 3:
56  return 4;
57  break;
58  default:
59  return -1;
60  }
61 }
62 
67 template <typename T, int DIM = 3>
68 class Grid
69 {
70  public:
71  using value_type = T;
73 
75  static constexpr int dim = DIM;
76 
78  static const Mat3<int> axis_vectors;
79  static const Mat3<T> identity_mat;
80 
83 
90  Grid(int nx, int ny, int nz);
91 
99  Grid(int nx, int ny);
100 
107  Grid(int nx);
108 
111  ~Grid();
112 
121  Vec3<T>& x(const int i, const int j = 0, const int k = 0);
122 
127  const int dimension() const;
128 
135  const int size() const;
136 
146  const int* getMask() const;
147 
154  const Vec3<int> numCells() const;
155 
160  const size_t totalCells() const;
161 
166  const int getPadding() const;
167 
178  const std::size_t index(const int i, const int j, const int k) const;
179 
186  const std::size_t index(const Vec3<int> node_id) const;
187 
194  const Vec3<int> baseNodeId(const Vec3<T>& x) const;
195 
200  const Vec3<T>& dX() const;
201 
206  const Vec3<T>& oneOverDX() const;
207 
212  const Vec3<T>& operator()(const int i, const int j, const int k) const;
213 
220  const Vec3<T>& operator()(const Vec3<int> node_id) const;
221 
228  void setPadding(const int pad);
229 
239  void generate(T x_min, T x_max, T y_min, T y_max, T z_min, T z_max);
240 
241  private:
242  int m_dimension, m_nx, m_ny, m_nz, m_pad;
243  size_t m_total_cells;
244  int m_mask[3];
245  Vec3<T> m_box_min, m_box_max;
246  Vec3<T> m_dx, m_one_over_dx;
247  std::vector<Vec3<T>> m_grid;
248 };
249 
250 template <typename T, int DIM>
251 const Mat3<int> Grid<T, DIM>::axis_vectors = Mat3<int>(1, 0, 0, 0, 1, 0, 0, 0, 1);
252 
253 template <typename T, int DIM>
254 const Mat3<T> Grid<T, DIM>::identity_mat = Mat3<T>(1, 0, 0, 0, 1, 0, 0, 0, 1);
255 
256 } // namespace CPU
257 } // namespace GALS
constexpr int num_mixed_derivatives(const int dim)
Definition: grid.h:46
const int size() const
Definition: grid.cc:87
const int dimension() const
Definition: grid.cc:81
void setPadding(const int pad)
Definition: grid.cc:168
const int getPadding() const
Definition: grid.cc:111
void generate(T x_min, T x_max, T y_min, T y_max, T z_min, T z_max)
Definition: grid.cc:174
const Vec3< T > & operator()(const int i, const int j, const int k) const
Definition: grid.cc:156
static constexpr int dim
Dimension.
Definition: grid.h:75
static const Mat3< int > axis_vectors
vector along x: {1, 0, 0}; y: {0, 1, 0}; z: {0, 0, 1}.
Definition: grid.h:78
const Vec3< int > baseNodeId(const Vec3< T > &x) const
Definition: grid.cc:132
Grid(int nx, int ny, int nz)
Definition: grid.cc:41
const Vec3< int > numCells() const
Definition: grid.cc:99
const Vec3< T > & oneOverDX() const
Definition: grid.cc:150
const Vec3< T > & dX() const
Definition: grid.cc:144
const int * getMask() const
Definition: grid.cc:93
T value_type
Definition: grid.h:71
const std::size_t index(const int i, const int j, const int k) const
Definition: grid.cc:117
const size_t totalCells() const
Definition: grid.cc:105
static const Mat3< T > identity_mat
Definition: grid.h:79
static constexpr int num_mixed_derivatives
Number of mixed derivatives.
Definition: grid.h:82
Vec3< T > & x(const int i, const int j=0, const int k=0)
Definition: grid.cc:75