Skip to content

Commit

Permalink
Correct enthalpy units and update assertion in all tests, all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinhong Liu authored and bknueven committed Jun 7, 2023
1 parent f358836 commit a54427c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 47 deletions.
12 changes: 6 additions & 6 deletions watertap/examples/chemistry/tests/test_enrtl_water_pH.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"3": (647.13, pyunits.K),
"4": (0.081, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-230.000, pyunits.kJ / pyunits.mol),
"enth_mol_form_liq_comp_ref": (0, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -288,7 +288,7 @@
# 1e-14 is defined on a molar basis. Thus, we must
# divide by the total (~55.2 M) concentration raised to the
# net reaction order (i.e., 2 in this case).
"dh_rxn_ref": (0, pyunits.kJ / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2**2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -594,7 +594,7 @@ def test_solution_water(self, water_model):
"3": (647.13, pyunits.K),
"4": (0.081, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-230.000, pyunits.kJ / pyunits.mol),
"enth_mol_form_liq_comp_ref": (0, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -726,7 +726,7 @@ def test_solution_water(self, water_model):
"3": (429.69, pyunits.K),
"4": (0.259, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (135749.9, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -759,7 +759,7 @@ def test_solution_water(self, water_model):
"3": (1595.8, pyunits.K),
"4": (0.6598, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -814,7 +814,7 @@ def test_solution_water(self, water_model):
# 1e-14 is defined on a molar basis. Thus, we must
# divide by the total (~55.2 M) concentration raised to the
# net reaction order (i.e., 2 in this case).
"dh_rxn_ref": (0, pyunits.kJ / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2**2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down
27 changes: 17 additions & 10 deletions watertap/examples/chemistry/tests/test_pH_dependent_solubility.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"mw": (40.078, pyunits.g / pyunits.mol),
"dens_mol_liq_comp_coeff": (55, pyunits.kmol * pyunits.m**-3),
"cp_mol_liq_comp_coeff": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.kJ / pyunits.mol),
"entr_mol_form_liq_comp_ref": (
-53,
pyunits.J / pyunits.K / pyunits.mol,
Expand Down Expand Up @@ -296,7 +296,7 @@
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -623,7 +623,7 @@ def test_case_1_low_precipitation():
"mw": (40.078, pyunits.g / pyunits.mol),
"dens_mol_liq_comp_coeff": (55, pyunits.kmol * pyunits.m**-3),
"cp_mol_liq_comp_coeff": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.kJ / pyunits.mol),
"entr_mol_form_liq_comp_ref": (
-53,
pyunits.J / pyunits.K / pyunits.mol,
Expand Down Expand Up @@ -772,7 +772,7 @@ def test_case_1_low_precipitation():
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -918,9 +918,9 @@ def run_case2(
assert degrees_of_freedom(model) == 0

## ==================== Start Scaling for this problem ===========================
_set_eps_vals(model.fs.rxn_params, rxn_config)
_set_equ_rxn_scaling(model.fs.unit, model.fs.rxn_params, rxn_config)
_set_mat_bal_scaling_FpcTP(model.fs.unit)
_set_eps_vals(model.fs.rxn_params, rxn_config, max_k_eq_ref=1e-12)
_set_equ_rxn_scaling(model.fs.unit, model.fs.rxn_params, rxn_config, min_k_eq_ref=1e-3)
_set_mat_bal_scaling_FpcTP(model.fs.unit, min_flow_mol_phase_comp=1e-2)
if has_energy_balance == True:
_set_ene_bal_scaling(model.fs.unit)

Expand All @@ -943,6 +943,13 @@ def run_case2(

assert degrees_of_freedom(model) == 0

for i in model.fs.unit.control_volume.equilibrium_reaction_extent_index:
if hasattr(model.fs.rxn_params.component("reaction_" + i[1]), "eps"):
iscale.constraint_scaling_transform(
model.fs.unit.control_volume.reactions[0.0].equilibrium_constraint[i[1]], 0.1
)
iscale.calculate_scaling_factors(model.fs.unit)

results = solver.solve(model, tee=True)

assert results.solver.termination_condition == TerminationCondition.optimal
Expand Down Expand Up @@ -1194,7 +1201,7 @@ def test_case_2_ultra_high_ca():
"mw": (40.078, pyunits.g / pyunits.mol),
"dens_mol_liq_comp_coeff": (55, pyunits.kmol * pyunits.m**-3),
"cp_mol_liq_comp_coeff": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.kJ / pyunits.mol),
"entr_mol_form_liq_comp_ref": (
-53,
pyunits.J / pyunits.K / pyunits.mol,
Expand Down Expand Up @@ -1380,7 +1387,7 @@ def test_case_2_ultra_high_ca():
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -2076,7 +2083,7 @@ def test_case_3_ultra_faux_added_lime_and_ash():
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down
10 changes: 5 additions & 5 deletions watertap/examples/chemistry/tests/test_recarbonation_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
pyunits.J / pyunits.K / pyunits.mol,
),
"pressure_sat_comp_coeff": {
"A": (4.6543, None), # [1], temperature range 255.9 K - 373 K
"A": (4.6543, pyunits.dimensionless), # [1], temperature range 255.9 K - 373 K
"B": (1435.264, pyunits.K),
"C": (-64.848, pyunits.K),
},
Expand Down Expand Up @@ -268,7 +268,7 @@
"3": (647.13, pyunits.K),
"4": (0.081, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-230.000, pyunits.kJ / pyunits.mol),
"enth_mol_form_liq_comp_ref": (0, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -396,7 +396,7 @@
"3": (429.69, pyunits.K),
"4": (0.259, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (135749.9, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -457,7 +457,7 @@
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -770,7 +770,7 @@ def test_solution_equilibrium(self, equilibrium_config):
)
)
assert pytest.approx(5.339891, rel=1e-4) == pH
assert pytest.approx(8.660655, rel=1e-4) == pOH
assert pytest.approx(8.654294, rel=1e-4) == pOH

CO2_sorbed = value(
model.fs.unit.control_volume.properties_out[0.0].conc_mol_phase_comp[
Expand Down
22 changes: 11 additions & 11 deletions watertap/examples/chemistry/tests/test_remineralization.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
pyunits.J / pyunits.K / pyunits.mol,
),
"pressure_sat_comp_coeff": {
"A": (4.6543, None), # [1], temperature range 255.9 K - 373 K
"A": (4.6543, pyunits.dimensionless), # [1], temperature range 255.9 K - 373 K
"B": (1435.264, pyunits.K),
"C": (-64.848, pyunits.K),
},
Expand Down Expand Up @@ -350,7 +350,7 @@
"3": (1595.8, pyunits.K),
"4": (0.6598, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -380,7 +380,7 @@
"3": (1, pyunits.K),
"4": (1, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -479,7 +479,7 @@
"3": (429.69, pyunits.K),
"4": (0.259, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (135749.9, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -631,7 +631,7 @@
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
pyunits.J / pyunits.K / pyunits.mol,
),
"pressure_sat_comp_coeff": {
"A": (4.6543, None), # [1], temperature range 255.9 K - 373 K
"A": (4.6543, pyunits.dimensionless), # [1], temperature range 255.9 K - 373 K
"B": (1435.264, pyunits.K),
"C": (-64.848, pyunits.K),
},
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
"3": (647.13, pyunits.K),
"4": (0.081, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-230.000, pyunits.kJ / pyunits.mol),
"enth_mol_form_liq_comp_ref": (0, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -1296,7 +1296,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
"3": (1595.8, pyunits.K),
"4": (0.6598, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-240.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (167039, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -1326,7 +1326,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
"3": (1, pyunits.K),
"4": (1, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-542.83, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (2.7637e5, pyunits.J / pyunits.kmol / pyunits.K),
"2": (-2.0901e3, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -1425,7 +1425,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
"3": (429.69, pyunits.K),
"4": (0.259, pyunits.dimensionless),
},
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.J / pyunits.mol),
"enth_mol_form_liq_comp_ref": (-677.1, pyunits.kJ / pyunits.mol),
"cp_mol_liq_comp_coeff": {
"1": (135749.9, pyunits.J / pyunits.kmol / pyunits.K),
"2": (0, pyunits.J / pyunits.kmol / pyunits.K**2),
Expand Down Expand Up @@ -1539,7 +1539,7 @@ def test_validation_appr_equ(self, remineralization_appr_equ):
"equilibrium_form": log_power_law_equil,
"concentration_form": ConcentrationForm.moleFraction,
"parameter_data": {
"dh_rxn_ref": (55.830, pyunits.J / pyunits.mol),
"dh_rxn_ref": (55.830, pyunits.kJ / pyunits.mol),
"k_eq_ref": (10**-14 / 55.2 / 55.2, pyunits.dimensionless),
"T_eq_ref": (298, pyunits.K),
# By default, reaction orders follow stoichiometry
Expand Down
Loading

0 comments on commit a54427c

Please sign in to comment.