---
url: /dyad/stable/stdlib/BlockComponents/tests/Logical.Tests.ZeroThresholds.md
description: >-
  Dyad Logical.Tests.ZeroThresholds docs.  MSL cross-validation:
  ModelicaTest.Blocks.ZeroThresholds
---

# `Logical.Tests.ZeroThresholds` {#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 {#Usage}

`BlockComponents.Logical.Tests.ZeroThresholds()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( ramp\_{+}y, limiter\_{min_zero\_{+}u} \right) \\
0 &= \mathrm{connect}\left( ramp\_{+}y, gain\_{+}u \right) \\
0 &= \mathrm{connect}\left( gain\_{+}y, limiter\_{max_zero\_{+}u} \right) \\
0 &= \mathrm{connect}\left( limiter\_{min_zero\_{+}y}, greater\_{threshold\_{+}u} \right) \\
0 &= \mathrm{connect}\left( limiter\_{min_zero\_{+}y}, greater\_{equal_threshold\_{+}u} \right) \\
0 &= \mathrm{connect}\left( limiter\_{max_zero\_{+}y}, less\_{threshold\_{+}u} \right) \\
0 &= \mathrm{connect}\left( limiter\_{max_zero\_{+}y}, less\_{equal_threshold\_{+}u} \right) \\
\mathtt{ramp.y}\left( t \right) &= ifelse\left( \mathtt{ramp.start_time} < t, ifelse\left( t < \mathtt{ramp.duration} + \mathtt{ramp.start_time}, \mathtt{ramp.offset} + \frac{\mathtt{ramp.height} ~ \left(  - \mathtt{ramp.start_time} + t \right)}{\mathtt{ramp.duration}}, \mathtt{ramp.height} + \mathtt{ramp.offset} \right), \mathtt{ramp.offset} \right) \\
\mathtt{gain.y}\left( t \right) &= \mathtt{gain.k} ~ \mathtt{gain.u}\left( t \right) \\
\mathtt{limiter_min_zero.y}\left( t \right) &= clamp\left( \mathtt{limiter_min_zero.u}\left( t \right), \mathtt{limiter_min_zero.y_min}, \mathtt{limiter_min_zero.y_max} \right) \\
\mathtt{limiter_max_zero.y}\left( t \right) &= clamp\left( \mathtt{limiter_max_zero.u}\left( t \right), \mathtt{limiter_max_zero.y_min}, \mathtt{limiter_max_zero.y_max} \right) \\
\mathtt{greater_threshold.y}\left( t \right) &= \mathtt{greater_threshold.threshold} < \mathtt{greater_threshold.u}\left( t \right) \\
\mathtt{greater_equal_threshold.y}\left( t \right) &= \mathtt{greater_equal_threshold.u}\left( t \right) \geq \mathtt{greater_equal_threshold.threshold} \\
\mathtt{less_threshold.y}\left( t \right) &= \mathtt{less_threshold.u}\left( t \right) < \mathtt{less_threshold.threshold} \\
\mathtt{less_equal_threshold.y}\left( t \right) &= \mathtt{less_equal_threshold.u}\left( t \right) \leq \mathtt{less_equal_threshold.threshold}
\end{align}
$$

## Source {#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
```

```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-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](hphcdps.svg)

```julia
plt
```

![](jktexhs.svg)

```julia
plt
```

![](rnfotqp.svg)

```julia
plt
```

![](fnrmwua.svg)

```julia
plt
```

![](nrljrou.svg)

```julia
plt
```

![](vfzliom.svg)

```julia
plt
```

![](bgfpmvz.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Gain`](Logical.Tests.ZeroThresholds.md)

  * [`GreaterEqualThreshold`](Logical.Tests.ZeroThresholds.md)

  * [`GreaterThreshold`](Logical.Tests.ZeroThresholds.md)

  * [`LessEqualThreshold`](Logical.Tests.ZeroThresholds.md)

  * [`LessThreshold`](Logical.Tests.ZeroThresholds.md)

  * [`Limiter`](Logical.Tests.ZeroThresholds.md)

  * [`Ramp`](Logical.Tests.ZeroThresholds.md)
