1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
richardson.cpp
Go to the documentation of this file.
1/**
2 * @file richardson.cpp
3 * @brief Richardson explicit scheme implementation.
4 */
5
7
8#include <cstddef> // for std::size_t
9
10void Richardson::step(const Grid& g,
11 double D,
12 double dt,
13 const std::vector<double>& Tprev,
14 const std::vector<double>& Tcurr,
15 std::vector<double>& Tnext) const
16{
17 const double r = D * dt / (g.dx * g.dx);
18 const std::size_t N = g.Nx;
19
20 // Update interior nodes only; boundaries are imposed by the solver.
21 for (std::size_t i = 1; i + 1 < N; ++i)
22 {
23 Tnext[i] = Tprev[i] + 2.0 * r * (Tcurr[i + 1] - 2.0 * Tcurr[i] + Tcurr[i - 1]);
24 }
25 // Tnext[0] and Tnext[N-1] left as-is
26}
void step(const Grid &g, double D, double dt, const std::vector< double > &Tprev, const std::vector< double > &Tcurr, std::vector< double > &Tnext) const override
Advance one time step using the Richardson explicit scheme.
Richardson explicit (central time - central space) scheme for the 1D heat equation.
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