| Author | djarvis <email> |
|---|---|
| Date | 2024-12-04 00:21:54 GMT-0800 |
| Commit | 4e15532b121379fd567ee23097c18d998c2b0304 |
| Parent | 3cb38eb |
| Delta | 58 lines added, 34 lines removed, 24-line increase |
|---|
| constructor() { | ||
| this.altitudes = new Telemetry('Altitude'); | ||
| - this.azimuths = new Telemetry('Azimuth'); | ||
| this.horizontalVelocities = new Telemetry('Horizontal Velocity'); | ||
| - this.horizontalAccelerations = new Telemetry('Horizontal Acceleration'); | ||
| this.verticalVelocities = new Telemetry('Vertical Velocity'); | ||
| - this.verticalAccelerations = new Telemetry('Vertical Acceleration'); | ||
| this.masses = new Telemetry('Mass'); | ||
| + this.horizontalAccelerations = new Telemetry('Horizontal Acceleration'); | ||
| + this.verticalAccelerations = new Telemetry('Vertical Acceleration'); | ||
| this.thrustAccelerations = new Telemetry('Thrust Acceleration'); | ||
| + this.azimuths = new Telemetry('Azimuth'); | ||
| } | ||
| */ | ||
| flying() { | ||
| - return this.mass > this.dryMass && this.altitude < this.targetAltitude; | ||
| + return (this.mass > this.dryMass && this.altitude < this.targetAltitude) | ||
| + || (this.hVelocity < this.hVelocityTarget && this.altitude > 0); | ||
| } | ||
| import $ from './Selector.js'; | ||
| -document.querySelectorAll('.submit').forEach(button => { | ||
| - button.addEventListener('click', function (event) { | ||
| - event.preventDefault(); | ||
| +class Simulation { | ||
| + constructor() { | ||
| + this.rocket = new Rocket(); | ||
| + } | ||
| - const INITIAL_VELOCITY = $('#initial_velocity').val(); // Mach | ||
| - const INITIAL_LATITUDE = $('#initial_latitude').val(); // degrees | ||
| - const INITIAL_ALTITUDE = $('#initial_altitude').val(); // meters | ||
| - const TARGET_ALTITUDE = $('#target_altitude').val() * 1000.0; // meters | ||
| + inputs() { | ||
| + const initialVelocity = $('#initial_velocity').val(); | ||
| + const initialLatitude = $('#initial_latitude').val(); | ||
| + const initialAltitude = $('#initial_altitude').val(); | ||
| + const targetAltitude = $('#target_altitude').val() * 1000.0; | ||
| - const ROCKET_DIAMETER = $('#diameter').val(); | ||
| - const WET_MASS = $('#wet_mass').val(); | ||
| - const PAYLOAD_MASS = $('#payload_mass').val(); | ||
| - const DRAG_COEFFICIENT = $('#drag_coefficient').val(); | ||
| - const SPECIFIC_IMPULSE = $('#specific_impulse').val(); // seconds | ||
| + const rocketDiameter = $('#diameter').val(); | ||
| + const wetMass = $('#wet_mass').val(); | ||
| + const payloadMass = $('#payload_mass').val(); | ||
| + const dragCoefficient = $('#drag_coefficient').val(); | ||
| + const specificImpulse = $('#specific_impulse').val(); | ||
| - const blackBox = new FlightRecorder(); | ||
| - const rocket = new Rocket(WET_MASS, PAYLOAD_MASS); | ||
| - const planet = new Earth(INITIAL_LATITUDE); | ||
| + this.planet = new Earth(initialLatitude); | ||
| + this.rocket = new Rocket(wetMass, payloadMass); | ||
| + this.rocket.on(this.planet); | ||
| + this.rocket.fuselage(rocketDiameter, dragCoefficient, specificImpulse); | ||
| + this.rocket.translocate(initialLatitude, initialAltitude); | ||
| + this.rocket.apogee(targetAltitude); | ||
| + this.rocket.launch(initialVelocity); | ||
| + } | ||
| - rocket.on(planet); | ||
| - rocket.recorder(blackBox); | ||
| - rocket.fuselage(ROCKET_DIAMETER, DRAG_COEFFICIENT, SPECIFIC_IMPULSE); | ||
| - rocket.translocate(INITIAL_LATITUDE, INITIAL_ALTITUDE); | ||
| - rocket.apogee(TARGET_ALTITUDE); | ||
| - rocket.launch(INITIAL_VELOCITY); | ||
| + run() { | ||
| + const blackBox = new FlightRecorder(); | ||
| + this.rocket.recorder(blackBox); | ||
| let time = 0.0; | ||
| const TIME_STEP = 0.01; | ||
| - while (rocket.flying()) { | ||
| - rocket.fly(TIME_STEP); | ||
| - rocket.record(time); | ||
| + while (this.rocket.flying()) { | ||
| + this.rocket.fly(TIME_STEP); | ||
| + this.rocket.record(time); | ||
| time += TIME_STEP; | ||
| } | ||
| blackBox.plot(); | ||
| + } | ||
| + | ||
| + simulate() { | ||
| + this.inputs(); | ||
| + this.run(); | ||
| + } | ||
| +} | ||
| + | ||
| +// Initialize simulation | ||
| +const simulation = new Simulation(); | ||
| + | ||
| +document.querySelectorAll('input').forEach(input => { | ||
| + input.addEventListener('change', function () { | ||
| + simulation.simulate(); | ||
| + }); | ||
| +}); | ||
| + | ||
| +document.querySelectorAll('.submit').forEach(button => { | ||
| + button.addEventListener('click', function (event) { | ||
| + event.preventDefault(); | ||
| + simulation.simulate(); | ||
| }); | ||
| }); |
| Form field values are explained in the <a href="#equations">Equations</a> | ||
| section, below. | ||
| - </p><form id="calculator"><button class="submit">Simulate</button><fieldset id="mission"><legend>Mission</legend><label for="initial_velocity">Initial velocity (Mach)</label><input tabindex="3" class="variable" type="number" step="1" min="0" value="8" id="initial_velocity" name="initial_velocity"><label for="initial_latitude">Initial latitude (°)</label><input tabindex="4" class="variable" type="number" step="any" min="0" value="1.469167" id="initial_latitude" name="initial_latitude"><label for="initial_altitude">Initial altitude (m)</label><input tabindex="5" class="variable" type="number" step="1" min="0" value="6212" id="initial_altitude" name="initial_altitude"><label for="target_altitude">Target altitude (km)</label><input tabindex="6" class="variable" type="number" step="1" min="1" value="400" id="target_altitude" name="target_altitude"></fieldset><fieldset id="rocket"><legend>Rocket</legend><label for="diameter">Diameter (m)</label><input tabindex="7" class="variable" type="number" step="any" min="0" value="0.6" id="diameter" name="diameter"><label for="wet_mass">Wet mass (kg)</label><input tabindex="8" class="variable" type="number" step="1" min="1" value="250" id="wet_mass" name="wet_mass" oninput="this.value = Math.abs(this.value)"><label for="payload">Payload mass (kg)</label><input tabindex="9" class="variable" type="number" step="1" min="1" value="25" id="payload_mass" name="payload_mass" oninput="this.value = Math.abs(this.value)"><label for="drag_coefficient">Drag coefficient</label><input tabindex="10" class="variable" type="number" step="any" min="0" value="0.219" id="drag_coefficient" name="drag_coefficient"><label for="specific_impulse">Specific impulse (s)</label><input tabindex="11" class="variable" type="number" step="1" min="1" value="1700" id="specific_impulse" name="specific_impulse"></fieldset><button class="submit">Simulate</button><fieldset id="result"><legend>Result</legend><div id="plots"></div></fieldset></form><a name="equations"></a><h1>Equations</h1><p> | ||
| + </p><form id="calculator"><button class="submit">Simulate</button><fieldset id="mission"><legend>Mission</legend><label for="initial_velocity">Initial velocity (Mach)</label><input tabindex="3" class="variable" type="number" step="1" min="0" value="6" id="initial_velocity" name="initial_velocity"><label for="initial_latitude">Initial latitude (°)</label><input tabindex="4" class="variable" type="number" step="any" min="0" value="1.469167" id="initial_latitude" name="initial_latitude"><label for="initial_altitude">Initial altitude (m)</label><input tabindex="5" class="variable" type="number" step="1" min="0" value="6212" id="initial_altitude" name="initial_altitude"><label for="target_altitude">Target altitude (km)</label><input tabindex="6" class="variable" type="number" step="1" min="1" value="400" id="target_altitude" name="target_altitude"></fieldset><fieldset id="rocket"><legend>Rocket</legend><label for="diameter">Diameter (m)</label><input tabindex="7" class="variable" type="number" step="any" min="0" value="0.6" id="diameter" name="diameter"><label for="wet_mass">Wet mass (kg)</label><input tabindex="8" class="variable" type="number" step="10" min="1" value="250" id="wet_mass" name="wet_mass" oninput="this.value = Math.abs(this.value)"><label for="payload">Payload mass (kg)</label><input tabindex="9" class="variable" type="number" step="1" min="1" value="25" id="payload_mass" name="payload_mass" oninput="this.value = Math.abs(this.value)"><label for="drag_coefficient">Drag coefficient</label><input tabindex="10" class="variable" type="number" step="any" min="0" value="0.219" id="drag_coefficient" name="drag_coefficient"><label for="specific_impulse">Specific impulse (s)</label><input tabindex="11" class="variable" type="number" step="10" min="1" value="1700" id="specific_impulse" name="specific_impulse"></fieldset><fieldset id="result"><legend>Result</legend><div id="plots"></div></fieldset></form><a name="equations"></a><h1>Equations</h1><p> | ||
| This section describes equation inputs and outputs. | ||
| </p><h2>Cross-section area</h2><p> |
| <label for="initial_velocity">Initial velocity (Mach)</label> | ||
| <input tabindex="3" | ||
| - class="variable" type="number" step="1" min="0" value="8" | ||
| + class="variable" type="number" step="1" min="0" value="6" | ||
| id="initial_velocity" name="initial_velocity" /> | ||
| <label for="wet_mass">Wet mass (kg)</label> | ||
| <input tabindex="8" | ||
| - class="variable" type="number" step="1" min="1" value="250" | ||
| + class="variable" type="number" step="10" min="1" value="250" | ||
| id="wet_mass" name="wet_mass" | ||
| oninput="this.value = Math.abs(this.value)" /> | ||
| <label for="specific_impulse">Specific impulse (s)</label> | ||
| <input tabindex="11" | ||
| - class="variable" type="number" step="1" min="1" value="1700" | ||
| + class="variable" type="number" step="10" min="1" value="1700" | ||
| id="specific_impulse" name="specific_impulse" /> | ||
| </fieldset> | ||
| - | ||
| - <button class="submit">Simulate</button> | ||
| <fieldset id="result"> | ||