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

Reformulate solubility_products constraints #1197

Merged
merged 23 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def return_expression(b, rblock, r_idx, T):
if Qunits is not None:
Q = Q / Qunits

return s - smooth_max(0, s - Q, rblock.eps) == 0
return Q - smooth_max(0, Q - s / (s + b.k_eq[r_idx]), rblock.eps) == 0
lxhowl marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def calculate_scaling_factors(b, sf_keq):
Expand Down Expand Up @@ -287,7 +287,8 @@ def return_expression(b, rblock, r_idx, T):
Q = b.log_k_eq[r_idx] - e
# Q should be unitless due to log form

return s - smooth_max(0, s - Q, rblock.eps) == 0
s = s * 10 / (s + b.k_eq[r_idx])
lxhowl marked this conversation as resolved.
Show resolved Hide resolved
return Q - smooth_max(0, Q - s, rblock.eps) == 0
Copy link
Member

Choose a reason for hiding this comment

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

If one or both Q and s need to be zero, could this just bee smooth min(Q, s) == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current expression goes Q-0.5(Q-s+|Q-s|) == 0 while the smooth min gives 0.5(Q+s-|Q-s|)==0. The complexity remains the same. The current expression keeps Q as a leading term, which might be easy for users to scale the solubility product with other equilibrium reactions.

Copy link
Member

Choose a reason for hiding this comment

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

@eslickj I think this formulation is correct - it is a bit more complicated than just one of Q or s needing to be zero.

Copy link
Member

Choose a reason for hiding this comment

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

@andrewlee94, I'm sure you are probably right. Can someone explain the difference to me? Why is this one preferred? I think both should work, but I may be missing something. To me, the the one in the code currently just seems convoluted.

Copy link
Member

Choose a reason for hiding this comment

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

@eslickj I cannot remember the details - I asked Larry Biegler to help with this is and this is the form he suggested.


@staticmethod
def calculate_scaling_factors(b, sf_keq):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def mole_frac_comp(b, j):

b.mole_frac_phase_comp = Var(
b.phase_component_set,
bounds=(1e-20, 1.001),
bounds=(1e-50, 1.001),
lxhowl marked this conversation as resolved.
Show resolved Hide resolved
initialize=1 / len(b.component_list),
doc="Phase mole fractions",
units=pyunits.dimensionless,
Expand Down