Jump to content

How does KSP calculate values from .cfg files?


Recommended Posts

Didn't know where else to put this, so feel free to give this thread a kick over to the appropriate subforum if needed.

 

I use several mods, among them Near Future Propulsion. NFP has .cfg files for parts, like "ionArgon-0625-3.cfg" For the GW3 Nested Hall Effect Thruster. Therein lie values like the following:

// --- standard part parameters ---
	mass =  0.30
	dragModelType = default
	maximum_drag = 0.2
	minimum_drag = 0.3
	angularDrag = 2
	crashTolerance = 6
	breakingForce = 200
	breakingTorque = 200
	maxTemp = 1700
	emissiveConstant = 0.7
	bulkheadProfiles = size0
	tags = #LOC_NFPropulsion_ionArgon-0625-3_tags

	MODULE
	{
		name = ModuleEnginesFX
		thrustVectorTransformName = thrustTransform
		powerEffectName = run_halla1in
		runningEffectName = run_halla1
		exhaustDamage = False
		ignitionThreshold = 0.1
		minThrust = 0
		maxThrust = 8.40
		heatProduction = 125.714825

		PROPELLANT
		{
			name = ElectricCharge
			ratio =  0.687301
			DrawGauge = True
			minResToLeave = 1.0
		}
		PROPELLANT
		{
			name = ArgonGas
			DrawGauge = True
			ratio = 1.0
		}
		atmosphereCurve
		{
			key = 0 3300
			key = 1 33
			key = 2 0.001
		}
	}

From this I get thrust (8.40 kN) and ISP (3300). Then there are ratio modifiers for how much EC and Argon (custom fuel from the mod) the engine uses. I would like to know how to calculate the fuel flow/s and the EC/s from these values, if possible. All I really need is a formula of sorts, although I heard getting KSP to give straight answers as to how it calculates stuff is like interrogating the Joker.

Link to comment
Share on other sites

At face value, the ratio is exactly what you're looking for.

Take any old liquid fuel engine: it has a PROPELLANT node for LiquidFuel at a ratio of 0.9, and one for Oxidizer at a ratio of 1.1. You just add them together. For any 0.9 + 1.1= 2.0 units of mass that the engine consumes, 0.9 units will be LiquidFuel, and 1.1 units will be Oxidizer.

It's important here to read carefully: I said "any two units of mass". Because the ratio is not about the unspecific "units" of a resource in a tank*. It's about a mass flow rate. Specifically, the mass flow rate that you calculate out of the relationship between thrust produced and specific impulse. That will tell you that the engine must have a throughput of XYZ kg/s of mass per second. The ratio then simply determines what percentage of each resource makes up that mass flow. It would work just the same way with a tripropellant engine.

And then you look at an electric engine, and things get weird.

Remember what I said about the ratio being about a mass flow rate? Well... it just so happens that ElectricCharge doesn't have mass. This is why you cannot make a pure electric engine like an EMdrive in KSP simply by copying the Dawn engine and removing its XenonGas propellant, leaving EC as the only remaining input. Such an engine would produce no thrust, because it would have no mass flow. Instead, electric engines like the Dawn define a ratio between a massless propellant and one that has mass. But how can that possibly work out in math?

Look at ArgonGas in the config snippet you quoted. It has a ratio of 1.0. Can you guess what that means?

The answer: no, you can't. :P Because in this configuration, the ratio assigned to ArgonGas does not matter. It has no meaning. It can be literally any number you want it to be. The result is always the same: since EC has no mass, the engine will field its entire mass flow rate with ArgonGas alone. Whatever the calculation of thrust and Isp says the engine must consume, that's how much ArgonGas it eats. The ratio number doesn't matter. Changing it doesn't change the ArgonGas consumption in any way, shape or form. Nertea simply decided to set it as 1.0 because that is as good a number as any other... or, perhaps, a better number than any other if you intend to do multiplication and division with it.

Because now we get to EC. It also has a ratio specified. But since the entire mass flow of the engine is already fielded by ArgonGas, it should be meaningless...? Except it isn't. Because the amount of EC the engine demands supplied is calculated off of the ArgonGas flow rate - pay attention now - measured in resource units, not mass units. Everywhere else, KSP works with mass flows; but in the case of massless resources alone, it works with resource units.

 

As an example, let's take the stock Dawn engine, because I just so happen to have all the relevant numbers I need for it on the KSP wiki:

4,200 seconds of specific impulse in vacuum. We convert this weight-based unit into a mass-based unit by multiplying in standard gravity:

4,200 s * 9.80665 m/s² = 41,187.951 m/s ("effective exhaust velocity"). This is dimensionally equivalent to thrust divided by the mass flow rate, and the engine develops 2,000 N of thrust in vacuum, so:

2,000 N / x = 41,187.951 m/s   --->  2,000 N = 41,187.951 m/s * x   --->  2,000 N / 41,187.951 m/s = x   --->  x = ~0.04856 kg/s mass flow rate.

One resource unit of XenonGas is 0.1 kg, ergo: 0.04856 kg/s / 0.1 kg = 0.4856/s XenonGas consumption measured in resource units.

The Dawn engine has an ElectricCharge ratio of 1.8, so: 0.4856/s * 1.8 EC = 0.87408 EC/s .

But wait! Squad decided to define the XenonGas ratio of the Dawn engine as 0.1. So we have to additionally divide by this ratio to get our final number. See now why Nertea chose 1.0 instead, even if the number is meaningless for the propellant flow rate? :P 

0.87408 EC/s / 0.1 = 8.7408 EC/s.

And if you look it up in an unmodded game, that's exactly what the Dawn engine says it needs.

 

 

*) However, coincidentally LiquidFuel and Oxidizer have the same mass per resource unit, so it just happens to work out to the same in resource units anyway. In this case.

 

Edited by Streetwind
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...