40 template <
typename T,
int DIM>
42 : m_dimension(DIM), m_nx(nx), m_ny(ny), m_nz(nz), m_pad(1), m_total_cells(nx * ny * nz)
44 m_mask[0] = 1, m_mask[1] = 0, m_mask[2] = 0;
49 m_mask[1] = 1, m_mask[2] = 1;
51 m_box_min =
Vec3<T>(INT_MIN, INT_MIN, INT_MIN);
52 m_box_max =
Vec3<T>(INT_MAX, INT_MAX, INT_MAX);
57 template <
typename T,
int DIM>
62 template <
typename T,
int DIM>
67 template <
typename T,
int DIM>
71 m_grid.shrink_to_fit();
74 template <
typename T,
int DIM>
77 return m_grid[this->
index(i, j, k)];
80 template <
typename T,
int DIM>
86 template <
typename T,
int DIM>
92 template <
typename T,
int DIM>
98 template <
typename T,
int DIM>
104 template <
typename T,
int DIM>
107 return m_total_cells;
110 template <
typename T,
int DIM>
116 template <
typename T,
int DIM>
119 const std::size_t idx = ((k + m_pad) * (m_nx + 2 * m_pad) * (m_ny + 2 * m_pad) * m_mask[2]) +
120 ((j + m_pad) * (m_nx + 2 * m_pad) * m_mask[1]) + ((i + m_pad) * m_mask[0]);
125 template <
typename T,
int DIM>
128 return this->
index(node_id[0], node_id[1], node_id[2]);
131 template <
typename T,
int DIM>
134 Vec3<int> base_node_id(INT_MAX, INT_MAX, INT_MAX);
136 for (
int axis = 0; axis < DIM; ++axis) {
137 base_node_id[axis] = floor(((x[axis] - m_box_min[axis]) * m_one_over_dx[axis]) - 0.5);
143 template <
typename T,
int DIM>
149 template <
typename T,
int DIM>
152 return m_one_over_dx;
155 template <
typename T,
int DIM>
158 return m_grid[this->
index(i, j, k)];
161 template <
typename T,
int DIM>
164 return m_grid[this->
index(node_id)];
167 template <
typename T,
int DIM>
173 template <
typename T,
int DIM>
176 if (m_grid.size()) m_grid.clear(), m_grid.shrink_to_fit();
178 m_box_min[0] = x_min, m_box_min[1] = y_min, m_box_min[2] = z_min;
179 m_box_max[0] = x_max, m_box_max[1] = y_max, m_box_max[2] = z_max;
181 m_grid.resize((m_nz + 2 * m_pad * m_mask[2]) * (m_ny + 2 * m_pad * m_mask[1]) * (m_nx + 2 * m_pad * m_mask[0]));
183 std::vector<T> domain_min({x_min, y_min, z_min}), domain_min_new(3);
185 m_dx[0] = (x_max - x_min) / m_nx;
186 m_dx[1] = (y_max - y_min) / m_ny;
187 m_dx[2] = (z_max - z_min) / m_nz;
189 for (
int i = 0; i < DIM; ++i) m_one_over_dx[i] = static_cast<T>(1.) / m_dx[i];
191 for (
int i = 0; i < DIM; ++i) domain_min_new[i] = domain_min[i] + (m_dx[i] * 0.5) - (m_dx[i] * m_mask[i]);
195 int i_min = -m_pad * m_mask[0], j_min = -m_pad * m_mask[1], k_min = -m_pad * m_mask[2];
199 for (
int i = i_min; i < m_nx + m_pad * m_mask[0]; ++i) {
200 for (
int j = j_min; j < m_ny + m_pad * m_mask[1]; ++j) {
201 for (
int k = k_min; k < m_nz + m_pad * m_mask[2]; ++k) {
206 for (
int axis = 0; axis < DIM; ++axis) elem[axis] = domain_min_new[axis] + vec[axis] * m_dx[axis];
208 this->
x(i, j, k) = elem;
215 for (
int d = 0; d < DIM; ++d) m_total_cells *= this->
numCells()[d];
const int dimension() const
void setPadding(const int pad)
const int getPadding() const
void generate(T x_min, T x_max, T y_min, T y_max, T z_min, T z_max)
const Vec3< T > & operator()(const int i, const int j, const int k) const
static constexpr int dim
Dimension.
const Vec3< int > baseNodeId(const Vec3< T > &x) const
Grid(int nx, int ny, int nz)
const Vec3< int > numCells() const
const Vec3< T > & oneOverDX() const
const Vec3< T > & dX() const
const int * getMask() const
const std::size_t index(const int i, const int j, const int k) const
const size_t totalCells() const
Vec3< T > & x(const int i, const int j=0, const int k=0)