Menu

Refreshing/Updating ChemSep Column

2019-06-05
2019-06-10
  • Adam Spencer

    Adam Spencer - 2019-06-05

    Hello,

    I am trying to model a ChemSep distillation column automatically in DWSIM. I have been using File I/O in the IronPython Script in DWSIM to open the assocaited ChemSep .txt files (located in the Temp folder) and edit the specifications, such as side-draws and feed stages. After the .txt file is edited, the column must be "updated" so the information in the ChempSep GUI and .txt file are the same (I can do this manually by simply opening the ChemSep Column, then closing it) Is there a method to update the column automatically?

    Thank you!

     
  • Adam Spencer

    Adam Spencer - 2019-06-05

    I was using the Edit() function to open the GUI, however DWSIM does not seem to continue reading any more code until the column has been closed. I am trying to make the process continuous so the user does not have to close/interact with the column at all (on a clicking basis).

    When I did Column.Validate() I recieve the error:

    Error running script: Traceback (most recent call last):
    File "<string>", line 110, in <module>
    Exception: Check the connections of the object. + Info</module></string>

    I called Column.Calculate() but because not everything is hooked up properly (because the text file and GUI have not been synced up yet) it returns an error.

    I guess what I was wondering is if there is a sort of "refresh" method that would not calculate anything but would effectively "open and immediately close" the GUI so the text file is synced up correctly.

    Thank you very much.

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-06-06

    The Unit Operation object in DWSIM has a Validate() method but I was referring to the CAPE-OPEN object itself, which is an internal private variable. On the next update I'll expose it to the script.

    Perhaps you could take a look at the CAPE-OPEN Unit Operation specification, it describes how to interact with the object and the expected behavior when you do such method calls. http://www.colan.org/wp-content/uploads/2016/05/CO_Unit_Operations_v6.25.pdf

     

    Last edit: Daniel Medeiros 2019-06-06
  • Adam Spencer

    Adam Spencer - 2019-06-06

    Hi Daniel,

    Sorry I am still a little confused on this. I looked at the source code and saw that when I call
    COColumn = Column.GetCAPEOPENObject() , COColumn is now an Object of type CAPE Open Unit Operation, which is represented by "couo" in the code. https://github.com/DanWBR/dwsim5/blob/f0461235563b579de47d4ce8a54b7f43792e02b4/DWSIM.UnitOperations/Unit%20Operations/CapeOpenUO.vb#L156
    If it is now exposed as a CAPE Open Unit Op, based on the CO pdf you sent me, the ICapeUnit interface deals with the interaction with the Unit Operation Object. So wouldn't I have access to the methods of ICapeUnit? (Which include Calculate(), Validate(), GetPorts(), etc.) I tried doing this in DWSIM by doing COColumn.Validate() but it tells me " 'ComObject' object has no attribute "Validate" " Sorry if Im sounding confusing Im just trying to understand.

    Also as a side question, is it possible to import os or fileinput into the python script in DWSIM? Whenever I tried, it gave me an error.

    Thanks again for your help!

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-06-06
    import clr
    import System
    
    clr.AddReference("DWSIM")
    clr.AddReference("System.Core")
    clr.ImportExtensions(System.Linq)
    clr.AddReference("CapeOpen")
    
    from CapeOpen import ICapeUnit
    
    cscol = Flowsheet.GetFlowsheetSimulationObject('CSCOL-000')
    
    co = cscol.GetCAPEOPENObject()
    
    # create an out/ref/ByRef variable of String type
    
    msg = clr.Reference[System.String]()
    
    # The following is the IronPython syntax to call methods from an interface implemented by the object.
    # Interface ICapeUnit is defined in CapeOpen.dll. Validate() is a method defined in ICapeUnit, which the ChemSep column object implements. 
    # (DWSIM unit operations also do it, but with a different objective).
    #
    # Validate() requires an argument of type string, which will be passed by reference (out/ref/ByRef) 
    # so it will contain the message regarding the validation process after it occurs.
    #
    # On IronPython you must do the call from the interface using the object as the first argument:
    
    ICapeUnit.Validate(co, msg)
    
    print msg
    

    The output I've got from the above was:

    'Feed port "Feed1_stage5" is not connected'

    Because my column doesn't have any stream connected to the feed ports. You might get something different.

     

    Last edit: Daniel Medeiros 2019-06-06
  • Daniel Medeiros

    Daniel Medeiros - 2019-06-06

    If you were to do the above in C#, you would do:

    CapeOpen.ICapeUnit myuo = (CapeOpen.ICapeUnit)co;
    String msg = "";
    myuo.Validate(out msg);
    

    In VB:

    Dim myuo As CapeOpen.ICapeUnit = DirectCast(CapeOpen.ICapeUnit, co)
    Dim msg As String = ""
    myuo.Validate(msg)
    
     
  • Adam Spencer

    Adam Spencer - 2019-06-06

    ICapeUnit.Validate(COColumn,msg) did not seem to work for me. It is still not allowing me to connect the side stream.

    Interestingly enough, If I connect every other port (except the one that I added through editing the .txt file) the column converges but gives me the following warning:

    Message Warning: product port "side stream" is not connected and has non-zero flow rate + Info

    Even more interestingly, when I run the script again using Validate() with all the side streams except 1 connected (because it won't let me), it returns "None"

    Any ideas on this? The flowsheet solver gives me an error, which means it is recognizing that another side stream has been added, but the Validate() method is not recognizing that another sidestream was added, otherwise it would not have returned "None".

    An idea I had is to try the "SaveUnit" Use Case but I am not sure if that would work. Like I mentioned before, manually opening and closing the column fixes this issue, but I'm trying to avoid that. Another note to make is that when I open the column and close it, without saving the current input, it still fixes the issue.

    Thank you!

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-06-06

    If you're changing ports on the SEP file, then you must tell DWSIM to update its connectors BEFORE trying to connect the streams to the modified ports by calling

    cscol = Flowsheet.GetFlowsheetSimulationObject('CSCOL-000')
    
    (... change SEP file)...
    
    cscol.UpdatePorts()
    cscol.UpdateConnectors()
    

    You must have noticed at this point that the CAPE-OPEN Unit Operation in DWSIM is actually a proxy between the Simulation Environment (= DWSIM) and the actual CAPE-OPEN object (ChemSep in this case), which resides in an internal, private variable of the proxy object: https://github.com/DanWBR/dwsim5/blob/windows/DWSIM.UnitOperations/Unit%20Operations/CapeOpenUO.vb#L157

     
  • Adam Spencer

    Adam Spencer - 2019-06-10

    Daniel,

    Apologies for the delayed response. I have attached the DWSIM file I have been working on. I will continue to observe the chemsep column .txt file so I can make more refined changes to the .sep file and hopefullyget everything to connect first try.
    Thank you for your help!

    NOTE: The dwsim file's code that I attached is not very robust, so I would suggest to look over it to change the username that it is referring to in order to access the sep file, as well as the first four letters of the .SEP file (I search for any .sep file beginning with 'CS_1') Also, for this to work all other DWSIM files with ChemSep columns must be closed

    Again, thank you for the help and I will respond again when I make a more robust code.

     
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.