Skip to content
LIBRARY
Logical.Tests.ZeroThresholds.md

Logical.Tests.ZeroThresholds

MSL cross-validation: ModelicaTest.Blocks.ZeroThresholds

Mirrors the MSL test exactly. A ramp (1 → 0 over 0.2 s starting at t=0.3) feeds through two limiter paths:

  • Positive path: Limiter(y_min=0) → GreaterThreshold(0), GreaterEqualThreshold(0)

  • Negative path: Gain(k=-1) → Limiter(y_max=0) → LessThreshold(0), LessEqualThreshold(0)

Verifies that threshold comparisons at zero behave correctly when the input signal is clamped to exactly zero by the limiter.

Usage

BlockComponents.Logical.Tests.ZeroThresholds()

Behavior

Source

dyad
"""
MSL cross-validation: ModelicaTest.Blocks.ZeroThresholds

Mirrors the MSL test exactly. A ramp (1 → 0 over 0.2 s starting at t=0.3)
feeds through two limiter paths:
- Positive path: Limiter(y_min=0) → GreaterThreshold(0), GreaterEqualThreshold(0)
- Negative path: Gain(k=-1) → Limiter(y_max=0) → LessThreshold(0), LessEqualThreshold(0)

Verifies that threshold comparisons at zero behave correctly when the input
signal is clamped to exactly zero by the limiter.
"""
test component ZeroThresholds
  ramp = BlockComponents.Sources.Ramp(duration = 0.2, height = -1.0, offset = 1.0, start_time = 0.3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  gain = BlockComponents.Math.Gain(k = -1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  limiter_min_zero = BlockComponents.Nonlinear.Limiter(y_max = 1e5, y_min = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  limiter_max_zero = BlockComponents.Nonlinear.Limiter(y_max = 0.0, y_min = -1e5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300.5, "y1": 20, "x2": 400.5, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  greater_threshold = BlockComponents.Logical.GreaterThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 301, "y1": 140, "x2": 401, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  greater_equal_threshold = BlockComponents.Logical.GreaterEqualThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 301, "y1": 260, "x2": 401, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  less_threshold = BlockComponents.Logical.LessThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 442, "y1": 140, "x2": 542, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  less_equal_threshold = BlockComponents.Logical.LessEqualThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 20, "x2": 550, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ramp.y, limiter_min_zero.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 190}], "E": 2}],
      "junctions": [{"x": 140, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, gain.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(gain.y, limiter_max_zero.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(limiter_min_zero.y, greater_threshold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(limiter_min_zero.y, greater_equal_threshold.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 280, "y": 310}], "E": 2}],
      "junctions": [{"x": 280, "y": 190}],
      "renderStyle": "standard"
    }
  }
  connect(limiter_max_zero.y, less_threshold.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 421, "y": 190}], "E": 2}],
      "junctions": [{"x": 421, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(limiter_max_zero.y, less_equal_threshold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": [
            "ramp.y",
            "limiter_min_zero.y",
            "limiter_max_zero.y",
            "greater_threshold.y",
            "greater_equal_threshold.y",
            "less_threshold.y",
            "less_equal_threshold.y"
          ]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
MSL cross-validation: ModelicaTest.Blocks.ZeroThresholds

Mirrors the MSL test exactly. A ramp (1 → 0 over 0.2 s starting at t=0.3)
feeds through two limiter paths:
- Positive path: Limiter(y_min=0) → GreaterThreshold(0), GreaterEqualThreshold(0)
- Negative path: Gain(k=-1) → Limiter(y_max=0) → LessThreshold(0), LessEqualThreshold(0)

Verifies that threshold comparisons at zero behave correctly when the input
signal is clamped to exactly zero by the limiter.
"""
test component ZeroThresholds
  ramp = BlockComponents.Sources.Ramp(duration = 0.2, height = -1.0, offset = 1.0, start_time = 0.3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  gain = BlockComponents.Math.Gain(k = -1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  limiter_min_zero = BlockComponents.Nonlinear.Limiter(y_max = 1e5, y_min = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  limiter_max_zero = BlockComponents.Nonlinear.Limiter(y_max = 0.0, y_min = -1e5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300.5, "y1": 20, "x2": 400.5, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  greater_threshold = BlockComponents.Logical.GreaterThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 301, "y1": 140, "x2": 401, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  greater_equal_threshold = BlockComponents.Logical.GreaterEqualThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 301, "y1": 260, "x2": 401, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  less_threshold = BlockComponents.Logical.LessThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 442, "y1": 140, "x2": 542, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  less_equal_threshold = BlockComponents.Logical.LessEqualThreshold(threshold = 0.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 20, "x2": 550, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ramp.y, limiter_min_zero.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 190}], "E": 2}],
      "junctions": [{"x": 140, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, gain.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(gain.y, limiter_max_zero.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(limiter_min_zero.y, greater_threshold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(limiter_min_zero.y, greater_equal_threshold.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 280, "y": 310}], "E": 2}],
      "junctions": [{"x": 280, "y": 190}],
      "renderStyle": "standard"
    }
  }
  connect(limiter_max_zero.y, less_threshold.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 421, "y": 190}], "E": 2}],
      "junctions": [{"x": 421, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(limiter_max_zero.y, less_equal_threshold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": [
            "ramp.y",
            "limiter_min_zero.y",
            "limiter_max_zero.y",
            "greater_threshold.y",
            "greater_equal_threshold.y",
            "less_threshold.y",
            "less_equal_threshold.y"
          ]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt