@@ -41,24 +41,24 @@ get_unit(x::Num) = get_unit(value(x))
41
41
get_unit (x:: Literal ) = screen_unit (getmetadata (x,VariableUnit, unitless))
42
42
get_unit (op:: Differential , args) = get_unit (args[1 ]) / get_unit (op. x)
43
43
get_unit (op:: Difference , args) = get_unit (args[1 ]) / get_unit (op. t)
44
- get_unit (op:: typeof (getindex),args) = get_unit (args[1 ])
44
+ get_unit (op:: typeof (getindex),args) = get_unit (args[1 ])
45
45
function get_unit (op,args) # Fallback
46
46
result = op (1 .* get_unit .(args)... )
47
- try
47
+ try
48
48
unit (result)
49
- catch
49
+ catch
50
50
throw (ValidationError (" Unable to get unit for operation $op with arguments $args ." ))
51
51
end
52
52
end
53
53
54
54
function get_unit (op:: Integral ,args)
55
55
unit = 1
56
- if op. x isa Vector
57
- for u in op. x
56
+ if op. domain . variables isa Vector
57
+ for u in op. domain . variables
58
58
unit *= get_unit (u)
59
59
end
60
60
else
61
- unit *= get_unit (op. x )
61
+ unit *= get_unit (op. domain . variables )
62
62
end
63
63
return get_unit (args[1 ]) * unit
64
64
end
@@ -105,12 +105,12 @@ function get_unit(op::Comparison, args)
105
105
return unitless
106
106
end
107
107
108
- function get_unit (x:: Symbolic )
108
+ function get_unit (x:: Symbolic )
109
109
if SymbolicUtils. istree (x)
110
110
op = operation (x)
111
111
if op isa Sym || (op isa Term && operation (op) isa Term) # Dependent variables, not function calls
112
112
return screen_unit (getmetadata (x, VariableUnit, unitless)) # Like x(t) or x[i]
113
- elseif op isa Term && ! (operation (op) isa Term)
113
+ elseif op isa Term && ! (operation (op) isa Term)
114
114
gp = getmetadata (x,Symbolics. GetindexParent,nothing ) # Like x[1](t)
115
115
return screen_unit (getmetadata (gp, VariableUnit, unitless))
116
116
end # Actual function calls:
@@ -195,4 +195,4 @@ validate(term::Symbolics.SymbolicUtils.Symbolic) = safe_get_unit(term,"") !== no
195
195
196
196
" Throws error if units of equations are invalid."
197
197
check_units (eqs... ) = validate (eqs... ) || throw (ValidationError (" Some equations had invalid units. See warnings for details." ))
198
- all_dimensionless (states) = all (map (x-> safe_get_unit (x," " ) in (unitless,nothing ),states))
198
+ all_dimensionless (states) = all (map (x-> safe_get_unit (x," " ) in (unitless,nothing ),states))
0 commit comments