-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from avdudchenko/main
Recommiting first API
- Loading branch information
Showing
53 changed files
with
12,747 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
black==24.8.0 | ||
pytest-cov | ||
idaes-pse>=2.5.0 | ||
watertap>=1.0.0 | ||
pyomo>=6.8.0 | ||
--editable .[testing] |
Empty file.
Empty file.
140 changes: 140 additions & 0 deletions
140
src/reaktoro_pse/core/pyomo_property_writer/property_functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
################################################################################# | ||
# WaterTAP Copyright (c) 2020-2024, The Regents of the University of California, | ||
# through Lawrence Berkeley National Laboratory, Oak Ridge National Laboratory, | ||
# National Renewable Energy Laboratory, and National Energy Technology | ||
# Laboratory (subject to receipt of any required approvals from the U.S. Dept. | ||
# of Energy). All rights reserved. | ||
# | ||
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license | ||
# information, respectively. These files are also available online at the URL | ||
# "https://github.com/watertap-org/reaktoro-pse/" | ||
################################################################################# | ||
from pyomo.environ import log10, log, exp | ||
|
||
|
||
def build_scaling_tendency_constraint(rkt_output_object): | ||
user_output_var = rkt_output_object.pyomo_var | ||
build_properties = rkt_output_object.pyomo_build_options.properties | ||
return ( | ||
user_output_var | ||
== 10 | ||
** build_properties[ | ||
("saturationIndex", rkt_output_object.property_index) | ||
].pyomo_var | ||
) | ||
|
||
|
||
def build_ph_constraint(rkt_output_object): | ||
user_output_var = rkt_output_object.pyomo_var | ||
build_properties = rkt_output_object.pyomo_build_options.properties | ||
return ( | ||
-build_properties[("speciesActivityLn", "H+")].pyomo_var / log(10) | ||
== user_output_var | ||
) | ||
|
||
|
||
def build_vapor_pressure_constraint(rkt_output_object): | ||
user_output_var = rkt_output_object.pyomo_var | ||
build_properties = rkt_output_object.pyomo_build_options.properties | ||
return ( | ||
exp( | ||
build_properties[ | ||
("speciesActivityLn", rkt_output_object.property_index) | ||
].pyomo_var | ||
) | ||
* 101325 | ||
== user_output_var | ||
) | ||
|
||
|
||
# work around provided in https://github.com/reaktoro/reaktoro/discussions/398 | ||
# can not be implemented as reference chemical potential is function of p and t | ||
# def build_vapor_pressure_direct_constraint(rkt_output_object): | ||
# user_output_var = rkt_output_object.pyomo_var | ||
# build_properties = rkt_output_object.pyomo_build_options.properties | ||
# build_options = rkt_output_object.pyomo_build_options.options | ||
# return ( | ||
# exp( | ||
# build_properties[ | ||
# ("speciesChemicalPotential", rkt_output_object.property_index) | ||
# ].pyomo_var | ||
# - build_options["reference_chemical_potential"] | ||
# ) | ||
# / ( | ||
# build_options["gas_constant"] | ||
# * build_properties[("temperature", None)].pyomo_var | ||
# ) | ||
# * 1e5 | ||
# == user_output_var | ||
# ) | ||
|
||
|
||
def build_osmotic_constraint(rkt_output_object): | ||
# reference https://help.syscad.net/PHREEQC_Reverse_Osmosis | ||
user_output_var = rkt_output_object.pyomo_var | ||
build_properties = rkt_output_object.pyomo_build_options.properties | ||
build_options = rkt_output_object.pyomo_build_options.options | ||
return ( | ||
user_output_var | ||
== -( | ||
build_options["gas_constant"] | ||
* build_properties[("temperature", None)].pyomo_var | ||
) | ||
/ build_properties[ | ||
("speciesStandardVolume", rkt_output_object.property_index) | ||
].pyomo_var | ||
* build_properties[ | ||
("speciesActivityLn", rkt_output_object.property_index) | ||
].pyomo_var | ||
) | ||
|
||
|
||
def build_direct_scaling_tendency_constraint(rkt_output_object): | ||
# https://reaktoro.org/api/namespaceReaktoro.html#a55b9a29cdf35e98a6b07e67ed2edbc25 | ||
user_output_var = rkt_output_object.pyomo_var | ||
build_properties = rkt_output_object.pyomo_build_options.properties | ||
build_options = rkt_output_object.pyomo_build_options.options | ||
# TODO: Needs to add temperature unit verificaiton and pressure unit verification | ||
temperature_var = build_properties[("temperature", None)].pyomo_var | ||
if build_options["logk_type"] == "Analytical": | ||
A_params = build_options["logk_paramters"] | ||
log_k = [A_params["A1"]] | ||
# temp dependence for phreeqc | ||
if A_params["A2"] != 0: | ||
log_k.append(A_params["A2"] * temperature_var) | ||
if A_params["A3"] != 0: | ||
log_k.append(A_params["A3"] * temperature_var**-1) | ||
if A_params["A4"] != 0: | ||
log_k.append(A_params["A4"] * log10(temperature_var)) | ||
if A_params["A5"] != 0: | ||
log_k.append(A_params["A5"] * temperature_var**-2) | ||
if A_params["A6"] != 0: | ||
log_k.append(A_params["A6"] * temperature_var**2) | ||
|
||
if build_options["logk_type"] == "VantHoff": | ||
vfparams = build_options["logk_paramters"] | ||
log_k = [ | ||
vfparams["lgKr"] | ||
- vfparams["dHr"] | ||
/ build_options["gas_constant"] | ||
* (1 / temperature_var - 1 / vfparams["Tr"]) | ||
] | ||
# pressure dependenance | ||
log_k.append( | ||
-( | ||
build_options["delta_V"] | ||
* (build_properties[("pressure", None)].pyomo_var - 101325) | ||
/ (log(10) * build_options["gas_constant"] * temperature_var) | ||
) | ||
) | ||
|
||
activities = [] | ||
for key, obj in build_properties.items(): | ||
if "speciesActivityLn" in key: | ||
activities.append(obj.pyomo_var * obj.stoichiometric_coeff / log(10)) | ||
return user_output_var == 10 ** ( | ||
sum(activities) | ||
+ sum( | ||
log_k | ||
) # this is postive here and in log10 fom, so we add instead of subtract | ||
) |
Oops, something went wrong.