Jump to content

How electricity works


Recommended Posts

Here's how I understand electricity in the game: Load is measured in Watts and is experienced the same by every connected wire. If that's incorrect then disregard what I'm going to say, but that's not how electricity works in the real world. Watts = current * voltage. Current varies from one part of a circuit to another based on how much is being drawn by the appliances connected to that part of the circuit. If you have a circuit of wires in your house, and a washing machine is turned on, it won't increase the current in the wire that goes from the wall to, say a lamp. Voltage on the other hand is the same throughout a circuit (if you don't consider the ohms of the wires that is, but that's another story), and you need a transformer to connect two circuits of differing voltage. It seems to me that electricity in the game would be more intuitive if you measured load in Volts, renamed "Heavi-Watt Wire" to "Heavi-Volt Wire", and make it impossible to connect wires and appliances of differing voltage. It's similar to how american houses commonly have 120v wall outlets, but occasionally have a 240v outlet for washers and dryers. You can't plug a 120v plug into a 240v socket or vice-versa, and if you do things will explode or simply not work.

Link to comment
Share on other sites

Alternatively; measure load in wires locally instead of grid-wide because wires that run between a high output power source and a high draw appliance will experience higher current which will create heat and cause wires to melt. 

Link to comment
Share on other sites

Welcome to the strange and exciting world of ONI physics.

There was a large uproar when this mechanic was introduced into the game but everyone got used to it eventually. Calculating load on every piece of wire is very complex mathematical problem in general case (wire with loops) and does not even make sense with ONI wires that have no resistance.

Now we have heavy wire that can transfer 20 kW, that's more than what normal players ever need in their whole colony, and we have transformers that can branch 1 kW loads off that backbone. It's not exactly how it works in real world but it works fine for the game.

Link to comment
Share on other sites

Yes, you are correct. Electricity (and it's ability to do work) relies on current and voltage potential to do work. However, your observation that everything run on the same voltage is only a preference/standard (to simplify electricity distribution in the real world)

If you look at everyday electronics, they're all plugged in to a system of some voltage ("120 V" in US). I put that in quotes because there is actually a voltage tolerance. Using a multimeter to measure voltage, you will realize voltage is not constant and depends on the grid pressure. Therefore "120V system" is really different from 120 V.

The universal idea is that you can run on any voltage as long as you have the means to convert it to your power needsThe computer you play ONI on does not run on 120 V :D

Yes, power, that's all we're interested. POWER and ENERGY

_______________________

Relating electricity to computer simulation,

Power (measured in Watts) = Current (measured in Amperes) x Voltage Potential (measured in Volts). This simplifies to W = I*V. That's two variables the game has to input then calculate to get a energy draw.

In the end, all we're interested is just energy E because it describes the ability to do work. Then, power is the rate of doing work, which simply is Energy per unit time. ONI has a built in clock (rendering) where each step is a second (a cycle is 600 seconds), all simulated simultaneously. It's very typical of a computer.

Now, this is where Watts come in. If everything is rated Watts, it makes things so much easier to compute. E = W/s. If the game progresses 2 steps, a 240 Watt air pump takes in 240 W x 2 seconds =  480 Joules. Imagine having to set a voltage and current draw for each individual item in the game.

You see adding volts and amperes complicates a lot of things, not just from a programming perspective but from a design standpoint. How should you distinguish how much current is drawn by a hydro switch vs air pump. It just introduces more real vs simulated inconsistency (and possibly more complaints from the players)

Remember, E, is all we're concerned because current and voltage are "meaningless" without one another.

 

To legitimize and rationalize ONI's preference, each object in the game has a built in transformer hence why things that should weigh 10 kg actually appear 400 kg. :o:o

________________________

P.S. Physicists use a water analogy to describe electricity: Hydraulic Analogy

Link to comment
Share on other sites

Power and specifically the transformers were the hardest things for me in this game, which is ironic considering I used to build substations as an electrician. "Transformers" just didn't make sense or work how I expected them to at all, I still have some trouble with it.

 

BTW Kashua, calculating load more correctly is not a very complex problem at all, you could do it with a variant of A* pathfinding which Klei would probably already be using elsewhere... having loops in the pathways around your base doesn't confuse dupes for example. ;)

Link to comment
Share on other sites

10 minutes ago, boggers said:

calculating load more correctly is not a very complex problem at all, you could do it with a variant of A* pathfinding

I don't think it's that simple. Let's have a simple case. What is the load on each wire?

0uxyPrK.png

 

 

Link to comment
Share on other sites

8 minutes ago, boggers said:

off the top of my head...

Just the obvous one: there definitely wouldn't be zeros on the leftmost wire. And the output of the generators wouldn't split 360+360. Plus you have one 360 + 720 = 360 in the graph.

Link to comment
Share on other sites

it really depends what youre trying to model, in "real world" you would not wire something like that, as the 0 wires are redundant.

 

My process was to use a simplified model that allows for crazy wiring, rather than preventing it. 

1) divide total load by number of inputs (lines to batteries would change from output to input where load exceeds supply.

2: step from input towards output until zero, combining or splitting along the way as required.

Link to comment
Share on other sites

But your approach is not even consistent. Power from producers split, while consumption from consumers doesn't. That doesn't make sense. There are two wires going to the tepidizer, one carries 960 W, the other nothing. That's wrong. Why there's no power carriend around the gas pump and towards the tepidizer from the other side? There's a wire there.

What I mean is, the implementation should either be realistic, or it should be simple. If it behaves correctly then it's acceptable that it's confusing because it makes people understand reality. But if it's unrealistic and confusing at the same time, then there's no point going that way, particularly if it also lowers performance of the game.

Link to comment
Share on other sites

You could do it either way (work from line to load or from load to line) but you cant do both, you need to have to have a start and an end or your code will go into infinite loops. I chose line to load for simplicity. 

 

A more "realistic" approach would be to use resistance on wires, and work from load to line. Calculate *minimum* resistance from each input to each output and draw power accordingly, the result would be about the same. I think it would approach exactly the same as wire resistance approached zero, but with resistance in the wires the "back" side of the transformers in your diagram would divert less power, as those wires are longer. The key word here is "minimum" The impossible system i think you have in mind is only unworkable because you want to ignore the path of least resistance, and calculate all paths in infinite loops, which is kinda the opposite of what electricity does. :) 

