Monthly Archive for February, 2010

XS Venture fuel cells work

Fuel cells now work, their simulation is not yet complete, but I’ve added a small placeholder in place. The next thing to do is add computer systems and placeholders for some other systems, and it’s gonna be ready for next spaceflight (XS10). After that I will pause developement on it for a bit to work on a different project.

There’s new panel for controlling fuel cell startup heaters and various water purge tasks (they are not currently used, simulation is not done yet):
fuelcells_r2

XSV three-position switches

I added three-position switches to XSV simulation, they are required by some panels – mostly to specify systems state as ON, OFF and AUTO (controlled by logic/computer).

This is the switch graphic, I know it’s not very nice actually, I’m gonna redraw the middle position later:
x-switch
x-switch_rack

Okay, those aren’t best switches ever, but they do the job. I’m going to post the entire neat graphics set for use with other panels eventually.

Now the switches on the fuel cell panel (the ones that control heaters) do work, and they do control the heaters. Their logic is hardwired when you mode it to AUTO position, and there is some logic interconnection there.

Even more thermal simulation

I’ve moved on to next stage of the “experiment”: now my thermal simulator simulates oxygen INSIDE the thermally conductive pipe with known parameters. You can specify pipe size, width of pipe, and many other parameters. The pipe is entirely isolated from external heat, so it only cools down with oxygen (which heats up).

Depending on radius of the tube, you might get stabilization time (after which both are in thermal ballance) of 20 to 200 seconds. It is roughly 20 seconds for a pipe of 3cm in radius, 2cm inside radius. This is the information I wanted in the first place, and I’m going to implement corrections into model already in XSV simulator.

I’m going to post this program for download, in case you want to play around with it (win32): heatsim.rar (~300kb).

This is how it looks like, with visualizations of all important fields, temperature graph, and a 2D representation of temperature field:
heatsim

If you get unstable simulation error, just lower the deltatime.

For sourcecode description read two previous posts (they explain math behind it), and here’s full sourcecode if you want it (not really expecting you to compile it as it is, you’ll probably need to rewrite it/port it to other language):
Continue reading ‘Even more thermal simulation’

More of thermal simulation

Okay, I’ve decided to test something with thermal simulation: one of my friends suggested that oxygen will heat up non-uniformly, and that it will be a noticable effect. So I decided to write a full simulation of the pipe with oxygen inside. I started with just simulating thermal diffusion (a process of establishing same temperature everywhere) in just oxygen.

Initial conditions: cold oxygen with hot circle of oxygen around it. It only accounts for conductive diffusion (there is no diffusion in gas itself). The walls of this pipe do not take part in thermal reactions (they always have same temperature as oxygen on boundary). Radius of pipe is 0.1 meters.

I have generated a neat animation for you:
heatflux_3

Now for some math behind this (behold the power of math). Thermal equation (heat equation, diffuse equation) in 1D case is specified as:
\frac{\partial U}{\partial T} = \frac{k}{c \rho} (\frac{\partial ^2 U}{\partial x^2})

This can be also written using so called laplacian (that’s not delta)
\frac{\partial U}{\partial T} = \frac{k}{c \rho} \Delta U
where
\Delta U = \frac{\partial ^2 U}{\partial x^2}

But that’s only valid for cartesian coordinate system. Since we’re simulating a cylinder, we have to move over to polar system. In polar coordinates laplacian is given as:
\Delta U  = {1 \over r} {\partial \over \partial r} \left( r {\partial U \over \partial r} \right)  + {1 \over r^2} {\partial^2 U \over \partial \theta^2}

We’re symmetrical on \theta axis, so this means we can simplify that to just one dimension:
\Delta U  = {1 \over r} {\partial \over \partial r} \left( r {\partial U \over \partial r} \right)

And this is our final iteration:
\frac{\partial U}{\partial T} = \frac{k}{c \rho} ({1 \over r} {\partial \over \partial r} \left( r {\partial U \over \partial r} \right))



And that’s actually pretty much it. I’m just implementing that equation in my simulation. Here’s some nasty pascal code for you:

    U: array[0..FieldSize] of Single;
   dU: array[0..FieldSize] of Single;
  ddU: array[0..FieldSize] of Single;
