@@ -91,34 +91,37 @@ function rhs(e::ExpRelaxation)
91
91
end
92
92
93
93
"""
94
- AdditionProcess(process, added)
94
+ AdditionProcess(process, added... )
95
95
96
- A convenience process for adding `added` to the `rhs` of the given `process`.
97
- `added` can be a `Process` or `Equation`, in which case it is checked that
98
- the `lhs_variable` matches. Otherwise, it can be an arbitrary expression.
96
+ A convenience process for adding processes `added` to the `rhs` of the given `process`.
97
+ `added` can be a single symbolic expression. Otherwise,
98
+ `added` can be a `Process` or `Equation`, or multitude of them, in which case it is checked
99
+ that the `lhs_variable` across all added components matches the `process`.
99
100
"""
100
101
struct AdditionProcess <: Process
101
102
process
102
- added
103
- function AdditionProcess (process, added)
104
- if typeof (added) <: Union{Process, Equation}
105
- if ModelingToolkit. getname (lhs_variable (process)) ≠ ModelingToolkit. getname (lhs_variable (added))
106
- @show lhs_variable (process), lhs_variable (added)
107
- throw (ArgumentError (" Added component does not have the same lhs variable." ))
103
+ added:: Vector
104
+ function AdditionProcess (process, added:: Vector )
105
+ for add in added
106
+ if typeof (add) <: Union{Process, Equation}
107
+ v1, v2 = ModelingToolkit. getname (lhs_variable (process)), ModelingToolkit. getname (lhs_variable (add))
108
+ if v1 ≠ v2
109
+ throw (ArgumentError (
110
+ " Added processes do not have the same lhs variable. Got: $(v1) , $(v2) "
111
+ ))
112
+ end
108
113
end
109
114
end
110
115
return new (process, added)
111
116
end
112
117
end
118
+ AdditionProcess (process, added... ) = AdditionProcess (process, collect (added))
119
+ AdditionProcess (process, added:: Num ) = AdditionProcess (process, lhs (process) ~ added)
113
120
114
121
lhs_variable (a:: AdditionProcess ) = lhs_variable (a. process)
115
122
timescale (a:: AdditionProcess ) = timescale (a. process)
116
123
117
124
function rhs (a:: AdditionProcess )
118
- if typeof (a. added) <: Union{Process, Equation}
119
- plus = rhs (a. added)
120
- else
121
- plus = a. added
122
- end
123
- return rhs (a. process) + plus
125
+ exprs = [rhs (p) for p in a. added]
126
+ return + (rhs (a. process), exprs... )
124
127
end
0 commit comments