I've integrated several Python unit operations into DWSIM flowsheets, and so far everything has been going well and I've been able to understand the documentation for the most part. I'm currently running into an issue where I need to enforce bounds on temperature and pressure variables (which I am adjusting in two separate Control/Adjust blocks) in order to satisfy an exhaust pressure, and I need the sheet to solve upon an event (e.g. saving the flowsheet). As a result, it seems that the only built-in way to enforce manipulated variable bounds is to use the Brent solver, and the best way to call the solver would be to use the simulation script manager.
It appears that if I did not need the Brent method, I could use FlowsheetSolver.SolveSimultaneousAdjusts(). Looking at the documentation for the Adjust class, I'm not seeing anything obvious that allows me to run the calculation aside from Adjust.Calculate() and Adjust.Solve(), which are not defined for this class. Is there somewhere else that I haven't looked yet which will enable me to trigger this operation programmatically?
On a side-note - is there anything that will allow me to enforce bounds on manipulated variables if I enable "Converge/Solve with Flowsheet Solver"? Again, the only reason I'm using this is because if bounds aren't enforced, I end up with negative pressure errors or flash errors in the simulation that interrupt the simulation.
Some example code below of me trying things...
fromDWSIM.FlowsheetSolverimportFlowsheetSolverpressureSolver=Flowsheet.GetFlowsheetSimulationObject('PRESSURE')# A "Control/Adjust" ObjecttempSolver=Flowsheet.GetFlowsheetSimulationObject('TEMP')# A "Control/Adjust" Objects=FlowsheetSolver()# Outputs: 1 10/21/2021 9:21:14 AM Message <class 'DWSIM.UnitOperations.SpecialOps.Adjust'> + InfoFlowsheet.WriteMessage(str(type(pressureSolver)))# 13 10/21/2021 9:55:04 AM Error Errors occurred during the # calculation of the flowsheet, please read the following messages for # more details. + Info# 14 10/21/2021 9:55:04 AM Error <NAME REDACTED>: The method# or operation is not implemented. + Infos.CalculateObject(Flowsheet,pressureSolver.Name)#pressureSolver.MinVal = #pressureSolver.MaxVal = #waterBalSolver.MinVal = #pressureSolver.MaxVal = #5 10/21/2021 9:21:57 AM Error Error running script '': System.NotImplementedException: The method or operation is not implemented.#pressureSolver.Calculate()#waterBalSolver.Solve()
Thanks,
Andrew
Last edit: Andrew L 2021-10-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The current method that support bounds to solve the controllers is tied to the GUI, that is, there is no way of calling its Calculate() function. When you use the simultaneous adjust solver, the Flowsheet Solver takes care of solving all controllers at once using a Newton/Secant method, which doesn't take into account variable bounds. This is its current behavior, but it can be enhanced to support variable bounds. There are no limitations, it was just a design decision.
Regards
Daniel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey all,
I've integrated several Python unit operations into DWSIM flowsheets, and so far everything has been going well and I've been able to understand the documentation for the most part. I'm currently running into an issue where I need to enforce bounds on temperature and pressure variables (which I am adjusting in two separate Control/Adjust blocks) in order to satisfy an exhaust pressure, and I need the sheet to solve upon an event (e.g. saving the flowsheet). As a result, it seems that the only built-in way to enforce manipulated variable bounds is to use the Brent solver, and the best way to call the solver would be to use the simulation script manager.
It appears that if I did not need the Brent method, I could use
FlowsheetSolver.SolveSimultaneousAdjusts(). Looking at the documentation for the Adjust class, I'm not seeing anything obvious that allows me to run the calculation aside fromAdjust.Calculate()andAdjust.Solve(), which are not defined for this class. Is there somewhere else that I haven't looked yet which will enable me to trigger this operation programmatically?On a side-note - is there anything that will allow me to enforce bounds on manipulated variables if I enable "Converge/Solve with Flowsheet Solver"? Again, the only reason I'm using this is because if bounds aren't enforced, I end up with negative pressure errors or flash errors in the simulation that interrupt the simulation.
Some example code below of me trying things...
Thanks,
Andrew
Last edit: Andrew L 2021-10-21
Hi Andrew,
The current method that support bounds to solve the controllers is tied to the GUI, that is, there is no way of calling its Calculate() function. When you use the simultaneous adjust solver, the Flowsheet Solver takes care of solving all controllers at once using a Newton/Secant method, which doesn't take into account variable bounds. This is its current behavior, but it can be enhanced to support variable bounds. There are no limitations, it was just a design decision.
Regards
Daniel
Thanks, Daniel. I searched the code and found the area of interest, which should give me enough to move on for now.
I'll consider branching and putting in a PR in the future.