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