public ScalarValue GetFuelFlow() { // fuelFlowGui is overidden by RealFuels to display massflow, so work around it. if (HasRealFuels) { double fuelFlow = 0; foreach (ModuleEngines e in FilteredEngineList) { // currentAmount does not update when there is no fuel flow, so only update when fuel is flowing. if (e.fuelFlowGui > 0.0f) { foreach (Propellant p in e.propellants) { fuelFlow += p.currentAmount / Time.fixedDeltaTime; } } } return(fuelFlow); } else { // Stock just shows flow. return(FilteredEngineList.Sum(e => e.fuelFlowGui)); } }
public ScalarValue GetIspAtAtm(ScalarValue atmPressure) { // Get the combined flow rate of all engines double flowRate = FilteredEngineList.Sum(e => e.GetThrust(atmPressure, operational: false) / e.GetIsp(atmPressure.GetDoubleValue())); // Divide combined thrust by combined flow rate to get a correct Isp for all engines combined return(flowRate > 0 ? FilteredEngineList.Sum(e => e.GetThrust(atmPressure, operational: false)) / flowRate : 0); }
public ScalarValue GetSeaLevelIsp() { // Get the combined flow rate of all engines double flowRate = FilteredEngineList.Sum(e => e.GetThrust(1, operational: false) / e.atmosphereCurve.Evaluate(1)); // Divide combined thrust by combined flow rate to get a correct Isp for all engines combined return(flowRate > 0 ? FilteredEngineList.Sum(e => e.GetThrust(1, operational: false)) / flowRate : 0); }
// The following functions calculate the correct Isp for multiple engines, regardless of individual performance. // Isps cannot be simply summed or averaged if the engines have different thrust output, // however mass flow and thrust can be summed, so these are used to derive a combined Isp. // This is based on the identity MassFlow = Thrust / (g0 * Isp), with g0 factored out. public ScalarValue GetIsp() { // Get the combined flow rate of all engines double flowRate = FilteredEngineList.Sum(e => e.GetThrust(operational: false) / e.realIsp); // Divide combined thrust by combined flow rate to get a correct Isp for all engines combined return(flowRate > 0 ? FilteredEngineList.Sum(e => e.GetThrust(operational: false)) / flowRate : 0); }
private void InitializeSuffixes() { AddSuffix("ACTIVATE", new NoArgsVoidSuffix(Activate)); AddSuffix("SHUTDOWN", new NoArgsVoidSuffix(Shutdown)); AddSuffix("THRUSTLIMIT", new ClampSetSuffix <ScalarValue>(() => FilteredEngineList.Average(e => e.thrustPercentage), value => RawEngineList.ForEach(e => e.thrustPercentage = value), 0f, 100f, 0f, "thrust limit percentage for this engine")); AddSuffix("MAXTHRUST", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.GetThrust()))); AddSuffix("THRUST", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.finalThrust))); AddSuffix("FUELFLOW", new Suffix <ScalarValue>(GetFuelFlow)); AddSuffix("MAXFUELFLOW", new Suffix <ScalarValue>(GetMaxFuelFlow)); AddSuffix("MASSFLOW", new Suffix <ScalarValue>(GetMassFlow)); AddSuffix("MAXMASSFLOW", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.maxFuelFlow))); AddSuffix("ISP", new Suffix <ScalarValue>(GetIsp)); AddSuffix(new[] { "VISP", "VACUUMISP" }, new Suffix <ScalarValue>(GetVacuumIsp)); AddSuffix(new[] { "SLISP", "SEALEVELISP" }, new Suffix <ScalarValue>(GetSeaLevelIsp)); AddSuffix("FLAMEOUT", new Suffix <BooleanValue>(() => FilteredEngineList.Any(e => e.flameout))); AddSuffix("IGNITION", new Suffix <BooleanValue>(() => FilteredEngineList.Any(e => e.getIgnitionState))); AddSuffix("ALLOWRESTART", new Suffix <BooleanValue>(() => FilteredEngineList.Any(e => e.allowRestart))); AddSuffix("ALLOWSHUTDOWN", new Suffix <BooleanValue>(() => FilteredEngineList.Any(e => e.allowShutdown))); AddSuffix("THROTTLELOCK", new Suffix <BooleanValue>(() => FilteredEngineList.All(e => e.throttleLocked))); AddSuffix("ISPAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetIspAtAtm)); AddSuffix("MAXTHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetMaxThrustAtAtm)); AddSuffix("AVAILABLETHRUST", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.GetThrust(useThrustLimit: true)))); AddSuffix("AVAILABLETHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetAvailableThrustAtAtm)); AddSuffix("POSSIBLETHRUST", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.GetThrust(useThrustLimit: true, operational: false)))); AddSuffix("POSSIBLETHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetPossibleThrustAtAtm)); AddSuffix("MAXPOSSIBLETHRUST", new Suffix <ScalarValue>(() => FilteredEngineList.Sum(e => e.GetThrust(operational: false)))); AddSuffix("MAXPOSSIBLETHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(atm => FilteredEngineList.Sum(e => e.GetThrust(atm, operational: false)))); AddSuffix("CONSUMEDRESOURCES", new Suffix <Lexicon>(GetConsumedResources, "A List of all resources consumed by this engine")); //MultiMode features AddSuffix("MULTIMODE", new Suffix <BooleanValue>(() => MultiMode)); AddSuffix("MODES", new Suffix <ListValue>(GetAllModes, "A List of all modes of this engine")); AddSuffix("MODE", new Suffix <StringValue>(GetCurrentMode)); AddSuffix("TOGGLEMODE", new NoArgsVoidSuffix(ToggleMode)); AddSuffix("PRIMARYMODE", new SetSuffix <BooleanValue>(GetRunningPrimary, SetRunningPrimary)); AddSuffix("AUTOSWITCH", new SetSuffix <BooleanValue>(GetAutoSwitch, SetAutoswitch)); //gimbal interface AddSuffix("HASGIMBAL", new Suffix <BooleanValue>(() => HasGimbal)); AddSuffix("GIMBAL", new Suffix <GimbalFields>(GetGimbal)); // RealFuels stuff AddSuffix("ULLAGE", new Suffix <BooleanValue>(GetUllage)); AddSuffix("FUELSTABILITY", new Suffix <ScalarValue>(GetFuelStability)); AddSuffix("PRESSUREFED", new Suffix <BooleanValue>(GetPressureFed)); AddSuffix("IGNITIONS", new Suffix <ScalarValue>(GetIgnitions)); AddSuffix("MINTHROTTLE", new Suffix <ScalarValue>(GetMinThrottle)); AddSuffix("CONFIG", new Suffix <StringValue>(GetEngineConfig)); }
public ScalarValue GetPossibleThrustAtAtm(ScalarValue atmPressure) { return(FilteredEngineList.Sum(e => e.GetThrust(atmPressure, useThrustLimit: true, operational: false))); }
public ScalarValue GetAvailableThrustAtAtm(ScalarValue atmPressure) { return(FilteredEngineList.Sum(e => e.GetThrust(atmPressure, useThrustLimit: true))); }
public ScalarValue GetMaxThrustAtAtm(ScalarValue atmPressure) { return(FilteredEngineList.Sum(e => e.GetThrust(atmPressure))); }