Skip to content

BinaryDistillation_CompositionFinder #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

omarbay
Copy link

@omarbay omarbay commented Mar 23, 2025

Reversing Mccabe Thiele to find compositions giving number of stages

omarbay added 5 commits March 23, 2025 12:25
taking N_stages as input, asserting y_top with none value to find it later the same with x_bot
extending the if and elsif to accept y_top,x_bot as unknowns
Updating different lines to make the pytest passing all unittest
Copy link
Member

@yoelcortes yoelcortes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omarbay,

Thank you for putting this together. I think its in the right direction. I have 3 comments and one super minor.

  1. It seems that the new specification (setting the number of stages and one top or bottom composition) is solved numerically (through the while loop). That should work, but did you know that there is a much more direct solution by moving up or down the equilibrium-operating line ladder? The numerical approach is what users do when treating the unit as a black-box (https://biosteam.readthedocs.io/en/latest/tutorial/Process_specifications.html#Numerical-specifications). For speed and robustness, let's use the analytical solution for biosteam internals. For example, setting x_bot and N_stages:

    yi = xi = x_bot # begin at operating line
    for i in range(N_stages):
            # Go Up
            x = np.array((xi, 1-xi))
            T, y = solve_Ty(x, P) # see compute_stages_McCabeThiele
            yi = y[0]
            y_stages.append(yi)
            T_stages.append(T)
            # Go Right
            xi = operating_line(yi)
            x_stages.append(xi)

    In _run_McCabeThiele you can edit a few lines of code to implement this. For example:

    try: 
        if self.N_stages is None:
            compute_stages_McCabeThiele(P, ss, x_stages, y_stages, T_stages, x_m, solve_Ty)
        else:
            # Insert new specification code going up/down the equlibrium/operating line ladder
    except RuntimeError as e: 
        error[0] = e
    yi = y_stages[-1]
    xi = rs(yi)
    x_stages[-1] = xi if xi < 1 else 0.99999
    try: 
        if self.N_stages is None:
            compute_stages_McCabeThiele(P, rs, x_stages, y_stages, T_stages, y_top, solve_Ty)
        else:
            # Insert new specification code going up/down the equlibrium/operating line ladder
    except RuntimeError as e:
        error[0] = e
  2. I did not see any tests for this new specification. Please add tests for both setting x_bot and N_stages and y_top and N_stages. You can make a new file called biosteam/tests/test_distillation.py and add the following:

    def test_binary_distillation_N_stages_and_y_top(): pass # Add tests here
    def test_binary_distillation_N_stages_and_x_bot(): pass # Add tests here
  3. It is possible that the feed composition lies outside the equilibrium/operating ladder. This can happen if there is an azeotrope or if given the number of stages is too small. We will need to check for this by making sure the feed composition is in between the the top and bottoms composition (and raise an error otherwise).

  4. Use variable is None instead of variable == None, it's actually faster in Python.

By the way, all of BioSTEAM tests are now passing (hooray!), please pull and don't forget to pip install thermosteam==0.51.9 or pull thermosteam if you have it locally.

Thank for the modifications.md file, that was helpful! I truly appreciate the work and effort you have made in this pull request. I believe users will be happy to see this new feature soon!

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants