1- using ModelingToolkit: operation
1+ using ModelingToolkit: operation, istree, arguments
22# Method of lines discretization scheme
33struct MOLFiniteDifference{T} <: DiffEqBase.AbstractDiscretization
44 dxs:: T
@@ -25,58 +25,62 @@ function get_bcs(bcs,tdomain,domain)
2525 num_bcs = size (bcs,1 )
2626 for i = 1 : num_bcs
2727 lhs = bcs[i]. lhs
28+ @show lhs
2829 # Extract the variable from the lhs
2930 if operation (lhs) isa Sym
3031 # Dirichlet boundary condition
3132 var = nameof (operation (lhs))
3233 α = 1.0
3334 β = 0.0
34- bc_args = lhs. args
35+ bc_args = arguments ( lhs)
3536 elseif operation (lhs) isa Differential
3637 # Neumann boundary condition
3738 # Check that we don't have a second-order derivative in the
3839 # boundary condition, by checking that the argument is a Sym
39- @assert operation (lhs. args [1 ]) isa Sym throw_bc_err (bcs[i])
40- var = nameof (operation (lhs. args [1 ]))
40+ @assert operation (arguments ( lhs) [1 ]) isa Sym throw_bc_err (bcs[i])
41+ var = nameof (operation (arguments ( lhs) [1 ]))
4142 α = 0.0
4243 β = 1.0
43- bc_args = lhs. args [1 ]. args
44- elseif operation (lhs) isa typeof ( + )
44+ bc_args = arguments ( arguments ( lhs) [1 ])
45+ elseif operation (lhs) === +
4546 # Robin boundary condition
46- lhs_l, lhs_r = lhs. args
47+ lhs_l, lhs_r = arguments ( lhs)
4748 # Left side of the expression should be Sym or α * Sym
49+ @show lhs_l
4850 if operation (lhs_l) isa Sym
4951 α = 1.0
5052 var_l = nameof (operation (lhs_l))
51- bc_args_l = lhs_l. args
52- elseif operation (lhs_l) isa typeof ( * )
53- α = lhs_l. args [1 ]
53+ bc_args_l = arguments ( lhs_l)
54+ elseif operation (lhs_l) === *
55+ α = arguments ( lhs_l) [1 ]
5456 # Convert α to a Float64 if it is an Int, leave unchanged otherwise
5557 α = α isa Int ? Float64 (α) : α
56- @assert operation (lhs_l. args [2 ]) isa Sym throw_bc_err (bcs[i])
57- var_l = nameof (operation (lhs_l. args [2 ]))
58- bc_args_l = lhs_l. args [2 ]. args
58+ @assert operation (arguments ( lhs_l) [2 ]) isa Sym throw_bc_err (bcs[i])
59+ var_l = nameof (operation (arguments ( lhs_l) [2 ]))
60+ bc_args_l = arguments ( arguments ( lhs_l) [2 ])
5961 else
6062 throw_bc_err (bcs[i])
6163 end
6264 # Right side of the expression should be Differential or β * Differential
6365 if operation (lhs_r) isa Differential
6466 # Check that we don't have a second-order derivative in the
6567 # boundary condition
66- @assert operation (lhs_r. args [1 ]) isa Sym throw_bc_err (bcs[i])
68+ @assert operation (arguments ( lhs_r) [1 ]) isa Sym throw_bc_err (bcs[i])
6769 β = 1.0
68- var_r = nameof (operation (lhs_r. args [1 ]))
69- bc_args_r = lhs_r. args [1 ]. args
70+ var_r = nameof (operation (arguments ( lhs_r) [1 ]))
71+ bc_args_r = arguments ( arguments ( lhs_r) [1 ])
7072 elseif operation (lhs_r) isa typeof (* )
71- β = lhs_r. args [1 ]
73+ β = arguments ( lhs_r) [1 ]
7274 # Convert β to a Float64 if it is an Int, leave unchanged otherwise
7375 β = β isa Int ? Float64 (β) : β
7476 # Check that the bc is a derivative
75- @assert operation (lhs_r. args[2 ]) isa Differential throw_bc_err (bcs[i])
77+ lhs_r2 = arguments (lhs_r)[2 ]
78+ @assert operation (lhs_r2) isa Differential throw_bc_err (bcs[i])
7679 # But not second order (argument should be a Sym)
77- @assert operation (lhs_r. args[2 ]. args[1 ]) isa Sym throw_bc_err (bcs[i])
78- var_r = nameof (operation (lhs_r. args[2 ]. args[1 ]))
79- bc_args_r = lhs_r. args[2 ]. args[1 ]. args
80+ lhsrr1 = arguments (lhs_r2)[1 ]
81+ @assert operation (lhsrr1) isa Sym throw_bc_err (bcs[i])
82+ var_r = nameof (operation (lhsrr1))
83+ bc_args_r = arguments (lhsrr1)
8084 else
8185 throw_bc_err (bcs[i])
8286 end
@@ -148,7 +152,7 @@ function discretize_2(input,deriv_order,approx_order,dx,X,len_of_indep_vars,
148152 if ! (input isa ModelingToolkit. Symbolic)
149153 return :($ (input))
150154 else
151- if input isa Sym || (input isa Term && operation (input) isa Sym)
155+ if input isa Sym || (istree ( input) && operation (input) isa Sym)
152156 expr = :(0.0 )
153157 var = nameof (input isa Sym ? input : operation (input))
154158 if haskey (indep_var_idx,var) # ind. var.
@@ -176,7 +180,7 @@ function discretize_2(input,deriv_order,approx_order,dx,X,len_of_indep_vars,
176180 end
177181 end
178182 return expr
179- elseif input isa Term && operation (input) isa Differential
183+ elseif istree ( input) && operation (input) isa Differential
180184 var = nameof (input. op. x)
181185 push! (deriv_var,var)
182186 return discretize_2 (input. args[1 ],deriv_order+ 1 ,approx_order,dx,X,
@@ -272,7 +276,7 @@ function DiffEqBase.discretize(pdesys::PDESystem,discretization::MOLFiniteDiffer
272276 if op isa Sym
273277 var = nameof (op)
274278 else # var isa Differential
275- var = nameof (operation (input. args [1 ]))
279+ var = nameof (operation (arguments ( input) [1 ]))
276280 lhs_deriv_depvars[var] = j
277281 end
278282 dep_var_idx[var] = j
0 commit comments