........
    U[FieldSize-1] := U[FieldSize-2];
    U[FieldSize] := U[FieldSize-1];
    U[0] := U[1];

    for I := 1 to FieldSize-1 do begin //calculate dU/dR
      r := radius * I / FieldSize;
      dU[I] := r*(U[I+1] - U[I-1])/(radius * 2.0/FieldSize);
    end;

    for I := 1 to FieldSize-2 do begin //calculate d(dU/dR)/dR
      r := radius * I / FieldSize;
      ddU[I] := (1/r)*(dU[I+1] - dU[I-1])/(radius * 2.0/FieldSize);
    end;

    for I := 1 to FieldSize-2 do begin //calculate U = U + deltaU, from heat equation
      U[I] := U[I] + (0.0238 / (0.918e3*1.429)) * ddU[I] * deltatime;
    end;

(that is the complete iteration, you just keep doing that over and over).

That code uses the approximate derivative of function U, which is:
\frac{\partial U}{\partial r} = {U(r+h) - U(r-h) \over 2h}

Some code explanation:

  • U[I+1] - U[I-1] is dU
  • (radius/FieldSize) is dR, our coordinate step for every cell
  • dU[I+1] - dU[I-1] is d(dU/dR)
  • 1/r, r are seen in the formula for polar coordinates laplacian
  • deltatime is time step, should be (much) less than radius, or else it becomes unstable
  • radius is radius of the pipe. I used 0.1 for that.

U[0] is ignored (assumed to be same as U[1]), so are last two cells. This is done in order to prevent problems with derivative on edges, and maintain stability of simulation. You just draw all cells from U[1] to U[FieldSize-2]

XS Venture fuel cell thermal simulation

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 \LaTeX 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:
tank_usage
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:
pV = \frac{m}{M}RT
where p is pressure, V is volume taken by gas, m is mass of gas, M is molar mass of gas, R = 8.314 is universal gas constant, and T 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:
p = \frac{\frac{m}{M}RT}{V} = \frac{mRT}{MV}

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:
P = U\cdot I

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:
Q = cm\Delta U
where Q is total heat required, c is specific heat capacity, m is mass of object. \Delta U is change of temperature we’re performing.

Our heater will produce this much heat over timespan of \Delta T seconds – let’s just pick some period in time. We know that:
Q = P\cdot \Delta T
because we’re producing P joules of energy every second.

Let’s now put that into formula seen before, we are gonna receive:
P \Delta T= cm \partial U

\frac{\Delta U}{\Delta T} = \frac{cm}{P}
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:
\Delta U = \frac{cm\Delta T}{P}





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 – U1 and U2 – 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:
\frac{\partial U}{\partial T} = \frac{k}{c \rho} (\frac{\partial ^2 U}{\partial x^2})
where k is thermal conductivity, c is specific heat capacity, \rho is density of our material. \frac{\partial U}{\partial T} is change of temperature over time, and \frac{\partial ^2 U}{\partial x^2} is double gradient of temperature field. Basically first derivative \frac{\partial U}{\partial x} 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:
\frac{\Delta U}{\Delta T} = \frac{k}{c \rho} (\frac{\Delta \frac{\Delta U}{\Delta x}}{\Delta x})



\frac{\Delta U}{\Delta x} is difference of temperatures between two endpoints. We can assume that \Delta x = 1 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:
\frac{\Delta U}{\Delta x} = \Delta U = U1 - U2 (inside the pipe)
\frac{\Delta U}{\Delta x} = \Delta U = U2 - U1 (for the pipe itself)

Okay, now the delta of delta is basically difference of difference of temperatures:
 \frac{\Delta \frac{\Delta U}{\Delta x}}{\Delta x} = \Delta \Delta U = (U1 - U2) - (U2 - U1) = 2(U1-U2)

Our equation becomes:
\frac{\Delta U}{\Delta T} = \frac{k}{c \rho}\cdot 2(U1-U2)

We’re gonna multiply by time delta…
\Delta U = \frac{k}{c \rho}\cdot 2(U1-U2) \Delta T
and there it is, our formula!



\Delta T is deltatime, time step of our simulation. Available as XSV.DeltaTime in my simulation, all processes are tied to it.

