Jump to content

Accurate Thermal Conductivity Calculator in C++


Recommended Posts

Sorry for creating too many threads but this one deserves it's own and may receive updates.  Basically I wrote a c++ program based on the post this Yothiel guy made and I confirmed that this is still accurate and I included it in the files.  So far I only did it for the cell to cell thermal transfer and only for 2 cells at a time so this is pretty limited.  I think I will probably expand this. But basically what I did was I created 2 1000kg igneous rock tiles in an insulated cell, one at 500K, one at 1500K.  And the C++ program I wrote accurately predicted the temperatures using Yothiel's thread as a guide.  Basically I watched the schedule timer and created the cells at the start of the cycle and paused it and end of the cycle to the best of my timing abilities and it was accurate not even off by 0.1 degrees so within the games limits it is accurate.  I tested it another time with solid and gas too and it worked and should note that Yothiel's post mentions "(S1[type of cell 2] * S2[type of cell 1]" so for this you only want to multiply by 25 not 25*25.

 

heatcalculator.jpg

heatcalculator2.jpg

 

 

ONItemp.cpp

Link to comment
Share on other sites

Excuse me but could someone perhaps decrypt the linked thread?

I'm seriously glad that someone is able to accurately predict this very odd mechanic but I am afraid that most will simply not understand or just skip it. One should be able write a much more compact and concise version since, welp, that's what I usually like to do and while mine may be still long posts, they are neither as long nor as blocky. Never even mind small paragraphs, those single sentences end even before reaching the halfway/width point.

I implore someone to consider doing this since, well, I'm currently sick and a headache makes it quite tough to focus on "dividing and conquering" (cutting away explanation, elaboration and justification, oh and symbolization, I like numbers, they are good playmates!).

Link to comment
Share on other sites

Look that thread may be tedious, but I think there is no interesting or more concise way to describe what amounts to a bunch of calculations.  I mean we're talking a one line comment followed by the actual mathematical equation itself.  I think the defining of quantities beforehand to make the later content more compact is very necessary, see if you can break something down into smaller bites, that makes it easier to understand and you kind of have to do that if you have so many if statements.

But I will try, to a first approximation the (Thermal Conductivity*Temperature Difference)/(ticks per second) tells you how much energy is going to be transferred per tick, the in game value you see is accurate if you convert it from watts to kilowatts, even though the description in the game says it's in watts.  While the heat capacity of the cell (Mass*Specific Heat Capacity) tells you how much this energy is going to change the temperature of the cell.  So the amount of energy transferred decreases overtime as the temperatures equalize.  That's a first approximation there are a bunch of conditional statements in there too.  But to make this more concrete, for 2 1000kg tiles of Igneous at 500 and 1500 degrees respectively we have a thermal conductivity of 2.0 and a specific heat capacity of 1.0 for Igneous.  So plugging that in you have (2.0TC*1000K)/(1.0SHC*1000kg*5ticks) = 0.4 degrees for the first tick, which is accurate but if then numbers were different it might be modified by one of the many if then, min, or clamping operations.

There's a bunch of other multipliers and conditions that modify this, insulated tiles, 25*multipliers for liquid to liquid or solid to gas.  That thread describes the precise process.  I'm going to have to modify my code for multiple cells and do more testing, implement the other scenarios like buildings and stuff.

Oh and i just spotted a bug, that apparently didn't effect the change the numbers in my particular experiment.  I forgot to actually update the thermal energy for the cells see I initially defined and used  a bunch of variables in the function and then to clean it up created variables in the class without changing all of the code completely.  I edited the OP to include the updated version.

Link to comment
Share on other sites

Some details 

 

Surface-Area multipliers

It's not always 25 or 1. The following document will help you.

https://docs.google.com/spreadsheets/d/1RW--zk9UniOmwDMqCM-0LPvhNatqRr3bHswu2aPQCjk/edit#gid=1792370217

 

Quote

the infamous factor of 5 for all building-related heat transfers

Still, it's not always true. You can decompile Assembly-CSharp.dll, find the function CreateBuildingDef, then you will see

float temperature_modification_mass_scale = 0.2f

  • In very few examples, the parameter equals to 1,  for example steam turbine.
  • Though this parameter of solid tiles is 0.2, you should still use 1. Because solid tiles are regarded as cells, instead of buildings
Link to comment
Share on other sites

2 hours ago, R9MX4 said:

Some details 

 

Surface-Area multipliers

It's not always 25 or 1. The following document will help you.

https://docs.google.com/spreadsheets/d/1RW--zk9UniOmwDMqCM-0LPvhNatqRr3bHswu2aPQCjk/edit#gid=1792370217

 

Still, it's not always true. You can decompile Assembly-CSharp.dll, find the function CreateBuildingDef, then you will see

float temperature_modification_mass_scale = 0.2f

  • In very few examples, the parameter equals to 1,  for example steam turbine.
  • Though this parameter of solid tiles is 0.2, you should still use 1. Because solid tiles are regarded as cells, instead of buildings

I don't have access to that document (edit: I require being granted permission) and I couldn't find the CreateBuildingDef function, it's like searching for a needle in a haystack and I tried to decompile the C simdll like the guy in the thread said and that is just completely unreadable.

Link to comment
Share on other sites

2 minutes ago, The Plum Gate said:

I use ILSpy portable when I feel the need to know.

I meant no disrespect.  Snooze != useless.

Oh I didn't mean to imply that you did.  But in that thread Yothiel siad he used a C decompiler to decompile the sim.dll file and the .net decompilers wouldn't read it but a C decompiler did and then proceded to spit out a bunch of extremely difficult to parse code that is completely unreadable.  I think I'm just going to stick to the Yothiel thread, it has gotten me accurate results so far and I feel like this decompiler stuff (which btw this is the first time I've decompiled a program) has been a waste of time.

cdecompile.jpg

Link to comment
Share on other sites

Ah, I think the take away here from ILSpy is one of configuration parameters.

That's interesting regarding the sim.dll. It has been my experience that c decompilers usually do spit out a bunch of c object code garbage. Now days you can mix mono interfaces with c object files.

IMO, if there's really a need to decompile a dll, it should be looked at through multiple decompilers or at the very least - intelligent ones.

Snowman might be useful for looking at machine code - look to linux-based  c, c++ decompilers instead,

Link to comment
Share on other sites

1 hour ago, MustardWarrior said:

I don't have access to that document (edit: I require being granted permission) and I couldn't find the CreateBuildingDef function, it's like searching for a needle in a haystack and I tried to decompile the C simdll like the guy in the thread said and that is just completely unreadable.

Looks like I close the permission by mistake.

Please try it again.

https://docs.google.com/spreadsheets/d/1RW--zk9UniOmwDMqCM-0LPvhNatqRr3bHswu2aPQCjk/edit?usp=sharing

Link to comment
Share on other sites

26 minutes ago, R9MX4 said:

Looks like I close the permission by mistake.

Please try it again.

https://docs.google.com/spreadsheets/d/1RW--zk9UniOmwDMqCM-0LPvhNatqRr3bHswu2aPQCjk/edit?usp=sharing

It's useful to have a table like that should I actually decide to make this program more user friendly and the flow rates look useful if I ever find any information on pressure changes.  Okay so at least for cells it does look like the multiplier is always 1 or 25 except for genetic ooze and crushed ice but my program was wrong.  Okay so apparently the multiplier is 25*25 for liquids, but for solids when interacting with a gas is 1 while for gasses interacting with a solid iit s 25.  So you have gas-solid interactions have a 25x multiplier while liquid-liquid have a 25*25x multiplier.  So his math equation is right but his description was a bit vague on gasses-solid being 25 while solid-gas being 1.  Alright I'll update the .cpp file again.

Link to comment
Share on other sites

Hey, nice to see that this old investigation of mine can still help people. When I started it, before we had proper automation, I was hell-bent on making correctly dimensioned radiators for my colonies. I remember doing a lot research in debug mode, then started digging into the code itself when I wasn't able to make sense of my observations! Now, I'd probably just slap together some automated AC system and call it a day ;)

R9MX4 already helped understanding that 25 vs 625 multiplier stuff, which was indeed caused by the solid<=>gas coefficients being asymetric. I'm somewhat surprised you were able to get accurate results using my works, since I remember something about using a log-average instead of the minimum conductivity in 2018, but I guess they may have rolled back that change. Aside from that, I'd expect errors for same-element gas or liquids tiles because I never covered the functions handling the additional stuff done on fluids..

MustardWarrior > I didn't decompile the DLL, I only disassembled it and interpreted the results. The "disassembly" is basically the "Instructions" window you have in Snowman. Disassembly interpretation & reverse engineering is very tedious and slow, especially with more complex languages (C was simple enough, I may not have gone that far with compiled C++), so you better arm yourself with courage and patience if you want to have a try at it someday!

If anyone ever wants to write a more readable version of that thread, feel free to do so! I know that I tend to get very verbose, especially in English since it's not my native language, Even so, I probably cut a lot of chatter, but couldn't commit myself to just write a naked version because I had some catharsis to do after discovering all this stuff over the weeks! :D
I think the simplest would be to focus on writing the pseudo-code, then gather all the info about "game/gamefile values" vs "pseudo-code values" equivalences somewhere else, but you may be unable to cut the wording past a certain point.

Link to comment
Share on other sites

@Yothiel. Your old thread was one of the most useful things for me when I wanted to finally understand the game mechanics.  Thanks for it.  I joined the forums too late to thank you there, so THANK YOU.  Your line,

  • if |ΔQ'| < 1.0E-4, no transfer is done,

started my obsession with chlorine clamping a steam turbine. This got me started on all kinds of other crazy contraptions.  Thanks so much for that post. 

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...