Class FWSimComponentGroup

java.lang.Object
net.simplace.sim.model.FWSimComponent
net.simplace.sim.model.FWSimComponentGroup
All Implemented Interfaces:
IntegratableComponent, FWSimFieldContainer

public class FWSimComponentGroup extends FWSimComponent implements IntegratableComponent
A SimComponent composed of several SimComponents. The members are defined in a group configuration file <package/name>.grp.xml on the class path (element simgroup with simcomponent elements). The group behaves like a single component: its members are initialized, processed and integrated in order, their ids are prefixed with the group name (Group_Member), and the inputs and outputs of the members are mapped to inputs and outputs of the group.

Repeated execution (sub-time-steps): if the simcomponent element of the group in the solution has the attribute repeatrule, its rule is evaluated once per time step and the members are processed that many times in a row (0 = not at all). After each pass the integratable members are integrated (IntegratableComponent.postIntegrate()), so the next pass works on the updated states; the integration at the end of the time step is then skipped for the group. A rule giving a decimal number is truncated; a rule that does not give a number or gives a negative number stops the simulation. Example:

<simcomponent id="Transport" class="net.simplace.sim.model.FWSimComponentGroup" repeatrule="${SubSteps.Count}">
  <group>soil.Transport.grp.xml</group>
  ...
</simcomponent>
A repeated group provides two outputs: <group id>.Repetition, the number of the current pass (1 to n, 0 before the first pass of a step), and <group id>.Repetitions, the number of passes of the current step. Members read them like any group input, e.g. <input id="iPass" source="Transport.Repetition"/> in the group configuration (with the simple name of the configuration file as prefix).
Author:
Andreas Enders
  • Field Details

    • REPEAT_ATTRIBUTE

      public static final String REPEAT_ATTRIBUTE
      Attribute of the simcomponent element holding the rule for the number of passes per time step
      See Also:
    • REPETITION

      public static final String REPETITION
      Name (without group prefix) of the output holding the number of the current pass
      See Also:
    • REPETITIONS

      public static final String REPETITIONS
      Name (without group prefix) of the output holding the number of passes of the current time step
      See Also:
    • iRepeatRule

      protected JexlRuleScript iRepeatRule
      Rule for the number of passes per time step, or null if the group is processed once
    • iRepetition

      protected FWSimVariable<Integer> iRepetition
      Number of the current pass (only for repeated groups)
    • iRepetitions

      protected FWSimVariable<Integer> iRepetitions
      Number of passes of the current time step (only for repeated groups)
    • iComponentMapping

      protected final HashMap<String,String> iComponentMapping
      Mapping from the ids in the group configuration (and the simple group name) to the ids used in the simulation
    • iComponentList

      protected final LinkedList<FWSimComponent> iComponentList
      The member components, in order of execution
    • iSimGroupElement

      protected org.jdom2.Element iSimGroupElement
      Root element of the group configuration file
    • iInternalInputLinkMap

      protected HashMap<String,String> iInternalInputLinkMap
      Input links of the members: map from input variable name to source variable name
    • iInternalOutputLinkMap

      protected HashMap<String,String> iInternalOutputLinkMap
      Output links: map from output variable of the group to the member variable it is taken from
    • iConfigurationXMLPath

      protected String iConfigurationXMLPath
      Name (class path location) of the group configuration
    • iSimpleName

      protected String iSimpleName
      Name of the group configuration without package, as used in the configuration file
    • iIsIntagratable

      protected boolean iIsIntagratable
      true if at least one member is an IntegratableComponent
  • Constructor Details

    • FWSimComponentGroup

      public FWSimComponentGroup()
      Default constructor, used to create the group by class name. The configuration name is read from the group child of the simcomponent element.
    • FWSimComponentGroup

      public FWSimComponentGroup(String aGroupName)
      Creates a group for a given configuration.
      Parameters:
      aGroupName - name of the group configuration, e.g. net.simplace.sim.groups.MyGroup (for net/simplace/sim/groups/MyGroup.grp.xml)
    • FWSimComponentGroup

      protected FWSimComponentGroup(String aName, HashMap<String, FWSimVariable<?>> aFieldMap, HashMap<String,String> aInputMap, org.jdom2.Element aSimComponentElement, FWSimVarMap aVarMap, int aOrderNumber, LinkedList<FWSimComponent> aComponentList, HashMap<String,String> aInternalInputLinkMap, HashMap<String,String> aInternalOutputLinkMap)
      Creates the group for a new simulation; the members are cloned with the new var map.
      Parameters:
      aName - name of the group
      aFieldMap - the shared field map
      aInputMap - the links of the group inputs
      aSimComponentElement - the configuration element
      aVarMap - var map of the new simulation
      aOrderNumber - position in the order of execution
      aComponentList - the members of the template group
      aInternalInputLinkMap - input links of the members
      aInternalOutputLinkMap - output links of the group
  • Method Details

    • readConfiguration

      protected void readConfiguration()
      Reads the group configuration; its name is taken from the group child of the configuration element (or from the constructor).
      See Also:
    • readConfiguration

      protected void readConfiguration(String aConfigurationXMLPath)
      Reads the group configuration file from the class path and renames the member ids to <group name>_<member id>. Errors are logged.
      Parameters:
      aConfigurationXMLPath - name of the configuration (dots as package separators, optionally with .grp.xml)
    • createVariables

      public final HashMap<String, FWSimVariable<?>> createVariables()
      Registers the variables of the members under the names of the group: group inputs are mapped to the member inputs (and vice versa for internal links), group outputs to the member outputs. The member variables are already in the field map (see create()).
      Specified by:
      createVariables in interface FWSimFieldContainer
      Specified by:
      createVariables in class FWSimComponent
      Returns:
      the field map
      See Also:
    • getComponentList

      public LinkedList<FWSimComponent> getComponentList()
      Returns:
      the member components, in order of execution
    • getComponentMapping

      public HashMap<String,String> getComponentMapping()
      Returns:
      the mapping from the ids in the group configuration to the ids used in the simulation
    • getInternalInputLinkMap

      public HashMap<String,String> getInternalInputLinkMap()
      Returns:
      the input links of the members: map from input variable name to source variable name
    • getInternalOutputLinkMap

      public HashMap<String,String> getInternalOutputLinkMap()
      Returns:
      the output links: map from output variable of the group to the member variable it is taken from
    • performOutputLinks

      public void performOutputLinks() throws SimLinkInvalidException
      Performs the output links from the members to the group outputs. Must be called before the external links are performed.
      Throws:
      SimLinkInvalidException - if a link is invalid
    • performLinks

      protected void performLinks(HashMap<String,String> aLinkMap) throws SimLinkInvalidException
      Registers linked variables in the var map under the destination names. Missing variables are reported as warnings.
      Overrides:
      performLinks in class FWSimComponent
      Parameters:
      aLinkMap - map with key = destination and value = source variable name
      Throws:
      SimLinkInvalidException - if a link is invalid
    • performInputLinks

      public void performInputLinks() throws SimLinkInvalidException
      Performs the input links of the members (from group inputs or other members). Must be called AFTER all external links are performed.
      Throws:
      SimLinkInvalidException - if a link is invalid
    • init

      protected final void init()
      Initializes all members. A repeated group also fetches its own outputs from the var map and sets them to 0.
      Specified by:
      init in class FWSimComponent
    • process

      protected final void process()
      Processes all members in order (each with its own frequency check). A repeated group evaluates its repeat rule and runs that many passes; after each pass the integratable members are integrated.
      Specified by:
      process in class FWSimComponent
    • postIntegrate

      public final void postIntegrate()
      Calls IntegratableComponent.postIntegrate() of all integratable members. Does nothing for a repeated group, whose members are integrated after each pass in process().
      Specified by:
      postIntegrate in interface IntegratableComponent
    • isRepeated

      public boolean isRepeated()
      Returns:
      true if the members are processed several times per time step (attribute "repeatrule")
    • create

      public final void create() throws SimLinkInvalidException
      Reads the group configuration and creates the member components, collecting their variables and links.
      Throws:
      SimLinkInvalidException - if a member cannot be created
    • getSimpleName

      public String getSimpleName()
      Returns:
      the name of the group configuration without package, as used inside the configuration file
    • toDocXML

      public org.jdom2.Element toDocXML()
      Creates the documentation XML of the group: the definitions of its input and output variables, sorted by content type and name.
      Overrides:
      toDocXML in class FWSimComponent
      Returns:
      the documentation element
    • fillTestVariables

      public HashMap<String, FWSimVariable<?>> fillTestVariables(int aParamIndex, FWSimComponent.TEST_STATE aDefineOrCheck)
      Collects the test values of all members.
      Specified by:
      fillTestVariables in class FWSimComponent
      Parameters:
      aParamIndex - number of the test case, starting with 0
      aDefineOrCheck - phase of the test
      Returns:
      the combined test variables of the members (empty if no member defines this test case)
      See Also:
    • clone

      protected FWSimComponent clone(FWSimVarMap aVarMap)
      Description copied from class: FWSimComponent
      Creates the instance of this component for a new simulation (usually via the protected clone constructor).
      Specified by:
      clone in class FWSimComponent
      Parameters:
      aVarMap - var map of the new simulation
      Returns:
      the new instance