Test_MultiportSwitch_IntegerSelector Test_MultiportSwitch_IntegerSelector Icon

Test_MultiportSwitch_IntegerSelector

Usage

PrimitiveComponents.Test_MultiportSwitch_IntegerSelector()

Behavior

\[ \begin{equation} \left[ \begin{array}{c} \mathrm{connect}\left( constant_{1_{+}y(t)}, multiportswitch_{+}u1(t) \right) \\ \mathrm{connect}\left( constant_{2_{+}y(t)}, multiportswitch_{+}u2(t) \right) \\ \mathrm{connect}\left( default_{value_{+}y(t)}, multiportswitch_{+}defaultValue(t) \right) \\ \mathrm{connect}\left( selector_{+}y(t), multiportswitch_{+}selector(t) \right) \\ \mathtt{multiportswitch.y}\left( t \right) = ifelse\left( \mathtt{multiportswitch.u1}\left( t \right), ifelse\left( \mathtt{multiportswitch.u2}\left( t \right), \mathtt{multiportswitch.defaultValue}\left( t \right); \mathtt{multiportswitch.selector}\left( t \right) = 2 \right); \mathtt{multiportswitch.selector}\left( t \right) = 1 \right) \\ \mathtt{selector.y}\left( t \right) = ifelse\left( t \geq \mathtt{selector.start\_time}, \mathtt{selector.height} + \mathtt{selector.offset}, \mathtt{selector.offset} \right) \\ \mathtt{constant\_1.y}\left( t \right) = \mathtt{constant\_1.k} \\ \mathtt{constant\_2.y}\left( t \right) = \mathtt{constant\_2.k} \\ \mathtt{default\_value.y}\left( t \right) = \mathtt{default\_value.k} \\ \end{array} \right] \end{equation} \]

Source

# This test demonstrates the behavior of the `MultiportSwitch_IntegerSelector` component.
#
# Three constant input signals are provided:
#   - u1 = 10
#   - u2 = 20
#   - defaultValue = 100
#
# An integer `selector` signal chooses which input appears at the output:
#   - When selector = 1 → output = u1
#   - When selector = 2 → output = u2
#   - When selector ≠ 1 or 2 → output = defaultValue
#
# During the test:
#   - Initially, selector chooses the default value → output = 100
#   - At t = 5s, selector steps to 2 → output = 20
component Test_MultiportSwitch_IntegerSelector
  multiportswitch = PrimitiveComponents.Switches.MultiportSwitch_IntegerSelector() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 460, "y1": 450, "x2": 560, "y2": 550, "rot": 0}
      }
    }
  }
  selector = PrimitiveComponents.Sources.Step_IntegerOut(start_time = 5, height = -1, offset = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 150, "x2": 220, "y2": 250, "rot": 0}
      }
    }
  }
  constant_1 = BlockComponents.Constant(k = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 350, "x2": 220, "y2": 450, "rot": 0}
      }
    }
  }
  constant_2 = BlockComponents.Constant(k = 20) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 110, "y1": 590, "x2": 210, "y2": 690, "rot": 0}
      }
    }
  }
  default_value = BlockComponents.Constant(k = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 790, "x2": 230, "y2": 890, "rot": 0}
      }
    }
  }
relations
  connect(multiportswitch.u1, constant_1.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 300, "y": 483}, {"x": 300, "y": 400}]}]}
  }
  connect(multiportswitch.u2, constant_2.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 334, "y": 513}, {"x": 334, "y": 640}]}]}
  }
  connect(multiportswitch.defaultValue, default_value.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 344, "y": 540}, {"x": 344, "y": 840}]}]}
  }
  connect(selector.y, multiportswitch.selector) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 340, "y": 200}, {"x": 340, "y": 460}], "E": 2}]}
  }
metadata {
  "Dyad": {
    "experiments": {"Test_MultiportSwitch_integer_selector_Boeing_": {"stop": 10}},
    "tests": {
      "case1": {
        "stop": 10,
        "abstol": 0.00001,
        "reltol": 0.00001,
        "expect": {"signals": ["multiportswitch.y"]}
      }
    }
  }
}
end
Flattened Source
component Test_MultiportSwitch_IntegerSelector
  multiportswitch = PrimitiveComponents.Switches.MultiportSwitch_IntegerSelector() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 460, "y1": 450, "x2": 560, "y2": 550, "rot": 0}
      }
    }
  }
  selector = PrimitiveComponents.Sources.Step_IntegerOut(start_time = 5, height = -1, offset = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 150, "x2": 220, "y2": 250, "rot": 0}
      }
    }
  }
  constant_1 = BlockComponents.Constant(k = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 350, "x2": 220, "y2": 450, "rot": 0}
      }
    }
  }
  constant_2 = BlockComponents.Constant(k = 20) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 110, "y1": 590, "x2": 210, "y2": 690, "rot": 0}
      }
    }
  }
  default_value = BlockComponents.Constant(k = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 790, "x2": 230, "y2": 890, "rot": 0}
      }
    }
  }
relations
  connect(multiportswitch.u1, constant_1.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 300, "y": 483}, {"x": 300, "y": 400}]}]}
  }
  connect(multiportswitch.u2, constant_2.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 334, "y": 513}, {"x": 334, "y": 640}]}]}
  }
  connect(multiportswitch.defaultValue, default_value.y) {
    "Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 344, "y": 540}, {"x": 344, "y": 840}]}]}
  }
  connect(selector.y, multiportswitch.selector) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 340, "y": 200}, {"x": 340, "y": 460}], "E": 2}]}
  }
metadata {
  "Dyad": {
    "experiments": {"Test_MultiportSwitch_integer_selector_Boeing_": {"stop": 10}},
    "tests": {
      "case1": {
        "stop": 10,
        "abstol": 0.00001,
        "reltol": 0.00001,
        "expect": {"signals": ["multiportswitch.y"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

plt
Example block output
  • Examples
  • Experiments
  • Analyses