Menu

Access Python user model variable value when controling DWsim via an external Python

2025-05-08
2025-05-12
  • Hugo Brunner

    Hugo Brunner - 2025-05-08

    Hello,

    How can I modify variables of a User model written as a Python script when controlling DWSIM externally via Python using Python.NET?

    For example, if I have a script that simulates a thermal storage system, where one of the input variables (other than fluid streams) is its volume, and I would like to modify it dynamically (for example to find an optimal shape), how can I do that?

    Is it with the scripting variables? If yes, how can I do that? Are they avalaible when controling DWsim through an external Python via Python.NET?

    Thank you in advance and have a good day,

     
    • Daniel Medeiros

      Daniel Medeiros - 2025-05-08

      you have to define the variable in the location you took the screenshot of and access it with

      myop.InputVariables['volume'] = 100
      
       
      • Hugo Brunner

        Hugo Brunner - 2025-05-12

        Thank you for your answer.

        So in the Python code that controls the DWsim flowsheet, when I would want to change the "volume", I will write the following line that you sent?
        myop.InputVariables['volume'] = 100
        The name of the scripting variable would be "volume" in my example (like in this screenshot)? The "myop" is the name to access the unit operation? How do I set it up?

        And in the Python code of the unit operation, what do I change to make the link with this variable and the unit operation code?

         
  • Hugo Brunner

    Hugo Brunner - 2025-05-09
     

    Last edit: Hugo Brunner 2025-05-12
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.