Class FWSimEngine
java.lang.Object
net.simplace.sim.FWSimEngine
Entry point of the simulation engine (singleton). It creates
FWSimSessions from a solution file
(.sol.xml) and an optional project file (.proj.xml), keeps the list of the current
sessions and holds the global settings: work, output, data and projects directory, number of parallel slots,
application mode and check level.
Typical use without GUI:
runProjects(String, String): prepares a session, runs all projects and shuts the engine down, orprepareSession(String, String, APPLICATION_MODE)followed byFWSimSession.run().
FWSimulationGenerator and optionally selected by a FWSimulationSelector (see
FWSimProject.PROJECT_MODE). The GUI uses call(int, String, HashMap, APPLICATION_MODE) with the action commands
createSolution and run. Listeners are registered per session: FWSimulationListener
at the session, FWSimOutputListener at its output manager.- Author:
- Andreas Enders
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intmaximum number of simulations the generator creates per chunk -
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes an action command in GUI mode without parameters, seecall(int, String, HashMap, APPLICATION_MODE).voidcall(int aClickCount, String aFunction, HashMap<String, FWSimVariable<?>> aParameterMap, FWSimSession.APPLICATION_MODE aAppMode) Executes an action command (controller of the GUI):createSolution: prepares a session from the parameter map (parametersolution, seeprepareSession(HashMap, Object[][], APPLICATION_MODE)); if the parametergo_on_automaticallyis true, the first current session is run afterwardsrun: runs the first current session The parameterslotcountsets the number of parallel slots.voidfinalizeSession(FWSimSession aCurrentSession) Finalizes a session (errors are logged) and removes it from the current sessions.static StringReturns the data directory.static FWSimEngineReturns the singleton instance and creates it if necessary.static StringReturns the output directory.static StringReturns the projects directory.static intstatic StringReturns the work directory.static FWSimSessionprepareSession(String aProjectFileName, String aSolutionFileName) Prepares a session inFWSimSession.APPLICATION_MODE.UNIT_TESTmode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).static FWSimSessionprepareSession(String aProjectFileName, String aSolutionFileName, Object[][] aParameters) Prepares a session with additional parameters inFWSimSession.APPLICATION_MODE.UNIT_TESTmode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).static FWSimSessionprepareSession(String aProject, String aSolution, Object[][] aParameters, Integer[] aLinesToBeRead, FWSimSession.APPLICATION_MODE aApplicationMode) Prepares a session for a solution and an optional project: creates the system parametersproject,solution, project id (testproject), simulation id (testsimulation) and the project lines to read, and callsprepareSession(HashMap, Object[][], APPLICATION_MODE).static FWSimSessionprepareSession(String aProjectFileName, String aSolutionFileName, FWSimSession.APPLICATION_MODE aApplicationMode) Prepares a session in the given application mode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).prepareSession(HashMap<String, FWSimVariable<?>> aParameterMap, Object[][] aParameters, FWSimSession.APPLICATION_MODE aApplicationMode) Prepares a session from a parameter map.prepareSession(org.jdom2.Element aSolutionElement, FWSimVarMap aVarMap, Object[][] aParameters, String aSessionName, FWSimSession.APPLICATION_MODE aApplicationMode, FileData aSolutionFile) Creates a session from a parsed solution, adds it to the current sessions and sets the application mode of the engine.static FWSimSessionregisterSession(FWSimSession aSessionO) Initializes the projects and outputs of a session and adds it to the current sessions.static FWSimSessionregisterSolution(FWSimSolution aSolutionO, FWSimSession.APPLICATION_MODE aApplicationMode) Creates a session for an already created solution and sets the application mode of the engine.static voidreset()Discards the singleton instance without finalizing its sessions, so the nextgetInstance()creates a new engine.static FWSimSessionrunProjects(String aProject, String aSolution) Prepares and runs a session and shuts the engine down afterwards, seerunProjects(String, String, HashMap).static FWSimSessionPrepares and runs a session and shuts the engine down afterwards.static voidsetAppMode(FWSimSession.APPLICATION_MODE aAppMode) voidsetCheckLevel(FWCheckHelper.CHECK_LEVEL aCheckLevel) voidsetCheckReport(FWCheckHelper.CHECK_REPORT aCheckReport) Sets how violations of the runtime checks are reported, for all sessions created afterwards (console option-checkreport).static voidsetDataDir(String aPathString) Sets the data directory and creates it if it does not exist (errors are logged as warning).static voidsetOutputDir(String aPathString) Sets the output directory and creates it if it does not exist (errors are logged).static voidsetProjectsDir(String aPathString) Sets the projects directory and creates it if it does not exist (errors are logged as warning).static voidsetSlotCount(int aSlotCount) static voidsetWorkDir(String aPathString) Sets the work directory and creates it if it does not exist (errors are logged).voidshutDown()Finalizes all active sessions and discards the singleton instance, so the nextgetInstance()creates a new engine with default settings.
-
Field Details
-
MAX_SIMULATION_COUNT
public static int MAX_SIMULATION_COUNTmaximum number of simulations the generator creates per chunk
-
-
Method Details
-
getInstance
Returns the singleton instance and creates it if necessary. Not synchronized.- Returns:
- the singleton instance
-
call
Executes an action command in GUI mode without parameters, seecall(int, String, HashMap, APPLICATION_MODE).Note: the parameter map is
nullhere, which the called method does not handle (it fails with aNullPointerException).- Parameters:
aClickCount- click count of the mouse button (only logged)aActionCommand- action command- Throws:
Exception- if the action fails
-
call
public void call(int aClickCount, String aFunction, HashMap<String, FWSimVariable<?>> aParameterMap, FWSimSession.APPLICATION_MODE aAppMode) throws Exception Executes an action command (controller of the GUI):createSolution: prepares a session from the parameter map (parametersolution, seeprepareSession(HashMap, Object[][], APPLICATION_MODE)); if the parametergo_on_automaticallyis true, the first current session is run afterwardsrun: runs the first current session
slotcountsets the number of parallel slots.- Parameters:
aClickCount- click count of the mouse button (only logged)aFunction- action commandaParameterMap- parameters, may benullforrun(createSolution then does nothing)aAppMode- application mode of the session to prepare- Throws:
Exception- if running the session fails; errors reading the solution are only logged
-
prepareSession
public static FWSimSession prepareSession(String aProjectFileName, String aSolutionFileName) throws IOException Prepares a session inFWSimSession.APPLICATION_MODE.UNIT_TESTmode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).- Parameters:
aProjectFileName- project file, ornullto simulate the solution onlyaSolutionFileName- solution file- Returns:
- the prepared session
- Throws:
IOException- if the solution cannot be read
-
prepareSession
public static FWSimSession prepareSession(String aProjectFileName, String aSolutionFileName, Object[][] aParameters) throws IOException Prepares a session with additional parameters inFWSimSession.APPLICATION_MODE.UNIT_TESTmode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).- Parameters:
aProjectFileName- project file, ornullto simulate the solution onlyaSolutionFileName- solution fileaParameters- additional parameters passed to the session, may benull- Returns:
- the prepared session
- Throws:
IOException- if the solution cannot be read
-
prepareSession
public static FWSimSession prepareSession(String aProjectFileName, String aSolutionFileName, FWSimSession.APPLICATION_MODE aApplicationMode) throws IOException Prepares a session in the given application mode, seeprepareSession(String, String, Object[][], Integer[], APPLICATION_MODE).- Parameters:
aProjectFileName- project file, ornullto simulate the solution onlyaSolutionFileName- solution fileaApplicationMode- application mode- Returns:
- the prepared session
- Throws:
IOException- if the solution cannot be read
-
prepareSession
public static FWSimSession prepareSession(String aProject, String aSolution, Object[][] aParameters, Integer[] aLinesToBeRead, FWSimSession.APPLICATION_MODE aApplicationMode) throws IOException Prepares a session for a solution and an optional project: creates the system parametersproject,solution, project id (testproject), simulation id (testsimulation) and the project lines to read, and callsprepareSession(HashMap, Object[][], APPLICATION_MODE). Without project the solution is simulated once.- Parameters:
aProject- project file, ornullto simulate the solution onlyaSolution- solution file name or solution XML contentaParameters- additional parameters passed to the session, may benullaLinesToBeRead- lines of the project data to simulate, ornullfor allaApplicationMode- application mode- Returns:
- the prepared session
- Throws:
IOException- if the solution cannot be read
-
runProjects
public static FWSimSession runProjects(String aProject, String aSolution, HashMap<String, String> aSplitMap) Prepares and runs a session and shuts the engine down afterwards. Without project the solution is simulated once.With a split map, one session is prepared and run per key; each key is a range of project lines (parsed with
StringHelper.parseIntegerToArray(String, boolean)). Add${sessionid}or${projectid}to the output file names in that case, otherwise the outputs overwrite each other.- Parameters:
aProject- project file, ornullto simulate the solution onlyaSolution- solution fileaSplitMap- map whose keys are the project line ranges to run separately, ornullto run all lines at once (values are not used)- Returns:
- the (last) session that was run, or
nullif an error occurred (the error is logged)
-
runProjects
Prepares and runs a session and shuts the engine down afterwards, seerunProjects(String, String, HashMap).- Parameters:
aProject- project file, ornullto simulate the solution onlyaSolution- solution file- Returns:
- the session that was run, or
nullif an error occurred (the error is logged)
-
prepareSession
public FWSimSession prepareSession(HashMap<String, FWSimVariable<?>> aParameterMap, Object[][] aParameters, FWSimSession.APPLICATION_MODE aApplicationMode) throws IOException Prepares a session from a parameter map. The parametersolutionholds either the solution file name (tokens${...}are replaced if the value is shorter than 256 characters) or the solution XML content.- Parameters:
aParameterMap- parameters, must containsolutionaParameters- additional parameters passed to the session, may benullaApplicationMode- application mode- Returns:
- the prepared session
- Throws:
IOException- if the solution cannot be read or parsed
-
prepareSession
public FWSimSession prepareSession(org.jdom2.Element aSolutionElement, FWSimVarMap aVarMap, Object[][] aParameters, String aSessionName, FWSimSession.APPLICATION_MODE aApplicationMode, FileData aSolutionFile) Creates a session from a parsed solution, adds it to the current sessions and sets the application mode of the engine.- Parameters:
aSolutionElement- root element of the solutionaVarMap- variable map with the system parametersaParameters- additional parameters passed to the session, may benullaSessionName- name of the session (the solution file name)aApplicationMode- application modeaSolutionFile- the solution data (file or content)- Returns:
- the created session
-
getCheckLevel
- Returns:
- the level the simulations are checked with while running, or
nullif not set
-
setCheckLevel
- Parameters:
aCheckLevel- the level the simulations are checked with while running
-
getCheckReport
- Returns:
- how violations of the runtime checks are reported, or
nullif not set (then project runs use SUMMARY and runs without project DETAIL, seeFWSimSession.initProjects(net.simplace.sim.util.FWSimVarMap))
-
setCheckReport
Sets how violations of the runtime checks are reported, for all sessions created afterwards (console option-checkreport).- Parameters:
aCheckReport- DETAIL (every violation), SUMMARY (counts at the end) ornull(depends on the run, seegetCheckReport())
-
setWorkDir
Sets the work directory and creates it if it does not exist (errors are logged).- Parameters:
aPathString- path of the work directory
-
getWorkDir
Returns the work directory. If not set, it defaults toSIMPLACE_WORK(relative to the current directory) outside the GUI, or to the settingSETTINGS.USER_CACHEin the GUI modes.- Returns:
- the path of the work directory
-
setOutputDir
Sets the output directory and creates it if it does not exist (errors are logged).- Parameters:
aPathString- path of the output directory
-
getOutputDir
Returns the output directory. If not set, it defaults toSIMPLACE_WORK/outputoutside the GUI, or to the settingSETTINGS.USER_OUTin the GUI modes.- Returns:
- the path of the output directory
-
setProjectsDir
Sets the projects directory and creates it if it does not exist (errors are logged as warning).- Parameters:
aPathString- path of the projects directory
-
getProjectsDir
Returns the projects directory. If not set, it defaults to the settingSETTINGS.USER_OUT.- Returns:
- the path of the projects directory
-
setDataDir
Sets the data directory and creates it if it does not exist (errors are logged as warning).- Parameters:
aPathString- path of the data directory
-
getDataDir
Returns the data directory. If not set, it defaults to the settingSETTINGS.USER_OUT.- Returns:
- the path of the data directory
-
registerSolution
public static FWSimSession registerSolution(FWSimSolution aSolutionO, FWSimSession.APPLICATION_MODE aApplicationMode) Creates a session for an already created solution and sets the application mode of the engine. The session is not added to the current sessions (seeregisterSession(FWSimSession)).- Parameters:
aSolutionO- the solutionaApplicationMode- application mode- Returns:
- the created session
-
registerSession
Initializes the projects and outputs of a session and adds it to the current sessions.- Parameters:
aSessionO- the session, e.g. created byregisterSolution(FWSimSolution, APPLICATION_MODE)- Returns:
- the given session
-
shutDown
public void shutDown()Finalizes all active sessions and discards the singleton instance, so the nextgetInstance()creates a new engine with default settings. -
reset
public static void reset()Discards the singleton instance without finalizing its sessions, so the nextgetInstance()creates a new engine. -
getSlotCount
public static int getSlotCount()- Returns:
- number of simulations run in parallel (default: number of processors minus one, at least 2)
-
setSlotCount
public static void setSlotCount(int aSlotCount) - Parameters:
aSlotCount- number of simulations run in parallel
-
setAppMode
- Parameters:
aAppMode- application mode of the engine
-
getSessions
- Returns:
- the current (not yet finalized) sessions; the live list, not a copy
-
finalizeSession
Finalizes a session (errors are logged) and removes it from the current sessions.- Parameters:
aCurrentSession- the session
-
getAppMode
- Returns:
- the application mode of the engine
-