Python on the input side
The Expression grammar is small on purpose. In this step, we'll look at what to do when a calculation outgrows it. A Script node is a Python function on the canvas whose parameters become input sockets and whose results become outputs. We'll use it on the input side of the model, turning a site altitude into the snow load on a portal's rafters, so a Range of altitudes sweeps the frame through loads it never held as numbers.
1.0 The idea
The frame's imposed load, ws, is a line load in kN/m. On a real project, though, what you usually know is the site's altitude, so we have to work out ws from it in three stages. First, we read the ground snow load for the site's zone and altitude from the code's snow map. Next, we multiply it by a shape coefficient for the roof pitch to get the snow load on the roof. Finally, we multiply that by the frame spacing, which turns a pressure on the roof into a line load on the rafter.
None of these values is a property of the structure, so they don't belong in the model as parameters. An Expression node holds a single formula, but this calculation takes several steps. When a calculation needs more than one line, we write it as a short Python function and put it on the canvas in a Script node.
The code runs in your browser, and it runs as you type. A Python runtime with numpy and scipy is downloaded once (a few tens of megabytes the first time, cached after that). Nothing goes to the server, and the solver only ever receives the numbers the script produces.
2.0 The script
:
: :