Class FWSimOutputManager

java.lang.Object
net.simplace.sim.io.output.FWSimOutputManager

public class FWSimOutputManager extends Object
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 Details

    • FWSimOutputManager

      public FWSimOutputManager(FWSimSession aFwSimSession)
      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 a FWSimCalibrationOutput; in other modes (e.g. in the solution) a CAL output is never written.
      Parameters:
      aOutput - the output element
      aVarMap - template variable map of the solution
      aProjectMode - project mode the output is active in
      See Also:
    • addOutput

      public void addOutput(FWSimOutput aOutput)
      Adds an existing output; an output with the same name is replaced.
      Parameters:
      aOutput - the output to add
    • getOutput

      public FWSimOutput getOutput(String aName)
      Parameters:
      aName - name of the output
      Returns:
      the output, or null if unknown
    • OUTPUT

      public void OUTPUT(LocalDateTime aCurrentDate, FWSimVarMap aVarMap, String aOutputType)
      Passes the current values of a simulation to the outputs; called in each simulation step. During the spin-up period only outputs with spinup="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; if null and no output name is given, nothing is written
      aVarMap - variable map of the simulation
      aOutputType - name of a single output to write to, or null for all outputs except CAL outputs
    • outputCalibrationResult

      public void outputCalibrationResult(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.
      Parameters:
      aVarMap - variable map of the selected simulation
    • calculateStatistics

      public void calculateStatistics(FWSimVarMap aVarMap)
      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 until stopOutputWriters() 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 (see isOutputStillWriting()), otherwise lines still in the queues are lost.
    • updateInterface

      public boolean updateInterface(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.
      Parameters:
      aInterface - the new interface
      aVarMap - passed to FWSimOutput.updateAdapter(FWSimInterface, FWSimVarMap)
      Returns:
      true if at least one output was updated
    • initializeOutputs

      public void initializeOutputs(FWSimVarMap aVarMap, FWSimProject.PROJECT_MODE aProject_MODE)
      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 solution
      aProject_MODE - project mode of the run
    • isOutputStillWriting

      public boolean isOutputStillWriting()
      Returns:
      true if any output is still writing or has data in its queue
    • reset

      public void reset() throws Exception
      Finalizes all outputs (closes files and connections) and the file pools of the session at the end of a session.
      Throws:
      Exception - if finalizing an output fails
    • getOutputs

      public ArrayList<FWSimOutput> getOutputs()
      Returns:
      a new list with all outputs (solution and project)
    • getOutputAdapters

      public ArrayList<FWSimOutputAdapter> getOutputAdapters()
      Returns:
      a new list with the adapters of all outputs
    • getInterface

      public FWSimInterface<?> getInterface(String aName)
      Parameters:
      aName - name of the output
      Returns:
      the interface of the output, or null if unknown
    • registerOutputListener

      public void registerOutputListener(FWSimOutputListener aOutputListener)
      Registers a listener that is notified on every output call.
      Parameters:
      aOutputListener - the listener
    • removeOutputListener

      public void removeOutputListener(FWSimOutputListener aOutputListener)
      Removes a listener.
      Parameters:
      aOutputListener - the listener
    • registerSimulations

      public void registerSimulations(List<FWSimSimulation> aSimulations)
      Registers the simulations at all memory output adapters, which keep a result cache per simulation.
      Parameters:
      aSimulations - the simulations
    • finishSimulationOutputs

      public void finishSimulationOutputs(FWSimVarMap aVarMap)
      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:
      true if the writer threads have been started
    • checkSkipAboveSize

      public boolean checkSkipAboveSize(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. 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:
      true if the project should be skipped
    • updateAdapter

      public void updateAdapter(FWSimVarMap aVarMap)
      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

      public void removeAdapter(FWSimFieldContainer aFieldContainer)
      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 the outputs element from copies of the original output elements; outputs without element (e.g. the default output of a simulation selector) are left out.
      Returns:
      the outputs element