Sources.Tests.CosineModes ​
Verifies all operating modes of the Cosine source against analytically known values.
Four Cosine instances share amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = π/4 (so 2π·frequency·start_time = π, half a cycle) and differ only in the continuous and shift_time parameters:
sig_default: new parameters left at their defaults (continuous = true,shift_time = start_time). Confirms the default reproduces the legacy value-continuous behavior (no breaking change).sig_gated:continuous = false,shift_time = start_time— output holds atoffsetbeforestart_time.sig_gated_abs:continuous = false,shift_time = 0— gated output with absolute time reference.sig_hold_abs:continuous = true,shift_time = 0— value-continuous output with absolute time reference.
Each signal feeds an integrator so the test checks both the instantaneous output (at time = 0, in the pre-start region, and at the stop time, in the active region) and the accumulated integral.
Usage ​
BlockComponents.Sources.Tests.CosineModes()
Behavior ​
Source ​
"""
Verifies all operating modes of the Cosine source against analytically known values.
Four `Cosine` instances share `amplitude = 2`, `frequency = 1`, `start_time = 0.5`,
`offset = 1`, `phase = π/4` (so `2π·frequency·start_time = π`, half a cycle) and differ
only in the `continuous` and `shift_time` parameters:
- `sig_default` : new parameters left at their defaults (`continuous = true`, `shift_time = start_time`).
Confirms the default reproduces the legacy value-continuous behavior (no breaking change).
- `sig_gated` : `continuous = false`, `shift_time = start_time` — output holds at `offset` before `start_time`.
- `sig_gated_abs`: `continuous = false`, `shift_time = 0` — gated output with absolute time reference.
- `sig_hold_abs` : `continuous = true`, `shift_time = 0` — value-continuous output with absolute time reference.
Each signal feeds an integrator so the test checks both the instantaneous output
(at `time = 0`, in the pre-start region, and at the stop time, in the active region)
and the accumulated integral.
"""
test component CosineModes
sig_default = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
sig_gated = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = false) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
sig_gated_abs = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = false, shift_time = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
},
"tags": []
}
}
sig_hold_abs = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = true, shift_time = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 380, "x2": 120, "y2": 480, "rot": 0}
},
"tags": []
}
}
int_default = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
int_gated = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
int_gated_abs = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 260, "x2": 260, "y2": 360, "rot": 0}
},
"tags": []
}
}
int_hold_abs = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 380, "x2": 260, "y2": 480, "rot": 0}
},
"tags": []
}
}
relations
connect(sig_default.y, int_default.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_gated.y, int_gated.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_gated_abs.y, int_gated_abs.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_hold_abs.y, int_hold_abs.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 2,
"abstol": 1e-8,
"reltol": 1e-8,
"atol": {
"sig_default.y": 0.01,
"sig_gated.y": 0.01,
"sig_gated_abs.y": 0.01,
"sig_hold_abs.y": 0.01,
"int_default.x": 0.01,
"int_gated.x": 0.01,
"int_gated_abs.x": 0.01,
"int_hold_abs.x": 0.01
},
"expect": {
"initial": {
"sig_default.y": 2.4142,
"sig_gated.y": 1,
"sig_gated_abs.y": 1,
"sig_hold_abs.y": -0.4142
},
"signals": ["sig_default.y", "sig_gated.y", "sig_gated_abs.y", "sig_hold_abs.y"],
"final": {
"sig_default.y": -0.4142,
"sig_gated.y": -0.4142,
"sig_gated_abs.y": 2.4142,
"sig_hold_abs.y": 2.4142,
"int_default.x": 2.2569,
"int_gated.x": 1.5498,
"int_gated_abs.x": 2.4502,
"int_hold_abs.x": 1.7431
}
}
}
}
}
}
endFlattened Source
"""
Verifies all operating modes of the Cosine source against analytically known values.
Four `Cosine` instances share `amplitude = 2`, `frequency = 1`, `start_time = 0.5`,
`offset = 1`, `phase = π/4` (so `2π·frequency·start_time = π`, half a cycle) and differ
only in the `continuous` and `shift_time` parameters:
- `sig_default` : new parameters left at their defaults (`continuous = true`, `shift_time = start_time`).
Confirms the default reproduces the legacy value-continuous behavior (no breaking change).
- `sig_gated` : `continuous = false`, `shift_time = start_time` — output holds at `offset` before `start_time`.
- `sig_gated_abs`: `continuous = false`, `shift_time = 0` — gated output with absolute time reference.
- `sig_hold_abs` : `continuous = true`, `shift_time = 0` — value-continuous output with absolute time reference.
Each signal feeds an integrator so the test checks both the instantaneous output
(at `time = 0`, in the pre-start region, and at the stop time, in the active region)
and the accumulated integral.
"""
test component CosineModes
sig_default = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
sig_gated = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = false) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
sig_gated_abs = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = false, shift_time = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
},
"tags": []
}
}
sig_hold_abs = BlockComponents.Sources.Cosine(amplitude = 2, frequency = 1, start_time = 0.5, offset = 1, phase = pi / 4, continuous = true, shift_time = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 380, "x2": 120, "y2": 480, "rot": 0}
},
"tags": []
}
}
int_default = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
int_gated = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
int_gated_abs = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 260, "x2": 260, "y2": 360, "rot": 0}
},
"tags": []
}
}
int_hold_abs = BlockComponents.Continuous.Integrator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 380, "x2": 260, "y2": 480, "rot": 0}
},
"tags": []
}
}
relations
connect(sig_default.y, int_default.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_gated.y, int_gated.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_gated_abs.y, int_gated_abs.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sig_hold_abs.y, int_hold_abs.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 2,
"abstol": 1e-8,
"reltol": 1e-8,
"atol": {
"sig_default.y": 0.01,
"sig_gated.y": 0.01,
"sig_gated_abs.y": 0.01,
"sig_hold_abs.y": 0.01,
"int_default.x": 0.01,
"int_gated.x": 0.01,
"int_gated_abs.x": 0.01,
"int_hold_abs.x": 0.01
},
"expect": {
"initial": {
"sig_default.y": 2.4142,
"sig_gated.y": 1,
"sig_gated_abs.y": 1,
"sig_hold_abs.y": -0.4142
},
"signals": ["sig_default.y", "sig_gated.y", "sig_gated_abs.y", "sig_hold_abs.y"],
"final": {
"sig_default.y": -0.4142,
"sig_gated.y": -0.4142,
"sig_gated_abs.y": 2.4142,
"sig_hold_abs.y": 2.4142,
"int_default.x": 2.2569,
"int_gated.x": 1.5498,
"int_gated_abs.x": 2.4502,
"int_hold_abs.x": 1.7431
}
}
}
}
}
}
endTest Cases ​
Test Case case1 ​
pltpltpltpltRelated ​
Examples
Experiments
Analyses
Tests