Skip to content

Recirculation calculation error in custom fermentor (parent CSTR) #225

@iilard

Description

@iilard

Dear BioSTEAM Team & Community,

I am currently building a simulatin for a specific lactic acid production process, via anaerobic fermentation.
FYI:

  • All my chemicals have Hf values set
  • Reactions are properly set up (ParallelReaction Set)
  • Parent class CSTR
  • Tried defining reactions directly in class definition, so my separate _reactions.py won't be shared below... either way leads to same error.

I hope I didn't share too much code for you to understand the issue. Either way, as you can see from the error message, dH is somehow 0. That doesn't make sense as in a separate file I actually calculated the reaction enthalpies and found dH to not be 0. So the issue must somehow persist in the custom class itself.
Any help to solve this is much appreciated!

PS. this is my first post here, any tipps on structuring this better are welcome!

My _settings.py:

import thermosteam as tmo
import biosteam as bst
from _chemicals import chemicals 
from thermosteam import settings

#Activate chemicals list & register them in bio/thermosteam
tmo.settings.set_thermo(chemicals) 
bst.settings.set_thermo(chemicals)

My _chemicals.py:

import thermosteam as tmo
import biosteam as bst
from thermosteam import Chemicals, Chemical

def create_chemicals():
    chemicals = Chemicals([])
    def add_chemical(ID, ref=None, **data):
        chemical = Chemical(ID, **data) if ref is None else ref.copy(ID, **data)
        chemicals.append(chemical)
        return chemical
    
    Water = add_chemical('H2O')
    Glucose = add_chemical('Glucose', phase='l', rho=1560, Cp=1.213)
    CaCO3 = add_chemical('CaCO3', phase='s', rho=2710, Cp=0.834)
    CalciumLactate = add_chemical('CalciumLactate', phase='l', Hf=-1686100, rho=1494) # NOTE: phase=l because only in solution in process simulation; Cp value not available (yet), filler could be ca. 1.4
    lla = add_chemical('L-LacticAcid', phase='l', Hf=-686300, Cp=2.109, rho=1206)
    SulfuricAcid = add_chemical('H2SO4', phase='l', rho=1840, Cp=1.38)
    CarbonDioxide = add_chemical('CO2', phase='g')
    Gypsum = add_chemical('CaSO4_2H2O', phase='s', rho=2320, MW=172.18, Hf=-2023000, Cp=1.081, search_db=False)
    # Biomass_l density assumption similar to water, biomass_s filter cake density according to paper
    Biomass_l = add_chemical('Biomass_l', phase='l', formula='CH1.8O0.5N0.2', MW=24.626, rho=1050, Hf=-106800, Cp=1.25, search_db=False) # Same biomass, but once filtered it's rather a solid (cake), liquid version to simulate suspended in stream
    Biomass_s = add_chemical('Biomass_s', phase='s', formula='CH1.8O0.5N0.2', MW=24.626, rho=1093, Hf=-106800, Cp=1.25, search_db=False) # Cp value from bioindustrial park, as not found in lit.
    EthylAcetate = add_chemical('EthylAcetate', phase='l', Hf=-479860, Cp=1.924)
    Octanol = add_chemical('Octanol', phase='l', Hf=-426600, Cp=2.334)
    
    chemicals.compile()
    return chemicals

chemicals = create_chemicals()

My _units.py:

import biosteam as bst
import thermosteam as tmo
from biosteam import CSTR

# -----------------------------------CUSTOM CLASSES----------------------------------------

# Custom Fermentor based on CSTR for cont. ferm.
class Fermentor(bst.CSTR):
    _N_ins = 1
    _N_outs = 2
    
    def __init__(self, ID='Fermentor', ins=None, outs=(), thermo=None, *, T=313.15, **kwargs):
        if outs == ():
            outs = [None, None]  # liquid, gas
        super().__init__(ID, ins, outs, thermo=thermo, **kwargs)

        self.T=T
        
        # Define reactions here like bioindustrial park lactic example
        self.fermentation_rxns = tmo.ParallelReaction([
            # Reaction definition, Reactant, Conversion
            tmo.Reaction('Glucose -> 2 L-LacticAcid', 'Glucose', 0.92),
            tmo.Reaction('2 L-LacticAcid + CaCO3 -> CalciumLactate + CO2 + H2O', 'L-LacticAcid', 1.0),
            tmo.Reaction('Glucose -> 10.97 Biomass_l', 'Glucose', 0.08)
        ])

    def _run(self):
        feed = self.ins[0]
        liquid_effluent, gas_vent = self.outs

        # Copy feed to effluent
        liquid_effluent.copy_like(feed)

        # Apply reactions using the class-defined reactions
        self.fermentation_rxns(liquid_effluent.mol)

        # Handle gas separation - remove CO2 from liquid and send to gas vent
        gas_vent.copy_flow(liquid_effluent, 'CO2', remove=True)

        # Set temperature for both outlets
        liquid_effluent.T = gas_vent.T = self.T

