Menu

IronPython Scripting Resources

2019-07-02
2023-01-03
1 2 > >> (Page 1 of 2)
  • Ja Eddouibi

    Ja Eddouibi - 2019-09-03

    I can't figure out how to use it exactly, can you send me an example ?

     
    • Daniel Medeiros

      Daniel Medeiros - 2019-09-03

      just write the command Flowsheet.RequestCalculation()

       
  • Jens Wallevik

    Jens Wallevik - 2019-09-16

    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...

     
    • Daniel Medeiros

      Daniel Medeiros - 2019-09-16

      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/s
      ms.Phases[0].Properties.molarflow = None
      ms.Phases[0].Properties.volumetric_flow = None 
      ms.Calculate() # assuming T, P and composition are already set
      
       

      Last edit: Daniel Medeiros 2019-09-16
      • Jens Wallevik

        Jens Wallevik - 2019-09-17

        Thank you Daniel. So you must re-calculate on each stream simulation object?

         
  • Ja Eddouibi

    Ja Eddouibi - 2019-09-16

    Hi Daniel,
    How i can override temperature and pressure of a flash separator from python script ?
    Thanks

     
    • Daniel Medeiros

      Daniel Medeiros - 2019-09-16

      Please create a new topic, Ja.

       
  • Mario Cilento

    Mario Cilento - 2020-01-14

    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

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-01-15

    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:

    source = Flowsheet.Scripts.Values.Where(lambda x: x.Title == 'Functions').FirstOrDefault().ScriptText.replace('\r', '')
    exec(source)
    
     
    • Mario Cilento

      Mario Cilento - 2020-01-19

      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:

       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?

       
  • Daniel Medeiros

    Daniel Medeiros - 2020-01-20

    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
    • Mario Cilento

      Mario Cilento - 2020-01-29

      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

      source = Flowsheet.Scripts.Values.Where(lambda x: x.Title == 'Functions').FirstOrDefault().ScriptText.replace('\r', '')
      exec(source)
      

      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
      • Daniel Medeiros

        Daniel Medeiros - 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

         
      • Mario Cilento

        Mario Cilento - 2020-04-06

        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).

         
  • Antonio P.

    Antonio P. - 2020-04-05

    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.

     
    • Daniel Medeiros

      Daniel Medeiros - 2020-04-06

      what are you trying to do? I usually use print(), but you can also insert breakpoints to check the variable values at such points.

       
      • Antonio P.

        Antonio P. - 2020-04-06

        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.

         
        • Daniel Medeiros

          Daniel Medeiros - 2020-04-06

          You could've just asked here in a new topic. :-)

           
    • Mario Cilento

      Mario Cilento - 2020-04-06

      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.

       
  • Daniel Medeiros

    Daniel Medeiros - 2020-04-06

    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
  • YASHRAJ PARAG KANASKAR

    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!

     
    • The One

      The One - 2021-04-15

      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).

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.