Skip to content

About

C++ coursework: 2D heat diffusion on a grid, initialized boundaries, and bitmap output.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Thermal distribution simulation

A C++ coursework program for exploring a discrete two-dimensional steady-state temperature field. It relaxes a grid with fixed boundary temperatures using Jacobi iteration and exports a color heatmap to thermal_distribution.bmp.

Build and run

Requires a C++17 compiler and Make; Python 3 is needed for the checks. No external libraries are required.

make
./thermal_sim

Alternatively: c++ -std=c++17 main.cpp -o thermal_sim.

The menu creates a grid, sets four boundary temperatures, applies an initial interior temperature, runs the solver, prints the grid, or exits. Coordinates are zero-based row and column indices. The stimulus must lie strictly inside the boundary.

A complete small example:

1
3
3
2
10
20
30
40
3
100
1 1
4
0.001
5
6

The sole interior cell reaches 25, the average of its four neighbors. Top/bottom boundaries take precedence at the corners. Any consistent temperature unit can be used; values must be finite, including negative values if that unit permits them.

Model and numerical behavior

Every new grid starts at zero. Boundary values remain fixed while interior cells update to the average of their four neighbors. A separate next-grid buffer makes each sweep a Jacobi step. The stimulus is an initial condition, not a continuously heated cell: it also relaxes after simulation begins. At equilibrium, the fixed boundaries determine the field.

The solver stops when the largest absolute change in a complete sweep is below the requested positive threshold. It prints the iteration count and final maximum change. This is an iteration-change criterion, not a proof of a specified error against the exact solution. There is a 100,000-iteration limit; reaching it reports an approximation and does not save a new image. Dimensions are limited to 3–1000 in each direction to bound memory use. Recreating a grid frees the old state and resets setup requirements; rejected dimensions preserve the current grid.

The BMP uses an 8-bit palette index with a blue-to-red color palette. Values are normalized to the current grid's minimum/maximum; a uniform field maps to a single color without division by zero. The image contains no absolute temperature legend, so compare numerical grids when comparing separate runs.

This is a discrete steady-state teaching model. It does not model physical elapsed time, conductivity, material parameters, or validated engineering heat transfer.

Checks

make test
make clean
make CXXFLAGS="-std=c++17 -O1 -g -Wall -Wextra -Wpedantic -fsanitize=address,undefined -fno-omit-frame-pointer" test

Checks cover initialized interiors, immediate exit, an analytic 3×3 solution, bitmap structure and uniform normalization, invalid coordinates, recreation, failed dimensions, and EOF. GitHub Actions runs them with sanitizers on Ubuntu.

Provenance and license

Original coursework by Ashmit Shankar Mukherjee, dated November 19, 2023: Assignment 2, Computer Programming for Engineers, NYU Abu Dhabi. Later maintenance corrects initialization, ownership, Jacobi buffering, input handling, and image normalization.

Bitmap_Helper.h was identified in the repository as instructor-provided. Its original author's name and redistribution permission have not been established from the available files. That attribution is retained; its output-error handling was adjusted during maintenance. The repository's MIT License applies to the repository owner's contributions and does not establish a license for that third-party helper. Verify the helper's permission before redistributing it as part of another project.

About

C++ coursework: 2D heat diffusion on a grid, initialized boundaries, and bitmap output.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages