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

Add modified ADM1 model with P extension #948

Merged
merged 61 commits into from
Mar 30, 2023

Conversation

luohezhiming
Copy link
Contributor

Fixes/Resolves:

(replace this with the issue # fixed or resolved, if no issue exists then a brief statement of what this PR does)

Summary/Motivation:

Changes proposed in this PR:

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.

@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Merging #948 (a74062a) into main (b100435) will increase coverage by 0.04%.
The diff coverage is 97.53%.

@@            Coverage Diff             @@
##             main     #948      +/-   ##
==========================================
+ Coverage   95.62%   95.66%   +0.04%     
==========================================
  Files         292      294       +2     
  Lines       27996    28497     +501     
==========================================
+ Hits        26770    27262     +492     
- Misses       1226     1235       +9     
Impacted Files Coverage Δ
...els/anaerobic_digestion/modified_adm1_reactions.py 98.23% <ø> (ø)
...ls/anaerobic_digestion/modified_adm1_properties.py 97.33% <97.33%> (ø)
watertap/unit_models/anaerobic_digestor.py 93.26% <100.00%> (+0.88%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@MarcusHolly MarcusHolly marked this pull request as ready for review March 28, 2023 15:00
@MarcusHolly
Copy link
Contributor

I've tried re-running the MacOS setup test, but it still fails. Is it fine if this test is just skipped?

Comment on lines 2083 to 2084
return self.conc_mol_Mg == self.conc_mass_comp_ref["X_PP"] / (
300.41 * pyo.units.kg / pyo.units.kmol
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a copy of the previous constraint.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thx for catching this - the expressions are equivalent, but I did forget to replace conc_mol_Mg with conc_mol_K

Copy link
Contributor

Choose a reason for hiding this comment

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

What molecule does that molecular weight correspond to? I figure X_PP represents polyphosphates but unsure what the MW assumption specifically ties to.

Copy link
Contributor

@MarcusHolly MarcusHolly Mar 29, 2023

Choose a reason for hiding this comment

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

Screenshot from Excel located here in Box: https://app.box.com/file/1153207546703
image

@adam-a-a
Copy link
Contributor

I've tried re-running the MacOS setup test, but it still fails. Is it fine if this test is just skipped?

So, I think it depends on what is failing in the test. Originally, it was just a matter of absolute tolerance. However, after latest changes, it appears to be more of a scaling issue (I suspect) that now throws off the AD unit's initialization. It'd be better to try to resolve that before we resort to skipping. That said, it'd be helpful for a Mac user to tinker with this. @bknueven could you take a look at this? I am sure you will find that there is substantial room for improvement in scaling and initialization for these models, but for now, we're just looking to hit the bare minimum requirement to get an initial implementation passing tests and merged. Following that, we'd have subsequent PRs to address scaling and initialization.

@adam-a-a
Copy link
Contributor

Another question/comment that I want @MarcusHolly and @luohezhiming to think about ahead of our meeting today: our slides showing ADM1->ASM2D and ASM2D ->ADM1 give a table that lists struvite (MgNH4PO4) as well as calcium phosphate (Ca3(PO4)2), both of which will be key for our 2336 team collaboration. It seems that the current implementation hasn't accounted for those species yet (but I may have missed that). If so, how much more would it take to incorporate those species? Think about it, and let's discuss later today =)

@MarcusHolly
Copy link
Contributor

Another question/comment that I want @MarcusHolly and @luohezhiming to think about ahead of our meeting today: our slides showing ADM1->ASM2D and ASM2D ->ADM1 give a table that lists struvite (MgNH4PO4) as well as calcium phosphate (Ca3(PO4)2), both of which will be key for our 2336 team collaboration. It seems that the current implementation hasn't accounted for those species yet (but I may have missed that). If so, how much more would it take to incorporate those species? Think about it, and let's discuss later today =)

The quick answer is that we don't currently account for these species. However, they are accounted for in the Precipitation Extension in the Flores-Alsina paper: https://app.box.com/file/1153202083720?s=he1whq9a66fvxj8y39puqsqijzuy7sbr

I haven't looked too closely at how much effort this would require, so I'll try to look into it before the meeting.

@adam-a-a adam-a-a mentioned this pull request Mar 29, 2023
@bknueven
Copy link
Contributor

For this PR we should just mark the failing tests with requires_idaes_solver. We should be removing that GHA check soon anyways (see #970).

@MarcusHolly
Copy link
Contributor

@adam-a-a I've avoided changing some of the pytest marks from component to unit because this test file follows the same conventions as other similar test files for adm1, asm1, and asm2d. So if these tests really are incorrectly marked, then maybe we/I should just fix them all in one-go (in a separate PR) rather than just updating this test file.

@adam-a-a adam-a-a added the 🍒 Merge to rel Merge commit(s) from this PR to release branch label Mar 30, 2023
Copy link
Contributor

@adam-a-a adam-a-a left a comment

Choose a reason for hiding this comment

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

LGTM- this model needs additions anyway that will take place in subsequent PRs

@adam-a-a adam-a-a merged commit 7d14f22 into watertap-org:main Mar 30, 2023
lbianchi-lbl pushed a commit that referenced this pull request Apr 5, 2023
* Add modified ADM1 model with P extension

* Add reference

* Add more sig figs

* R10-R11

* R12-R18

* add stoichiometry

* add details for modified ADM1

* Correct f_xi_xb value

* Fix R3 S_IP stoich

* Remove X_IP terms from stoich

* Remove X_c terms from stoich

* update Z_h2s

* Rename packages

* add tests

* ADD TESTS

* Update parameter values and test file reference

* Update test file

* Add to-do note

* add P extension

* Add P extension

* Add S_IC, S_IP, and S_IN for R19-R25

* Fix test file failures

* Remove completed to-do tasks

* delete unused parameters

* Resolve completed to-do items

* Resolve some test failures

* Remove X_c from thermo test

* Solve InconsistentUnitError by making Y_SO4 dimensionless

* Temporarily fixes DOF failure

* Undo last change

* Replace instances of f_si_xb with 0

* Make Z_h2s a parameter

* Undo last change and input initial rxn rate values for R19-25

* Try initialization utility tools

* Update test feed conditions and replaces X_K & X_Mg with S_K & S_Mg

* Add the values for the remaining rxn rates

* Correct initial values for rxn rates

* Expand rxn rate bounds and add to-do list for test file

* improve scaling on adm1+P reactions and remove bounds on rate_reaction

* add stream table to AD unit and additional solve to initialization

* fix modified adm1 tests, add scale factors and todo notes to AD unit

* make sure temporary scaling in AD unit is only used for resolving modified ADM1 until real fix is implemented

* replace relative tolerances with absolute tolerances--for results expected to be ~0

* missed an abs tolerance

* Clean up to-do items and comments

* Track Mg and K ions

* Fix initialization failure associated with tracking Mg & K ions

* Address Adam's comment

* Add requires_idaes_solver marks

* Only mark the failing initialization test w/requires_idaes_solver

* Add require_idaes_solver to all failing tests

---------

Co-authored-by: MarcusHolly <marcus.holly@keylogic.com>
Co-authored-by: adam-a-a <aatia@keylogic.com>
(cherry picked from commit 7d14f22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 Merge to rel Merge commit(s) from this PR to release branch Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants