1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
dufort_frankel.cpp
Go to the documentation of this file.
2
3#include <algorithm> // std::copy
4#include <cstddef> // std::size_t
5
7 double D,
8 double dt,
9 const std::vector<double>& Tprev,
10 const std::vector<double>& Tcurr,
11 std::vector<double>& Tnext) const
12{
13 const double r = D * dt / (g.dx * g.dx);
14 const std::size_t N = g.Nx;
15
16 // Ensure the output vector is of the correct size
17 if (Tnext.size() != N)
18 {
19 Tnext.resize(N);
20 }
21
22 // Start from the current state: this preserves the boundaries
23 std::copy(Tcurr.begin(), Tcurr.end(), Tnext.begin());
24
25 // Internal nodes
26 for (std::size_t i = 1; i + 1 < N; ++i)
27 {
28 Tnext[i] = ((1.0 - 2.0 * r) * Tprev[i] + 2.0 * r * (Tcurr[i + 1] + Tcurr[i - 1])) /
29 (1.0 + 2.0 * r);
30 }
31}
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
Computes the temperature field at the next time step (T^{n+1}).
DuFort–Frankel explicit method (3-level scheme).
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