private void RunSimulation(int maxSteps = 10000) { SimulationSteps.Clear(); OutputByStage.Clear(); Output = new OutputParams(); OutputOrbit = new OrbitOutput(); SimulationStep prev = null; SimulationStep current = CreateFirstStep(); SimulationSteps.Add(current); for (int i = 0; i < maxSteps; i++) { WriteToLog(current.GetLogMessage()); prev = current; current = RunStep(prev); var output = CheckOutput(prev, current); if (current.Stage > Launcher.Stages.Count) { Output = output; break; } SimulationSteps.Add(current); } CalculateOutputOrbit(); if (PitchProgram.Tmax != Output.T) { PitchProgram.Tmax = Output.T; RunSimulation(maxSteps); return; } OutputByStage.ForEach(os => WriteToLog(os.GetLogMessage())); WriteToLog(Output.GetLogMessage()); WriteToLog(OutputOrbit.GetLogMessage()); }
private OutputParams CheckOutput(SimulationStep prev, SimulationStep current) { if (prev == null || prev.Stage == current.Stage) { return(null); } var stageOutput = new OutputParams(); stageOutput.T = current.T; stageOutput.Index = current.Index; stageOutput.CV = current.CV; // ? stageOutput.Stage = prev.Stage; OutputParams prevStageOutput = null; if (prev.Stage > 1) { prevStageOutput = OutputByStage[prev.StageIndex - 1]; stageOutput.CVdelta = stageOutput.CV - prevStageOutput.CV; } stageOutput.V = current.Velocity.V; stageOutput.Vx = current.Velocity.Vxabs; stageOutput.Vy = current.Velocity.Vy; stageOutput.H = current.Coordinates.Altitude / 1000.0; stageOutput.MassT = current.M / 1000.0; stageOutput.Pitch = current.Pitch.Thrust; OutputByStage.Add(stageOutput); // TODO : Stage, CVreserve? return(stageOutput); }