Class SimulationEngine

java.lang.Object
gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine
All Implemented Interfaces:
AutoCloseable

public final class SimulationEngine extends Object implements AutoCloseable
A representation of the work remaining to do during a simulation, and its accumulated results.
  • Constructor Details

    • SimulationEngine

      public SimulationEngine(LiveCells initialCells)
  • Method Details

    • init

      public void init(Map<String,gov.nasa.jpl.aerie.merlin.protocol.model.Resource<?>> resources, gov.nasa.jpl.aerie.merlin.protocol.model.TaskFactory<gov.nasa.jpl.aerie.merlin.protocol.types.Unit> daemons) throws Throwable
      Initialize the engine by tracking resources and kicking off daemon tasks.
      Throws:
      Throwable
    • getElapsedTime

      public gov.nasa.jpl.aerie.merlin.protocol.types.Duration getElapsedTime()
    • step

      public SimulationEngine.Status step(gov.nasa.jpl.aerie.merlin.protocol.types.Duration simulationDuration) throws Throwable
      Step the engine forward one batch.
      Throws:
      Throwable
    • scheduleTask

      public <Output> SpanId scheduleTask(gov.nasa.jpl.aerie.merlin.protocol.types.Duration startTime, gov.nasa.jpl.aerie.merlin.protocol.model.TaskFactory<Output> state)
      Schedule a new task to be performed at the given time.
    • trackResource

      public <Dynamics> void trackResource(String name, gov.nasa.jpl.aerie.merlin.protocol.model.Resource<Dynamics> resource, gov.nasa.jpl.aerie.merlin.protocol.types.Duration nextQueryTime)
      Register a resource whose profile should be accumulated over time.
    • invalidateTopic

      public void invalidateTopic(gov.nasa.jpl.aerie.merlin.protocol.driver.Topic<?> topic, gov.nasa.jpl.aerie.merlin.protocol.types.Duration invalidationTime)
      Schedules any conditions or resources dependent on the given topic to be re-checked at the given time.
    • extractNextJobs

      public JobSchedule.Batch<SimulationEngine.JobId> extractNextJobs(gov.nasa.jpl.aerie.merlin.protocol.types.Duration maximumTime)
      Removes and returns the next set of jobs to be performed concurrently.
    • performJobs

      public SimulationEngine.StepResult performJobs(Collection<SimulationEngine.JobId> jobs, LiveCells context, gov.nasa.jpl.aerie.merlin.protocol.types.Duration currentTime, gov.nasa.jpl.aerie.merlin.protocol.types.Duration maximumTime) throws SpanException
      Performs a collection of tasks concurrently, extending the given timeline by their stateful effects.
      Throws:
      SpanException
    • performJob

      public void performJob(SimulationEngine.JobId job, TaskFrame<SimulationEngine.JobId> frame, gov.nasa.jpl.aerie.merlin.protocol.types.Duration currentTime, gov.nasa.jpl.aerie.merlin.protocol.types.Duration maximumTime, SimulationEngine.ResourceUpdates resourceUpdates) throws SpanException
      Performs a single job.
      Throws:
      SpanException
    • stepTask

      public void stepTask(TaskId task, TaskFrame<SimulationEngine.JobId> frame, gov.nasa.jpl.aerie.merlin.protocol.types.Duration currentTime) throws SpanException
      Perform the next step of a modeled task.
      Throws:
      SpanException
    • updateCondition

      public void updateCondition(ConditionId condition, TaskFrame<SimulationEngine.JobId> frame, gov.nasa.jpl.aerie.merlin.protocol.types.Duration currentTime, gov.nasa.jpl.aerie.merlin.protocol.types.Duration horizonTime)
      Determine when a condition is next true, and schedule a signal to be raised at that time.
    • updateResource

      public void updateResource(ResourceId resourceId, TaskFrame<SimulationEngine.JobId> frame, gov.nasa.jpl.aerie.merlin.protocol.types.Duration currentTime, SimulationEngine.ResourceUpdates resourceUpdates)
      Get the current behavior of a given resource and accumulate it into the resource's profile.
    • close

      public void close()
      Resets all tasks (freeing any held resources). The engine should not be used after being closed.
      Specified by:
      close in interface AutoCloseable
    • unscheduleAfter

      public void unscheduleAfter(gov.nasa.jpl.aerie.merlin.protocol.types.Duration duration)
    • getDirectiveDetailsFromSpan

      public DirectiveDetail getDirectiveDetailsFromSpan(gov.nasa.jpl.aerie.merlin.protocol.driver.Topic<gov.nasa.jpl.aerie.types.ActivityDirectiveId> activityTopic, Iterable<MissionModel.SerializableTopic<?>> serializableTopics, SpanId spanId)
      Get an Activity Directive Id from a SpanId, if the span is a descendent of a directive.
    • computeActivitySimulationResults

      public SimulationEngine.SimulationActivityExtract computeActivitySimulationResults(Instant startTime, gov.nasa.jpl.aerie.merlin.protocol.driver.Topic<gov.nasa.jpl.aerie.types.ActivityDirectiveId> activityTopic, Iterable<MissionModel.SerializableTopic<?>> serializableTopics)
    • computeActivitySimulationResults

      public SimulationEngine.SimulationActivityExtract computeActivitySimulationResults(Instant startTime, gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine.SpanInfo spanInfo)
      Computes only activity-related results when resources are not needed
    • computeResults

      public SimulationResults computeResults(Instant startTime, gov.nasa.jpl.aerie.merlin.protocol.driver.Topic<gov.nasa.jpl.aerie.types.ActivityDirectiveId> activityTopic, Iterable<MissionModel.SerializableTopic<?>> serializableTopics, SimulationResourceManager resourceManager)
      Compute a set of results from the current state of simulation.
    • computeResults

      public SimulationResults computeResults(Instant startTime, gov.nasa.jpl.aerie.merlin.protocol.driver.Topic<gov.nasa.jpl.aerie.types.ActivityDirectiveId> activityTopic, Iterable<MissionModel.SerializableTopic<?>> serializableTopics, SimulationResourceManager resourceManager, Set<String> resourceNames)
    • getSpan

      public SimulationEngine.Span getSpan(SpanId spanId)
    • spanIsComplete

      public boolean spanIsComplete(SpanId spanId)
    • duplicate

      public SimulationEngine duplicate()
    • peekNextTime

      public Optional<gov.nasa.jpl.aerie.merlin.protocol.types.Duration> peekNextTime()
    • combineTimeline

      public TemporalEventSource combineTimeline()
      Create a timeline that in the output of the engine's reference timeline combined with its expanded timeline.