Changeset 351
- Timestamp:
- 03/27/08 16:32:18 (8 months ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/book.c
r350 r351 35 35 int init_triangle_array It returns zero or an error code. 36 36 37 int resolution Resolution of the discretization , two and up.37 int resolution Resolution of the discretization (number of points on a side). 38 38 39 ternary_point *points 39 ternary_point *points Array of ternary points of size 40 +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 41 -latex-(N+1)(N+2)/2, where N is the resolution. 40 42 ++++++++++++++++++++++++++++++++++++++*/ 41 43 … … 69 71 return 0; 70 72 } 73 74 75 /*++++++++++++++++++++++++++++++++++++++ 76 This scales the free energy of an array of ternary points to the 77 +latex+$y$-coordinate 78 -latex-y-coordinate 79 and colors the points according to free energy as well. 80 81 int scale_triangle_array It returns zero or an error code. 82 83 int num_points Number of points in the array 84 85 ternary_point *points Array of ternary points of size 86 +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 87 -latex-(N+1)(N+2)/2, where N is the resolution. 88 89 double y0 Reference (minimum) 90 +latex+$y$-coordinate value. 91 -latex-y-coordinate value. 92 93 double G0 Free energy corresponding to reference 94 +latex+$y$-coordinate value. 95 -latex-y-coordinate value. 96 97 double y1 Second (maximum) 98 +latex+$y$-coordinate value. 99 -latex-y-coordinate value. 100 101 double G1 Free energy corresponding to second 102 +latex+$y$-coordinate value. 103 -latex-y-coordinate value. 104 105 double *Gmin Optional address to store the minimum free energy in the array 106 on return (NULL if unwanted), used as G0 if both G0 and G1 are zero. 107 108 double *Gmax Optional address to store the maximum free energy in the array 109 on return (NULL if unwanted), used as G1 if both G0 and G1 are zero. 110 ++++++++++++++++++++++++++++++++++++++*/ 111 112 int scale_triangle_array (int num_points, ternary_point *points, 113 double y0, double G0, double y1, double G1, 114 double *Gmin, double *Gmax) 115 { 116 int i; 117 118 if (G0==0. && G1==0.) 119 { 120 G0 = G1 = points[0].G; 121 for (i=0; i<num_points; i++) 122 { 123 G0 = fmin (points[i].G, G0); 124 G1 = fmax (points[i].G, G1); 125 } 126 if (Gmin) 127 *Gmin = G0; 128 if (Gmax) 129 *Gmax = G1; 130 } 131 else 132 { 133 if (Gmin) 134 { 135 *Gmin = points[0].G; 136 for (i=0; i<num_points; i++) 137 *Gmin = fmin (points[i].G, *Gmin); 138 } 139 if (Gmax) 140 { 141 *Gmax = points[0].G; 142 for (i=0; i<num_points; i++) 143 *Gmax = fmax (points[i].G, *Gmax); 144 } 145 } 146 147 #define Grel(G) (y0 + (y1-y0) * ((G)-G0) / (G1-G0)) 148 #define RED(G) (((G)<.25) ? 1. : (((G)<.5) ? 2.-4.*(G) : 0.)) 149 #define GREEN(G) (((G)<.25) ? 4.*(G) : (((G)<.75) ? 1. : 4.-4.*(G))) 150 #define BLUE(G) (((G)<.5) ? 0. : (((G)<.75) ? 4.*(G)-2. : 1.)) 151 152 for (i=0; i<num_points; i++) 153 { 154 points[i].y = Grel(points[i].G); 155 points[i].red = RED (Grel (points[i].G)); 156 points[i].green = GREEN (Grel (points[i].G)); 157 points[i].blue = BLUE (Grel (points[i].G)); 158 points[i].alpha = 1.; 159 } 160 161 return 0; 162 } -
trunk/matml/src/ternary/ternary.c
r350 r351 30 30 char gv_version[100], *qh_version; 31 31 FILE *pfd = NULL; 32 double Gmin, Gmax,T=1.;32 double T=1.; 33 33 ternary_point *points; 34 34 /* eparams: R,T0, G1@T0,G2,G3, C1,C2,C3, M1,M2,M3, O12,O13,O23,O123 */ … … 58 58 #define ROWSTART(row) ((row)*(loop_max+1) - ((row)*((row)-1))/2) 59 59 60 Gmin = Gmax = free_energy (0., 0., T, &eparams1); 61 for (i=0; i<=loop_max; i++) 62 for (j=0; j<=loop_max-i; j++) 63 { 64 index = (ROWSTART (i) + j); 60 for (index=0; index<(loop_max+1)*(loop_max+2)/2; index++) 61 points[index].G = 62 free_energy (points[index].C2, points[index].C3, T, &eparams1); 65 63 66 points[index].G = 67 free_energy (points[index].C2, points[index].C3, T, &eparams1); 68 Gmin = (points[index].G<Gmin) ? points[index].G : Gmin; 69 Gmax = (points[index].G>Gmax) ? points[index].G : Gmax; 70 } 71 72 #define Grel(G) (((G)-Gmin)/(Gmax-Gmin)) 73 #define RED(G) (((G)<.25) ? 1. : (((G)<.5) ? 2.-4.*(G) : 0.)) 74 #define GREEN(G) (((G)<.25) ? 4.*(G) : (((G)<.75) ? 1. : 4.-4.*(G))) 75 #define BLUE(G) (((G)<.5) ? 0. : (((G)<.75) ? 4.*(G)-2. : 1.)) 76 77 /* Rescale points from C2,C3 to x,y and calculate colors */ 78 for (i=0; i<=loop_max; i++) 79 for (j=0; j<=loop_max-i; j++) 80 { 81 index = (ROWSTART (i) + j); 82 83 /* Switch y and z because geomview uses z as depth */ 84 points[index].y = Grel(points[index].G); 85 86 points[index].red = RED (Grel (points[index].G)); 87 points[index].green = GREEN (Grel (points[index].G)); 88 points[index].blue = BLUE (Grel (points[index].G)); 89 points[index].alpha = 1.; 90 } 64 if (i=scale_triangle_array ((loop_max+1)*(loop_max+2)/2, points, 65 0., 0., 1., 0., NULL, NULL)) 66 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 91 67 92 68 /* Calculate triangle vertex indices */ -
trunk/matml/src/ternary/ternary.h
r349 r351 88 88 } energy_params; 89 89 90 /* From freenergy.c */ 90 91 double free_energy (double C2, double C3, double T, energy_params *eparams); 91 92 93 /* From geomview.c */ 92 94 int GeomviewBegin (FILE **geompipe, char *version); 93 95 int GeomviewDisplayTriangleCOFF … … 96 98 int GeomviewEnd (FILE **geompipe); 97 99 100 /* From qhull.c */ 98 101 int qhullCalcHull (int dim, int numpoints, ternary_point *points, int *facets, 99 102 int **verts, char **version); 100 103 104 /* From book.c */ 105 int init_triangle_array (int resolution, ternary_point *points); 106 int scale_triangle_array (int num_points, ternary_point *points, 107 double y0, double G0, double y1, double G1, 108 double *Gmin, double *Gmax); 109 101 110 #endif /* TERNARY_H */