Menu

IronPython scripting error with reaction sets

Mauro
2024-07-08
2024-07-17
  • Mauro

    Mauro - 2024-07-08

    Hi,
    I appreciate the work on DWSIM as an open source simulation tool. Thank you!
    I know it must be time consuming to follow up all the issues, but let me explain my problem.

    Now I’m trying to modify the kinetic preexpoential factor following this other post.
    The difference with that post is that in my case I have a couple of reaction sets (with a couple of reactions each).
    And also, I’m using a python script unit operation instead of spreadsheets (because in Mac OS, it wasn’t possible to get working the spreadsheet).

    The main problem is that, I want to input (to the python unit operation) only the “reaction set” name (reactionsetkey variable in code), and then with code get the reactions corresponding to the reaction set and modify their “A_Forward” by some factor. A minimal code is as below (I also attach a simulation file with the minimum setting to run the code):

    import clr
    import System
    clr.AddReference('System.Core')
    clr.ImportExtensions(System.Linq)
    
    #get reaction set object
    rxset=Flowsheet.GetReactionSet(reactionsetkey)
    
    #in reaction set correct each reaction preexponential factor
    for r in rxset.Reactions.Keys.ToList():
     rj=Flowsheet.GetReaction(r)
     #rj=Flowsheet.Options.Reactions.Values.Where(lambda x: x.Name == r).FirstOrDefault()
     rj.A_Forward=0.5*rj.A_Forward
    

    Running the code I got the error: Error in 'Microsoft.Dynamic': 'NoneType' object has no attribute ‘A_Forward’.

    I tried some others workarounds but always got the same error.
    Is there a mistake in my code? or is it something else?

    Currently I’m using:
    macOS Sonoma 14.5
    DWSIM 8.7.1

    Sorry for such a basic question and for taking your time. Thanks again.
    Kind regards.

     
  • Daniel Medeiros

    Daniel Medeiros - 2024-07-08

    This should suffice, but you don't need to use a custom unit op to run it, use the script manager instead.

    import clr
    import System
    clr.AddReference('System.Core')
    clr.ImportExtensions(System.Linq)
    
    #in reaction set correct each reaction preexponential factor
    
    for r in Flowsheet.Reactions.Values:
        r.A_Forward = 0.5 * r.A_Forward
    
    #I will set the properties of outlet stream later
    
     
    👍
    1
  • Mauro

    Mauro - 2024-07-17

    Hello, Daniel

    I Appreciate for your time and reply to this basic question.

    I see. Only the script manager and above code. Got it.

    (my own memo: I don't know why sourceforge didn't alert me of your reply.
    Next time I'll be checking myself the thread for any update)

    Thank you again!
    Looking forward to keep engaged in DWSIM project.

     

Log in to post a comment.