22namespace fs = std::filesystem;
38 const std::string& schemeName)
40 std::cout <<
"\n=== Running " << schemeName <<
" Solver ===\n";
47 fs::path outDir = fs::path(
"results") / schemeName;
48 if (!fs::exists(outDir))
50 fs::create_directories(outDir);
55 auto onDump = [&](
double t,
const Grid& g,
const std::vector<double>& T)
57 std::ostringstream name;
59 name <<
"profile_t_" << std::fixed << std::setprecision(2) << t <<
"h.csv";
61 fs::path fullPath = outDir / name.str();
67 std::cout <<
"Results saved to " << outDir <<
"\n";
85 std::cout <<
"=== 1D Heat Equation Solver ===\n";
103 "Enter Δx [cm] (suggested 0.05): ",
104 [](
double v) {
return v > 0.0 && v <= 1.0; },
105 "Δx must be positive and <= 1.0 cm.");
116 std::cout <<
"Grid created ✅ Nx = " << g.
Nx <<
", dx = " << g.
dx <<
" cm\n";
121 std::cout <<
"\nSelect numerical method:\n";
122 std::cout <<
"1. DuFort-Frankel\n";
123 std::cout <<
"2. Richardson\n";
124 std::cout <<
"3. Laasonen (Simple Implicit)\n";
125 std::cout <<
"4. Crank-Nicolson\n";
126 std::cout <<
"5. Run All (Batch + Analytical)\n";
127 std::cout <<
"6. Laasonen Stability Study (dt = 0.01, 0.025, 0.05, 0.1)\n";
131 "Enter choice (1-6): ",
132 [](
double v) {
return v >= 1.0 && v <= 6.0; },
133 "Please enter a number between 1 and 6."));
140 if (choice == 1 || choice == 5)
146 if (choice == 2 || choice == 5)
152 if (choice == 3 || choice == 5)
158 if (choice == 4 || choice == 5)
166 std::cout <<
"\n=== Computing Analytical Solution ===\n";
167 std::string outDir =
"results/Analytical";
168 fs::create_directories(outDir);
178 std::ostringstream name;
179 name << outDir <<
"/profile_t_" << std::fixed << std::setprecision(2) << t
184 for (
int i = 0; i <= steps; ++i)
193 std::ostringstream name;
194 name << outDir <<
"/profile_t_" << std::fixed << std::setprecision(2) << t
198 std::cout <<
"Results saved to " << outDir <<
"\n";
204 std::cout <<
"\n=== Running Laasonen Stability Study ===\n";
205 std::vector<double> dts = {0.01, 0.025, 0.05, 0.1};
207 for (
double dt : dts)
213 std::ostringstream name;
214 name <<
"Laasonen_dt_" << std::fixed << std::setprecision(3) << dt;
222 std::cout <<
"\nAll requested simulations completed successfully ✅\n";
225 catch (
const std::exception& e)
227 std::cerr <<
"Fatal error: " << e.what() <<
"\n";
static std::vector< double > get_profile(double t, const std::vector< double > &x_grid, const PhysParams &phys)
Generate a full temperature profile for a set of grid points.
void run(const std::function< void(double, const Grid &, const std::vector< double > &)> &onDump)
Run the simulation from t=0 to t=tEnd.
bool validate_grid(const Grid &g, double tol=1e-12)
Validate grid consistency (assertions in Debug mode).
void save_profile_csv(const std::string &path, const std::vector< double > &x, const std::vector< double > &T)
Save a temperature profile (x, T) to a CSV file.
void run_simulation(const PhysParams &phys, const NumParams &num, SchemeKind scheme, const std::string &schemeName)
Run a single simulation with the specified scheme.
int main()
Main entry point for the 1D Heat Equation Solver.
SchemeKind
Enumeration of the numerical schemes available in the solver.
@ Laasonen
Simple Implicit (forward time, central space).
@ DuFortFrankel
Modified Richardson (explicit, stable).
@ CrankNicolson
Trapezoidal Implicit (second order accuracy).
@ Richardson
Central time, central space (explicit, unstable).
High-level solver orchestrating BCs and time integration.
Uniform 1D grid on x ∈ [0, L], including both boundary nodes.
std::size_t Nx
Number of nodes (including boundaries).
double dx
Spatial step [cm].
std::vector< double > x
Node coordinates [cm].
Numerical parameters controlling the discretization and output.
double dx
Spatial step [cm].
double outEvery
Output interval [h].
double tEnd
Final time [h].
Physical parameters of the wall heat conduction problem.
double Tin
Initial temperature [°C].
double D_cm2h
Thermal diffusivity [cm^2/h].
double L_cm
Wall thickness [cm].
double Tsur
Surface (Dirichlet) temperature [°C].
Basic physical and numerical parameter types for the 1D heat problem.