Home /  Sketchbook /  p5.js - Thermal Cells
  • Info

Overview

This is a p5.js sketch that models basic heat-transfer through finite element analysis.

Each cell has a concept of temperature, and with each cycle will transfer (gaining or losing) heat with its neighbors.

The temperature is visualized along a gradient from blue (cold temperatures) to red (hot temperatures) with white in the middle.

Some other concepts:

  • Walls - denoted by solid, dark grey cells have zero-conductivity
  • Sinks and Sources - Will either absorb or generate heat on each cycle.

Heat Transfer is modeled off of:

 q = - k * delta T

Similar to Thermal Conduction: Differential Form (wikipedia.org).

And implemented as

    let heatGained = (otherCell.temp - this.temp) *  this.condFactor;
    this.deltaTemp += heatGained;
    otherCell.deltaTemp -= heatGained;

Controls

Mouse /

Click & Drag will modify the cell at the mouse location based on the active mode (changable via button and keys).

Keyboard Switch the mode of the mouse cursor.

  • W will add a Wall cell
  • Q will restore the cell to a plain cell (removing any Wall, Sink or Source)
  • A will add a heat source
  • S will add a heat sink
  • any other key will remove heat from the cell
  • (no key pressed) will add heat from the cell

References:

  • Wikipedia: Finite Element Method

Links:

  • Live View
  • Source on Github

Screenshot:

screenshot

With Walls and heat syncs in place:

screenshot