Skip to content
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

Mcas w/generic crystallizer #1487

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

adam-a-a
Copy link
Contributor

@adam-a-a adam-a-a commented Sep 10, 2024

Fixes/Resolves:

Summary/Motivation:

Building on @OOAmusat 's work on a generic crystallizer by making it compatible with MCAS and also revising to match more closely with IDAES/WaterTAP standards.

Changes proposed in this PR:

  • add enthalpy relationship for seawater into MCAS
  • remove unnecessary inclusions related to properties or ion sets from crystallizer model and point to prop pack
  • general code cleanup

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@adam-a-a adam-a-a changed the title Mcas generic crystallizer Mcas w/generic crystallizer Sep 10, 2024
__author__ = "Oluwamayowa Amusat, Adam Atia"


def add_crystallizer_rbf_model(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am thinking about bringing this back as a method of the unit model...

Copy link
Contributor

Choose a reason for hiding this comment

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

The question is whether we want to do that, or allow the user to define their own function entirely.

I don't think it should be in the unit model file. However, we could support rbfs and maybe even NN models as defaults. We could have the code in a different file that the user can load as the default with optional arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was what I was thinking--something along the lines of calling the method on the unit model to build some surrogate(s). And defaults could sit in our data folder with a new directory for default_surrogates or something like that. Either way, I don't love the idea of it living in this test file or in some future example flowsheet file.

Comment on lines 200 to 211
# elif surrogate_model_form == "NN":
# print("\nNN models selected.\n")
# add_crystallizer_nn_model(
# m.fs.cryst,
# surrogate_inputs_with_bounds=surrogate_inputs,
# surrogate_outputs=surrogate_outputs,
# path_to_onnx_model=r"C:\Users\OOAmusat-II\Desktop\NAWI\WATERTAP\Phreeqc\crystallization\NN_40_NL_3_sigmoid_WD_1e-06_LR_0.01_testing.onnx",
# path_to_offsetscaler_json=r"C:\Users\OOAmusat-II\Desktop\NAWI\WATERTAP\Phreeqc\crystallization\scalingfile_testing.json",
# surrogate_to_flowsheet_basis_ratio=1,
# )
# else:
# raise ValueError('"surrogate_model_form" must be "RBF" or "NN"')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can probably test the NN surrogate form as well but just trying rbf first.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to exclude this for now since it might not be a priority given latest developments.

Copy link
Contributor

@OOAmusat OOAmusat Sep 10, 2024

Choose a reason for hiding this comment

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

This looks good. The main changes seem to be in the way the ion list and vapor property package are handled.

The only comment I have is with your change to the mass balance constraint (eq_mass_balance_constraints(b, j)). You don't fix self.S['H2O'].fix(0.0), but instead, eliminate it from the water mass balance. Do you think the model will be more stable with that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider that this was fixed to zero in the first place here, and that we only really need to index S by the ion list, I removed S[j] from the water mass balance.

Comment on lines 200 to 211
# elif surrogate_model_form == "NN":
# print("\nNN models selected.\n")
# add_crystallizer_nn_model(
# m.fs.cryst,
# surrogate_inputs_with_bounds=surrogate_inputs,
# surrogate_outputs=surrogate_outputs,
# path_to_onnx_model=r"C:\Users\OOAmusat-II\Desktop\NAWI\WATERTAP\Phreeqc\crystallization\NN_40_NL_3_sigmoid_WD_1e-06_LR_0.01_testing.onnx",
# path_to_offsetscaler_json=r"C:\Users\OOAmusat-II\Desktop\NAWI\WATERTAP\Phreeqc\crystallization\scalingfile_testing.json",
# surrogate_to_flowsheet_basis_ratio=1,
# )
# else:
# raise ValueError('"surrogate_model_form" must be "RBF" or "NN"')
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

__author__ = "Oluwamayowa Amusat, Adam Atia"


def add_crystallizer_rbf_model(
Copy link
Contributor

Choose a reason for hiding this comment

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

The question is whether we want to do that, or allow the user to define their own function entirely.

I don't think it should be in the unit model file. However, we could support rbfs and maybe even NN models as defaults. We could have the code in a different file that the user can load as the default with optional arguments.

@kurbansitterley
Copy link
Contributor

@adam-a-a are you only planning on making the surrogate compatible with MCAS or also the physical model?

@adam-a-a adam-a-a marked this pull request as ready for review October 24, 2024 21:21
@adam-a-a
Copy link
Contributor Author

@OOAmusat I think this is ready to go. @ElmiraShamlou @carson-tucker @avdudchenko this could use a review from at least one of you so that we can merge this and subsequently bring in Mayo's additional changes

@ElmiraShamlou
Copy link
Contributor

@OOAmusat I think this is ready to go. @ElmiraShamlou @carson-tucker @avdudchenko this could use a review from at least one of you so that we can merge this and subsequently bring in Mayo's additional changes

I would suggest adding saturation vapor pressure, as it directly impacts the system’s energy consumption. It is required for any Crystallizer heat recovery analysis.

@adam-a-a
Copy link
Contributor Author

@adam-a-a are you only planning on making the surrogate compatible with MCAS or also the physical model?

@kurbansitterley for the moment we were just doing this for the surrogate crystallizer, but we can think about doing so for the physical model. I am guessing that accounting for solids in MCAS would up the ante.

@adam-a-a
Copy link
Contributor Author

saturation vapor pressure

This sounds like something that we can address in a subsequent PR. This PR just focuses on making MCAS compatible with the surrogate crystallizer formulation. As you can see, one of the surrogates incorporated in the test case predicts vapor pressure, but it is treated as a custom function that is separate from the unit model. Thus, it would be on the user to add such surrogates (at this point in time), so I presume that we could do the same with saturation vapor pressure.

@adam-a-a
Copy link
Contributor Author

saturation vapor pressure

This sounds like something that we can address in a subsequent PR. This PR just focuses on making MCAS compatible with the surrogate crystallizer formulation. As you can see, one of the surrogates incorporated in the test case predicts vapor pressure, but it is treated as a custom function that is separate from the unit model. Thus, it would be on the user to add such surrogates (at this point in time), so I presume that we could do the same with saturation vapor pressure.

Unless you were implying that we should incorporate pressure_sat from the seawater property model, similar to how I brought in enthalpy @ElmiraShamlou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants