Skip to content

Improve type stability of basic sources #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ Generate ramp signal.
- `output`
"""
@component function Ramp(; name,
height = 1,
duration = 1,
offset = 0,
start_time = 0,
height = 1.0,
duration = 1.0,
offset = 0.0,
start_time = 0.0,
smooth = false)
@named output = RealOutput()
pars = @parameters offset=offset start_time=start_time height=height duration=duration
equation = if smooth == false
offset + ifelse(t < start_time, 0,
offset + ifelse(t < start_time, zero(height),
ifelse(t < (start_time + duration), (t - start_time) * height / duration,
height))
else
Expand Down Expand Up @@ -320,20 +320,20 @@ Generate step signal.

- `output`
"""
@component function Step(; name, height = 1, offset = 0, start_time = 0, duration = Inf,
@component function Step(; name, height = 1.0, offset = 0.0, start_time = 0.0, duration = Inf,
smooth = 1e-5)
@named output = RealOutput()
duration_numeric = duration
pars = @parameters offset=offset start_time=start_time height=height duration=duration
equation = if smooth == false # use comparison in case smooth is a float
offset + ifelse((start_time < t) & (t < start_time + duration), height, 0)
offset + ifelse((start_time < t) & (t < start_time + duration), height, zero(height))
else
smooth === true && (smooth = 1e-5)
if duration_numeric == Inf
smooth_step(t, smooth, height, offset, start_time)
else
smooth_step(t, smooth, height, offset, start_time) -
smooth_step(t, smooth, height, 0, start_time + duration)
smooth_step(t, smooth, height, zero(start_time), start_time + duration)
end
end

Expand Down Expand Up @@ -366,17 +366,17 @@ Exponentially damped sine signal.
"""
@component function ExpSine(; name,
frequency,
amplitude = 1,
amplitude = 1.0,
damping = 0.1,
phase = 0,
offset = 0,
start_time = 0,
phase = 0.0,
offset = 0.0,
start_time = 0.0,
smooth = false)
@named output = RealOutput()
pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase damping=damping

equation = if smooth == false
offset + ifelse(t < start_time, 0,
offset + ifelse(t < start_time, zero(amplitude),
amplitude * exp(-damping * (t - start_time)) *
sin(2 * pi * frequency * (t - start_time) + phase))
else
Expand Down