numerics 0.1.0
Loading...
Searching...
No Matches
grid3d.hpp
Go to the documentation of this file.
1/// @file fields/grid3d.hpp
2/// @brief 3D uniform Cartesian grid: geometry only, no field data.
3///
4/// Grid3D describes an nx*ny*nz lattice with uniform spacing dx and origin
5/// (ox,oy,oz). It carries no field values -- those live in a ScalarField3D --
6/// mirroring the geometry/data split of Grid2D and ScalarField2D.
7/// Flat layout: idx = k*ny*nx + j*nx + i (x is fastest, z is slowest).
8#pragma once
9
10#include "core/types.hpp"
11
12namespace num {
13
14struct Grid3D {
15 int nx, ny, nz; ///< nodes per axis
16 double dx = 1.0; ///< uniform cell size
17 double ox = 0.0, oy = 0.0, oz = 0.0; ///< origin (physical coordinate of node 0)
18
19 int size() const { return nx * ny * nz; }
20
21 idx flat(int i, int j, int k) const {
22 return static_cast<idx>((k * ny * nx) + (j * nx) + i);
23 }
24
25 double x(int i) const { return ox + (i * dx); }
26 double y(int j) const { return oy + (j * dx); }
27 double z(int k) const { return oz + (k * dx); }
28};
29
30} // namespace num
Core type definitions.
std::size_t idx
Definition types.hpp:11
int size() const
Definition grid3d.hpp:19
double y(int j) const
Definition grid3d.hpp:26
idx flat(int i, int j, int k) const
Definition grid3d.hpp:21
double x(int i) const
Definition grid3d.hpp:25
double dx
uniform cell size
Definition grid3d.hpp:16
double ox
Definition grid3d.hpp:17
double z(int k) const
Definition grid3d.hpp:27
double oy
Definition grid3d.hpp:17
double oz
origin (physical coordinate of node 0)
Definition grid3d.hpp:17
int nz
nodes per axis
Definition grid3d.hpp:15