Link to comment
Share on other sites

But you do realize that with zero resistance wires the length of the path should play no role? Why should longer wire carry less load if it has zero resistance? 

For proper solution, you'd need to take into account all non-looping paths from each producer to each consumer, and split the load over them. Even that would be arbitrary but it would be consistent. And unbelievably CPU heavy. And in some configurations, it would still be unintuitive and illogical.

All in all, there are countless arbitrary ways of distributing load over the grid. What developers chose was one of possible options and from the gameplay point of view, after considering all pros and cons, I believe they chose the best solution, however unrealistic it is.

Link to comment
Share on other sites

My issue with the current implementation, which this directly addresses, is that overload damage is distributed seemingly at random accross the grid, whereas what I propose focuses the problem to the specific area which needs to be rewired.

Link to comment
Share on other sites

5 minutes ago, boggers said:

My issue with the current implementation, which this directly addresses, is that overload damage is distributed seemingly at random accross the grid, whereas what I propose focuses the problem to the specific area which needs to be rewired.

The damaged wire is selected at random but the part that needs to be rewired is obvious - it's the whole connected wire on which the damage happened. You need to split it any way you like to reduce the load.

Link to comment
Share on other sites

in game though, I can build a 100% functional system that dupes never need to visit again, seal it up with multiple layers of insulated tile, then add something elsewhere on the same circuit at a later time, but now parts within the sealed room are subject to random damage and eventually break, rather than one of the the overloaded lines supplying both the functional sealed room and the new piece.

Link to comment
Share on other sites

On 2017-6-15 at 0:38 AM, Kasuha said:

For proper solution, you'd need to take into account all non-looping paths from each producer to each consumer, and split the load over them. Even that would be arbitrary but it would be consistent. And unbelievably CPU heavy. And in some configurations, it would still be unintuitive and illogical.

I've been thinking about this a bit. It would still not be CPU heavy to work out all non-looping paths. What you'd need though is a combination of grid based and node based A*. Grid based is only needed for tiles with exactly 2 neighbours, and these become a special case "sub-node" or "path" that don't require the functionality of a "full" node with 3, 4 or 5 connections that are used for node topology.

A "path" node contains only the 2 distances to the nearest full nodes, and they only store that to make things easier later when player changes the topology. Full nodes store their connections to other full nodes directly, and each of these connections has an associated list of tiles which is the path sub-nodes. Conveniently, the length of those lists doubles as the distance between the nodes.

So, now you have a bunch of nodes with a hard maximum of 5 connections (an X of wires over an input or output) and precalculated distances on each of those connections - this is more or less a perfect setup for node based A*. Working backwards from consumers to producers you could, if so desired, split the load across the pathways based on the length of each path. You could store a node list to each and every producer inside each and every node, although for practical purposes I would still put a limit there to avoid the n^2 scaling problems of the "perfect" system (the limit of my previous example was one - ie. only take the shortest path, but you could increase it to 5 or 10 easily).

