1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
HeatSolver Class Reference

#include <solver.hpp>

Collaboration diagram for HeatSolver:
Collaboration graph

Public Member Functions

 HeatSolver (const PhysParams &phys, const NumParams &num, SchemeKind scheme)
 Construct the solver with physical and numerical parameters and a scheme kind.
void run (const std::function< void(double, const Grid &, const std::vector< double > &)> &onDump)
 Run the simulation from t=0 to t=tEnd.

Private Member Functions

void apply_dirichlet (std::vector< double > &T) const
 Apply Dirichlet boundary conditions (Tsur) at both ends of the vector.
void init_field ()
 Initialize the temperature field with Tin and enforce boundary conditions.
void bootstrap_if_needed ()
 Perform a warm-up step when the method needs two previous time levels.

Private Attributes

PhysParams phys_
 Physical parameters (copied for convenience).
NumParams num_
 Numerical parameters (copied for convenience).
Grid grid_
 Spatial grid built from phys/num input.
std::unique_ptr< Methodmethod_
 Selected time integration method.
bool uses_prev_step_ = false
 True when the method requires T^{n-1}.
std::vector< double > T_
 Current solution (typically holds T^n).
std::vector< double > Tprev_
 Previous solution (stores T^{n-1} when required).
std::vector< double > next_
 Buffer used to store the next time layer T^{n+1}.

Detailed Description

Definition at line 14 of file solver.hpp.

Constructor & Destructor Documentation

◆ HeatSolver()

HeatSolver::HeatSolver ( const PhysParams & phys,
const NumParams & num,
SchemeKind scheme )

Construct the solver with physical and numerical parameters and a scheme kind.

Parameters
physPhysical parameters (D [cm^2/h], L [cm], Tin, Tsur).
numNumerical parameters (dx [cm], dt [h], tEnd [h], outEvery [h]).
schemeSelected time-stepping scheme (e.g. DuFort-Frankel).

Definition at line 10 of file solver.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ apply_dirichlet()

void HeatSolver::apply_dirichlet ( std::vector< double > & T) const
private

Apply Dirichlet boundary conditions (Tsur) at both ends of the vector.

Parameters
TTemperature field updated in-place

Definition at line 34 of file solver.cpp.

Here is the caller graph for this function:

◆ bootstrap_if_needed()

void HeatSolver::bootstrap_if_needed ( )
private

Perform a warm-up step when the method needs two previous time levels.

We call the scheme once with T^{n-1} = T^{n} = T^0 so that T_ holds T^1 while Tprev_ keeps a copy of T^0 (needed by three-level methods).

Definition at line 47 of file solver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_field()

void HeatSolver::init_field ( )
private

Initialize the temperature field with Tin and enforce boundary conditions.

Definition at line 41 of file solver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

void HeatSolver::run ( const std::function< void(double, const Grid &, const std::vector< double > &)> & onDump)

Run the simulation from t=0 to t=tEnd.

Parameters
onDumpCallback executed at t=0 and then every outEvery hours: onDump(time, grid, T). Use it to write CSV, compute errors, etc.

Definition at line 83 of file solver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ grid_

Grid HeatSolver::grid_
private

Spatial grid built from phys/num input.

Definition at line 35 of file solver.hpp.

◆ method_

std::unique_ptr<Method> HeatSolver::method_
private

Selected time integration method.

Definition at line 36 of file solver.hpp.

◆ next_

std::vector<double> HeatSolver::next_
private

Buffer used to store the next time layer T^{n+1}.

Definition at line 41 of file solver.hpp.

◆ num_

NumParams HeatSolver::num_
private

Numerical parameters (copied for convenience).

Definition at line 34 of file solver.hpp.

◆ phys_

PhysParams HeatSolver::phys_
private

Physical parameters (copied for convenience).

Definition at line 33 of file solver.hpp.

◆ T_

std::vector<double> HeatSolver::T_
private

Current solution (typically holds T^n).

Definition at line 39 of file solver.hpp.

◆ Tprev_

std::vector<double> HeatSolver::Tprev_
private

Previous solution (stores T^{n-1} when required).

Definition at line 40 of file solver.hpp.

◆ uses_prev_step_

bool HeatSolver::uses_prev_step_ = false
private

True when the method requires T^{n-1}.

Definition at line 37 of file solver.hpp.


The documentation for this class was generated from the following files: