Gradient Augmented Levelset Implementation in CPU & GPU
array.cc (Latest change: Author:Lakshman A <acrlakshman@yahoo.co.in>, 2019-07-21 09:01:14 -0500, [commit: c84eabc])
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 #include "gals/utilities/array.h"
33 
34 #include "gals/utilities/mat3.h"
35 #include "gals/utilities/vec_n.h"
36 
37 template <typename T_GRID, typename T_ARRAY>
39  : m_grid(grid),
40  m_nx(grid.numCells()[0]),
41  m_ny(grid.numCells()[1]),
42  m_nz(grid.numCells()[2]),
43  m_pad(grid.getPadding())
44 {
45  m_data.resize(m_grid.size());
46 
47  for (int i = 0; i < m_data.size(); ++i) {
48  m_data[i] = T_ARRAY();
49  }
50 }
51 
52 template <typename T_GRID, typename T_ARRAY>
54 {
55  m_data.clear();
56  m_data.shrink_to_fit();
57 }
58 
59 template <typename T_GRID, typename T_ARRAY>
60 const std::size_t GALS::CPU::Array<T_GRID, T_ARRAY>::size() const
61 {
62  return m_data.size();
63 }
64 
65 template <typename T_GRID, typename T_ARRAY>
67 {
68  return m_grid;
69 }
70 
71 template <typename T_GRID, typename T_ARRAY>
73 {
74  return Vec3<int>(m_nx, m_ny, m_nz);
75 }
76 
77 template <typename T_GRID, typename T_ARRAY>
78 const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator[](const std::size_t idx) const
79 {
80  return m_data[idx];
81 }
82 
83 template <typename T_GRID, typename T_ARRAY>
84 T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator[](const std::size_t idx)
85 {
86  return m_data[idx];
87 }
88 
89 template <typename T_GRID, typename T_ARRAY>
90 const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const int i, const int j, const int k) const
91 {
92  const std::size_t idx = m_grid.index(i, j, k);
93  return m_data[idx];
94 }
95 
96 template <typename T_GRID, typename T_ARRAY>
97 T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const int i, const int j, const int k)
98 {
99  const std::size_t idx = m_grid.index(i, j, k);
100  return m_data[idx];
101 }
102 
103 template <typename T_GRID, typename T_ARRAY>
104 const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const Vec3<int> node_id) const
105 {
106  return m_data[m_grid.index(node_id)];
107 }
108 
109 template <typename T_GRID, typename T_ARRAY>
111 {
112  return m_data[m_grid.index(node_id)];
113 }
114 
115 template <typename T_GRID, typename T_ARRAY>
117 {
118  m_data = array.data();
119 }
120 
121 template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, double>;
122 template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, double>;
123 template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, double>;
125 template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Vec3<double>>;
126 template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Vec3<double>>;
130 template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::VecN<double, 2>>;
131 template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::VecN<double, 2>>;
134 template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Mat3<double>>;
135 template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Mat3<double>>;
const std::size_t size() const
Definition: array.cc:60
const Vec3< int > numCells() const
Definition: array.cc:72
Array(const Grid< typename T_GRID::value_type, T_GRID::dim > &grid)
Definition: array.cc:38
const T_ARRAY & operator()(const int i, const int j, const int k) const
Definition: array.cc:90
void operator=(const Array< T_GRID, T_ARRAY > &array)
Definition: array.cc:116
const T_GRID & grid() const
Definition: array.cc:66
const std::vector< T_ARRAY > & data() const
Definition: array.h:88
const T_ARRAY & operator[](const std::size_t idx) const
Definition: array.cc:78