XS Venture fuel cell simulation progress

Now I’m writing simulation for fuel cells themselves – and related systems. Today I finished part of the so-called PRSD – power reactant storage & distribution system. That includes tanks which store oxygen and hydrogen, and all pipes which connect those tanks to fuel cells. XS Venture PRSD system almost entirely mimics that one of space shuttle, here’s roughly how it looks like:
prsd

You can control MANF VLV (manifold valves) from the panel shown in earlier post, as well as control REAC VLV (reactant valve) to open or close reactant supply to specific fuel cell. Manifold valves allow you to isolate system in such way, that fuel cell 1 (FC1) would take fuel from fuel tank set 1, FC2 would take fuel from fuel tank set 2, and FC3 would take fuel from tank sets 3, 4, 5, … and so on (depends on how many you have installed).

In event of sudden loss of fuel fuel cells will still work for roughly 90 seconds, so you have time to quickly close manifold valves, and possibly initiate fuel cell restart while they still work.

I wrote simulation for fuel tanks themselves (simulates pressure in tanks, depends on fuel quantity and current temperature), and fuel lines (pipes that interconnect them). I don’t know of real values for the spacecraft, but I picked diameter of pipes as 1 cm, and typical length of 3-8 meters (average length of pipes in specific section).

Currently it only simulates two sections (with manifold valves closed), in two states (closed system or open system). Closed system means there is no fuel input, and therefore any fuel that remains in fuel lines will experience thermal effects (basically it heats up because pipes heat up by orbiter itself). Open system means that fuel valves are opened, and there is fuel flowing in pipes – in this case fuel will cool down the pipes, and remain same temperature and pressure as in tank (because any heat instantly gets distributed amongst all fuel reserve, and there is a real lot of it).

There are various relief valves etc, which will be simulated (I’ll write their logic after I finish thermal simulation) – but they are only triggered in case you lock all valves, so fuel has nowhere to go (it will start heating up and expanding inside pipes).

XS Venture fuel cells panel

Here it is, I’m currently working on logic behind it:
fcells

There are three fuel cells in XS Venture, they provide stable 28 volts, direct current. They are the heart of the ship, if all of them fail, entire spacecraft looses all power, and there is currently no way to restart them (they require external electric power to restart).

They mix oxygen and hydrogen, which results in water and electric power. Every fuel cell consists of 192 smaller ones, in total they can generate up to 16kW each.

XS Venture panel & fuel cell update

I’ve worked on sensor system a bit today – fixed small bug which resulted in wrong variable decoding (now voltage different from nominal is properly compensated), now it works fine and gives you pretty precise values. I’ve roughly estimated that in electric system like this background noise in voltage levels would be roughly 10^-5 volts, that’s 0.01 millivolts.

That results in noticable sensor noise, and for fixing that I’ve added a feature to some panels (the voltage panel actually) which smoothes out the sensor values.

And I started working on fuel cell simulation – I added hydrogen and oxygen tanks, which are simulated with pressure and temperature, and later will add heater systems (the tanks are heated up so stable pressure remains in them), distribution system (pipes and valves), and of course fuel cells themselves (they produce water), and probably water purge systems as well. This also gives some extra stuff I need for water boiler system – which relates to coolant systems…

Some stats about fuel tanks – there are 5 pairs of spheric tanks, every one is roughly 1 meter in diameter, one for oxygen (0.3 cubic meters/300 liters; 30.5 kg of oxygen inside at a pressure of 6 megapascals/850 psi; -171 deg C temperature), and one for hydrogen (0.6 cubic meters/600 liters; 10.5 kg of hydrogen at pressure of 1.5 megapascals/250 psi; -251 deg C temperature). Their pressure is kept constant by heaters which heat up the gas, and increase pressure inside the tanks.

Also I’ve manually entered one of X-Plane EFIS fonts, and now it’s used for those LED screens, so instead of this:
panel_o6
you get a much nicer, fixed-width, smooth bitmap font.

Here’s the entire top panel, ignore the missing buttons on panels O1 – O5, they are just not done, and there are no systems to link them to (and are there as placeholders of a sort):
panels_top