Class FWSimOutputManager
java.lang.Object
net.simplace.sim.io.output.FWSimOutputManager
Manages the outputs of a session (one instance per session). The outputs are created from the
outputs
part of the solution, each with its format (interface), frequency (YEARLY, MONTHLY, DAILY, COMPLEX, ...) and
aggregation modes (SUM, AVG, MIN, MAX, ...). In each simulation step the manager passes the variable map to all
outputs (OUTPUT(LocalDateTime, FWSimVarMap, String)); each output writes its data in its own thread (see
runOutputWriters()). Output listeners are notified on every output call.- Author:
- Andreas Enders
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOutput(FWSimOutput aOutput) Adds an existing output; an output with the same name is replaced.voidaddOutput(org.jdom2.Element aOutput, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProjectMode) Creates an output from its element and adds it.voidcalculateStatistics(FWSimVarMap aVarMap) Calculates and writes the statistics of all outputs for a finished simulation; only in project mode SIMULATION.booleancheckSkipAboveSize(FWSimVarMap aVarMap) Checks the CSV outputs with a skip-above-size limit: their output file is determined for the project and the project is skipped if ALL these files already exceed their limit (i.e.voidRemoves the registered simulations from all memory output adapters.voidfinishSimulationOutputs(FWSimVarMap aVarMap) Removes the aggregation caches of a finished simulation from all outputs.getInterface(String aName) voidinitializeOutputs(FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProject_MODE) Sets the current project mode and initializes all outputs of this mode.booleanbooleanvoidOUTPUT(LocalDateTime aCurrentDate, FWSimVarMap aVarMap, String aOutputType) Passes the current values of a simulation to the outputs; called in each simulation step.voidoutputCalibrationResult(FWSimVarMap aVarMap) Passes the values of a selected simulation to all calibration outputs (FWSimCalibrationOutputs with frequency CAL; other CAL outputs are ignored) and notifies the output listeners.voidregisterOutputListener(FWSimOutputListener aOutputListener) Registers a listener that is notified on every output call.voidregisterSimulations(List<FWSimSimulation> aSimulations) Registers the simulations at all memory output adapters, which keep a result cache per simulation.voidremoveAdapter(FWSimFieldContainer aFieldContainer) Removes the output of an adapter from the solution; used in the GUI.voidremoveOutputListener(FWSimOutputListener aOutputListener) Removes a listener.voidreset()Finalizes all outputs (closes files and connections) and the file pools of the session at the end of a session.voidStarts the writer thread of each output; further calls have no effect untilstopOutputWriters()was called.voidStops the writer threads: the executor is shut down and the writer loops waiting for data are interrupted, so the threads end.org.jdom2.ElementtoXML()Creates theoutputselement from copies of the originaloutputelements; outputs without element (e.g.voidupdateAdapter(FWSimVarMap aVarMap) Updates the output files of all CSV and NetCDF outputs for the current project (e.g.booleanupdateInterface(FWSimInterface<?> aInterface, FWSimVarMap aVarMap) Replaces the adapter of every output that uses an interface with the same name by a copy using the new interface.
-
Constructor Details
-
FWSimOutputManager
- Parameters:
aFwSimSession- the session
-
-
Method Details
-
addOutput
public void addOutput(org.jdom2.Element aOutput, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProjectMode) Creates an output from its element and adds it. In project mode CALIBRATION an output with frequency CAL becomes aFWSimCalibrationOutput; in other modes (e.g. in the solution) a CAL output is never written.- Parameters:
aOutput- theoutputelementaVarMap- template variable map of the solutionaProjectMode- project mode the output is active in- See Also:
-
addOutput
Adds an existing output; an output with the same name is replaced.- Parameters:
aOutput- the output to add
-
getOutput
- Parameters:
aName- name of the output- Returns:
- the output, or
nullif unknown
-
OUTPUT
Passes the current values of a simulation to the outputs; called in each simulation step. During the spin-up period only outputs withspinup="true"are written and the output listeners are not notified (#623). The output listeners are notified first. Synchronized, so the simulations call it one after another.- Parameters:
aCurrentDate- current simulation date; ifnulland no output name is given, nothing is writtenaVarMap- variable map of the simulationaOutputType- name of a single output to write to, ornullfor all outputs except CAL outputs
-
outputCalibrationResult
Passes the values of a selected simulation to all calibration outputs (FWSimCalibrationOutputs with frequency CAL; other CAL outputs are ignored) and notifies the output listeners.- Parameters:
aVarMap- variable map of the selected simulation
-
calculateStatistics
Calculates and writes the statistics of all outputs for a finished simulation; only in project mode SIMULATION.- Parameters:
aVarMap- variable map of the simulation
-
runOutputWriters
public void runOutputWriters()Starts the writer thread of each output; further calls have no effect untilstopOutputWriters()was called. After a stop, a new executor is created, so the writers can be started again. -
stopOutputWriters
public void stopOutputWriters()Stops the writer threads: the executor is shut down and the writer loops waiting for data are interrupted, so the threads end. Must only be called when all output is written (seeisOutputStillWriting()), otherwise lines still in the queues are lost. -
updateInterface
Replaces the adapter of every output that uses an interface with the same name by a copy using the new interface.- Parameters:
aInterface- the new interfaceaVarMap- passed toFWSimOutput.updateAdapter(FWSimInterface, FWSimVarMap)- Returns:
trueif at least one output was updated
-
initializeOutputs
Sets the current project mode and initializes all outputs of this mode. Outputs created for SOLUTION_ONLY are switched to SIMULATION if a project is run.- Parameters:
aVarMap- template variable map of the solutionaProject_MODE- project mode of the run
-
isOutputStillWriting
public boolean isOutputStillWriting()- Returns:
trueif any output is still writing or has data in its queue
-
reset
-
getOutputs
- Returns:
- a new list with all outputs (solution and project)
-
getOutputAdapters
- Returns:
- a new list with the adapters of all outputs
-
getInterface
- Parameters:
aName- name of the output- Returns:
- the interface of the output, or
nullif unknown
-
registerOutputListener
Registers a listener that is notified on every output call.- Parameters:
aOutputListener- the listener
-
removeOutputListener
Removes a listener.- Parameters:
aOutputListener- the listener
-
registerSimulations
Registers the simulations at all memory output adapters, which keep a result cache per simulation.- Parameters:
aSimulations- the simulations
-
finishSimulationOutputs
Removes the aggregation caches of a finished simulation from all outputs.- Parameters:
aVarMap- variable map of the simulation
-
clearSimulations
public void clearSimulations()Removes the registered simulations from all memory output adapters. -
isWriterThreadStarted
public boolean isWriterThreadStarted()- Returns:
trueif the writer threads have been started
-
checkSkipAboveSize
Checks the CSV outputs with a skip-above-size limit: their output file is determined for the project and the project is skipped if ALL these files already exceed their limit (i.e. the project was already run completely); if one file is missing or smaller, the project is run again.- Parameters:
aVarMap- variable map of the first simulation of the project- Returns:
trueif the project should be skipped
-
updateAdapter
Updates the output files of all CSV and NetCDF outputs for the current project (e.g. file names with${projectid}). Waits first until the lines of the previous project are written.- Parameters:
aVarMap- variable map of the first simulation of the project
-
removeAdapter
Removes the output of an adapter from the solution; used in the GUI.- Parameters:
aFieldContainer- the output adapter (its name is the name of the output)
-
toXML
public org.jdom2.Element toXML()Creates theoutputselement from copies of the originaloutputelements; outputs without element (e.g. the default output of a simulation selector) are left out.- Returns:
- the
outputselement
-