Menu

Python Script: energy balance did not converge within tolerance

Linus
2020-09-15
2022-12-16
1 2 > >> (Page 1 of 2)
  • Linus

    Linus - 2020-09-15

    Hi Daniel,

    I'm using a custom Python Script to calculate the equilibrium composition of a synthesis gas, because the Gibbs-Reactor won't converge when methane is taken into account. To test the implementation, I'm comparing both reactor models with a simpler mixture (no methane).

    As you can see in the attached screenshot, both models produce pretty much the same results. However, I get a energy balance warning with my custom script, but none for the original reactor. Is there a difference in how both energy balances are calculated?

     
  • The One

    The One - 2020-09-17

    Hey Linus,
    I don't think the energy is balanced. Heat load can be calculated as Hout-Hin.
    In this case, heat load should have been (27391.9-28006.2)x44.4761/3600 =-7.6 KW. Check your energy balance once.
    Thank you

     
  • Linus

    Linus - 2020-09-17

    Hi TheOne,
    the molar enthalpy, which you used to calculate the heat load, only accounts for the change in the heat capacity of the two gases. When you keep the temperature constant while the gas changes it heat capacity (for example in a reaction), you have to add/remove energy (in this case -7.6 kW)

    The other part is the heat of reaction, which you can calculate quite easily in this case because its basically just a water gas shift reaction:
    (CO2_out - CO2_in) * Q_r_WGS = Q_reaction
    (4.35 mol/s - 3.23 mol/s) * 41 kJ/mol = 45.9 kW

    If you add both, you should get the total amount of heat added/removed:
    Q_total = 38.3 kW

    This is the result for both reactors as well, but still I get a warning for the python implementation and none for the gibbs-reactor.

    Maybe I overlooked something, let me know what you think!

     

    Last edit: Linus 2020-09-17
  • The One

    The One - 2020-09-17

    Hey Linus,
    I am a bit confused regarding the conservation of energy equation. Is it possible for you to post the Custom Model? I would love to go through it.
    Thank you, Regards

     

    Last edit: The One 2020-09-17
  • Linus

    Linus - 2020-09-17

    Sure, I've attached the code. Make sure to choose Python.NET as the interpreter and that you have python 3.7, scipy and numpy installed. All those are included in WinPython.

     
  • The One

    The One - 2020-09-17

    Could you also attach the custom model .dwxml file

     
  • Linus

    Linus - 2020-09-17

    See attached file

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-09-17

    Linus, your script is so elegant and clean. Congratulations!

     
  • Linus

    Linus - 2020-09-17

    Thanks Daniel! Got some good ideas by looking through the code from the original gibbs reactor. Any idea why I would get the warning about the energy balance?

     
  • Mohammad

    Mohammad - 2020-09-20

    Linus,
    Many thanks for sharing this gibbs code! I got an error
    14 9/20/2020 3:57:32 PM Error RWGS: Unable to load DLL 'python37': The specified module could not be found. (Exception from HRESULT: 0x8007007E) + Info

    I have Python 3.8 installed with SciPy. Is there any need to have Python 3.7?

     
    • nihal

      nihal - 2021-02-25

      How did you rectify the error , i didnt understand

       

      Last edit: nihal 2021-02-25
  • The One

    The One - 2020-09-20

    Hi Linus,
    I went through your code. I am unable to find the bug.

     
  • Mohammad

    Mohammad - 2020-09-24

    Daniel, I got the same energy balance error! Would you please explain why we should ignore it? and why it has been hard coded. Thank you

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-09-24

    The current balance check does not take into account the heats of formation, which is why it gives a "wrong" warning if applied to reactors.

    Perhaps I should expand it to include heats of formation? Not sure if this would work for some unit ops like the component separator...

     
  • Mohammad

    Mohammad - 2020-09-26

    Daniel,
    I have not read the source code of Gibbs reactor in DWSIM, but to my little understanding, I think to solve a Gibbs Reactor in adiabatic/non-isothermal mode one needs to account the heat of formation. So, the heat balance absolutely needs the heat of formation.

    It should be possible to ignore reactions for equipments with no reaction!

     
  • Linus

    Linus - 2020-09-28

    I also think that the heat of formation should be respected in the heat balance. If no reaction occurs, the heat of reaction will automatically be 0, so there is no need to ignore the reactions in equipment where no reaction is expected.

     
  • Linus

    Linus - 2020-09-28

    Was this already included in Update 9? I still get the same warning (see attached model)

     
    • Simen

      Simen - 2022-11-17

      Hi Linus,
      Thank you for a very nice example. I am trying to solve the flowsheet from your file, but I get an error message on the AUX_DELGF_T method. Do you have an idea what I am doing wrong?

       
  • Daniel Medeiros

    Daniel Medeiros - 2020-09-28

    Not yet, Linus, it will be available in Update 10, but is already coded. I just haven't compiled it yet.

     
  • Linus

    Linus - 2020-09-28

    Okay - thanks for your dedication to the project!

     

    Last edit: Linus 2020-09-28
  • Simen

    Simen - 2022-12-14

    Hi Daniel,

    I'm new to DWSIM, but find Linus' example model of a custom Gibbs reactor very helpful in trying to set up my own unit model based on thermodynamic equilibrium and membrane separation.

    When trying to run the model Linus shared (https://sourceforge.net/p/dwsim/discussion/scripting/thread/e2b817afbf/#942a) I get the error message "System.Exception: CustomGibbs: 'IPropertyPackage' object has no attribute 'AUX_DELGF_T'".

    Do you have any advice that can help me in the right direction trying to solve this?

     
    • Daniel Medeiros

      Daniel Medeiros - 2022-12-14

      check this

       
1 2 > >> (Page 1 of 2)
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.