@@ -56,95 +56,6 @@ function removeQuoteNode(ex::Expr)
56
56
Expr (ex. head, [removeQuoteNode (arg) for arg in ex. args]. .. )
57
57
end
58
58
59
- prependPar (ex, prefix, parameters= [], inputs= []) = ex
60
-
61
- function prependPar (ex:: Symbol , prefix, parameters= [], inputs= [])
62
- if prefix == nothing ; ex elseif ex in [:time , :instantiatedModel , :_leq_mode , :_x ]; ex else Expr (:ref , prefix, QuoteNode (ex)) end
63
- end
64
-
65
- function prependPar (ex:: Expr , prefix, parameters= [], inputs= [])
66
- if isexpr (ex, :.)
67
- Expr (:ref , prependPar (ex. args[1 ], prefix, parameters, inputs), QuoteNode (ex. args[2 ]. value))
68
- else
69
- Expr (ex. head, [prependPar (arg, prefix, parameters, inputs) for arg in ex. args]. .. )
70
- end
71
- end
72
-
73
- """
74
- e = castToFloatType(ex,value)
75
-
76
- If manageable, cast `ex` to FloatType, if this is an `AbstractFloat` (`typeof(value) <: AbstractFloat`)
77
- and define it to be FloatType (called _FloatType in getDerivatives), so `FloatType(ex)::FloatType`.
78
-
79
- If this is not manageable, cast `ex` to `valueType = typeof(value)` if this is a numeric data datatype
80
- (`eltype(value) <: Number`), and define it to be `valueType`, so `valueType(ex)::valueType`.
81
-
82
- As a result, the generated code of `ex` will have the correct type instead of `Any`,
83
- so will be more efficient and no unnecessary memory will be calculated at run-time.
84
-
85
- Note, this function should only be used on parameter, init, or start values.
86
- """
87
- function castToFloatType (ex,value)
88
- if eltype (value) <: Number
89
- valueType = typeof (value)
90
- if valueType <: AbstractFloat && ! (valueType <: Unitful.AbstractQuantity ||
91
- valueType <: Measurements.Measurement ||
92
- valueType <: MonteCarloMeasurements.AbstractParticles )
93
- :( _FloatType ($ ex):: _FloatType )
94
- else
95
- :( $ valueType ($ ex):: $valueType )
96
- end
97
- else
98
- ex
99
- end
100
- end
101
-
102
- """
103
- e = makeDerVar(ex)
104
-
105
- Recursively converts der(x) to Symbol(:(der(x))) in expression `ex`
106
-
107
- * `ex`: Expression or array of expressions
108
- * `return `e`: ex with der(x) converted
109
- """
110
- function makeDerVar (ex, parameters, inputs, evaluateParameters= false )
111
- if typeof (ex) in [Symbol, Expr]
112
- if ex in keys (parameters)
113
- castToFloatType ( prependPar (ex, :(_p), parameters, inputs), parameters[ex] )
114
- elseif ex in keys (inputs)
115
- prependPar (ex, :(_p), parameters, inputs)
116
- else
117
- ex
118
- end
119
- else
120
- ex
121
- end
122
- end
123
-
124
- function makeDerVar (ex:: Expr , parameters, inputs, evaluateParameters= false )
125
- if ex. head == :call && ex. args[1 ] == :der
126
- Symbol (ex)
127
- elseif isexpr (ex, :.) && ex in keys (parameters)
128
- if evaluateParameters
129
- parameters[ex]
130
- else
131
- castToFloatType ( prependPar (ex, :(_p), parameters, inputs), parameters[ex] )
132
- end
133
- elseif isexpr (ex, :.) && ex in keys (inputs)
134
- if evaluateParameters
135
- inputs[ex]
136
- else
137
- prependPar (ex, :(_p), parameters, inputs)
138
- end
139
- elseif ex. head == :.
140
- Symbol (ex)
141
- elseif ex. head == :call # Don't change dot-notation for function calls
142
- Expr (ex. head, ex. args[1 ], [makeDerVar (arg, parameters, inputs, evaluateParameters) for arg in ex. args[2 : end ]]. .. )
143
- else
144
- Expr (ex. head, [makeDerVar (arg, parameters, inputs, evaluateParameters) for arg in ex. args]. .. )
145
- end
146
- end
147
-
148
59
removeUnits (ex) = if typeof (ex) <: Unitful.Quantity ; @show ex; ustrip (ex) else ex end
149
60
removeUnits (ex:: Expr ) = if ex. head == :macrocall && ex. args[1 ] == Symbol (" @u_str" ); 1 else Expr (ex. head, [removeUnits (arg) for arg in ex. args]. .. ) end
150
61
0 commit comments