| | 998 | int b=0, bound=-1, p0, p1, p2, e=0, phase = points [v0].efunc; |
| | 999 | double C02 = points [v0].C2, C03 = points [v0].C3, |
| | 1000 | C12 = points [v1].C2, C13 = points [v1].C3, |
| | 1001 | C22 = points [v2].C2, C23 = points [v2].C3, |
| | 1002 | G0 = points [v0].G, G1 = points [v1].G, |
| | 1003 | G2 = points [v2].G; |
| | 1004 | |
| | 1005 | if (free_energy ((C02+C12)/2,(C03+C13)/2,T,P,eparams+phase) > |
| | 1006 | (G0+G1)/2) |
| | 1007 | { |
| | 1008 | printf ("v2 alone, Gav=%g, Gmid=%g\n", |
| | 1009 | (G0+G1)/2, free_energy ((C02+C12)/2,(C03+C13)/2,T,P,eparams+phase)); |
| | 1010 | p0 = MIN (v0, v1); |
| | 1011 | p1 = MAX (v0, v1); |
| | 1012 | p2 = v2; |
| | 1013 | } |
| | 1014 | else if (free_energy ((C02+C22)/2,(C03+C23)/2,T,P,eparams+phase) > |
| | 1015 | (G0+G2)/2) |
| | 1016 | { |
| | 1017 | printf ("v1 alone, Gav=%g, Gmid=%g\n", |
| | 1018 | (G0+G2)/2, free_energy ((C02+C22)/2,(C03+C23)/2,T,P,eparams+phase)); |
| | 1019 | p0 = MIN (v0, v2); |
| | 1020 | p1 = MAX (v0, v2); |
| | 1021 | p2 = v1; |
| | 1022 | } |
| | 1023 | else |
| | 1024 | { |
| | 1025 | printf ("v0 alone, Gav=%g, Gmid=%g\n", |
| | 1026 | (G1+G2)/2, free_energy ((C22+C12)/2,(C23+C13)/2,T,P,eparams+phase)); |
| | 1027 | p0 = MIN (v1, v2); |
| | 1028 | p1 = MAX (v1, v2); |
| | 1029 | p2 = v0; |
| | 1030 | } |
| | 1031 | |
| | 1032 | // Check for a boundary with tie lines across this miscibility gap |
| | 1033 | for (b=0; b<*n_bounds; b++) |
| | 1034 | if ((*boundaries) [b].n_phases == 1 && |
| | 1035 | (*boundaries) [b].flags == TIE_SIMPLICES && |
| | 1036 | (*boundaries) [b].phases[0] == phase) |
| | 1037 | bound = b; |
| | 1038 | |
| | 1039 | if (bound == -1) |
| | 1040 | { |
| | 1041 | bound = *n_bounds; |
| | 1042 | // No tie-line boundary in this phase, make a new one |
| | 1043 | printf ("Making new tie-line boundary %d\n", *n_bounds); |
| | 1044 | if (!(*boundaries = realloc |
| | 1045 | (*boundaries, (*n_bounds+1) * sizeof (phase_boundary)))) |
| | 1046 | return 1; |
| | 1047 | |
| | 1048 | (*boundaries) [bound].compos = 2; |
| | 1049 | (*boundaries) [bound].n_phases = 1; |
| | 1050 | if (!((*boundaries) [bound].phases = malloc (sizeof (int)))) |
| | 1051 | return 1; |
| | 1052 | (*boundaries) [bound].phases [0] = phase; |
| | 1053 | (*boundaries) [bound].n_edges = 0; |
| | 1054 | (*boundaries) [bound].edges = NULL; |
| | 1055 | (*boundaries) [bound].flags = TIE_SIMPLICES; |
| | 1056 | (*n_bounds) ++; |
| | 1057 | e=0; |
| | 1058 | } |
| | 1059 | else |
| | 1060 | e = (*boundaries) [bound].n_edges; |
| | 1061 | |
| | 1062 | // All of these reallocs are pretty expensive... |
| | 1063 | // Later use compos to store size of array, sort out later |
| | 1064 | if (!((*boundaries) [bound].edges = realloc |
| | 1065 | ((*boundaries) [bound].edges, (2*e+2) * sizeof (int)))) |
| | 1066 | return 1; |
| | 1067 | (*boundaries) [bound].n_edges += 1; |
| | 1068 | |
| | 1069 | (*boundaries) [bound].edges [2*e] = MIN (p0, p1); |
| | 1070 | (*boundaries) [bound].edges [2*e+1] = MAX (p0, p1); |
| | 1071 | printf (" Corners for bound %d edges %d,%d: %d,%d\n", |
| | 1072 | bound, e, e+1, (*boundaries) [bound].edges [2*e], |
| | 1073 | (*boundaries) [bound].edges [2*e+1]); |
| | 1074 | |
| | 1075 | // Check for a boundary with an edge on this miscibility gap |
| | 1076 | for (b=0, bound=-1; b<*n_bounds; b++) |
| | 1077 | if ((*boundaries) [b].n_phases == 1 && |
| | 1078 | (*boundaries) [b].flags == ONE_PHASE_EDGE && |
| | 1079 | (*boundaries) [b].phases[0] == phase) |
| | 1080 | bound = b; |
| | 1081 | |
| | 1082 | if (bound == -1) |
| | 1083 | { |
| | 1084 | // No edge boundary with this miscibility gap, make a new one |
| | 1085 | bound = *n_bounds; |
| | 1086 | printf ("Making new phase edge boundary %d\n", *n_bounds); |
| | 1087 | if (!(*boundaries = realloc |
| | 1088 | (*boundaries, (bound+1) * sizeof (phase_boundary)))) |
| | 1089 | return 1; |
| | 1090 | |
| | 1091 | (*boundaries) [bound].compos = 2; |
| | 1092 | (*boundaries) [bound].n_phases = 1; |
| | 1093 | if (!((*boundaries) [bound].phases = malloc (sizeof (int)))) |
| | 1094 | return 1; |
| | 1095 | (*boundaries) [bound].phases [0] = phase; |
| | 1096 | (*boundaries) [bound].n_edges = 0; |
| | 1097 | (*boundaries) [bound].edges = NULL; |
| | 1098 | (*boundaries) [bound].flags = ONE_PHASE_EDGE; |
| | 1099 | (*n_bounds) ++; |
| | 1100 | e=0; |
| | 1101 | } |
| | 1102 | else |
| | 1103 | e = (*boundaries) [bound].n_edges; |
| | 1104 | |
| | 1105 | // All of these reallocs are pretty expensive... |
| | 1106 | if (!((*boundaries) [bound].edges = realloc |
| | 1107 | ((*boundaries) [bound].edges, (2*e+4)*sizeof (int)))) |
| | 1108 | return 1; |
| | 1109 | (*boundaries) [bound].edges [2*e] = MIN (p0, p2); |
| | 1110 | (*boundaries) [bound].edges [2*e+1] = MAX (p0, p2); |
| | 1111 | (*boundaries) [bound].edges [2*e+2] = MIN (p1, p2); |
| | 1112 | (*boundaries) [bound].edges [2*e+3] = MAX (p1, p2); |
| | 1113 | (*boundaries) [bound].n_edges += 2; |
| | 1114 | printf (" Corners for bound %d edge %d: %d,%d, %d,%d\n", |
| | 1115 | bound, e, (*boundaries) [bound].edges [2*e], |
| | 1116 | (*boundaries) [bound].edges [2*e+1], |
| | 1117 | (*boundaries) [bound].edges [2*e+2], |
| | 1118 | (*boundaries) [bound].edges [2*e+3]); |
| | 1119 | |