I’ve been working on the thermal part of the simulation today – basically it computes how heat influences the fuel lines and fuel tanks (there is noticable influence – change in temperature will change pressure as well). Also I finished more of fuel lines themselves – now they handle all switch positions except for one (the whole system is isolated).
Fuel lines are simulated as three distinct fuel sections – two sections are only connected to specific tank and fuel cell, and they are only computed if they are isolated. This means that they are computed only when they are separate from the rest of the system. In case it’s not isolated, it’s just ignored, and extra pipe volume is added to biggest section. The biggest section is always simulated, because you can’t isolate it (well, apart from just that one single case which I’m gonna add handling for).
Now about thermal simulation. I’ve installed
plugin for WordPress, which means we can have some formulas now! Okay, let’s start with general stuff first:
- There are plenty of fuel tanks in the ship. Every tank is pretty much a thermos, it doesn’t gain too much heat from its envrionment, so oxygen remains at roughly same temperature
- There are pipes, and it is possible to isolate certain section, cutting off oxygen/hydrogen flow through this section. These gases will start expanding as they are heated up by pipes (which are in turn heated up by envrionment), increasing pressure in fuel lines. Yikes, good thing there are some relief valves which will lower the pressure back into fuel tanks once it exceeds some limit.
- When some oxygen/hydrogen leave fuel tank, pressure in it drops.
- Every tank has heater that can heat up gas inside the tank, increasing pressure. Pressure is kept at roughly 6 megapascals for oxygen, and 1.5 megapascals for hydrogen.
Here’s good illustration of the heaters working:

It’s taken over a large timespan. You can see pressure in tank dropping because it is being used up by fuel cell. After it reaches minimum pressure an electric heater turns on, and brings its pressure up to high level again. Temperature, of course, rises.
Okay, now closer to the thermal simulation itself. In my simulation I’m using approximated model of ideal gas. This might be wrong, but it will work for now.
Ideal gas law states that:

where
is pressure,
is volume taken by gas,
is mass of gas,
is molar mass of gas,
is universal gas constant, and
is of course temperature.
Every gas tank is defined by its volume (a constant value), mass of gas in it, type of gas, and its temperature. This gives us enough data to compute gas pressure, and we do it using this formula:

Now if we take some gas from tank, its quantity (mass) will decrease, so pressure lowers. In order to increase pressure, we need to enable electric heater. Every heater is specified by its power – that is, how much energy it consumes every second. It is measured in watts:

Our electric heater is located inside the tank, and all power it uses is turned into heat – this means it has nearly 100% efficiency, and all energy consumed by it is used for heating oxygen/hydrogen in the tank. It is assumed that there is nowhere else for heat to go, and walls do not take part in thermal processes (they instantly heat up to temperature of surrounding oxygen, and their thermal capacity is very low).
We know that heat required to change temperature of some object using conductivity (what we’re using) is:

where
is total heat required,
is specific heat capacity,
is mass of object.
is change of temperature we’re performing.
Our heater will produce this much heat over timespan of
seconds – let’s just pick some period in time. We know that:

because we’re producing
joules of energy every second.
Let’s now put that into formula seen before, we are gonna receive:


at this point we could really pick a really small timespan, and move on to differentials, but actually we’re fine with deltas – after all we’re iteratively simulating this.
Our resulting formula for temperature increase when electric heater is active is:
Now we know what happens in the tank as fuel depletes, and how we should react to that. But that’s not all! There is one more thermal process here, due to construction of fuel distribution system it is possible to end up isolating part of the system, while fuel is still in there. The fuel will start warming up inside pipes, and pressure will increase.
There are two parameters now –
and
– temperatures of fuel and pipe it’s in. We need to compute iteratively how temperature changes in both of those. The computations below do not account for external heat. This will be done later.
Okay, so no external heat, let’s start. First of all, we want to describe how heat transfers, and we will use heat equation for this. It’s an equation which describes change of temperature when distribution of temperatures in space is known.
In our case we have just two points – inside pipe and pipe itself, and there is certain difference in temperatures (significant one). I’m gonna skip the description on receiving 1D heat equation (which is what we want), you can read about that in a wikipedia article, given above.
This is the equation:

where
is thermal conductivity,
is specific heat capacity,
is density of our material.
is change of temperature over time, and
is double gradient of temperature field. Basically first derivative
is heat flow, and second derivative specifies change of heat flow between two endpoints (so to say).
Now let’s go from differentials to deltas, since we have only two endpoints between which we compute heat transfer:

is difference of temperatures between two endpoints. We can assume that
for computations to be a bit easier (actually it might be important to preserve distance, but lets just assume it’s 1 for now). This means that for our two points:
(inside the pipe)
(for the pipe itself)
Okay, now the delta of delta is basically difference of difference of temperatures:

Our equation becomes:

We’re gonna multiply by time delta…

and there it is, our formula!
is deltatime, time step of our simulation. Available as XSV.DeltaTime in my simulation, all processes are tied to it.