Menu

Python Script not waiting for the flowsheet to finish calculating.

2021-03-19
2021-03-27
  • Leandro Favaretto

    Hello sir. I have this Python Script, using IronPython interpreter:

    TempoDesejado = 1211431.76 
    CSTR = Flowsheet.GetFlowsheetSimulationObject('CSTR-01')
    LIQUID = Flowsheet.GetFlowsheetSimulationObject('LIQUID')
    BIOGAS = Flowsheet.GetFlowsheetSimulationObject('BIOGAS')
    
    TimeL = CSTR.ResidenceTimeL
    TimeV = CSTR.ResidenceTimeV
    
    Vazao_Liq = LIQUID.GetPhase('Overall').Properties.volumetric_flow # in m3/s
    Vazao_Vap = BIOGAS.GetPhase('Overall').Properties.volumetric_flow # in m3/s
    
    Volume_Vapor = Vazao_Vap * TempoDesejado #estimativa para o próximo Headspace
    Volume_Liq = Vazao_Liq * TempoDesejado #estimativa para o próximo Volume
    
    CSTR.Headspace = Volume_Vapor
    CSTR.Volume = Volume_Liq
    
    
    Flowsheet.RequestCalculation() #calcula o fluxograma
    
    TimeL = CSTR.ResidenceTimeL
    TimeV = CSTR.ResidenceTimeV
    
    print("Vazao de Vapor: ",Vazao_Vap)
    print("Vazao de Liquido: ",Vazao_Liq)
    print("Tempo de Residencia da Fase Vapor: ",CSTR.ResidenceTimeV,"s")
    print("Tempo de Residencia da Fase Liquida: ", CSTR.ResidenceTimeL,"s")
    

    The thing is: The moment I click to start the script, it instantenously prints the last 4 messages even before the Flowsheet BEGINS calculating. How do I make sure the script "waits" for the Flowsheet to calculate before going to the next step? This happens in Async or Not Async mode

     
  • Daniel Medeiros

    Daniel Medeiros - 2021-03-19

    RequestCalculation() runs asynchronously. Use SolveFlowsheet2() for a synchronous calculation.

     
  • Leandro Favaretto

    I didn't answer before, but obviously this answered my question!

     
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.