Menu

Display Chart Object, Concentration Profile

2019-10-10
2019-10-14
  • Patrick Veiltl

    Patrick Veiltl - 2019-10-10

    Hello Community,

    I'm creating a heterogeneous catalytic Methanol reactor in my current simulation and attempting to display the chart containing Concentration and Temperature Profiles.
    I've finished the program but two issues emerged.
    All concentration curves are colored identically and therefore indistinguishable. I see no menu where I could adjust the colors or change other important things, like selectively plotting certain concentrations while ignoring others.
    I can change the units of concentration by editing "System of Units" though, but unfortunately there is no option to choose molar fractions, which I would prefer in this case.
    Another point that I want to mention is a tiny bug. The plotted graphs begin to visibly flicker once the Flowsheet is solved.

    I tried both Classic and New UI (Version 5.7 Update 14) and got the same problems.
    The file is linked below.

    Could you please assist?

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-10-10

    Download and install v5.8, you'll find a new Charts tab where you can view the concentration profile and configure the chart for your needs. To display molar fractions, you'll have to use a python script and the spreadsheet as described in the How-To Tutorial #3 in the User Guide.

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-10-10

    Add and run this script:

    import clr
    import System
    
    clr.AddReference('System.Core')
    clr.ImportExtensions(System.Linq)
    
    n = Flowsheet.SelectedCompounds.Count
    
    reactor = Flowsheet.GetFlowsheetSimulationObject("REACTOR")
    
    profile = reactor.points
    
    cnames = Flowsheet.SelectedCompounds.Values.Select(lambda x: x.Name).ToArray()
    
    Spreadsheet.Worksheets[0].Cells["A1"].Data = "Reactor Distance (relative)"
    
    for i in range(1, n):
        Spreadsheet.Worksheets[0].Cells[0, i].Data = cnames[i]
    
    j = 1
    for pointset in profile:
        Spreadsheet.Worksheets[0].Cells[j, 0].Data = j
        tmols = 0
        for i in range (0, n-1):
            tmols += pointset[i]
        for i in range (0, n-1):
                Spreadsheet.Worksheets[0].Cells[j, i+1].Data = pointset[i] / tmols
        j += 1
    

    Go to the Spreadsheet, select the entire data range and create a new chart frmo the range:

    The generated chart can be fully configured by you.

     
  • Patrick Veiltl

    Patrick Veiltl - 2019-10-11

    Hello Daniel,

    first things first, I tried out the new update and I have to congratulate you. The interface and design are much improved and when it comes to calculation times of scripted programs it is astonishingly quicker then 5.7.
    Thanks a lot for your hard work.

    Back to business.
    The script you posted works and I get to simulate and manipulate the charts as wished.
    But there's still an issue with the value output. As you can see in my other simulation, which is based on the following paper https://terpconnect.umd.edu/~nsw/chbe446/VandenBussche-syngas2MeOH.pdf , the molar fractions displayed on the floating tables of the flowsheet at reactor in- and outlet are nearly identical with the model. But the plotted graph gives almost diametrically different values, especially when I run the script various times or change the inlet streams
    I guess it has to do with the way the script accesses molar fractions. How can the code be adjusted accordingly?

     

    Last edit: Patrick Veiltl 2019-10-11
  • Daniel Medeiros

    Daniel Medeiros - 2019-10-11

    Hi Patrick,

    My script has some errors.

    1. The compound names in the reactor are not necessarily the same as in the simulation, as there may be some inerts. We must get them from the CompoundConversions dictionary of the reactor, as they will be in the same order as the concentrations in the points vector.

    2. The points vector in the reactor already includes the length as the first element, the following being the concentrations and the last two being the temperature and pressure:

    reactor.points = vector of vectors: [RL, C1, ..., Cn, T, P]

    See this for the code part that creates and adds data to the points list: https://github.com/DanWBR/dwsim5/blob/windows/DWSIM.UnitOperations/Reactors/PFR.vb#L795

    So, the correct script is this one:

    reactor = Flowsheet.GetFlowsheetSimulationObject("REACTOR")
    
    profile = reactor.points
    
    cnames = reactor.ComponentConversions.Keys.ToArray()
    
    n = cnames.Count
    
    Spreadsheet.Worksheets[0].Cells["A1"].Data = "Reactor Length (m)"
    
    for i in range(0, n-1):
        Spreadsheet.Worksheets[0].Cells[0, i+1].Data = cnames[i]
    
    j = 1
    for pointset in profile:
        Spreadsheet.Worksheets[0].Cells[j, 0].Data = pointset[0]
        tmols = 0
        for i in range (1, n):
            tmols += pointset[i]
        for i in range (1, n):
                Spreadsheet.Worksheets[0].Cells[j, i].Data = pointset[i] / tmols
        j += 1
    

    You can link the script with the Object Calculation Finished event of the reactor so it is always executed after the reactor is calculated.

    Regards
    Daniel

     

    Last edit: Daniel Medeiros 2019-10-11
  • Patrick Veiltl

    Patrick Veiltl - 2019-10-14

    Hello again Daniel,
    perfect. Thank you for your help.
    Just one tiny note. The code left out one component, but by slightly changing the range in three of the four for-loops, to include Methanol as the last object in the list 'cnames', the script correctly displays all concentration profiles I need.

    import clr
    import System
    
    clr.AddReference('System.Core')
    clr.ImportExtensions(System.Linq)
    
    
    reactor = Flowsheet.GetFlowsheetSimulationObject("REACTOR")
    
    profile = reactor.points
    
    cnames = reactor.ComponentConversions.Keys.ToArray()
    
    n = cnames.Count
    
    Spreadsheet.Worksheets[0].Cells["A1"].Data = "Reactor Length (m)"
    
    for i in range(0, n):    # instead of n-1
        Spreadsheet.Worksheets[0].Cells[0, i+1].Data = cnames[i]
    
    j = 1
    for pointset in profile:
        Spreadsheet.Worksheets[0].Cells[j, 0].Data = pointset[0]
        tmols = 0
        for i in range (1, n+1):     # instead of n
            tmols += pointset[i]
        for i in range (1, n+1):     # instead of n
                Spreadsheet.Worksheets[0].Cells[j, i].Data = pointset[i] / tmols
        j += 1
    

    Keep up your work on DWSIM, the frequent improvements and your support are greatly appreciated.

     
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.