Class FWSimulationControlCache

java.lang.Object
net.simplace.sim.io.FWSimCache
net.simplace.sim.control.FWSimulationControlCache
All Implemented Interfaces:
FWSimFieldContainer

public class FWSimulationControlCache extends FWSimCache
State of a project run (one instance per session): the project ids, the current project and iteration, the simulation counters and progress, the calibration mode, the selected simulations and the control variable map (a copy of the solution variable map used by generators, iterators and selectors). As cache it holds the project data of the selected simulations by simulation id (see loadProjectData()).
Author:
lap
  • Field Details

    • iCurrentSimulationCount

      protected int iCurrentSimulationCount
      the current count of simulations in that project
    • iCurrentUpdateSimulationCount

      protected int iCurrentUpdateSimulationCount
      the current count of update simulations cycle in that project
  • Constructor Details

    • FWSimulationControlCache

      public FWSimulationControlCache(FWSimSession aSession)
      Creates the control cache with a control copy of the solution variable map.
      Parameters:
      aSession - the session (its solution must already exist)
  • Method Details

    • toXML

      public org.jdom2.Element toXML()
      Not implemented.
      Returns:
      always null
      See Also:
    • getCreateFormXML

      public org.jdom2.Element getCreateFormXML()
      No form.
      Returns:
      always null
      See Also:
    • getEditFormXML

      public org.jdom2.Element getEditFormXML(boolean aEnabled)
      No form.
      Parameters:
      aEnabled - if false, the form fields are read-only
      Returns:
      always null
      See Also:
    • keepIterationData

      public Boolean keepIterationData()
      Returns:
      true if the project data of the selected simulations of all iterations is kept
    • keepIterationData

      public void keepIterationData(Boolean aKeepFlag)
      Parameters:
      aKeepFlag - true to keep the project data of the selected simulations of all iterations
    • getIteration

      public FWSimVariable<Integer> getIteration()
      Returns:
      the variable holding the current iteration
    • newIteration

      public void newIteration()
      Starts a new iteration: increases the iteration number and resets the project counter.
    • resetIteration

      public void resetIteration()
      Resets the control variable map, the iteration number (to 0) and the project counter, e.g. before the next project in INDIVIDUAL mode.
    • getProjectIDs

      public LinkedHashSet<String> getProjectIDs()
      Returns:
      the project ids in the order they were added (the live set)
    • getProjectCount

      public int getProjectCount()
      Returns:
      the number of projects, at least 1
    • getFirstProjectID

      public String getFirstProjectID()
      Returns:
      the first project id, or null
    • startProject

      public void startProject(String aProjectID)
      Starts a project: resets the simulation counters, increases the project counter and remembers the previous project.
      Parameters:
      aProjectID - id of the project
    • getCurrentProjectID

      public String getCurrentProjectID()
      Returns:
      the id of the current project
    • getCurrentProjectCount

      public int getCurrentProjectCount()
      Returns:
      the number of projects started in the current iteration
    • addProjectCount

      public void addProjectCount()
      Increases the project counter by 1.
    • setProjectCount

      public void setProjectCount(int aProjectCount)
      Parameters:
      aProjectCount - the number of projects started in the current iteration
    • resetProjectCount

      public void resetProjectCount()
      Resets the project counter to 0.
    • getLastProjectID

      public String getLastProjectID()
      Returns:
      the last project id added, or null
    • getPrevProjectID

      public String getPrevProjectID()
      Returns:
      the id of the previous project, or null
    • addProject

      public void addProject(String aProjectID)
      Adds a project id; the first one becomes the first project id.
      Parameters:
      aProjectID - id of the project
    • getSession

      public FWSimSession getSession()
      Returns:
      the session
    • clearProjectIDs

      public LinkedHashSet<String> clearProjectIDs()
      Removes all project ids and resets first, last and current project.
      Returns:
      a copy of the removed project ids
    • getCalibrationMode

      public FWSimSession.CALIBRATION_MODE getCalibrationMode()
      Returns:
      the calibration mode of the run
    • setCalibrationMode

      public void setCalibrationMode(FWSimSession.CALIBRATION_MODE aCalibrationMode)
      Parameters:
      aCalibrationMode - the calibration mode of the run
    • getSelectedSimulations

      public String[] getSelectedSimulations()
      Returns:
      the ids of the selected simulations, or null
    • getSelectedSimulationsVar

      public FWSimVariable<String[]> getSelectedSimulationsVar()
      Returns:
      the variable holding the selected simulations
    • setSelectedSimulations

      public void setSelectedSimulations(String[] aSelectedSimulations)
      Parameters:
      aSelectedSimulations - the ids of the selected simulations
    • putAllVariables

      public void putAllVariables(LinkedHashMap<String, FWSimVariable<?>> aFieldMap)
      Adds the variables of a field map (except outputs) as columns of the cache.
      Parameters:
      aFieldMap - the variables
    • loadProjectData

      public void loadProjectData() throws SQLException
      Loads the project data of the selected simulations from PROJECT_DATA into the cache, keyed by simulation id. In INDIVIDUAL mode only the rows of the current project are read. Unless iterations are kept, the cache is cleared first. Without selected simulations nothing is read.
      Throws:
      SQLException - if reading fails
    • getControlMap

      public FWSimVarMap getControlMap()
      Returns:
      the control variable map
    • getCurrentSimulationCount

      public int getCurrentSimulationCount()
      Returns:
      the number of simulations of the current project
    • addSimulationCount

      public void addSimulationCount()
      Increases the simulation counter by 1.
    • setSimulationCount

      public void setSimulationCount(int aSimulationCount)
      Parameters:
      aSimulationCount - the number of simulations of the current project
    • resetSimulationCount

      public void resetSimulationCount()
      Resets the simulation counter to 0.
    • getUpdateSimulationCount

      public int getUpdateSimulationCount()
      Returns:
      the number of simulation chunks created for the current project
    • addUpdateSimulationCount

      public void addUpdateSimulationCount()
      Increases the chunk counter by 1.
    • resetUpdateSimulationCount

      public void resetUpdateSimulationCount()
      Resets the chunk counter to 0.
    • getPercentFinished

      public int getPercentFinished()
      Returns the progress last calculated by calculateFractionFinished(long).
      Returns:
      the progress in percent [0-100]
    • getFractionFinished

      public double getFractionFinished()
      Returns:
      the progress [0-1]
    • setFractionFinished

      public void setFractionFinished(double aFractionFinished)
      Parameters:
      aFractionFinished - the progress of the run [0-1]
    • getVarMap

      public FWSimVarMap getVarMap()
      Returns the control variable map.
      Returns:
      the var map this container belongs to
      See Also:
    • getSynchronizeRule

      public String getSynchronizeRule()
      Returns:
      the rule for synchronized simulations from the control map
    • getSynchronizeFrequence

      public FWSimIOAdapter.FREQUENCE getSynchronizeFrequence()
      Returns:
      the synchronization frequency from the control map
    • calculateFractionFinished

      public void calculateFractionFinished(long aCompletedTaskCount)
      Calculates the progress of the run from the finished projects, the iterations and the completed simulations of the current (started) project.
      Parameters:
      aCompletedTaskCount - number of completed simulations of the current project