PeriDyno 1.0.0
Loading...
Searching...
No Matches
Array3D.h
Go to the documentation of this file.
1#pragma once
2#include "Platform.h"
3#include <vector>
4
5namespace dyno {
6 template<typename T, DeviceType deviceType> class Array3D;
7
8 template<typename T>
9 class Array3D<T, DeviceType::CPU>
10 {
11 public:
12 Array3D() {};
13
14 Array3D(uint nx, uint ny, uint nz)
15 {
16 this->resize(nx, ny, nz);
17 };
18
22 ~Array3D() { };
23
24 void resize(uint nx, uint ny, uint nz);
25
26 void reset();
27
28 void clear();
29
30 inline const std::vector<T>* handle() const { return &m_data; }
31 inline std::vector<T>* handle() { return &m_data; }
32
33 inline const T* begin() const { return m_data.data(); }
34
35 inline uint nx() const { return m_nx; }
36 inline uint ny() const { return m_ny; }
37 inline uint nz() const { return m_nz; }
38
39 inline T operator () (const uint i, const uint j, const uint k) const
40 {
41 return m_data[i + j * m_nx + k * m_nxy];
42 }
43
44 inline T& operator () (const uint i, const uint j, const uint k)
45 {
46 return m_data[i + j * m_nx + k * m_nxy];
47 }
48
49 inline size_t index(const uint i, const uint j, const uint k) const
50 {
51 return i + j * m_nx + k * m_nxy;
52 }
53
54 inline T operator [] (const uint id) const
55 {
56 return m_data[id];
57 }
58
59 inline T& operator [] (const uint id)
60 {
61 return m_data[id];
62 }
63
64 inline size_t size() const { return m_data.size(); }
65 inline bool isCPU() const { return true; }
66 inline bool isGPU() const { return false; }
67
68 void assign(const T& val);
69 void assign(uint nx, uint ny, uint nz, const T& val);
70
71#ifndef NO_BACKEND
72 void assign(const Array3D<T, DeviceType::GPU>& src);
73#endif
74
75 void assign(const Array3D<T, DeviceType::CPU>& src);
76
77 private:
78 uint m_nx = 0;
79 uint m_ny = 0;
80 uint m_nz = 0;
81 uint m_nxy = 0;
82 std::vector<T> m_data;
83 };
84
85 template<typename T>
87 {
88 m_data.clear();
89 m_nx = nx; m_ny = ny; m_nz = nz; m_nxy = nx * ny;
90
91 m_data.resize((size_t)nx * ny * nz);
92 }
93
94 template<typename T>
96 {
97 std::fill(m_data.begin(), m_data.end(), 0);
98 }
99
100 template<typename T>
102 {
103 m_nx = 0;
104 m_ny = 0;
105 m_nz = 0;
106 m_data.clear();
107 }
108
109 template<typename T>
110 void Array3D<T, DeviceType::CPU>::assign(uint nx, uint ny, uint nz, const T& val)
111 {
112 if (m_nx != nx || m_ny != ny || m_nz != nz) {
113 this->resize(nx, ny, nz);
114 }
115
116 m_data.assign(m_data.size(), val);
117 }
118
119 template<typename T>
121 {
122 m_data.assign(m_data.size(), val);
123 }
124
125 template<typename T>
127 {
128 if (m_nx != src.size() || m_ny != src.size() || m_nz != src.size()) {
129 this->resize(src.nx(), src.ny(), src.nz());
130 }
131
132 m_data.assign(src.m_data.begin(), src.m_data.end());
133 }
134
135 template<typename T>
137}
138
139#ifdef CUDA_BACKEND
141#endif
142
143#ifdef VK_BACKEND
145#endif
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14
Array3D< T, DeviceType::CPU > CArray3D
Definition Array3D.h:136