Class FWSimSession

java.lang.Object
net.simplace.sim.FWSimSession

public final class FWSimSession extends Object
A session is one run of a solution with its projects. It creates and initializes the FWSimSolution, reads the project data via the FWSimulationController, and holds the managers used during the run: output, resource, synchronization and post-processing manager, and the checker (FWCheckHelper).

run() runs all projects according to the calibration mode (FWSimSession.CALIBRATION_MODE) and project mode (FWSimProject.PROJECT_MODE), notifies the registered FWSimulationListeners and finalizes the session afterwards. Sessions are usually created by FWSimEngine.

Author:
Andreas Enders
  • Constructor Details

    • FWSimSession

      public FWSimSession(org.jdom2.Element aSolutionElement, FWSimVarMap aVarMap, Object[][] aParameters, String aSessionName, FileData aSolutionFile)
      Creates a session: creates and initializes the solution, sets the additional parameters, creates the checker (check level and class from the solution variables CHECK.LEVEL and CHECK.CLASS, unless the engine already has a check level) and initializes projects and outputs.
      Parameters:
      aSolutionElement - root element of the solution
      aVarMap - variable map with the system parameters
      aParameters - additional parameters as pairs {name, value} that override solution variables; unknown names are logged as warning. May be null.
      aSessionName - name of the session (the solution file name)
      aSolutionFile - the solution data (file or content)
    • FWSimSession

      public FWSimSession(FWSimSolution aSolution, FileData aSolutionFile)
      Creates a session for an existing solution: creates control cache, post-process manager and checker and initializes projects and outputs.
      Parameters:
      aSolution - the solution; if null, the session is not initialized and has no checker and no control cache
      aSolutionFile - the solution data (file or content)
  • Method Details

    • getSolutionFile

      public FileData getSolutionFile()
      Returns:
      the solution data (file or content)
    • getProjectFile

      public FileData getProjectFile()
      Returns:
      the project data (file or content), or null without project
    • getDataFrame

      public FWSimDataframe getDataFrame()
      Returns:
      the data frame with the solution variables
    • initProjects

      public void initProjects(FWSimVarMap aVarMap)
      Creates the project controller and reads the project data. The variable project holds the project file name (tokens ${...} are replaced if shorter than 256 characters) or the project content; if it is empty, the solution is run without project. Errors reading the project are logged and the default project is used. The project variables are added to the field map of the solution. With a project, the checker only summarizes the violations of the runtime checks, unless the engine's check report is set (see FWSimEngine.setCheckReport(net.simplace.sim.check.FWCheckHelper.CHECK_REPORT)).
      Parameters:
      aVarMap - variable map of the solution
    • getSolution

      public FWSimSolution getSolution()
      Returns:
      the solution
    • getPoolInterface

      public DatabaseInterface getPoolInterface()
      Returns:
      the default connection pool interface of the solution
    • getSessionID

      public String getSessionID()
      Returns:
      a unique session id for unique folders etc.
    • getProjectControler

      public FWSimulationController getProjectControler()
      Returns:
      the project controller
    • getProjectList

      public List<FWSimProject> getProjectList()
      Returns:
      a new list with the projects of the project controller
    • getProject

      public FWSimProject getProject(String aProjectID)
      Parameters:
      aProjectID - id of the project
      Returns:
      the project, or null if the id is empty or unknown
    • run

      public ArrayList<FWSimProject> run() throws Exception
      Runs all projects of the session and finalizes the session afterwards:
      • calibration mode INDIVIDUAL: each project is iterated separately; after every iteration the controller selects the best simulations of the project
      • calibration mode GLOBAL: in every iteration all projects are run, then the selection is done over all projects
      • project mode SENSITIVITY: one iteration per project
      • otherwise all projects of the project data are run once (for SOLUTION_ONLY the single project is generated first)
      Returns:
      the projects that have been run; in calibration mode with the simulations of the last iteration
      Throws:
      Exception - if creating or running the simulations fails
    • postprocess

      public void postprocess() throws Exception
      Runs the post-processing (element postprocess of the project file or, without project file, of the solution) on the output files on disk, without simulation; see FWSimPostProcessManager. After a run the post-processing is done automatically in finalize().
      Throws:
      Exception - if a step of the post-processing fails
    • getOutputManager

      public FWSimOutputManager getOutputManager()
      Returns:
      the output manager
    • getPostProcessManager

      public FWSimPostProcessManager getPostProcessManager()
      Returns:
      the post-process manager
    • getResourceManager

      public FWSimResourceManager getResourceManager()
      Returns:
      the resource manager
    • getSyncManager

      public FWSimSyncManager getSyncManager()
      Returns:
      the synchronization manager
    • getChecker

      public FWCheckHelper getChecker()
      Returns:
      the used checker for this session
    • runProject

      public List<FWSimSimulation> runProject(FWSimProject aProject) throws Exception
      Runs all simulations of a project chunk by chunk: links the resource variables, lets the project create the simulations and runs them until the generator has no more. In check level ONLY at most the first simulation is run, and only if the checker requests it. If the first chunk is empty or the project run is skipped (output already exists), nothing is run for the project.
      Parameters:
      aProject - the project to run
      Returns:
      the simulations that have been run; only filled in application modes GUI and EXTERN, otherwise empty
      Throws:
      Exception - if creating or running the simulations fails
    • runSimulations

      public void runSimulations(List<FWSimSimulation> aSimulationList, boolean aSelectSimulation) throws Exception
      Runs a given list of simulations in their project (taken from the project id of the first simulation): links the resource variables, registers the simulations at the output manager and runs them.
      Parameters:
      aSimulationList - the simulations, all of the same project
      aSelectSimulation - not used
      Throws:
      Exception - declared for callers
    • registerModelListener

      public void registerModelListener(FWSimulationListener aModelListener)
      Registers a listener that is notified about simulation, project and iteration events of this session.
      Parameters:
      aModelListener - the listener
    • removeModelListener

      public void removeModelListener(FWSimulationListener aModelListener)
      Removes a listener.
      Parameters:
      aModelListener - the listener
    • getModelListeners

      public List<FWSimulationListener> getModelListeners()
      Returns:
      the registered listeners (the live list)
    • handleModelErrorEvent

      public void handleModelErrorEvent(FWSimulationErrorEvent aModelEvent)
      Passes an error event to all listeners.
      Parameters:
      aModelEvent - the error event
    • simulationStarted

      public void simulationStarted(FWSimSimulation aFWSimSimulation, Integer aPercentage)
      Notifies all listeners that a simulation has started.
      Parameters:
      aFWSimSimulation - the simulation
      aPercentage - progress in percent
    • simulationEnded

      public void simulationEnded(FWSimSimulation aFWSimSimulation, Integer aPercentage)
      Notifies all listeners that a simulation has ended. The listeners are iterated over a copy, so a listener may remove itself here without causing a ConcurrentModificationException.
      Parameters:
      aFWSimSimulation - the simulation
      aPercentage - progress in percent
    • projectEnded

      public void projectEnded(FWSimProject aFWSimProject, Integer aPercentage)
      Notifies all listeners that a project has ended. The listeners are iterated over a copy, so a listener may remove itself here.
      Parameters:
      aFWSimProject - the project
      aPercentage - progress in percent
    • iterationEnded

      public void iterationEnded(FWSimulationControlCache aControlCache)
      Notifies all listeners that a calibration iteration has ended. The listeners are iterated over a copy, so a listener may remove itself here.
      Parameters:
      aControlCache - the control cache (event source); the progress is taken from the control cache of this session
    • finalize

      public void finalize() throws Exception
      Finalizes the session: waits until all outputs are written, stops the output writer threads, resets the output manager (closes the output files), runs the post-processing (once, if the run has written output files, see FWSimPostProcessManager), resets the resource manager, finalizes the project controller and the checker and sets the session inactive. An error of the post-processing is thrown after the clean-up.

      Note: this overrides Object.finalize(), so the garbage collector may call it as well.

      Overrides:
      finalize in class Object
      Throws:
      Exception - if the post-processing or finalizing the project controller or the checker fails
    • clone

      public FWSimSession clone()
      Creates a new session with a copy of the solution of this session.
      Overrides:
      clone in class Object
      Returns:
      the new session
    • isActive

      public boolean isActive()
      Returns:
      false after the session has been finalized
    • setInActive

      public void setInActive()
      Sets the session inactive.
    • setActive

      public void setActive()
      Sets the session active.
    • getControlCache

      public FWSimulationControlCache getControlCache()
      Returns:
      the simulation control cache of this session
    • toString

      public String toString()
      Overrides:
      toString in class Object