We all have an intuitive understanding of heat - when heat is added to something, it gets hotter. Hot things will radiate their heat into their cooler surroundings. But how do we quantify and model this phenomenon?
Let's start by defining our terms clearly.
Heat (Q) is a measure of energy, and so often is expressed in units of joules.
This energy is "attached" to the mass (m) of an object, measured in kilograms.
The more heat an object has the higher it's temperature (T) will get, often measured in °C.
Different types of materials can store more energy per unit before increasing their temperaure,
and the measure of how many joules of heat are required to raise one kilogram of material by one °C is called its Specific Heat Capacity (c).
All of these quantities are related by the Specific Heat Equation:
$$\Large Q = m c T$$
For the purpose of our simulation, we will assume that all heat is only transferred by direct contact, a process known as Conduction.
Heat flow doesn't actually strictly flow from areas of higher heat-density to lower heat-density, but rather from areas of hotter temperature to areas of lower temperature.
Certain materials allow the flow of heat through themselves more easily than others, and a measure of this is the material's Thermal Conductivity (k), often measured in units of joules / (seconds * kilograms * °C).
The amount of heat transferred between two points (let's call them p1 and p2) with different temperatures can be approximated by the discrete version of Fourier's Law:
$$\Large \frac{Q}{\Delta t} = -kA \frac{\Delta T}{\Delta x}$$
Where
Q is the total amount of Heat which has been transferred from p1 to p2, Δt is the total Time which has elapsed, k is the Thermal Conductivity of the material between the two points, A is the cross-sectional contact area of the material between the two points, ΔT is the difference in temperature between the two points (specicially, T2 - T1), and Δx is the direct distance between p1 and p2.
Let's imagine two adjacent cubes with edge lengths measuring 1 cm.
Both cubes are made out of stainless steel, which has a Specific Heat Capacity of 475 joules / (kilograms * °C), Thermal Conductivity of 20 joules / (seconds * kilograms * °C), and Density of 7850 kilograms / meters^3.
Initially the first cube is at 20 °C, and the second is at 200°C.
The equation assumes that all heat moves uniformly between cubes, and so Δx = 1 cm.
By using an elapsed time of Δt = 1 second, we can calculate that Q = 36 joules of heat will be transferred from cube 2 to cube 1 over the course of that 1 second.
Time Elapsed (s) │ T1 Initial (°C) │ T2 Initial (°C) ║ Heat Transferred (Q) │ T1 Final (°C) │ T2 Final (°C)
──────────────────┼─────────────────┼─────────────────╫──────────────────────┼───────────────┼───────────────
1.0 │ 20.000 │ 200.000 ║ 36.000 │ 29.655 │ 190.345
However, this is a rather poor approximation. To improve our resolution, we can decrease the Δt parameter and run more iterations.
Time Elapsed (s) │ T1 Initial (°C) │ T2 Initial (°C) ║ Heat Transferred (Q) │ T1 Final (°C) │ T2 Final (°C)
──────────────────┼─────────────────┼─────────────────╫──────────────────────┼───────────────┼───────────────
0.1 │ 20.000 │ 200.000 ║ 3.600 │ 20.965 │ 199.035
0.2 │ 20.965 │ 199.035 ║ 3.561 │ 21.920 │ 198.080
0.3 │ 21.920 │ 198.080 ║ 3.523 │ 22.865 │ 197.135
0.4 │ 22.865 │ 197.135 ║ 3.485 │ 23.800 │ 196.200
0.5 │ 23.800 │ 196.200 ║ 3.448 │ 24.725 │ 195.275
0.6 │ 24.725 │ 195.275 ║ 3.411 │ 25.640 │ 194.360
0.7 │ 25.640 │ 194.360 ║ 3.374 │ 26.545 │ 193.455
0.8 │ 26.545 │ 193.455 ║ 3.338 │ 27.440 │ 192.560
0.9 │ 27.440 │ 192.560 ║ 3.302 │ 28.328 │ 191.674
1.0 │ 28.328 │ 191.674 ║ 3.267 │ 29.202 │ 190.798
For our simulation, let's imagine we have 2D grid of 1cm * 1cm * 1cm cubes W columns wide by H rows deep.
At the beginning of each Δt interval, each cube will exchange heat with its orthogonal neighbors.
Note that all these exchanges happen "simultaneously", such that no two heat exchanges during the same interval will be affected by one another.
Round each cell's temperature to the nearest 0.001 °C after each iteration.
Input Data
First line is Q, the quantity of testcases.
Q * 3 groups of lines then follow, in groups of 3. The first line contains four space-separated values W H N Δt T0 T1 ρ c k, where
W is the quantity of columns in the grid, H is the quantity of rows in the grid, N is the quantity of turns the simulation should be run for, Δt is the time interval in seconds,T0 is the initial temperature of the material in °C,T1 is the secondary temperature in °C.c is the Heat Capacity of the material in joules / (kilograms * °C), k is the Thermal Conductivity of the material in joules / (seconds * kilograms * °C), andρ is the Density of the material in kilograms / meters^3.Initially the entire material will be kept at the temperature T0. At time = 0, certain cells in the grid will be instantly set to the temperature T1.
Those cells are listed in the second line of each group, as pairs of integers corresponding to the column and row of the cell's location in the grid (note that rows and columns are indexed at 0).
The third line will contain a pair of integers corresponding to the column and row of a cell whose final temperature is to be reported as the answer.
Answer
Should be Q space-separated integers, corresponding to final temperatures of each given cell after the simulated testcase.
Example
input data:
3
1 2 1 1 20 200 7850 475 20
0 1
0 0
1 2 10 0.1 20 200 7850 475 20
0 1
0 0
7 8 1000 0.1 17 212 7766 456 23
1 0 2 2 6 7 4 2
3 3
answer:
29.655 29.202 31.357