I am trying to determine a phase diagram along the lines of Fig 3. or Fig 4. of this pubilcation. The curves plotted are binodals and are determined by the conditions of equality of chemical potentials of each component in all phases and equality of osmotic pressure in each phase (Section 4 of the SI is a good primer).
As an example, I use free energy function similar to the one defined in the paper (although the one I am actually interested in a bit more complex. Ideally I can come up with a solution that is robust and generally applicable). This is still a good starting point because my system does reduce to this under certain limits.
We narrow our attention to the case of two solutes (1 solvent) and 2 phases. Then we wish to find the locus of points in ($\phi_a,\phi_b$) for which the following conditions hold
$$\mu_a^{(1)} (\phi^{(1)}_a,\phi^{(1)}_b) = \mu_a^{(2)} (\phi^{(2)}_a,\phi^{(2)}_b)$$ $$\mu_b^{(1)} (\phi^{(1)}_a,\phi^{(1)}_b) = \mu_b^{(2)} (\phi^{(2)}_a,\phi^{(2)}_b)$$ $$\Pi^{(1)} (\phi^{(1)}_a,\phi^{(1)}_b) = \Pi^{(2)} (\phi^{(2)}_a,\phi^{(2)}_b)$$
Essentially, we have 4 unknowns $\phi^{(1)}_a,\phi^{(1)}_b, \phi^{(0)}_a,\phi^{(0)}_b$ and 3 equations. Subscripts here in my notation label the components and superscripts the phase. The solutions should look like the curves present in Fig 3 or Fig 4 of the linked publication (depending on parameter values). The conditions described above should be equivalent to equations (39)-(41) in this SI
Here are the function definitions
F[a_, b_, uaa_, ubb_, uab_, na_, nb_] :=
a/na*Log[a] + b/nb*Log[b] + (1 - a - b)*Log[1 - a - b + 10^-14] -
1/2*uaa*a^2 - 1/2*ubb*b^2 - uab*b*a
det[a_, b_, uaa_, ubb_, uab_, na_, nb_] :=
Det[D[F[a, b, uaa, ubb, uab, na, nb], {{a, b}, 2}]] // Evaluate
\[Mu]a[a_, b_, uaa_, ubb_, uab_, na_, nb_] :=
D[F[a, b, uaa, ubb, uab, na, nb], a] // Evaluate
\[Mu]b[a_, b_, uaa_, ubb_, uab_, na_, nb_] :=
D[F[a, b, uaa, ubb, uab, na, nb], b] // Evaluate
\[CapitalPi]F[a_, b_, uaa_, ubb_, uab_, na_,
nb_] := \[Mu]a[a, b, uaa, ubb, uab, na, nb]*
a + \[Mu]b[a, b, uaa, ubb, uab, na, nb]*b -
F[a, b, uaa, ubb, uab, na, nb] // Evaluate
My first thought was to use NSolve
NSolve[{\[Mu]a[a1, b1, 0, 0, 4.36, 10, 6] == \[Mu]a[a2, b2, 0, 0,
4.36, 10, 6],
\[Mu]b[a1, b1, 0, 0, 4.36, 10, 6] == \[Mu]b[a2, b2, 0, 0, 4.36, 10,
6],
\[CapitalPi]F[a1, b1, 0, 0, 4.36, 10, 6] == \[CapitalPi]F[a2, b2, 0,
0, 4.36, 10, 6], a1 >= 0, b1 >= 0, a2 >= 0, b2 >= 0,
a2 + b2 <= 1, a1 + b1 <= 1
}, {a1, b1, a2, b2}, Reals]
but it seems like that is not the right way to do it.
Alternatively, I thought of using FindRoot
combined with grid search in the region, but I am not quite sure how to implement it, or if it is the optimum most efficient way to solve this problem. An intelligent way of choosing seed values for FindRoot
might be to use the spinodal which can be visualized as follows. Since if I understand correctly the binodal curve we are interested in should envelop this so we can try seeding points on the exterior of this?
Manipulate[ContourPlot[det[a, b, uaa, ubb, uab, 10, 6] == 0,
{a, 0, 1}, {b, 0, 1}],
{uaa, 0, 10}, {uab, 0, 10}, {ubb, 0, 10}]
Q1 : Is there any other built-in function in mathematica that can help me solve my problem? Q2 : If not are there any standard approaches/algorithms that can be applied to this situation ?
EDIT : Partially Cross-posted Stack Overflow. Includes a janky-python brute force solution attempt using a grid search I attempted.
F
as well. $\endgroup$F
. As I understand from discussion about data shown in Figure 2, they simulate some biological noise. $\endgroup$