CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.51k stars 4.16k forks source link

Power Generation for Vehicles (and in general) needs an audit #63615

Closed KKDavion closed 1 year ago

KKDavion commented 1 year ago

Describe the bug

In JSON_INFO.md under Vehicle Parts, ePower is defined as 1:1 to Watts. Therefore, whenever a part is stated to generate X ePower, one would expect it to generate x ePower in a connected battery in 1 hour. This is most obvious with the part "7.5kW Generator", an alterator that takes 10444 units of motive power and generates 7500 units electrical power as far as the game is concerned in the vehicles menu. However, if one fills up a portable generator and slaps on an excessively large battery, it'll instead produce ~26700-26900 ePower in the battery over 1 hour. Similarly, a truck alternator should produce 1320 ePower, but produces ~4500-4600.

Attach save file

Power Test-trimmed.tar.gz

Steps to reproduce

  1. Spawn in Portable Generator
  2. Replace battery with Very Large Storage Battery
  3. Run for 1 hour (should consume ~3.2L of gasoline)
  4. Note the increase in power

Expected behavior

For vehicle parts to generate the listed ePower in 1 hour, as is the definition of a Watt-Hour.

Screenshots

No response

Versions and configuration

Additional context

These values are consistently ~x3.6 as large as the expected values, which coincidentally enough, is the conversion ratio between Watts-Hours and Kilojoules. I can't remember if power used to be done in Joules (everything before 0.A blends together, really, though I vaguely recall something of that nature, possibly in WhalesCataclysm), and I haven't done any digging into the vehicle code (which I've heard is a bit of a monster) but it's clear that at some point there's a conversion between Watts to Joules in there, which needs to be hashed out. This in turn, is likely going to warrant a slight rebalance and checkup on things that do generate ePower in vehicles, as well as storage battery sizes, which very well could impact power usage of tools and the like.

Additionally, this does seem to apply to appliances as well. While I have a sneaking suspicion that the prevalence of Solar Panels & Wind Turbines made this difficult to confirm as they're not really known for consistent power generation, the Water Wheel appliance I've recently submitted demonstrates this exact x3.6 increase in expected power generation.

Keeping consistency in mind, it would likely be best to see how exactly the vehicle code is manipulating that ePower number and to adjust accordingly. I suspect that if some appliances or tools were created with this increased potential power generation in mind, rather than their power costs in wattage, then they'll need to be readjusted as well.

This issue is mostly me opening the door to others' thoughts while I make notes & get data on my real passion (water wheels), as I need to know what actual generation value is correct & realistic for the game. Realistically, I don't know how much I can do myself, as my C++ knowledge is barely passable (the most coding I do is using python and matlab for fourier transforms & waveform analysis), but if I can hack it as I go then we'll see what comes of it.

Zireael07 commented 1 year ago

Yes, power used to be in joules

KKDavion commented 1 year ago

That's what I thought, but I couldn't remember. Seeing as the listed values are correct in terms of watts but the produced power is in joules, I can only assume that when the change was made, ePower generators had their values slashed to match the appropriate watt output, but numerically generation was buffed to not rock the boat in terms of numbers too much. But that's pure speculation.

In my "Knows-Enough-To-Be-Dangerous" poking around at the source code, under vehicle.cpp lines 1131-1138, specifically 1136, defines the conversion ratio between vhp and epower to be 1:373. I need to reremember how to compile the source code for this before I can confirm that this value does correctly adjust the power generation of items, but that's where I'll be starting at least.

irwiss commented 1 year ago

Putting the vph aside I'm not sure where you see the problem with the watts to battery charge

7.5kW generator produces 7500W so +7500J/s v2_combustion engine consumes 50W so -50J/s Net battery flow should be +7450J/s as long as setup is stable

Running the setup for 1 hour: 7450 J/s * 3600 seconds = 26820 kilojoules That's equivalent to ~26820 battery charges or ~26% of a very large storage battery capacity, besides a tiny bit of jitter due to some RNG in vehicle::power_to_energy_bat

Hirmuolio commented 1 year ago

61950 takes steps to moving from epower to watts and joules. It also gets rid of "vhp" (which was confusingly actually half horse power. And also used almost nowhere.).

X ePower, one would expect it to generate x ePower in a connected battery in 1 hour.

Where do you pull hour into this? Power generation is per second. So epower of 7500 is 7500 watts which is 7500 J in second (1 battery charge = 1 kJ).

KKDavion commented 1 year ago

So I think that there might be some confusion in the case of terms, potentially on my part. Yes, Watts are 1:1 with Joules in all but one way, a Watt is specifically a measure of force over time (power, or one Joule over 1 second), while Joules are simply force (energy, or 1 Newton-Meter). This is important because Watts aren't used an an actual unit of storage, while Joules are. The standard storage units for batteries are typically Watt-Hours, or Amp-Hours in some cases, which is defined as the amount of Watts expended or gained in one hour. Or, taking our unit of power and multiplying it by a non-standard time unit to get a unit of energy. Yes, this means that 1 Watt-Hour is equivalent to 3600 Joules, and a generator rated at 7.5 kW should generate 7.5 kWh, or the equivalent in Joules. So we're both correct and incorrect, in a way.

Maybe this is splitting hairs a little bit, and may be less transparent for the sake of realism, but currently power and generation is documented to all be in Watts (and presumably the sibling Watt-Hour), but storage is all done and displayed in Joules. If the consensus is just to create the unit the Watt-Second, which would functionally be 1:1 with Joules, that's kind of okay? Really I just want to find out whether or not this is intentional or misunderstanding, because any data from the real world that uses Watt-Hours needs to keep this conversion in mind when translating to the Watts/Joules hybrid right now

Hirmuolio commented 1 year ago

AFAIK watt-hours are not used anywhere in the game. Quick search didn't find any hits in docs, json or code.

(almost) everything uses directly watts ands joules (via the new units::energy and units::power) or older systems that play fast and loose with raw unlabeled unmarked and uncommented watts and joules (with the assumption of 1 second intervals you usually can just treat them as same. But it gets really messy and error prone).

KKDavion commented 1 year ago

AFAIK watt-hours are not used anywhere in the game. Quick search didn't find any hits in docs, json or code.

(almost) everything uses directly watts ands joules (via the new units::energy and units::power) or older systems that play fast and loose with raw unlabeled unmarked and uncommented watts and joules (with the assumption of 1 second intervals you usually can just treat them as same. But it gets really messy and error prone).

Acknowledged. I also couldn't find any references to Watt-Hours, but the assumption was made as Joules as a measure of electricity typically isn't used in my experience.

So is the current use of Joules/Watt-Seconds a set-in-stone kind of deal, or could it be hashed out? I acknowledge that, on the user end, using Watt-Hours would be less granular and a little more confusing to people not in the know of what a Watt-Hour is. Perhaps this shouldn't be changed as far as the UX is concerned, but I just can't tell if it's bugging me because it's technically wrong, even if mechanically/mathematically it works/checks out, and is just a little more annoying on my end.

Also, ignore my earlier conjecture about vhp & that ratio. Reading more into it, 755:1 is about correct for Watts to Horsepower so I'm assuming that's what that's for and is all kosher. Looks like it's not an issue of the actual generation of power, but how it's represented in units.

Hirmuolio commented 1 year ago

Watts and joules are the most sensible units to be used in code side of things. SI units just are easiest for math point of view and consistently using same units for everything is very helpful. UI could display whatever. But same units for everything has major advantages as energy can be freely used/moved in various systems (vehicle, fuel, engines, generators, items, bionics). It would be realy confusing if batteries had their contents in watt-hours but items had their power consumption in joules per use. Representing energy per activation in milliwatt-hours per use would be pretty weird too.

KKDavion commented 1 year ago

Understood. I'll take this as a lesson in reality simulation vs game design then ;;;

I think I'll close this issue since the actual problem at hand isn't really a problem, and go ahead with checking power numbers for batteries, tools, & generators for sanity with the joules/watts distinction in mind.

Raikiri commented 1 year ago

Just for context, CMB's show stored internal energy in Joules, revealing that they are indeed the units used. Watt-hour is not a SI unit, so I definitely see an argument why Joules are used instead.

That being said, I do find it odd that small batteries in CDDA store about 100J, because real-life usual AA batteries store about 10kJ, which is about 100 times more than that. Correct me if I'm wrong here.

KKDavion commented 1 year ago

Yeah, I totally understand the reasoning behind using Joules/Watts as a standard, but my monkey brain just dislikes not seeing capacity in Watt-Hours.

As for batteries, that's a somewhat separate topic I'm researching into right now, but you're not wrong in that batteries in CDDA store a weird amount of charge. Long story short (and skipping over a lot of details about discharge curves & nominal vs. max/min operating voltage), battery capacity in real life depends on the current voltage drawn of the load on the circuit, and whether that load is constant. In broad strokes, however, a AA Duracell Coppertop at 1.5V & 2000 mAh (something like that, notes on the internet vary), would sorta-not-really contain 3 Watt-Hours or 10.8kJ. I can't for the life of me find the source in the docs, but IIRC 1 battery charge is actually 1 Kilojoule, not just 1 Joule, which means that a light battery (if it's based off of a AA) is actually 10x larger than it should be, and most items are probably drawing way too much charge.

Raikiri commented 1 year ago

Car battery in CDDA has 3000 charges and according to some random internet posts https://www.quora.com/How-many-joules-are-in-a-car-battery it should have 2.6MJ, which sort of matches if you assume 1 CDDA unit of energy = 1KJ. It also matches with the hitchhiker's guide that lists charges in KJ: https://nornagon.github.io/cdda-guide/#/item/battery_car

However, this does mean that CDDA light batteries have 10x-30x greater capacity than a single AA cell. Which maybe makes sense if you assume that the "small battery" is actually a bunch of them taped together or a li-ion pouch.

So I'd say all the values we've looked at so far make reasonable sense. There are some crazy outliers such as vehicle water purifiers that consume ungodly amounts of energy in short amount of time, but I don't think matters too much.

KKDavion commented 1 year ago

Aye, vehicle batteries were all touched in #57193, and the notes seem all good so I'm generally not looking into them myself.

And... huh. You're actually right, I hadn't done the math on this yet, but a AA battery is ~14mm diameter by 50mm height, which is 0.00245L in volume. If that's the case, then the description on the item should be changed, but the item could likely stay as it is.