Skip to content

Commit e60b1f2

Browse files
Merge pull request #1230 from ashutosh-b-b/newIntegral
Refactor get_unit for Integral
2 parents 93c1ec2 + 21537f5 commit e60b1f2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/systems/validation.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ get_unit(x::Num) = get_unit(value(x))
4141
get_unit(x::Literal) = screen_unit(getmetadata(x,VariableUnit, unitless))
4242
get_unit(op::Differential, args) = get_unit(args[1]) / get_unit(op.x)
4343
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])
4545
function get_unit(op,args) # Fallback
4646
result = op(1 .* get_unit.(args)...)
47-
try
47+
try
4848
unit(result)
49-
catch
49+
catch
5050
throw(ValidationError("Unable to get unit for operation $op with arguments $args."))
5151
end
5252
end
5353

5454
function get_unit(op::Integral,args)
5555
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
5858
unit *= get_unit(u)
5959
end
6060
else
61-
unit *= get_unit(op.x)
61+
unit *= get_unit(op.domain.variables)
6262
end
6363
return get_unit(args[1]) * unit
6464
end
@@ -105,12 +105,12 @@ function get_unit(op::Comparison, args)
105105
return unitless
106106
end
107107

108-
function get_unit(x::Symbolic)
108+
function get_unit(x::Symbolic)
109109
if SymbolicUtils.istree(x)
110110
op = operation(x)
111111
if op isa Sym || (op isa Term && operation(op) isa Term) # Dependent variables, not function calls
112112
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)
114114
gp = getmetadata(x,Symbolics.GetindexParent,nothing) # Like x[1](t)
115115
return screen_unit(getmetadata(gp, VariableUnit, unitless))
116116
end # Actual function calls:
@@ -195,4 +195,4 @@ validate(term::Symbolics.SymbolicUtils.Symbolic) = safe_get_unit(term,"") !== no
195195

196196
"Throws error if units of equations are invalid."
197197
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

Comments
 (0)