Upload src/sim/propulsion.ts
Browse files- src/sim/propulsion.ts +18 -0
src/sim/propulsion.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {G0,clamp} from './math';
|
| 2 |
+
import type {FlightState} from './state';
|
| 3 |
+
export const STAGES=[{dry:25000,capacity:360000,thrust:7600000,isp:300},{dry:5500,capacity:95000,thrust:1300000,isp:370}];
|
| 4 |
+
export function mass(s:FlightState){return (s.phase==='ABORT'||s.phase==='LANDED'||s.phase==='IMPACT')?6000:6000+5500+s.fuel[1]+(s.stage===0?25000+s.fuel[0]:0);}
|
| 5 |
+
export function propulsion(s:FlightState,dt:number,density:number){
|
| 6 |
+
const spec=STAGES[s.stage];
|
| 7 |
+
const enabled=s.engineArmed&&s.systems.power&&s.systems.propulsion&&s.fuel[s.stage]>0&&!['PRELAUNCH','COUNTDOWN','ABORT','LANDED','IMPACT'].includes(s.phase);
|
| 8 |
+
const target=enabled?s.throttle:0;
|
| 9 |
+
s.actualThrottle+=clamp(target-s.actualThrottle,-dt*0.8,dt*0.45);
|
| 10 |
+
if(!enabled)s.actualThrottle=0;
|
| 11 |
+
const requested=spec.thrust*s.actualThrottle*(1-0.1*Math.min(1,density/1.225));
|
| 12 |
+
const wanted=requested/(spec.isp*G0)*dt;
|
| 13 |
+
const burned=Math.min(s.fuel[s.stage],wanted);
|
| 14 |
+
s.fuel[s.stage]-=burned;s.fuelFlow=burned/dt;
|
| 15 |
+
s.thrust=s.fuelFlow*spec.isp*G0;
|
| 16 |
+
s.mass=mass(s);
|
| 17 |
+
s.engineTemperature+=(22+860*s.actualThrottle-s.engineTemperature)*dt/14;
|
| 18 |
+
}
|