-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Model and simulate the transfer of heat.
Heat is generated in the reactor, transferred to coolant, and then radiated into space through three separate systems
- Loading branch information
1 parent
285da4b
commit 04462f4
Showing
20 changed files
with
746 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {getSystemInventory} from "@server/utils/getSystemInventory"; | ||
import {MeterSquared, StephanBoltzmannConstant} from "@server/utils/unitTypes"; | ||
import {Entity, System} from "../utils/ecs"; | ||
|
||
// W = A * a * T^5 | ||
// W = Watts | ||
// A = area of radiator | ||
// σ = Stefan-Boltzmann constant | ||
// T^4 = radiator temperature | ||
// Increasing it by another power as | ||
// space magic. | ||
|
||
// For transferring the heat of the coolant | ||
// into watts | ||
// 𝚫T = (W * 𝚫t) / (c * m) | ||
// 𝚫t = change in time | ||
// c = specific heat | ||
// m = mass | ||
// 𝚫T = change in temperature | ||
|
||
// Specific heat is in J/gK, 1J = 1 wattsecond | ||
|
||
const RADIATOR_AREA: MeterSquared = 1; | ||
|
||
export class HeatDispersionSystem extends System { | ||
test(entity: Entity) { | ||
return !!entity.components.heat; | ||
} | ||
update(entity: Entity, elapsed: number) { | ||
const elapsedInSeconds = elapsed / 1000; | ||
if (!entity.components.heat) return; | ||
const inventory = getSystemInventory(entity) || []; | ||
// Radiate the heat of the coolant into space | ||
for (let item of inventory) { | ||
if (!item.flags?.coolant) continue; | ||
const temp = item.temperature; | ||
const wattsDispersed = | ||
RADIATOR_AREA * StephanBoltzmannConstant * temp ** 5; | ||
|
||
const tempDrop = | ||
(wattsDispersed * elapsedInSeconds) / | ||
(item.flags.coolant.heatCapacity * | ||
item.flags.coolant.massPerUnit * | ||
1000 * | ||
item.count); | ||
if (item.room) { | ||
item.room.contents[item.name].temperature = Math.max( | ||
2.7, | ||
temp - tempDrop | ||
); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.