Hi-I am also trying with these commands from the script, but it looks like it only updates when I click "Solve Flowsheet". I am setting mass flow but the volumetric flow does not update until I click...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you want to preserve other input data like T, P and/or composition and setting any of the flows, you must make the other ones null (C#), Nothing (VB.NET) or None (Python), so DWSIM will know internally which one you've set and calculate the other two:
ms.Phases[0].Properties.massflow=100#kg/sms.Phases[0].Properties.molarflow=Nonems.Phases[0].Properties.volumetric_flow=Nonems.Calculate()# assuming T, P and composition are already set
Last edit: Daniel Medeiros 2019-09-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding the programming organization of scripts:
I have a script for any block in the flowsheet I want to control (settings parameters, providing modification when the calculation on the block is over ecc...). What is missing is a main script from which introduce 'global' variables to use in the blocks afterward (instead of use the spreadsheet, cause it enlarges too much the computing effort in case I would do sensitivity analysis).
My question is:
can I share functions (i.e. def) and variables from a main script with the remaining scripts?
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think your code is useful to share the 'def' defined in an other script, not so much for variables. is that right?
Below the structure of my scripts for complex steam-grid model.
Main
with the main settings and internal calculation of parameters to input in blocks. This code is not linked to events. At the end of the script I run the solve the times, or I can do dynamic simulations by:
Solver.SolveFlowsheet(Flowsheet,1)
PS: what does the second input the function is useful for? (i mean the integer 1).
Function
i can write all the def useful for razionalize the code. In next scripts I will use your code above to load the def to use
Block script
An script for each block I want to control. Each script is linked to the "calculation executed" event on that block. At the beginning of each script I run the function script and load the defs. For a splitter when the solver.solveflowsheet occurs and the iteration reach the splitter, the slipt will modify the process at the end of the iteration on the blocks. It worked greatfully as you suggested to me.
Issue: how to load variables (integers, strings, boolean ...) form the main to the block scripts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As for the integer solver argument, it defines the solving method to be used, 0 uses the main (GUI) thread, meaning that the graphical interface will become sluggish until the solver finishes its job. 1 uses a background thread, it is faster and the GUI remains responsive all the time.
Last edit: Daniel Medeiros 2020-01-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Daniel,
thank for your greatful support.
Nonetheless I don't manage to succed yet my task.
As I wrote in my reply of 2020-01-19, I have a main with my variables on it (constants, integers ...). Then I have several scripts that activate when calculations on customized python blocks is over.
I would like to get with scripts my variables defined in the main.
or to use global method as you suggested.
But the variables of the main script are not available when running "secondary" scripts.
Additionally
I am unable to load the functions from a script to an other by using the Flowsheet.Scripts.Values.Where() method. I mean, I have many defs in the script 'Functions' but using this code I cannot load anything from an reuse on purpose.
Last edit: Mario Cilento 2020-01-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Without access to your simulation, I can't do anything else to help you. You could become a Patron and we would then have a private support channel where you could send me your file through.
Regards
Daniel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For completion,
I was able to proceed with this by assigning simulation variables needed to the object in the flowsheet as custom object attributes (I mean by adding a ".attribute" to pre-defined object, a custom value to use from wherever I want).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I was wondering if it was possible to develop Python code in some other development environment (for example Spyder, and then "copy / paste" into DWSIM Python Script Editor). It is a bit hard for me to check for intermediate results without the Console window and some graphical help.
Also I was not able to find a complete list of all the syntax that can be used (for example to call a flash)... maybe I searched badly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the reply Daniel.
For example I was stuck trying to do a flash with imposed pressure and enthalpy. I know that writing a complete help is very time consuming, but even a simple list of the main syntax associated with DWSIM-Python would be quite useful for all the community.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Honestly, I need too of a complete "help" for the ironpythonic usage of script manager.
Nonetheless, you can set 'pause' along your script, and from last releases of DWSIM the object inspector opens, so that you can inspect whatever object you want, together with all object from current flowsheet.
Simultaneously, it can be very handly to use print "something" function, displaying along the run the results of your code, as Daniele suggested.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is very time-consuming to write a complete help for the scripting system. It is not something easy to do and there are so many possibilities which makes it impossible to cover everything.
If you really need more specialized help, you can join the DWSIM Patron Program starting from Tier 2 and I'll be able to help you directly, as you will have priority on my to-do list.
Regards
Daniel
Last edit: Daniel Medeiros 2020-04-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have participated in the FOSSEE Custom modeling project hence was looking at some previously completed codes.
So what is the use of the command 'Flowsheet.Writemessage()'
Thanks in advance!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Start a new discussion thread for such questions to help other people with similar doubt.
coming back to your question, the above command is used to print text or variables in the text box where errors are written (message box).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Last edit: Daniel Medeiros 2024-05-05
Hello Daniel,
How can we use SolveFlowsheet method in a python script withon DWSIM ?
Kindly
Classic UI:
1. Flowsheet.RequestCalculation(): https://github.com/DanWBR/dwsim5/blob/windows/DWSIM/Forms/Flowsheet/FormFlowsheet.vb#L2787
2. Flowsheet.SolveFlowsheet2(): https://github.com/DanWBR/dwsim5/blob/windows/DWSIM/Forms/Flowsheet/FormFlowsheet.vb#L442
Cross-Platform UI:
1. Flowsheet.RequestCalculation(): https://github.com/DanWBR/dwsim5/blob/windows/DWSIM.FlowsheetBase/FlowsheetBase.vb#L305
I can't figure out how to use it exactly, can you send me an example ?
just write the command Flowsheet.RequestCalculation()
Hi-I am also trying with these commands from the script, but it looks like it only updates when I click "Solve Flowsheet". I am setting mass flow but the volumetric flow does not update until I click...
When you want to preserve other input data like T, P and/or composition and setting any of the flows, you must make the other ones null (C#), Nothing (VB.NET) or None (Python), so DWSIM will know internally which one you've set and calculate the other two:
Last edit: Daniel Medeiros 2019-09-16
Thank you Daniel. So you must re-calculate on each stream simulation object?
Hi Daniel,
How i can override temperature and pressure of a flash separator from python script ?
Thanks
Please create a new topic, Ja.
Regarding the programming organization of scripts:
I have a script for any block in the flowsheet I want to control (settings parameters, providing modification when the calculation on the block is over ecc...). What is missing is a main script from which introduce 'global' variables to use in the blocks afterward (instead of use the spreadsheet, cause it enlarges too much the computing effort in case I would do sensitivity analysis).
My question is:
can I share functions (i.e. def) and variables from a main script with the remaining scripts?
Thank you
Yes. Take a look at the dynamic simulation tutorial for some insights: http://dwsim.inforside.com.br/wiki/index.php?title=Dynamic_Simulation_Tutorial_with_DWSIM_and_Python,_Part_2:_Building_the_Dynamic_Model
You can get the text from other scripts and run it using exec:
Thank you daniel madeiros for the answer.
I think your code is useful to share the 'def' defined in an other script, not so much for variables. is that right?
Below the structure of my scripts for complex steam-grid model.
Main
with the main settings and internal calculation of parameters to input in blocks. This code is not linked to events. At the end of the script I run the solve the times, or I can do dynamic simulations by:
PS: what does the second input the function is useful for? (i mean the integer 1).
Function
i can write all the def useful for razionalize the code. In next scripts I will use your code above to load the def to use
Block script
An script for each block I want to control. Each script is linked to the "calculation executed" event on that block. At the beginning of each script I run the function script and load the defs. For a splitter when the solver.solveflowsheet occurs and the iteration reach the splitter, the slipt will modify the process at the end of the iteration on the blocks. It worked greatfully as you suggested to me.
For variables you must use the global qualifier as in this example (counter variable): http://dwsim.inforside.com.br/wiki/index.php?title=Dynamic_Simulation_Tutorial_with_DWSIM_and_Python,_Part_4:_Tuning_the_PID_Controller_through_Non-Linear_Optimization#Tuning_the_PID_Controller_using_the_Simplex_method
More info: https://www.programiz.com/python-programming/global-keyword
As for the integer solver argument, it defines the solving method to be used, 0 uses the main (GUI) thread, meaning that the graphical interface will become sluggish until the solver finishes its job. 1 uses a background thread, it is faster and the GUI remains responsive all the time.
Last edit: Daniel Medeiros 2020-01-20
Dear Daniel,
thank for your greatful support.
Nonetheless I don't manage to succed yet my task.
As I wrote in my reply of 2020-01-19, I have a main with my variables on it (constants, integers ...). Then I have several scripts that activate when calculations on customized python blocks is over.
I would like to get with scripts my variables defined in the main.
I tried to do
or to use global method as you suggested.
But the variables of the main script are not available when running "secondary" scripts.
Additionally
I am unable to load the functions from a script to an other by using the Flowsheet.Scripts.Values.Where() method. I mean, I have many defs in the script 'Functions' but using this code I cannot load anything from an reuse on purpose.
Last edit: Mario Cilento 2020-01-29
Hi Mario,
Without access to your simulation, I can't do anything else to help you. You could become a Patron and we would then have a private support channel where you could send me your file through.
Regards
Daniel
For completion,
I was able to proceed with this by assigning simulation variables needed to the object in the flowsheet as custom object attributes (I mean by adding a ".attribute" to pre-defined object, a custom value to use from wherever I want).
Hello,
I was wondering if it was possible to develop Python code in some other development environment (for example Spyder, and then "copy / paste" into DWSIM Python Script Editor). It is a bit hard for me to check for intermediate results without the Console window and some graphical help.
Also I was not able to find a complete list of all the syntax that can be used (for example to call a flash)... maybe I searched badly.
what are you trying to do? I usually use print(), but you can also insert breakpoints to check the variable values at such points.
Thanks for the reply Daniel.
For example I was stuck trying to do a flash with imposed pressure and enthalpy. I know that writing a complete help is very time consuming, but even a simple list of the main syntax associated with DWSIM-Python would be quite useful for all the community.
You could've just asked here in a new topic. :-)
Honestly, I need too of a complete "help" for the ironpythonic usage of script manager.
Nonetheless, you can set 'pause' along your script, and from last releases of DWSIM the object inspector opens, so that you can inspect whatever object you want, together with all object from current flowsheet.
Simultaneously, it can be very handly to use print "something" function, displaying along the run the results of your code, as Daniele suggested.
It is very time-consuming to write a complete help for the scripting system. It is not something easy to do and there are so many possibilities which makes it impossible to cover everything.
As free resources, you have this forum and some pages with samples, where you can take some code snippets here and there and build what you need: http://dwsim.inforside.com.br/wiki/index.php?title=Tutorials
If you really need more specialized help, you can join the DWSIM Patron Program starting from Tier 2 and I'll be able to help you directly, as you will have priority on my to-do list.
Regards
Daniel
Last edit: Daniel Medeiros 2020-04-06
I have participated in the FOSSEE Custom modeling project hence was looking at some previously completed codes.
So what is the use of the command 'Flowsheet.Writemessage()'
Thanks in advance!
Start a new discussion thread for such questions to help other people with similar doubt.
coming back to your question, the above command is used to print text or variables in the text box where errors are written (message box).