Class FWSimSimulation

java.lang.Object
net.simplace.sim.FWSimSimulation
All Implemented Interfaces:
Callable<FWSimVarMap>

public final class FWSimSimulation extends Object implements Callable<FWSimVarMap>
A simulation is one configured run of the simulation model. It holds its own clone of the template FWSimModel of the FWSimSolution, with a FWSimVarMap containing the start values (the FWSimVariables) of this run, and the result caches of the outputs. It implements Callable, so several simulations of a session can run in parallel in an executor; call() initializes, runs and finishes the model and returns the final variable map.
Author:
Andreas Enders
  • Constructor Details

    • FWSimSimulation

      public FWSimSimulation(FWSimVarMap aVarMap, FWSimModel aModel)
      Creates a simulation: clones the template model with the given variable map. The name is taken from the variable map.
      Parameters:
      aVarMap - variable map with the start values of this simulation
      aModel - template model of the solution
  • Method Details

    • call

      public FWSimVarMap call()
      Runs the simulation: init(), the model run and finish(). An AbortSimulationException is logged as warning.
      Specified by:
      call in interface Callable<FWSimVarMap>
      Returns:
      the variable map after the model run, or null if the simulation was aborted
      See Also:
    • init

      public void init()
      Initializes the simulation run: initializes the model and notifies the session that the simulation has started. Errors are logged and passed to the session as FWSimulationErrorEvent.
      Throws:
      AbortSimulationException - if the model aborts during initialization; the simulation outputs are finished before
    • finish

      public void finish()
      Finishes the simulation run: finishes the simulation outputs, notifies the session that the simulation has ended and logs the duration. Errors are logged and passed to the session as FWSimulationErrorEvent.
    • registerResultCache

      public void registerResultCache(FWSimResultCache aCache)
      Registers a result cache of this simulation under its name.
      Parameters:
      aCache - the result cache
    • setValue

      public void setValue(String aColName, FWSimVariable.DATA_TYPE aDataType, Object aObject)
      Sets a value in the variable map of this simulation as variable of content type var, so it can be used in the model. Range errors are logged.
      Parameters:
      aColName - name of the variable
      aDataType - data type of the variable
      aObject - the value
    • getVarMap

      public FWSimVarMap getVarMap()
      Returns:
      the variable map of the model of this simulation
    • getName

      public String getName()
      Returns:
      the name of the simulation
    • getID

      public String getID()
      Returns:
      the simulation id from the variable map
    • getVariableValue

      public Object getVariableValue(String aName)
      Parameters:
      aName - name of the variable
      Returns:
      the current value of the variable; after the model run the final value
    • getResultCache

      public FWSimResultCache getResultCache(String aName)
      Parameters:
      aName - name of the result cache
      Returns:
      the result cache, or null if none is registered under this name
    • getCacheNames

      public Set<String> getCacheNames()
      Returns:
      the names of the registered result caches
    • getModel

      public FWSimModel getModel()
      Returns:
      the model (clone of the template model) of this simulation
    • clone

      public FWSimSimulation clone(Integer aSimulationNumber)
      Creates a copy of this simulation with cloned model and variable map.
      Parameters:
      aSimulationNumber - simulation number of the copy
      Returns:
      the copy
    • equals

      public boolean equals(Object aObj)
      Two simulations are equal if they have the same simulation id.
      Overrides:
      equals in class Object
      See Also:
    • hashCode

      public int hashCode()
      Identity hash code, deliberately not based on the simulation id like equals(Object): the id of a simulation is only set when it runs, and existing hash maps (e.g. result caches per simulation in the result chart filler) rely on the identity order.
      Overrides:
      hashCode in class Object
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object