Changeset 432 for trunk/matml
- Timestamp:
- 03/06/2009 04:49:33 PM (3 years ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/qhull.c
r430 r432 705 705 int numfacets Number of facets. 706 706 707 energy_params *eparams Collection of energy parameter structures. 708 709 double T Temperature. 710 711 double P Pressure. 712 707 713 phase_boundary **boundaries Pointer to array of phase_boundary objects. This 708 714 is changed by realloc() each time the function is called, so it should be … … 714 720 int hullReturnPhaseBoundaries 715 721 (ternary_point *points, int n_points, hull_facet *facets, int n_facets, 722 energy_params *eparams, double T, double P, 716 723 phase_boundary **boundaries, int *n_bounds) 717 724 { … … 731 738 v2 = facets[f].vertex[2]; 732 739 733 printf ("Last facet %d vertices %d, %d, %d\n", n_facets-1,734 facets[n_facets-1].vertex[0], facets[n_facets-1].vertex[1],735 facets[n_facets-1].vertex[2]);736 737 740 printf ("Facet %d: type %d, vertices %d ",f, facets [f].type, v0); 738 fflush (stdout);739 741 printf ("(%d), %d (%d), %d(%d)\n", 740 742 points[v0].efunc, v1, … … 745 747 { 746 748 case ONE_PHASE: 747 { 748 printf ("Type 0 facet\n"); fflush (stdout); 749 // Totally uninteresting 750 break; 751 } 749 // Totally uninteresting 750 break; 752 751 753 752 case THREE_PHASE: … … 795 794 (*boundaries) [bound].edges [2] = MAX3 (v0, v1, v2); 796 795 (*n_bounds) ++; 796 printf (" Corners for bound %d edge 0: %d, %d, %d\n", bound, 797 (*boundaries) [bound].edges [0], 798 (*boundaries) [bound].edges [1], 799 (*boundaries) [bound].edges [2]); 797 800 } 798 801 else … … 811 814 (*boundaries) [bound].edges [3*e+2] = MAX3 (v0, v1, v2); 812 815 (*boundaries) [bound].n_edges += 1; 816 printf (" Corners for bound %d edge %d: %d, %d, %d\n", bound,e, 817 (*boundaries) [bound].edges [3*e], 818 (*boundaries) [bound].edges [3*e+1], 819 (*boundaries) [bound].edges [3*e+2]); 813 820 } 814 821 … … 820 827 case TWO_PHASE: 821 828 { 822 int b=0, bound=-1, p0, p1, p2, 829 int b=0, bound=-1, p0, p1, p2, nphases=2, e=0, 823 830 phase0 = MIN3 (points [v0].efunc, points [v1].efunc, 824 831 points [v2].efunc), … … 833 840 p1 = MAX (v0, v1); 834 841 p2 = v2; 835 // If all three are on the same phase, need to check midpoint 836 // energies to determine which are one- and two-phase segments. 837 // Punt for the default case later! 842 843 // If all three are on the same phase, this is a miscibility 844 // gap facet, set nphases to 1 and figure out which vertex is 845 // across from the other two 838 846 if (points [v0].efunc == points [v2].efunc) 839 { printf ("Miscibility gap!\n"); break; } 847 { 848 double C02 = points [v0].C2, C03 = points [v0].C3, 849 C12 = points [v1].C2, C13 = points [v1].C3, 850 C22 = points [v2].C2, C23 = points [v2].C3, 851 G0 = points [v0].G, G1 = points [v1].G, 852 G2 = points [v2].G; 853 854 printf ("Misc gap: "); 855 nphases=1; 856 857 if (free_energy ((C02+C12)/2,(C03,C13)/2,T,P,eparams+phase0) < 858 G0+G1/2) 859 { 860 printf ("v2 alone, Gav=%g, Gmid=%g\n", 861 G0+G1/2, free_energy ((C02+C12)/2,(C03,C13)/2,T,P,eparams+phase0)); 862 p0 = MIN (v0, v1); 863 p1 = MAX (v0, v1); 864 p2 = v2; 865 } 866 else if (free_energy ((C02+C22)/2,(C03,C23)/2,T,P,eparams+phase0) < 867 G0+G2/2) 868 { 869 printf ("v1 alone, Gav=%g, Gmid=%g\n", 870 G0+G2/2, free_energy ((C02+C22)/2,(C03,C23)/2,T,P,eparams+phase0)); 871 p0 = MIN (v0, v2); 872 p1 = MAX (v0, v2); 873 p2 = v1; 874 } 875 else 876 { 877 printf ("v0 alone, Gav=%g, Gmid=%g\n", 878 G1+G2/2, free_energy ((C22+C12)/2,(C23,C13)/2,T,P,eparams+phase0)); 879 p0 = MIN (v1, v2); 880 p1 = MAX (v1, v2); 881 p2 = v0; 882 } 883 } 840 884 } 841 885 else if (points [v0].efunc == points [v2].efunc) … … 854 898 // Check for a boundary with tie lines between these two phases 855 899 for (b=0; b<*n_bounds; b++) 856 if ((*boundaries) [b].n_phases == 2&&900 if ((*boundaries) [b].n_phases == nphases && 857 901 (*boundaries) [b].flags == TIE_SIMPLICES && 858 902 (*boundaries) [b].phases[0] == phase0 && 859 (*boundaries) [b].phases[ 1] == phase1)903 (*boundaries) [b].phases[nphases-1] == phase1) 860 904 bound = b; 861 905 … … 870 914 871 915 (*boundaries) [bound].compos = 2; 872 (*boundaries) [bound].n_phases = 2;916 (*boundaries) [bound].n_phases = nphases; 873 917 if (!((*boundaries) [bound].phases = 874 malloc ( 2*sizeof (int))))918 malloc (nphases*sizeof (int)))) 875 919 return 1; 876 920 (*boundaries) [bound].phases [0] = phase0; 877 (*boundaries) [bound].phases [1] = phase1; 878 (*boundaries) [bound].n_edges = 2; 879 if (!((*boundaries) [bound].edges = 880 malloc (4*sizeof (int)))) 881 return 1; 882 (*boundaries) [bound].edges [0] = MIN (p0, p2); 883 (*boundaries) [bound].edges [1] = MAX (p0, p2); 884 (*boundaries) [bound].edges [2] = MIN (p1, p2); 885 (*boundaries) [bound].edges [3] = MAX (p1, p2); 921 (*boundaries) [bound].phases [nphases-1] = phase1; 922 (*boundaries) [bound].n_edges = 0; 923 (*boundaries) [bound].edges = NULL; 886 924 (*boundaries) [bound].flags = TIE_SIMPLICES; 887 925 (*n_bounds) ++; 926 e=0; 888 927 } 889 928 else 890 { 891 int e = (*boundaries) [bound].n_edges; 892 printf ("Tie-line boundary %d adding edges %d,%d\n",bound,e,e+1); 893 // All of these reallocs are pretty expensive... 894 // Later use compos to store size of array, sort out later 895 if (!((*boundaries) [bound].edges = realloc 896 ((*boundaries) [bound].edges, (2*e+4)*sizeof (int)))) 897 return 1; 898 (*boundaries) [bound].edges [2*e] = MIN (p0, p2); 899 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p2); 900 (*boundaries) [bound].edges [2*e+2] = MIN (p1, p2); 901 (*boundaries) [bound].edges [2*e+3] = MAX (p1, p2); 902 (*boundaries) [bound].n_edges += 2; 903 } 929 e = (*boundaries) [bound].n_edges; 930 931 // All of these reallocs are pretty expensive... 932 // Later use compos to store size of array, sort out later 933 if (!((*boundaries) [bound].edges = realloc 934 ((*boundaries) [bound].edges, (2*e+4) * sizeof (int)))) 935 return 1; 936 (*boundaries) [bound].n_edges += 2; 937 938 (*boundaries) [bound].edges [2*e] = MIN (p0, p2); 939 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p2); 940 (*boundaries) [bound].edges [2*e+2] = MIN (p1, p2); 941 (*boundaries) [bound].edges [2*e+3] = MAX (p1, p2); 942 printf (" Corners for bound %d edges %d,%d: %d,%d, %d,%d\n", 943 bound, e, e+1, (*boundaries) [bound].edges [2*e], 944 (*boundaries) [bound].edges [2*e+1], 945 (*boundaries) [bound].edges [2*e+2], 946 (*boundaries) [bound].edges [2*e+3]); 904 947 905 948 // Check for a boundary with an edge on the "majority" phase 906 949 for (b=0, bound=-1; b<*n_bounds; b++) 907 if ((*boundaries) [b].n_phases == 2&&950 if ((*boundaries) [b].n_phases == nphases && 908 951 (*boundaries) [b].flags == ONE_PHASE_EDGE && 909 952 (*boundaries) [b].phases[0] == points[p0].efunc && 910 (*boundaries) [b].phases[ 1] == points[p2].efunc)953 (*boundaries) [b].phases[nphases-1] == points[p2].efunc) 911 954 bound = b; 912 955 … … 921 964 922 965 (*boundaries) [bound].compos = 2; 923 (*boundaries) [bound].n_phases = 2;966 (*boundaries) [bound].n_phases = nphases; 924 967 if (!((*boundaries) [bound].phases = 925 malloc ( 2*sizeof (int))))968 malloc (nphases*sizeof (int)))) 926 969 return 1; 927 970 (*boundaries) [bound].phases [0] = points[p0].efunc; 928 (*boundaries) [bound].phases [1] = points[p2].efunc; 929 (*boundaries) [bound].n_edges = 1; 930 if (!((*boundaries) [bound].edges = 931 malloc (2*sizeof (int)))) 932 return 1; 933 (*boundaries) [bound].edges [0] = MIN (p0, p1); 934 (*boundaries) [bound].edges [1] = MAX (p0, p1); 971 (*boundaries) [bound].phases [nphases-1] = points[p2].efunc; 972 (*boundaries) [bound].n_edges = 0; 973 (*boundaries) [bound].edges = NULL; 935 974 (*boundaries) [bound].flags = ONE_PHASE_EDGE; 936 975 (*n_bounds) ++; 976 e=0; 937 977 } 938 978 else 939 { 940 int e = (*boundaries) [bound].n_edges; 941 printf ("Phase edge boundary %d adding edge %d\n",bound,e); 942 // All of these reallocs are pretty expensive... 943 if (!((*boundaries) [bound].edges = realloc 944 ((*boundaries) [bound].edges, (2*e+2)*sizeof (int)))) 945 return 1; 946 (*boundaries) [bound].edges [2*e] = MIN (p0, p1); 947 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p1); 948 (*boundaries) [bound].n_edges += 1; 949 } 950 979 e = (*boundaries) [bound].n_edges; 980 981 // All of these reallocs are pretty expensive... 982 if (!((*boundaries) [bound].edges = realloc 983 ((*boundaries) [bound].edges, (2*e+2)*sizeof (int)))) 984 return 1; 985 (*boundaries) [bound].edges [2*e] = MIN (p0, p1); 986 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p1); 987 (*boundaries) [bound].n_edges += 1; 988 printf (" Corners for bound %d edge %d: %d,%d\n", 989 bound, e, (*boundaries) [bound].edges [2*e], 990 (*boundaries) [bound].edges [2*e+1]); 991 992 break; 993 } 994 995 case CRITICAL_POINT: 996 { 997 printf ("Critical point case\n"); 951 998 break; 952 999 } … … 962 1009 points [facets[f].vertex[1]].efunc, 963 1010 points [facets[f].vertex[2]].efunc); 1011 printf (" Coords: %d %g,%g, %d %g,%g, %d %g,%g\n", 1012 facets[f].vertex[0], points [facets[f].vertex[0]].C2, 1013 points [facets[f].vertex[0]].C3, 1014 facets[f].vertex[1], points [facets[f].vertex[1]].C2, 1015 points [facets[f].vertex[1]].C3, 1016 facets[f].vertex[2], points [facets[f].vertex[2]].C2, 1017 points [facets[f].vertex[2]].C3); 964 1018 } 965 1019 } -
trunk/matml/src/ternary/ternary.c
r431 r432 121 121 122 122 if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, 123 &allbounds, &numbounds))123 allparams, T, P, &allbounds, &numbounds)) 124 124 { printf ("main: error %d in hullReturnPhaseBoundaries\n", i); exit (i); } 125 125 … … 144 144 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 145 145 146 if (i=GeomviewDisplayPhaseBoundary 147 (pfd, "Boundary 4", "bd4", "-face +edge", 148 numpoints, points, allbounds+4)) 149 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 150 151 if (i=GeomviewDisplayPhaseBoundary 152 (pfd, "Boundary 5", "bd5", "-face +edge", 153 numpoints, points, allbounds+5)) 154 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 155 146 156 printf ("Press <return> to close up... "); 147 157 fflush (stdout);