Jump to content

[BUG] Problem with ResourceHarvester atmospheric rate (proposed solution attached)


Recommended Posts

This is a weird bug to report because it's for an existing module, but there is no stock part that makes use of harvesting resources from the atmosphere. Is this a report for stock or for modded?

Regardless, I put this up over on github, but am placing it here just in the hopes of getting more eyes on this and having people sanity check what I'm doing. I model how plants grow for my day job; I don't usually mess around with things involving the ideal gas law and how it applies to to atmospheres on other planets.

----------------------------------------------

I think the code for HarvesterType == 2 in REGO_ModuleResourceHarvester.cs is incorrectly calculating the rate. Even though Regolith is rolled into stock KSP, now, I hope this makes sense and it helps fix things. Sorry for the length, but it's hard to explain. Example calcs at https://www.dropbox.com/s/ulgrl91vkm63s4i/REGO_ModuleResourceHarvester.xlsx?dl=0

Right now, the rate units atmospheric collection are incorrect given how a planetary resource is configured. I'm not a unity guy, I mainly use python, but instead of

var rate = abundance * Efficiency;

I think you need something like the following:

**Step 1**: either calculate the L/mol of a gas at STP for Kerbin or just hard code it.

The calculate is (n*R*T)/P=V; where n=1, P=101.325kPa, R=8.314, and K=273.16. V is in L

V=22.4135 L/mol, but it's easier to just say 22.4 L/mol

**Step 2**: use the harvested resource's density to estimate it's molecular weight

For example's sake, let's use CO2 from the community resource pack.

DensityCO2=0.000001951tonne/L at STP. It's easier to work with in g/L, so: 1.951 g/L

The density of the gas multplied by the ideal gas L/mol will give an approximation of the gas' molecular weight at STP:

1.951g/L * 22.4 L/mol = 43.7024 g/mol (the real-world value is 44.01 g/mol, so we're in the ballpark)

**Step 3**: calculate the number of moles in a given sample of atmosphere.

Let's assume a part is sucking in 1L of atmosphere, so V=1. Let's also assume the percent CO2 in the atmosphere is 1.5% by volume (value coming from community resource pack).

That means 1.5% of the 1L atmosphere is CO2, so 0.015L

(P*V)/(R*T)=n; (101.325*0.015)/(8.314*273.16)=n; n=0.000669 mol CO2 in 1 L of atmosphere.

**Step 4**: calculate the g CO2.

Use the moles calculated in step 3 and the g/mol estimated in step 2

0.000669 mol CO2 * 43.7024 g/mol CO2= 0.02924 g CO2

**Step 5**: calculate the L of CO2 at STP in the sample of atmosphere.

Doing this calculation using the density of the resource at STP of Kerbin is critical because of the gas law.

DensityCO2 at STP=1.951g/L

0.02924g CO2/(1.951g/L)=0.01499 L CO2 in the sample.

Edit: yes, the value 0.01499L is the same (with rounding errors) to the 0.015L of CO2 in the percentage calculation. Which is excellent, because this calculation was done at STP, so it should be the same value. As you change the atmospheric pressure or the temp, the value will change

I'm sure you can see the volume of the sample would be the rate that a part like a ATMIntake is taking in atmosphere, and it can be adjusted by the part's efficiency.

I'm not really used to explaining something like this without a whiteboard or something, so I'm sorry fror the wordiness. I put an excel sheet showing example calculations of the steps above at https://www.dropbox.com/s/ulgrl91vkm63s4i/REGO_ModuleResourceHarvester.xlsx?dl=0

Doing the above calculations allows you to get the amount of gas in liters as the pressure and/or temp changes. So as a ship's altitude changes, or the temp of the atmosphere changes over the course of the day, it should result in reasonable changes in the amount of gas harvested.

I just threw this together quickly, so I happily admit I might have missed something critical.

Edited by seanth
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...