// Management · RimWorld Mod

FVM Thermal System

FVM Thermal System mod preview for RimWorld

(please report any problem you have here this is still a very early stage mod and a lot of things need to be fixed and I don't even fully know what may go wrong now) Features 2D advection-diffusion based temperature model Heat and cold move with outdoor wind Pawns can feel the te

[h1I was driven crazy by my thesis project so I decided to replace RimWorld's temperature system with PDE.


Combat Extended is recommended but not required


(please report any problem you have here this is still a very early stage mod and a lot of things need to be fixed and I don't even fully know what may go wrong now)




Features



  • 2D advection-diffusion based temperature model
  • Heat and cold move with outdoor wind
  • Pawns can feel the temperature of each cell
  • High-temperature cells can ignite things or pawns
  • Intercepts the stock game heating/cooling input and uses an FVM model to calculate it instead
  • Writes the cell average back to the vanilla room temperature system after finite volume method done its job for maximum compatibility


Spoiler
With my default parameters the oven cell can reach up to 100°C when working for a long time, now Milira can actually blow up your kitchen





Disclaimer



To guarantee performance, I made a lot of assumptions and simplifications.
The temperature field is NOT PHYSICALLY ACCURATE, but it should be good enough for gameplay.




MATH WARNING



The following is deep dark math to explain what I did. Please stop reading if you feel dizzy or sleepy.

Main Formula




Where:

  • T^i_xy: cell temperature
  • t: time
  • u^i_xy, v^i_xy: field velocity in x / y direction
  • a^i_xy: diffusion parameter
  • S^i_xy: heat / cold source


Material Types




The whole field is separated into 4 types of materials:

  • Outdoor air: just air
  • Indoor air: u = v = 0, with 10x diffusion parameter to simulate indoor heat exchange
  • Wall: u = v = 0, with 0.01x diffusion parameter to simulate insulation
  • Vacuum: u = v = 0, with 0.02x diffusion parameter to simulate black body radiation cooling


boundary condition


Uhh I'll try make it short

All outdoor air have u and v from weather, for example, breeze SW.
If there is wall at left or right of the outdoor cell, u=0
If at up or down, v=0.


All outdoor cell have a trend to return to environment temp so that you won't have a big chuck of hot air in no wind days.




Q/A




Q: Why not try something even fancier, since it already gets so complicated?

A: I tried a 2D incompressible Navier-Stokes equation for the velocity field. It was slow as hell and a bit unstable, so I decided to use something easier.






Q: Compatibility?

A: Theoretically, any mod *building or furniture* that generates temperature or heat using the stock game functions should work. (all kinds of vanilla expansion, nuclear power plant, etc.)

(Very likely) not compatible with Celsius




Q: Combat Extended?

A: I recommend using it. CE has a decent wind speed and wind direction system, which I use for convection parameters. The mod is still playable without CE, but I was too lazy to build a full wind system myself. Without CE, you will get a fixed SE wind during summer and NW wind during winter.




Q: Performance?

A:Surely impact a lot, but Jacobi method is naturally suitable for multi thread calculation. The slowest part is reading vanilla heat sources and writing average cell temp back to room temp, but it should be playable. My late game saving with 150+ mods dropped from 120TPS to 100-110TPS with this mod.

If its really laggy, you can safely change refresh rate in setting (the first bar).




Source Files



All C# code and MATLAB code for early-stage tests are uploaded with the mod in the Source folder. Feel free to edit anything you like.




Known Issue



Wall mounted air vent doesn't work for now cause map reader is confused about is it a wall or a vent, I'll try fix it later.

Only vanilla vac barrier can block temperature now, mod barrier may not work. The code decides is the door a wall or indoor air by open/close, but vac barrier is a open only door.

For now the mod does not have a function to save cell temp, and every loading or restart game will reset all cell temp back to environment temp, may cause problem for meat storage and other things.




Credits / Notes



I don't have Anomaly cause its too scary to me, so I don't know how the 'meat wall'(I don't know what its called in English) will perform. If the game consider it as a wall, things should work fine.




Idea and math: 95% me. ChatGPT introduced some methods to make the simulation run faster, etc.

Code: 95% Codex, because I know basically nothing about C#.