How should the scope of variables be embedded in ModelingToolkit?

When using ModelingToolkit to model and using NonlinearSolve to solve, I find that the variable range I have set seems to be ineffective.

@variables z[1:numcomp] [bounds = (0,1),guess=0.2] 
@variables x[1:numcomp] [bounds = (0,1),guess=0.2]  y[1:numcomp] [bounds = (0,1),guess=0.2] 
@variables flow_in [bounds = (0,100),guess=50]  liquid_out [bounds = (0,100),guess=50] vapor_out [bounds = (0,100),guess=50]
@variables enthalpy_in [bounds = (-1e18,1e18),guess=50]  enthalpy_liquid [bounds = (-1e18,1e18),guess=50] enthalpy_vapor [bounds = (-1e18,1e18),guess=50]
@variables vaporFraction [bounds = (0,1),guess=0.5]  T [bounds = (100,500),guess=298.15]  P [bounds = (0,10132500),guess=101325] 
@variables Q
@parameters flow_scale

How should I set the variable range to be an effective constraint when solving a system of nonlinear equations?

1 Like

ModelingToolkit is missing a check for the bounds, and NonlinearSolve.jl cannot force bounds on solves. It should throw an error here. Can you please open an issue on the ModelingToolkit.jl?

Using an unconstrained optimization with a trivial cost function (i.e. a constraint satisfaction problem) would be the right way to get solvers for this.

MTK could do a transform to make this work well, or NonlienarSolve could, but it at least doesn’t right now.

bounds = (-1e18,1e18) and that’s a bad idea :sweat_smile:

Thank you for your reply, I will go back and submit the relevant issue.