Skip to content

Comments

Calculation of pH for systems in equilibrium with atmospheric carbon dioxide#6

Closed
mhvwerts wants to merge 6 commits intornelsonchem:masterfrom
mhvwerts:air_equilibrated
Closed

Calculation of pH for systems in equilibrium with atmospheric carbon dioxide#6
mhvwerts wants to merge 6 commits intornelsonchem:masterfrom
mhvwerts:air_equilibrated

Conversation

@mhvwerts
Copy link

Hello Ryan,

As discussed, here is the code for calculation of pH of a system in equilibrium with ambient air using pHcalc.

It takes the form of a subclass of System, called SystemAirEquilibrated, which adds the necessary carbon dioxide/carbonic acid equilibria. The central property is the total 'dissolved inorganic carbon' (DIC), which is adjusted by the algorithm such that the dissolved CO2 is at equilibrium with the CO2 in the air, recalculating pH in the process.

I have made initial docstrings and added further details as comments in the code. There is also a test/example script test_air_equilibrated.py (reminding us that atmospheric CO2 levels are rising). I will be happy to update the documentation in README.rst later on.

All new code is in separate files. I did make some very minor edits to the core pHcalc.py but these are essentially cosmetic. As you may notice, I anticipated the re-naming of Acid and Inert but kept this compatible with the existing names.

Best wishes,
Martin

@rnelsonchem
Copy link
Owner

@mhvwerts Thanks so much for this very detailed PR! I have been looking it over these past couple of days, and this led to a couple of big picture thoughts...

  • The new System class w/ CO2 is very cool! But unfortunately, it is specific for CO2... Wouldn't it be neat if it was more flexible for other types of gasses that participate in acid/base equilibria?
  • There total dissolved carbon concentration is solved using a minimizer, and the minimizer function also uses another minimizer call. This leads to a pretty significant performance hit. Is it possible to do this same calculation with a single call to a minimizer function?

So anyway, I tried to do this using a different strategy -- a new AcidGas class for gasses that participate in acid/base equilibria. I created a new PR -- GH-7 -- for a skeleton version of this addition. There's a link in the PR to a GIST demonstrating the usage. I'll add some other thoughts to the PR here as well.

Copy link
Owner

@rnelsonchem rnelsonchem left a comment

Choose a reason for hiding this comment

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

Some file-specific comments on this PR

rnelsonchem referenced this pull request Mar 29, 2023
@mhvwerts
Copy link
Author

mhvwerts commented Apr 1, 2023

Your new #7 indeed provides a superior method for taking into account a solution in equilibrium with a gas-phase reservoir for a species. I will use that from now on, and we may close this particular pull request.

@mhvwerts mhvwerts closed this Apr 1, 2023
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