Changeset 354
- Timestamp:
- 03/27/08 17:22:53 (8 months ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/ChangeLog
r353 r354 5 5 * Parameterized free energy function with temperature support. 6 6 * Moved many O(N) functions from main() out to new book.c file. 7 * TODO: better single-phase check in ternary.c, 8 multiple free energy functions; later refine qhull concave facets. 7 * Multiple free energy functions work. 8 * TODO: better single-phase check in ternary.c; 0.3 refine qhull concave 9 facets. 9 10 10 11 -- -
trunk/matml/src/ternary/book.c
r353 r354 83 83 +latex+$N^2$, where $N$ is the resolution. 84 84 +html+ <i>N</i><sup>2</sup>, where <i>N</i> is the resolution. 85 86 int offset Constant to add to vertex indices, usually 0. 85 87 ++++++++++++++++++++++++++++++++++++++*/ 86 88 87 int init_triangle_vertices (int resolution, int *vertex_array )89 int init_triangle_vertices (int resolution, int *vertex_array, int offset) 88 90 { 89 91 int i,j, index; … … 93 95 for (j=0; j<resolution-i-1; j++) 94 96 { 95 vertex_array [3*index] = ROWSTART(i)+j;96 vertex_array [3*index+1] = ROWSTART(i)+j+1;97 vertex_array [3*index+2] = ROWSTART(i+1)+j;97 vertex_array [3*index] = offset + ROWSTART(i)+j; 98 vertex_array [3*index+1] = offset + ROWSTART(i)+j+1; 99 vertex_array [3*index+2] = offset + ROWSTART(i+1)+j; 98 100 index++; 99 101 100 vertex_array [3*index] = ROWSTART(i)+j+1;101 vertex_array [3*index+1] = ROWSTART(i+1)+j+1;102 vertex_array [3*index+2] = ROWSTART(i+1)+j;102 vertex_array [3*index] = offset + ROWSTART(i)+j+1; 103 vertex_array [3*index+1] = offset + ROWSTART(i+1)+j+1; 104 vertex_array [3*index+2] = offset + ROWSTART(i+1)+j; 103 105 index++; 104 106 } 105 vertex_array [3*index] = ROWSTART(i)+resolution-i-1;106 vertex_array [3*index+1] = ROWSTART(i)+resolution-i;107 vertex_array [3*index+2] = ROWSTART(i+1)+resolution-i-1;107 vertex_array [3*index] = offset + ROWSTART(i)+resolution-i-1; 108 vertex_array [3*index+1] = offset + ROWSTART(i)+resolution-i; 109 vertex_array [3*index+2] = offset + ROWSTART(i+1)+resolution-i-1; 108 110 index++; 109 111 } 110 vertex_array [3*index] = ROWSTART(resolution-1);111 vertex_array [3*index+1] = ROWSTART(resolution-1)+1;112 vertex_array [3*index+2] = ROWSTART(resolution);112 vertex_array [3*index] = offset + ROWSTART(resolution-1); 113 vertex_array [3*index+1] = offset + ROWSTART(resolution-1)+1; 114 vertex_array [3*index+2] = offset + ROWSTART(resolution); 113 115 114 116 return 0; -
trunk/matml/src/ternary/ternary.c
r353 r354 8 8 9 9 #include "ternary.h" /*+ Ternary prototypes, typedefs, etc. +*/ 10 #include <stdlib.h> /*+ For calloc +*/ 10 #include <stdlib.h> /*+ For calloc() +*/ 11 #include <math.h> /*+ For fabs() +*/ 11 12 12 13 … … 30 31 char gv_version[100], *qh_version; 31 32 FILE *pfd = NULL; 32 double T=1. ;33 double T=1.5; 33 34 ternary_point *points; 34 35 /* eparams: R,T0, G1@T0,G2,G3, C1,C2,C3, M1,M2,M3, O12,O13,O23,O123 */ 35 36 energy_params /* Solid, liquid */ 36 eparams1 = {1.,1., 0.,-.1,-.2, 1.,1.1,1.2, 1.,2.,5., -.5,2.,.2, 0.},37 eparams2 = {1.,1., .3,.1,-.1, 2.2,2.,1.8, 1.,1.,1.5, -.3,-.4,-.1, -.5};37 eparams1 = {1.,1., 0.,-.1,-.2, -1.,-1.1,-1.2, 1.,2.,5., -.5,2.,.2, 0.}, 38 eparams2 = {1.,1., .3,.1,-.1, -2.2,-2.,-1.8, 1.,1.,1.5, -.3,-.4,-.1, -.5}; 38 39 39 40 if (argc>1) 40 41 sscanf (argv[1], "%d", &loop_max); 41 42 42 /* Allocate array s for point coordinates and colors and triangle vertices */43 if (!(points = calloc ((loop_max+1)*(loop_max+2) /2, sizeof (ternary_point))))43 /* Allocate array pairs for ternary points and triangle vertices */ 44 if (!(points = calloc ((loop_max+1)*(loop_max+2), sizeof (ternary_point)))) 44 45 { printf ("Cannot allocate point coordinate array\n"); exit (1); } 45 46 if (!(verts = calloc (loop_max*loop_max * 3, sizeof (int)))) 46 if (!(verts = calloc (loop_max*loop_max * 6, sizeof (int)))) 47 47 { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 48 48 … … 52 52 printf("Geomview version: %s\n", gv_version); 53 53 54 /* Initialize coordinates of triangle array*/54 /* Initialize coordinates of both triangle array halves */ 55 55 if (i=init_triangle_array (loop_max, points)) 56 56 { printf ("main: Error %d in init_triangle_array\n", i); exit (i); } 57 if (i=init_triangle_array (loop_max, points+(loop_max+1)*(loop_max+2)/2)) 58 { printf ("main: Error %d in init_triangle_array\n", i); exit (i); } 57 59 58 /* Calculate triangle vertex indices */ 59 if (i=init_triangle_vertices (loop_max, verts)) 60 /* Calculate triangle vertex indices for both arrays */ 61 if (i=init_triangle_vertices (loop_max, verts, 0)) 62 { printf ("main: Error %d in init_triangle_vertices\n", i); exit (i); } 63 if (i=init_triangle_vertices (loop_max, verts + loop_max*loop_max*3, 64 (loop_max+1)*(loop_max+2)/2)) 60 65 { printf ("main: Error %d in init_triangle_vertices\n", i); exit (i); } 61 66 … … 64 69 points[index].G = 65 70 free_energy (points[index].C2, points[index].C3, T, &eparams1); 71 for (index=(loop_max+1)*(loop_max+2)/2; 72 index<(loop_max+1)*(loop_max+2); index++) 73 points[index].G = 74 free_energy (points[index].C2, points[index].C3, T, &eparams2); 66 75 67 /* Scale free energy values to (0->1) */68 if (i=scale_energy_array ((loop_max+1)*(loop_max+2) /2, points,69 0., 0., 1., 0., NULL, NULL))76 /* Scale all free energy values to (0->1) */ 77 if (i=scale_energy_array ((loop_max+1)*(loop_max+2), points, 78 0., -1.5, 1., 1., NULL, NULL)) 70 79 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 71 80 … … 73 82 if (i=GeomviewDisplayTriangleCOFF 74 83 (pfd, "Ternary Free Energy", "tfe", "shading smooth", 75 (loop_max+1)*(loop_max+2) /2, points, loop_max*loop_max, verts))84 (loop_max+1)*(loop_max+2), points, loop_max*loop_max*2, verts)) 76 85 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 77 86 78 if (i=qhullCalcHull (3, (loop_max+1)*(loop_max+2)/2, points, &hullnumverts, 87 /* Calculate the lower convex hull */ 88 if (i=qhullCalcHull (3, (loop_max+1)*(loop_max+2), points, &hullnumverts, 79 89 &hullverts, &qh_version)) 80 90 { printf ("main: qhullCalcHull returned %d\n", i); exit (i); } … … 113 123 if (i=GeomviewDisplayTriangleCOFF 114 124 (pfd, "Binodal and Tie Lines", "ech", "-face +edge", 115 (loop_max+1)*(loop_max+2) /2, points, hullnumverts, hullverts))125 (loop_max+1)*(loop_max+2), points, hullnumverts, hullverts)) 116 126 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 117 127 -
trunk/matml/src/ternary/ternary.h
r353 r354 104 104 /* From book.c */ 105 105 int init_triangle_array (int resolution, ternary_point *points); 106 int init_triangle_vertices (int resolution, int *vertex_array );106 int init_triangle_vertices (int resolution, int *vertex_array, int offset); 107 107 int scale_energy_array (int num_points, ternary_point *points, 108 108 double y0, double G0, double y1, double G1,