Skip to content

Commit d158f95

Browse files
author
Sathvik Bhagavan
committed
refactor(Blocks): add isarray kwarg in RealInput/Output to have the option of creating 1 element symbolic vector
1 parent 02a134c commit d158f95

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Blocks/utils.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
@connector function RealInput(; name, nin = 1, u_start = nin > 1 ? zeros(nin) : 0.0)
2-
if nin == 1
1+
@connector function RealInput(;
2+
name, nin = 1, isarray = false, u_start = isarray ? zeros(nin) : 0.0)
3+
if nin == 1 && !isarray
34
@variables u(t)=u_start [
45
input = true,
56
description = "Inner variable in RealInput $name"
@@ -21,13 +22,15 @@ Connector with one input signal of type Real.
2122
# Parameters:
2223
- `nin=1`: Number of inputs
2324
- `u_start=0`: Initial value for `u`
25+
- `isarray=false`: This is only applicable for `nin=1`. Boolean flag to use a scalar or a one element symbolic vector
2426
2527
# States:
2628
- `u`: Value of the connector; if nin=1 this is a scalar
2729
""" RealInput
2830

29-
@connector function RealOutput(; name, nout = 1, u_start = nout > 1 ? zeros(nout) : 0.0)
30-
if nout == 1
31+
@connector function RealOutput(;
32+
name, nout = 1, isarray = true, u_start = isarray ? zeros(nout) : 0.0)
33+
if nout == 1 && !isarray
3134
@variables u(t)=u_start [
3235
output = true,
3336
description = "Inner variable in RealOutput $name"
@@ -49,6 +52,7 @@ Connector with one output signal of type Real.
4952
# Parameters:
5053
- `nout=1`: Number of outputs
5154
- `u_start=0`: Initial value for `u`
55+
- `isarray=false`: This is only applicable for `nout=1`. Boolean flag to use a scalar or a one element symbolic vector
5256
5357
# States:
5458
- `u`: Value of the connector; if nout=1 this is a scalar

0 commit comments

Comments
 (0)