The point is, the potential loads are calculated once when topology changes (ie a path turns into a full node, vice versa, or when a new consumer or producer appears) and the loads are then applied along each node list per tick, which in turn drops down into the grid based system to put load on each wire tile.

The application of load per tile per game tick would be similar CPU wise to the current system which applies all connected loads to all connected wires; quite possibly less CPU if we have optimised out redundant wires. The work is done once when player changes topology, and I'm pretty sure you could localise those changes, ie. make minimal delta changes to the current topology, rather than recalculating the whole system each time a new node appears..

 

eh, maybe I should do a demo of it or something.. it's really not that hard.

Link to comment
Share on other sites

22 minutes ago, boggers said:

I've been thinking about this a bit. It would still not be CPU heavy to work out all non-looping paths.

Just the amount of pairs producer-consumer is O(n^2). And number of non-looping paths between single producer and single consumer is another O(n^2) by number of connection nodes, at best. I'm not sure if it isn't actually exponential, I'm lazy to put too much brain activity into it.

You actually admit you're about to drop a lot of these paths to make the algorithm efficient.

36 minutes ago, boggers said:

The point is, the potential loads are calculated once when topology changes

That's actually more often than you think. The topology changes every time one consumer is switched off. Which may be a pump that's waiting for its output pipe to become empty. You can have a topology change every second.

 

Don't let me stop you working on this little challenge if you like it. You may realize over time where the problems are, or you may not. You certainly didn't convince me that you have approach that could work, I can see flaws but I'm too lazy to keep pointing them out. My opinion that the approach devs chose was the best choice, however unphysical it may seem, remains unchanged.

 

Link to comment
Share on other sites

Only the applied load changes when you turn things on and off, likewise switching batteries from consumers to producers just changes the flow through the precalculated nodes. Actual node topology only changes when adding or removing things like new consumers or T junctions in existing wires etc.

This really is comparatively simple compared to some systems I've built in the past.

My issue with the current system is that I found it utterly baffling because I have some knowledge of how power distribution works, having worked on it for years. Things that are normal and sensible simply do not work in ONI and what works in ONI makes no sense to me at all. ONI "transformers" aren't even remotely close to actual transformers for eg, which work just as well in either direction, and don't limit wattage or store any significant charge.

 

edit: What I'm saying is this is how you would wire things "in real life"  The fact that this setup overloads in ONI is evidence that their electrical system needs a bit of fixing.power2.jpgvalid. 

Link to comment
Share on other sites

3 hours ago, boggers said:

My issue with the current system is that I found it utterly baffling because I have some knowledge of how power distribution works, having worked on it for years.

I understand you completely. I know how power system work, I know how to calculate load (and I know when I would not like to do it). I was baffled too when it was introduced and I was one of first to post a suggestion to do something about it. The thing that was done was addition of transformers. Many don't like or understand them, but that's the ONI way of realism. You have transformers in real power systems. You have them in this game. And they actually do their job fine.

The point is, ONI is a game. I know enough about physics to be able to say that there's almost nothing realistic on physics in this game. It only somewhat resembles how things work in real world, if you don't look too close and don't actually take a pen and paper and don't start calculating something. Because when you do, you realize that the rabbit hole is very deep. The way power systems work is one of easier to accept ones.

Link to comment
Share on other sites

I never saw the game before transformers were in it, so I don't know what the problem was that were supposed to fix.

The thing about ONI transformers, they're a 6 tile floor mounted device that can only supply 4 pumps each, and have a massive decor hit attached to one side, requiring you to design the entire base around them. Gas and liquid by comparison have 2 tile wall mounted units for flow limiting. If power was handled the same way, and the electric valve / limiter / uh.. AC diode? was not misnamed "transformer" then I probably wouldn't have such an issue with it.

I think the next colony I make will not use transformers at all, but pipe gas to generators distributed around the base as needed instead, since you need almost 1:1 generators to transformers anyway and gas is easier to manage on multiple levels.

Link to comment
Share on other sites

1 hour ago, boggers said:

I never saw the game before transformers were in it, so I don't know what the problem was that were supposed to fix.

The thing about ONI transformers, they're a 6 tile floor mounted device that can only supply 4 pumps each, and have a massive decor hit attached to one side, requiring you to design the entire base around them. Gas and liquid by comparison have 2 tile wall mounted units for flow limiting. If power was handled the same way, and the electric valve / limiter / uh.. AC diode? was not misnamed "transformer" then I probably wouldn't have such an issue with it.

I think the next colony I make will not use transformers at all, but pipe gas to generators distributed around the base as needed instead, since you need almost 1:1 generators to transformers anyway and gas is easier to manage on multiple levels.

You lost me at AC diode.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...