My _system.py:

import biosteam as bst
from _units import Fermentor  # custom classes
from _reactions import fermentation_reactions, acidification_reaction  # reaction functions
from _settings import chemicals  # compiled thermo package

# -------------------- FEED STREAMS --------------------
glucose_feed = bst.Stream('glucose_feed', Glucose=100, Water=500, units='kg/hr')
CaCO3_feed = bst.Stream('CaCO3_feed', CaCO3=120, Water=100, units='kg/hr')
feedstock_mixer = bst.Mixer('feedstock_mixer', ins=[glucose_feed, CaCO3_feed])

# -------------------- SUBSYSTEM 1: CONVERSION --------------------
preheater = bst.HXutility('preheater', T=313.15) # NOTE: placeholder 40°C
fermentor = Fermentor('fermentor', T=313.15, tau=24, V_wf=0.8)    
# cooler = bst.HXutility('fermentor_cooler', T=313.15)

# Connect the Conversion section
preheater.ins[0] = feedstock_mixer.outs[0]
fermentor.ins[0] = preheater.outs[0]
# cooler.ins[0] = fermentor.outs[0]  # Liquid to cooler

# Create the Conversion subsystem
conversion_sys = bst.System('conversion_sys', path=[feedstock_mixer, preheater, fermentor])




# -------------------- MAIN SYSTEM --------------------
# Combine subsystems into the main system
lactic_acid_system = bst.System('lactic_acid_system',
                                path=[conversion_sys])

The error I get in my terminal:
Traceback (most recent call last):
File "c:\Users\ivano\Desktop\Masterarbeit\Code_system.py", line 34, in
lactic_acid_system.simulate()
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_system.py", line 3105, in simulate
with self.flowsheet:
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_flowsheet.py", line 120, in exit
if exception: raise exception
^^^^^^^^^^^^^^^
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_system.py", line 3166, in simulate
raise error
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_system.py", line 3154, in simulate
if design_and_cost: self._summary()
^^^^^^^^^^^^^^^
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_system.py", line 2862, in _summary
f(i, i._summary)
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 94, in try_method_with_object_stamp
raise_error_with_object_stamp(object, error)
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 84, in raise_error_with_object_stamp
raise error
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 88, in try_method_with_object_stamp
return method(*args)
^^^^^^^^^^^^^
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_system.py", line 2862, in _summary
f(i, i._summary)
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 94, in try_method_with_object_stamp
raise_error_with_object_stamp(object, error)
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 84, in raise_error_with_object_stamp
raise error
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 88, in try_method_with_object_stamp
return method(*args)
raise error
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 88, in try_method_with_object_stamp
return method(*args)
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\thermosteam\exceptions.py", line 88, in try_method_with_object_stamp
return method(*args)
^^^^^^^^^^^^^
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_unit.py", line 1191, in _summary
self._design(**design_kwargs) if design_kwargs else self._design()
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam_unit.py", line 1191, in _summary
self._design(**design_kwargs) if design_kwargs else self._design()
self._design(**design_kwargs) if design_kwargs else self._design()
^^^^^^^^^^^^^^
File "C:\Users\ivano\miniconda3\envs\glukose-env\Lib\site-packages\biosteam\units\stirred_tank_reactor.py", line 329, in _design
recirculation_ratio = reactor_duty / dH # Recirculated flow over net product flow
~~~~~~~~~~~~~^~~~
FloatingPointError: <System: conversion_sys> <Fermentor: fermentor> divide by zero encountered in scalar divide

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions