1- function ode_def_opts (name:: Symbol ,opts:: Dict{Symbol,Bool} ,ex:: Expr ,params... ;_M = I, depvar= :t )
1+ function ode_def_opts (name:: Symbol ,opts:: Dict{Symbol,Bool} ,ex:: Expr ,params... ;depvar= :t )
22 # depvar is the dependent variable. Defaults to t
33 # M is the mass matrix in RosW, must be a constant!
4+
45 origex = copy (ex) # Save the original expression
56
67 if ! (eltype (params) <: Symbol )
@@ -42,7 +43,7 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
4243
4344 numsyms = length (indvar_dict)
4445 numparams = length (params)
45- M = Matrix (1 * _M ,numsyms,numsyms)
46+ M = Matrix (1 * LinearAlgebra . I ,numsyms,numsyms)
4647 # Parameter Functions
4748 paramfuncs = Vector {Vector{Expr}} (undef, numparams)
4849 for i in 1 : numparams
@@ -52,8 +53,10 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
5253 end
5354 paramfuncs[i] = tmp_pfunc
5455 end
56+
5557 pfuncs = build_p_funcs (paramfuncs,indvar_dict,params)
5658
59+
5760 # Symbolic Setup
5861 symfuncs = Vector {SymEngine.Basic} (undef, 0 )
5962 symtgrad = Vector {SymEngine.Basic} (undef, 0 )
@@ -88,6 +91,7 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
8891 param_symjac = Matrix {SymEngine.Basic} (undef,numsyms,numparams)
8992 pderiv_exists = false
9093
94+
9195 if opts[:build_tgrad ] || opts[:build_jac ] || opts[:build_dpfuncs ]
9296 try # do symbolic calculations
9397
@@ -105,6 +109,7 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
105109 tgradex = build_tgrad_func (symtgrad,indvar_dict,params)
106110 catch err
107111 @warn (" Time Derivative Gradient could not be built" )
112+ symtgrad = Vector {SymEngine.Basic} (undef, 0 )
108113 end
109114 end
110115
@@ -118,11 +123,15 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
118123 end
119124 end
120125
126+
121127 # Build the Julia function
122128 Jex = build_jac_func (symjac,indvar_dict,params)
123129 bad_derivative (Jex)
124130 jac_exists = true
125131
132+
133+
134+
126135 if opts[:build_expjac ]
127136 try
128137 expjac = exp (γ* symjac) # This does not work, which is why disabled
@@ -145,11 +154,12 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
145154 @warn (" Jacobian could not invert" )
146155 end
147156 end
157+
148158 if opts[:build_invW ]
149159 try # Rosenbrock-W Inverse
150- L = Base. convert (SymEngine. CDenseMatrix,M - γ* symjac)
160+ L = Base. convert (SymEngine. CDenseMatrix,1 LinearAlgebra . I - γ* symjac)
151161 syminvW = inv (L)
152- L = Base. convert (SymEngine. CDenseMatrix,M / γ - symjac)
162+ L = Base. convert (SymEngine. CDenseMatrix,1 LinearAlgebra . I / γ - symjac)
153163 syminvW_t = inv (L)
154164 invWex = build_jac_func (syminvW,indvar_dict,params)
155165 bad_derivative (invWex)
@@ -158,6 +168,7 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
158168 bad_derivative (invWex_t)
159169 invW_t_exists = true
160170 catch err
171+ throw (err)
161172 @warn (" Rosenbrock-W could not invert" )
162173 end
163174 end
@@ -167,6 +178,7 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
167178 for i in eachindex (funcs), j in eachindex (syms)
168179 symhes[i,j] = diff (symjac[i,j],syms[j])
169180 end
181+
170182 # Build the Julia function
171183 Hex = build_jac_func (symhes,indvar_dict,params)
172184 bad_derivative (Hex)
@@ -187,7 +199,9 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
187199 end
188200 end
189201 catch err
202+ throw (err)
190203 @warn (" Failed to build the Jacobian. This means the Hessian is not built as well." )
204+ symjac = Matrix {SymEngine.Basic} (undef, 0 ,0 )
191205 end
192206 end # End Jacobian tree
193207
@@ -275,7 +289,6 @@ function ode_def_opts(name::Symbol,opts::Dict{Symbol,Bool},ex::Expr,params...;_M
275289 else
276290 param_jac_expr = :(nothing )
277291 end
278-
279292 # Build the type
280293 exprs = Vector {Expr} (undef, 0 )
281294
0 commit comments