Class FWSimOutput
java.lang.Object
net.simplace.sim.io.output.FWSimOutput
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
FWSimCalibrationOutput
An output of the solution (
output element). In each simulation step OUTPUT(LocalDateTime, FWSimVarMap, PROJECT_MODE) collects the values of the header variables per simulation in an
FWSimOutputCache and, depending on the frequency (DAILY, YEARLY, COMPLEX rule, ...), hands the aggregated
line (SUM, AVG, MIN, MAX, ...) to its FWSimOutputAdapter, which writes it to the interface. As
Runnable the output runs the writing thread of its adapter. Optionally statistics (e.g. model efficiency of
simulated against observed values) are calculated at the end of a simulation.- Author:
- Andreas Enders
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FWSimOutputAdapteradapter writing the data to the interfaceprotected FWSimIOAdapter.FREQUENCEFrequency of the outputprotected StringName (id) of the outputprotected HashMap<String, FWSimOutputCache> aggregation caches by simulation idprotected JexlRuleScriptRule deciding when a line is written (for frequencies COMPLEX and BOOLEAN)protected FWSimProject.PROJECT_MODEproject mode the output is active in; calls in other modes are ignoredprotected JexlRuleScriptRule deciding when the aggregation is reset (for frequencies COMPLEX and BOOLEAN)protected booleantrueif the output is also written during the spin-up period (attributespinup="true"); the system variableFWSimVarMap.SPINUP_ACTIVEtells the spin-up lines apart -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFWSimOutput(String aName, FWSimIOAdapter.FREQUENCE aFrequence, FWSimVarMap aVarMap, String aRule, String aResetRule) Creates an output for calibration (project mode CALIBRATION) without solution element; the data is written to aDatabaseOutputAdapter.FWSimOutput(org.jdom2.Element aOutputElement, int aOrderNumber, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProjectMode) Constructor from output Element: format like The adapter is created matching the interface of the output (seeFWSimOutputAdapter.createAdapter(Element, int, FWSimVarMap)). -
Method Summary
Modifier and TypeMethodDescriptionvoidcalculateStatistics(String aSimulationID) Calculates the statistics of a simulation from the collected pairs of observed and simulated values and writes one line (project id, simulation id and one value per statistic) to the statistics adapter.protected voidfinalize()Finalizes the adapter and its statistics adapter (e.g.getName()org.jdom2.Elementbooleanvoidinitialize(FWSimVarMap aVarMap) Initializes the adapter (e.g.booleanbooleanvoidOUTPUT(LocalDateTime aCurrentDate, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aCurrentProjectMode) Called in every simulation step: adds the current values of the header variables to the aggregation cache of the simulation and, if the frequency or rule requires it, passes the aggregated line to the adapter queue.voidremoveSimulationCache(FWSimVarMap aVarMap) Removes the aggregation cache of a finished simulation (nothing to do for DAILY and CAL outputs, which do not aggregate).voidrun()Runs the writing loop of the adapter (in its own thread).voidsetFrequenceAndRule(FWSimIOAdapter.FREQUENCE aFrequence, String aRule) Changes frequency and rule of the output and its adapter (e.g.toString()voidupdateAdapter(FWSimInterface<?> aInterface, FWSimVarMap aVarMap) Replaces the adapter by a copy using the new interface.
-
Field Details
-
iName
Name (id) of the output -
iFrequence
Frequency of the output -
iOutputScript
Rule deciding when a line is written (for frequencies COMPLEX and BOOLEAN) -
iResetScript
Rule deciding when the aggregation is reset (for frequencies COMPLEX and BOOLEAN) -
iAdapter
adapter writing the data to the interface -
iOutputCache
aggregation caches by simulation id -
iProjectMode
project mode the output is active in; calls in other modes are ignored -
iSpinupOutput
protected boolean iSpinupOutputtrueif the output is also written during the spin-up period (attributespinup="true"); the system variableFWSimVarMap.SPINUP_ACTIVEtells the spin-up lines apart
-
-
Constructor Details
-
FWSimOutput
public FWSimOutput(org.jdom2.Element aOutputElement, int aOrderNumber, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProjectMode) Constructor from output Element: format like The adapter is created matching the interface of the output (seeFWSimOutputAdapter.createAdapter(Element, int, FWSimVarMap)).- Parameters:
aOutputElement- theoutputelementaOrderNumber- order number of the adapteraVarMap- template variable map of the solutionaProjectMode- project mode the output is active in
-
FWSimOutput
protected FWSimOutput(String aName, FWSimIOAdapter.FREQUENCE aFrequence, FWSimVarMap aVarMap, String aRule, String aResetRule) Creates an output for calibration (project mode CALIBRATION) without solution element; the data is written to aDatabaseOutputAdapter.- Parameters:
aName- name of the outputaFrequence- frequency of the outputaVarMap- template variable map of the solutionaRule- rule deciding when a line is writtenaResetRule- not used; the reset rule is taken from the adapter
-
-
Method Details
-
updateAdapter
Replaces the adapter by a copy using the new interface. Errors are logged.- Parameters:
aInterface- the new interfaceaVarMap- not used
-
setFrequenceAndRule
Changes frequency and rule of the output and its adapter (e.g. in the GUI).- Parameters:
aFrequence- the frequencyaRule- the rule, empty for none (required for COMPLEX and BOOLEAN)- Throws:
IllegalArgumentException- if the frequency is COMPLEX or BOOLEAN and no rule is given
-
initialize
Initializes the adapter (e.g. creates the output file or table).- Parameters:
aVarMap- variable map used for replacing tokens
-
OUTPUT
public void OUTPUT(LocalDateTime aCurrentDate, FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aCurrentProjectMode) Called in every simulation step: adds the current values of the header variables to the aggregation cache of the simulation and, if the frequency or rule requires it, passes the aggregated line to the adapter queue. DAILY and CAL outputs pass a line in every step. For COMPLEX and BOOLEAN the reset rule resets the aggregation.- Parameters:
aCurrentDate- current simulation dateaVarMap- variable map of the simulationaCurrentProjectMode- current project mode; the call is ignored if it differs from the mode of the output- Throws:
org.apache.commons.jexl3.JexlException- if the output rule cannot be evaluated (logged and rethrown)
-
getName
- Returns:
- the name (id) of the output
-
getFrequence
- Returns:
- the frequency of the output
-
isSpinupOutput
public boolean isSpinupOutput()- Returns:
trueif the output is also written during the spin-up period (attributespinup="true")
-
getOutputScript
- Returns:
- the rule deciding when a line is written
-
getResetScript
- Returns:
- the rule deciding when the aggregation is reset
-
hasStatistics
public boolean hasStatistics()- Returns:
trueif the adapter defines statistics
-
calculateStatistics
Calculates the statistics of a simulation from the collected pairs of observed and simulated values and writes one line (project id, simulation id and one value per statistic) to the statistics adapter.- Parameters:
aSimulationID- id of the simulation
-
removeSimulationCache
Removes the aggregation cache of a finished simulation (nothing to do for DAILY and CAL outputs, which do not aggregate).- Parameters:
aVarMap- variable map of the simulation
-
getProjectMode
- Returns:
- the project mode the output is active in
-
run
-
isWriting
public boolean isWriting()- Returns:
trueif the adapter is active and still writing or has data in its queue
-
finalize
-
getAdapter
- Returns:
- the adapter of the output
-
getOutputElement
public org.jdom2.Element getOutputElement()- Returns:
- the
outputelement of the solution, ornullfor calibration outputs
-
toString
-