1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
grid.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file grid.hpp
4 * @brief Uniform 1D spatial grid.
5 */
6
7#include <vector>
8#include <cstddef>
9
10/**
11 * @brief Uniform 1D grid on x ∈ [0, L], including both boundary nodes.
12 *
13 * Builds Nx = round(L/dx) + 1 nodes with coordinates x[i] = i * dx.
14 */
15struct Grid {
16 double L; ///< Domain length [cm]
17 double dx; ///< Spatial step [cm]
18 std::size_t Nx; ///< Number of nodes (including boundaries)
19 std::vector<double> x; ///< Node coordinates [cm]
20
21 /**
22 * @brief Construct a grid with given length and spacing.
23 * @param L_cm Domain length [cm]
24 * @param dx_cm Spatial step [cm]
25 */
26 Grid(double L_cm, double dx_cm);
27};
28
29/**
30 * @brief Validate grid consistency (assertions in Debug mode).
31 *
32 * Checks endpoints, monotonicity, uniform spacing and Nx consistency.
33 * @param g Grid to validate
34 * @param tol Tolerance for floating-point comparisons (default 1e-12)
35 * @return true if all assertions pass
36 */
37bool validate_grid(const Grid& g, double tol = 1e-12);
bool validate_grid(const Grid &g, double tol=1e-12)
Validate grid consistency (assertions in Debug mode).
Definition grid.cpp:26
Uniform 1D grid on x ∈ [0, L], including both boundary nodes.
Definition grid.hpp:15
std::size_t Nx
Number of nodes (including boundaries).
Definition grid.hpp:18
double dx
Spatial step [cm].
Definition grid.hpp:17
std::vector< double > x
Node coordinates [cm].
Definition grid.hpp:19
double L
Domain length [cm].
Definition grid.hpp:16
Grid(double L_cm, double dx_cm)
Construct a grid with given length and spacing.
Definition grid.cpp:11