Class FWSimSession
java.lang.Object
net.simplace.sim.FWSimSession
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumMode the application runs in.static enumCalibration mode of a session run, taken from the control cache. -
Constructor Summary
ConstructorsConstructorDescriptionFWSimSession(FWSimSolution aSolution, FileData aSolutionFile) Creates a session for an existing solution: creates control cache, post-process manager and checker and initializes projects and outputs.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 variablesCHECK.LEVELandCHECK.CLASS, unless the engine already has a check level) and initializes projects and outputs. -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a new session with a copy of the solution of this session.voidfinalize()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, seeFWSimPostProcessManager), resets the resource manager, finalizes the project controller and the checker and sets the session inactive.getProject(String aProjectID) voidhandleModelErrorEvent(FWSimulationErrorEvent aModelEvent) Passes an error event to all listeners.voidinitProjects(FWSimVarMap aVarMap) Creates the project controller and reads the project data.booleanisActive()voiditerationEnded(FWSimulationControlCache aControlCache) Notifies all listeners that a calibration iteration has ended.voidRuns the post-processing (elementpostprocessof the project file or, without project file, of the solution) on the output files on disk, without simulation; seeFWSimPostProcessManager.voidprojectEnded(FWSimProject aFWSimProject, Integer aPercentage) Notifies all listeners that a project has ended.voidregisterModelListener(FWSimulationListener aModelListener) Registers a listener that is notified about simulation, project and iteration events of this session.voidremoveModelListener(FWSimulationListener aModelListener) Removes a listener.run()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)runProject(FWSimProject aProject) 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.voidrunSimulations(List<FWSimSimulation> aSimulationList, boolean aSelectSimulation) 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.voidSets the session active.voidSets the session inactive.voidsimulationEnded(FWSimSimulation aFWSimSimulation, Integer aPercentage) Notifies all listeners that a simulation has ended.voidsimulationStarted(FWSimSimulation aFWSimSimulation, Integer aPercentage) Notifies all listeners that a simulation has started.toString()
-
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 variablesCHECK.LEVELandCHECK.CLASS, unless the engine already has a check level) and initializes projects and outputs.- Parameters:
aSolutionElement- root element of the solutionaVarMap- variable map with the system parametersaParameters- additional parameters as pairs{name, value}that override solution variables; unknown names are logged as warning. May benull.aSessionName- name of the session (the solution file name)aSolutionFile- the solution data (file or content)
-
FWSimSession
Creates a session for an existing solution: creates control cache, post-process manager and checker and initializes projects and outputs.- Parameters:
aSolution- the solution; ifnull, the session is not initialized and has no checker and no control cacheaSolutionFile- the solution data (file or content)
-
-
Method Details
-
getSolutionFile
- Returns:
- the solution data (file or content)
-
getProjectFile
- Returns:
- the project data (file or content), or
nullwithout project
-
getDataFrame
- Returns:
- the data frame with the solution variables
-
initProjects
Creates the project controller and reads the project data. The variableprojectholds 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 (seeFWSimEngine.setCheckReport(net.simplace.sim.check.FWCheckHelper.CHECK_REPORT)).- Parameters:
aVarMap- variable map of the solution
-
getSolution
- Returns:
- the solution
-
getPoolInterface
- Returns:
- the default connection pool interface of the solution
-
getSessionID
- Returns:
- a unique session id for unique folders etc.
-
getProjectControler
- Returns:
- the project controller
-
getProjectList
- Returns:
- a new list with the projects of the project controller
-
getProject
- Parameters:
aProjectID- id of the project- Returns:
- the project, or
nullif the id is empty or unknown
-
run
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
Runs the post-processing (elementpostprocessof the project file or, without project file, of the solution) on the output files on disk, without simulation; seeFWSimPostProcessManager. After a run the post-processing is done automatically infinalize().- Throws:
Exception- if a step of the post-processing fails
-
getOutputManager
- Returns:
- the output manager
-
getPostProcessManager
- Returns:
- the post-process manager
-
getResourceManager
- Returns:
- the resource manager
-
getSyncManager
- Returns:
- the synchronization manager
-
getChecker
- Returns:
- the used checker for this session
-
runProject
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 projectaSelectSimulation- not used- Throws:
Exception- declared for callers
-
registerModelListener
Registers a listener that is notified about simulation, project and iteration events of this session.- Parameters:
aModelListener- the listener
-
removeModelListener
Removes a listener.- Parameters:
aModelListener- the listener
-
getModelListeners
- Returns:
- the registered listeners (the live list)
-
handleModelErrorEvent
Passes an error event to all listeners.- Parameters:
aModelEvent- the error event
-
simulationStarted
Notifies all listeners that a simulation has started.- Parameters:
aFWSimSimulation- the simulationaPercentage- progress in percent
-
simulationEnded
Notifies all listeners that a simulation has ended. The listeners are iterated over a copy, so a listener may remove itself here without causing aConcurrentModificationException.- Parameters:
aFWSimSimulation- the simulationaPercentage- progress in percent
-
projectEnded
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 projectaPercentage- progress in percent
-
iterationEnded
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
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, seeFWSimPostProcessManager), 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. -
clone
Creates a new session with a copy of the solution of this session. -
isActive
public boolean isActive()- Returns:
falseafter the session has been finalized
-
setInActive
public void setInActive()Sets the session inactive. -
setActive
public void setActive()Sets the session active. -
getControlCache
- Returns:
- the simulation control cache of this session
-
toString
-