If you use the symbolic ModelingToolkit route, as you’re doing here, then you need to make sure your functions are symbolically-representable. CoolProp.jl’s functions are not registered for symbolic operations and so that’s what you’re hitting. I would either suggest just doing the normal purely numeric route (that would probably be more familiar, that’s usage more similar to SciPy), i.e. the first tutorial of NonlinearSolve.jl
Or if you stick the symbolic route (more similar to Modelica, CASADI, SymPy), you register your symbolic functions. The latter is done by:
using Symbolics
@register_symbolic CoolProp.PropsSI(x::String,y::String,z,a::String,b,c::String)
The full code looks like:
using ModelingToolkit, NonlinearSolve, CoolProp
using Symbolics
@register_symbolic CoolProp.PropsSI(x::String,y::String,z,a::String,b,c::String)
@variables dm ρ1 k1
@parameters a1 T1 P1
# Define a nonlinear system
eqs = [
ρ1 ~ PropsSI("D","T",T1,"P",P1,"AIR"),
k1 ~ PropsSI("ISENTROPIC_EXPANSION_COEFFICIENT","T",T1,"P",P1,"AIR"),
dm ~ a1 * sqrt(k1*ρ1*P1*(2/(k1+1))^((k1+1)/(k1-1)))
]
@mtkbuild ns = NonlinearSystem(eqs, [dm, ρ1, k1], [a1, T1, P1])
d1 = 0.15e-3
guess = [
dm => 0.5e-3,
ρ1 => 20
]
ps = [
P1 => 20e5,
a1 => (d1/2)^2 * pi,
T1 => 293.0
]
prob = NonlinearProblem(ns, guess, ps)
sol = solve(prob, NewtonRaphson())
sol[dm]
sol[ρ1]
sol[k1]
In this case, all of the equations symbolically simplify away and it builds the equations for the analytical solution. But that shouldn’t be surprising because the equations are all written as explicit computations, so I assume the real case must be more complex.