12 if (
L <= 0.0 ||
dx <= 0.0) {
13 throw std::invalid_argument(
"Grid: L and dx must be positive.");
16 Nx =
static_cast<std::size_t
>(std::llround(
L /
dx)) + 1;
18 throw std::invalid_argument(
"Grid: Nx < 2 (check L and dx).");
21 for (std::size_t i = 0; i <
Nx; ++i) {
22 x[i] =
static_cast<double>(i) *
dx;
30 assert(std::fabs(g.
x.front() - 0.0) <= tol);
31 assert(std::fabs(g.
x.back() - g.
L) <= tol);
34 for (std::size_t i = 1; i < g.
Nx; ++i) {
35 assert(g.
x[i] >= g.
x[i-1]);
39 for (std::size_t i = 1; i < g.
Nx; ++i) {
40 const double step = g.
x[i] - g.
x[i-1];
41 assert(std::fabs(step - g.
dx) <= tol);
45 const std::size_t idxL =
static_cast<std::size_t
>(std::llround(g.
L / g.
dx));
46 assert(idxL + 1 == g.
Nx);
bool validate_grid(const Grid &g, double tol)
Validate grid consistency (assertions in Debug mode).
Uniform 1D grid on x ∈ [0, L], including both boundary nodes.
std::size_t Nx
Number of nodes (including boundaries).
double dx
Spatial step [cm].
std::vector< double > x
Node coordinates [cm].
double L
Domain length [cm].
Grid(double L_cm, double dx_cm)
Construct a grid with given length and spacing.