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

BSM2 Anoxic CSTR Costing #1186

Merged
merged 32 commits into from
Dec 5, 2023
Merged

Conversation

MarcusHolly
Copy link
Contributor

@MarcusHolly MarcusHolly commented Nov 7, 2023

Summary/Motivation:

Adds costing method for anoxic CSTRs

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.

@MarcusHolly MarcusHolly added the Priority:Normal Normal Priority Issue or PR label Nov 7, 2023
@MarcusHolly MarcusHolly self-assigned this Nov 7, 2023
Copy link
Contributor

@luohezhiming luohezhiming left a comment

Choose a reason for hiding this comment

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

Probably we want to add a testing file for the costing, rather than direclty add to the current BSM2 cause other unit models' costings are still pending.

@MarcusHolly
Copy link
Contributor Author

Probably we want to add a testing file for the costing, rather than directly add to the current BSM2 cause other unit models' costings are still pending.

I could be wrong, but I don't think we have tests for any of the other costing models? I don't see an obvious problem with just adding costing to the BSM2 flowsheet piece-by-piece

@luohezhiming
Copy link
Contributor

Probably we want to add a testing file for the costing, rather than directly add to the current BSM2 cause other unit models' costings are still pending.

I could be wrong, but I don't think we have tests for any of the other costing models? I don't see an obvious problem with just adding costing to the BSM2 flowsheet piece-by-piece

The other costing tests are within their specific test files, like if you check test_electroNP_ZO.py, there is a test for costing

@MarcusHolly
Copy link
Contributor Author

Probably we want to add a testing file for the costing, rather than directly add to the current BSM2 cause other unit models' costings are still pending.

I could be wrong, but I don't think we have tests for any of the other costing models? I don't see an obvious problem with just adding costing to the BSM2 flowsheet piece-by-piece

The other costing tests are within their specific test files, like if you check test_electroNP_ZO.py, there is a test for costing

Would that belong in WaterTAP or IDAES tho? For example, the HEX and mixer are IDAES models that we added WaterTAP costing for, and neither of these models have tests associated with them from what I can see. Although maybe we should add tests for these...

@bknueven
Copy link
Contributor

bknueven commented Nov 7, 2023

Would that belong in WaterTAP or IDAES tho? For example, the HEX and mixer are IDAES models that we added WaterTAP costing for, and neither of these models have tests associated with them from what I can see. Although maybe we should add tests for these...

The test should be in WaterTAP, probably in the costing directory.

There's not a test for the Mixer because we never wrote one. There's an open issue (#1187) to make sure all the costing methods have a unit test. Most do, but a few do not.

@MarcusHolly MarcusHolly marked this pull request as ready for review November 20, 2023 15:09
@MarcusHolly
Copy link
Contributor Author

@bknueven I'll make your cost_by_flow_volume change, but do you know why the UI tests are failing in the linux builds? Maybe this is more of a question for Dan...

@MarcusHolly MarcusHolly marked this pull request as ready for review November 21, 2023 18:44
#
###############################################################################
"""
Anoxic CSTR unit model for BSM2 and plant-wide wastewater treatment modeling.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename filename to anoxic_cstr instead of cstr. Either that, or rename the class which is currently named AnoxicCSTR. The only dilemma I see with this sort of naming is that anoxic is not anaerobic, technically. So maybe it makes more sense to rename the class as CSTR, which would just build on top of IDAES' CSTR and be the WaterTAP version,

# Call UnitModel.build to set up dynamics
super(AnoxicCSTRData, self).build()

self.HRT = Var(
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that we used the acronym (HRT) in ZO models previously. I spelled it out in my recent PR and I think @agarciadiego did too. We should be consistent and spell it out here too.

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.

Looks good- just some quick changes needed

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f063c13) 90.75% compared to head (e92f616) 94.78%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1186      +/-   ##
==========================================
+ Coverage   90.75%   94.78%   +4.03%     
==========================================
  Files         352      355       +3     
  Lines       35446    35478      +32     
==========================================
+ Hits        32168    33628    +1460     
+ Misses       3278     1850    -1428     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adam-a-a adam-a-a mentioned this pull request Nov 27, 2023
8 tasks
def build_cstr_cost_param_block(blk):
# Source: https://www.fwrj.com/articles/9812.pdf
blk.sizing_cost = pyo.Var(
initialize=0.34,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the unit cost for the largest size shown in the range from the reference. Perhaps we should choose a value like the mean or median.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I chose the largest size is because the flowrate in BSM2 actually goes way beyond the ranges listed in this reference. The largest flow in the reference is 100,000 GPD (378.5 m3/day) whereas the BSM2 feed flowrate is 20648 m3/day. So I didn't think it made sense to choose a mean or median value. Although if we intend on using this CSTR for non-BSM2 purposes, then it would make more sense to use an average value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough!


# Check solutions
assert pytest.approx(526.45, rel=1e-5) == value(m.fs.unit.costing.capital_cost)
assert pytest.approx(9.0847e-8, rel=1e-5) == value(m.fs.costing.LCOW)
Copy link
Contributor

Choose a reason for hiding this comment

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

THis is the only check failing (on Mac) which leads me to believe that a tweak in scaling might resolve. However, this LCOW is approximately 0, and I am not totally confident that the result should/would be that low.

Copy link
Contributor Author

@MarcusHolly MarcusHolly Nov 29, 2023

Choose a reason for hiding this comment

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

Perhaps I'll try using the median value for the sizing cost above and see if this resolves the issue (although I'm not convinced it will).

Copy link
Contributor Author

@MarcusHolly MarcusHolly Nov 29, 2023

Choose a reason for hiding this comment

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

It was actually just a unit/scaling problem. Once I specified that the inlet flowrate was in m3/s and corrected the LCOW value, the Mac failure resolved itself. I didn't change the unit cost value though... still not sure if using the average/median makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

What was the unit/scaling problem?

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 needed to specify the units of volumetric flow when I set the operating conditions in the test file

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!

Copy link
Contributor

@agarciadiego agarciadiego left a comment

Choose a reason for hiding this comment

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

LGTM

@adam-a-a adam-a-a enabled auto-merge (squash) December 5, 2023 18:15
@adam-a-a adam-a-a merged commit 35e90bd into watertap-org:main Dec 5, 2023
24 checks passed
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.

6 participants