1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
method.hpp
Go to the documentation of this file.
1#ifndef METHOD_HPP
2#define METHOD_HPP
3
4#include "grid.hpp"
5#include <memory>
6#include <string>
7#include <vector>
8
9/**
10 * @brief Enumeration of the numerical schemes available in the solver.
11 */
12enum class SchemeKind
13{
14 Richardson, ///< Central time, central space (explicit, unstable).
15 DuFortFrankel, ///< Modified Richardson (explicit, stable).
16 Laasonen, ///< Simple Implicit (forward time, central space).
17 CrankNicolson ///< Trapezoidal Implicit (second order accuracy).
18};
19
20/**
21 * @class Method
22 * @brief Abstract interface for time-integration schemes solving the 1D heat equation.
23 *
24 * This interface abstracts away the difference between explicit/implicit schemes
25 * and 2-level/3-level time stepping schemes.
26 */
27class Method
28{
29 public:
30 virtual ~Method() = default;
31
32 /**
33 * @brief Get human-readable name of the scheme.
34 */
35 virtual std::string name() const = 0;
36
37 /**
38 * @brief Computes the temperature field at the next time step (T^{n+1}).
39 *
40 * @param g Grid metadata (spacing dx and node count Nx).
41 * @param D Thermal diffusivity [cm^2/h].
42 * @param dt Time step size [h].
43 * @param Tprev Temperature at time step n-1 (Read-only).
44 * Required only for 3-level schemes (Richardson, DuFort-Frankel).
45 * For 2-level schemes, this vector may be ignored.
46 * @param Tcurr Temperature at time step n (Read-only).
47 * @param Tnext Output vector to be filled with temperature at time step n+1.
48 */
49 virtual void step(const Grid& g,
50 double D,
51 double dt,
52 const std::vector<double>& Tprev,
53 const std::vector<double>& Tcurr,
54 std::vector<double>& Tnext) const = 0;
55
56 /**
57 * @brief Indicates if the scheme requires data from time step n-1.
58 *
59 * @return true For 3-level schemes (e.g., Richardson, DuFort-Frankel).
60 * @return false For 2-level schemes (e.g., Laasonen, Crank-Nicolson).
61 */
62 virtual bool uses_previous_step() const = 0;
63};
64
65/**
66 * @brief Factory function to create a concrete method instance.
67 *
68 * @param scheme The type of numerical scheme requested.
69 * @return std::unique_ptr<Method> Pointer to the created solver method.
70 */
71std::unique_ptr<Method> make_method(SchemeKind scheme);
72
73#endif // METHOD_HPP
Crank-Nicolson scheme implementation.
Laasonen implicit method (Backward Euler in time + Central in space). Unconditionally stable for the ...
Definition laasonen.hpp:12
Abstract interface for time-integration schemes solving the 1D heat equation.
Definition method.hpp:28
virtual std::string name() const =0
Get human-readable name of the scheme.
virtual ~Method()=default
virtual bool uses_previous_step() const =0
Indicates if the scheme requires data from time step n-1.
virtual void step(const Grid &g, double D, double dt, const std::vector< double > &Tprev, const std::vector< double > &Tcurr, std::vector< double > &Tnext) const =0
Computes the temperature field at the next time step (T^{n+1}).
Implementation of the explicit Richardson scheme (CTCS).
Uniform 1D spatial grid.
SchemeKind
Enumeration of the numerical schemes available in the solver.
Definition method.hpp:13
std::unique_ptr< Method > make_method(SchemeKind scheme)
Factory function to create a concrete method instance.
Definition method.cpp:27
Uniform 1D grid on x ∈ [0, L], including both boundary nodes.
Definition grid.hpp:15