/// <summary> /// Add an element to the sequence that begins at time and evolves based on the orbit data provided. /// /// Orbit elements must be added in increasing time order. /// </summary> /// <param name="time"></param> /// <param name="orbitData"></param> /// <param name="body"></param> /// <param name="centerBody"></param> /// <param name="callback">(Optional) Method to call when sequence starts</param> /// <returns></returns> public OrbitUniversal AppendElementOrbitData(double time, OrbitData orbitData, NBody body, NBody centerBody, ElementStarted callback) { if (BadTime(time)) { return(null); } KeplerElement ke = new KeplerElement { timeStart = time, returnToGE = false, callback = callback }; OrbitUniversal orbit = orbitsGO.AddComponent <OrbitUniversal>(); orbit.centerNbody = centerBody; orbit.SetNBody(body); orbit.InitFromOrbitData(orbitData, time); orbit.evolveMode = OrbitUniversal.EvolveMode.KEPLERS_EQN; ke.orbit = orbit; keplerElements.Add(ke); return(orbit); }
/// <summary> /// Add an element to the sequence using r0/v0/t0 initial conditions. /// /// Position and velocity are with respect to the center body (NOT world/physics space!). /// /// Orbit segements must be added in increasing time order. /// </summary> /// <param name="r0"></param> /// <param name="v0"></param> /// <param name="time"></param> /// <param name="relativePos"></param> /// <param name="body"></param> /// <param name="centerBody"></param> /// <param name="callback">(Optional) Method to call when sequence starts</param> /// <returns></returns> public OrbitUniversal AppendElementRVT(Vector3d r0, Vector3d v0, double time, bool relativePos, NBody body, NBody centerBody, ElementStarted callback) { if (BadTime(time)) { return(null); } KeplerElement ke = new KeplerElement { timeStart = time, callback = callback, returnToGE = false }; OrbitUniversal orbit = orbitsGO.AddComponent <OrbitUniversal>(); orbit.centerNbody = centerBody; orbit.SetNBody(body); orbit.InitFromRVT(r0, v0, time, centerBody, relativePos); orbit.evolveMode = OrbitUniversal.EvolveMode.KEPLERS_EQN; ke.orbit = orbit; keplerElements.Add(ke); return(orbit); }
/// <summary> /// Executes the element. /// </summary> /// <param name="element">The element.</param> /// <exception cref="EngineException"> /// The element '{element.Name}' cannot be executed. This task was aborted. /// or /// The element {element.Name} (id: {element.InstanceID}) was not executed cause one or more errors occurs. This task was aborted. /// or /// The element {element.Name} (id: {element.InstanceID}) was executed but one or more warning occurs. This task was aborted. /// </exception> public void ExecuteElement(IEngineElement element) { // Check if element can be executed if (!element.CanBeExecuted()) { element.AddMessage($"The element cannot be executed.", MessageSeverity.Error); if (element.ParentTask.FailIfAnyElementHasError) { throw new EngineException(logger, $"The element cannot be executed. This task was aborted."); } else { return; } } // Execute element if (ElementStarted != null) { ElementStarted.Invoke((Guid)element.EntityId, (Guid)element.InstanceID); } element.Start(); // stop element element.Stop(); if (element.HasErrors) { element.AddMessage($"The element (instance: {element.InstanceID}) was not executed cause one or more errors occurs.", MessageSeverity.Error); if (element.ParentTask.FailIfAnyElementHasError) { if (ElementFinished != null) { ElementFinished.Invoke((Guid)element.EntityId, (Guid)element.InstanceID, false); } throw new EngineException(logger, $"The element (instance: {element.InstanceID}) was not executed cause one or more errors occurs. This task was aborted."); } } else if (element.HasWarnings) { element.AddMessage($"The element (instance: {element.InstanceID}) was executed but one or more warning occurs.", MessageSeverity.Warning); if (element.ParentTask.FailIfAnyElementHasWarning) { if (ElementFinished != null) { ElementFinished.Invoke((Guid)element.EntityId, (Guid)element.InstanceID, false); } throw new EngineException(logger, $"The element (instance: {element.InstanceID}) was executed but one or more warning occurs. This task was aborted."); } } if (ElementFinished != null) { ElementFinished.Invoke((Guid)element.EntityId, (Guid)element.InstanceID, true); } }
/// <summary> /// Add an element using an existing OrbitUniversal instance /// /// Orbit elements must be added in increasing time order. /// </summary> /// <param name="orbitU"></param> /// <param name="callback">(Optional) Method to call when sequence starts</param> public void AppendElementExistingOrbitU(OrbitUniversal orbitU, ElementStarted callback) { if (BadTime(orbitU.GetStartTime())) { return; } KeplerElement ke = new KeplerElement { timeStart = orbitU.GetStartTime(), returnToGE = false }; ke.orbit = orbitU; ke.callback = callback; keplerElements.Add(ke); }