Changeset 459 for trunk/matml
- Timestamp:
- 06/17/2009 03:52:54 PM (3 years ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 12 modified
-
book.c (modified) (9 diffs)
-
ChangeLog (modified) (2 diffs)
-
configure.in (modified) (1 diff)
-
freenergy.c (modified) (3 diffs)
-
geomview.c (modified) (6 diffs)
-
Makefile.am (modified) (3 diffs)
-
qhull.c (modified) (14 diffs)
-
spinodal.c (modified) (10 diffs)
-
square.c (modified) (7 diffs)
-
ternary.c (modified) (6 diffs)
-
ternary.h (modified) (8 diffs)
-
ternary.tex.in (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/book.c
r443 r459 8 8 9 9 10 #include "freenergy.h" /*+ Free energy prototypes, typedefs, etc. +*/ 10 11 #include "ternary.h" /*+ Ternary prototypes, typedefs, etc. +*/ 11 12 #include <math.h> /*+ For sqrt(), fmin()/fmax() +*/ 13 #include <stdlib.h> /*+ For malloc and free +*/ 12 14 13 15 … … 32 34 side). 33 35 34 ternary_point *points Array of ternary points of size36 energy_point *points Array of energy points of size 35 37 +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 36 38 -latex-(N+1)(N+2)/2, where N is the resolution. … … 53 55 54 56 int init_triangle_array 55 (int resolution, ternary_point *points, int efunc,57 (int resolution, energy_point *points, int efunc, 56 58 double A2, double A3, double B2, double B3, double C2, double C3) 57 59 { … … 107 109 -latex-C3-direction. 108 110 109 ternary_point *points Array of ternary points of size111 energy_point *points Array of energy points of size 110 112 +latex+({\tt res2}+1)$\times$({\tt res3}+1). 111 113 -latex-(res2+1) * (res3+1). … … 132 134 133 135 int init_rectangle_array 134 (int res2, int res3, ternary_point *points, int efunc,136 (int res2, int res3, energy_point *points, int efunc, 135 137 double A2, double A3, double B2, double B3) 136 138 { … … 243 245 and colors the points according to free energy as well. 244 246 245 int scale_energy_array It returns zero or an error code.247 int energy_to_visual_array It returns zero or an error code. 246 248 247 249 int num_points Number of points in the array 248 250 249 ternary_point *points Array of ternary points of size251 energy_point *epoints Array of energy points of size 250 252 +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 251 253 -latex-(N+1)(N+2)/2, where N is the resolution. 254 255 visual_point **tpoints Pointer to array of ternary points of size 256 +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 257 -latex-(N+1)(N+2)/2, where N is the resolution. 258 This will free and re-create this array if present. 252 259 253 260 double y0 Reference (minimum) … … 277 284 ++++++++++++++++++++++++++++++++++++++*/ 278 285 279 int scale_energy_array (int num_points, ternary_point *points,280 double y0, double G0, double y1, double G1,281 double *Gmin, double *Gmax, int square)286 int energy_to_visual_array 287 (int num_points, energy_point *epoints, visual_point **tpoints, double y0, 288 double G0, double y1, double G1, double *Gmin, double *Gmax, int square) 282 289 { 283 290 int i; 284 291 292 if (*tpoints) 293 free (*tpoints); 294 295 if (!(*tpoints = (visual_point *) malloc (num_points * sizeof (visual_point)))) 296 return -1; 297 285 298 if (G0==0. && G1==0.) 286 299 { 287 G0 = G1 = points[0].G;300 G0 = G1 = epoints[0].G; 288 301 for (i=0; i<num_points; i++) 289 302 { 290 G0 = fmin ( points[i].G, G0);291 G1 = fmax ( points[i].G, G1);303 G0 = fmin (epoints[i].G, G0); 304 G1 = fmax (epoints[i].G, G1); 292 305 } 293 306 if (Gmin) … … 300 313 if (Gmin) 301 314 { 302 *Gmin = points[0].G;315 *Gmin = epoints[0].G; 303 316 for (i=0; i<num_points; i++) 304 *Gmin = fmin ( points[i].G, *Gmin);317 *Gmin = fmin (epoints[i].G, *Gmin); 305 318 } 306 319 if (Gmax) 307 320 { 308 *Gmax = points[0].G;321 *Gmax = epoints[0].G; 309 322 for (i=0; i<num_points; i++) 310 *Gmax = fmax ( points[i].G, *Gmax);323 *Gmax = fmax (epoints[i].G, *Gmax); 311 324 } 312 325 } … … 321 334 if (square) 322 335 { 323 points[i].x =points[i].C2;324 points[i].z = 1.-points[i].C3;336 (*tpoints)[i].x = epoints[i].C2; 337 (*tpoints)[i].z = 1.-epoints[i].C3; 325 338 } 326 339 else 327 340 { 328 points[i].x = points[i].C2 + 0.5*points[i].C3;329 points[i].z = (1. -points[i].C3) * sqrt(3)/2.;330 } 331 points[i].y = Grel(points[i].G);332 points[i].red = RED (Grel (points[i].G));333 points[i].green = GREEN (Grel (points[i].G));334 points[i].blue = BLUE (Grel (points[i].G));335 points[i].alpha = 1.;336 } 337 338 return 0; 339 } 341 (*tpoints)[i].x = epoints[i].C2 + 0.5*epoints[i].C3; 342 (*tpoints)[i].z = (1. - epoints[i].C3) * sqrt(3)/2.; 343 } 344 (*tpoints)[i].y = Grel(epoints[i].G); 345 (*tpoints)[i].red = RED (Grel (epoints[i].G)); 346 (*tpoints)[i].green = GREEN (Grel (epoints[i].G)); 347 (*tpoints)[i].blue = BLUE (Grel (epoints[i].G)); 348 (*tpoints)[i].alpha = 1.; 349 } 350 351 return 0; 352 } -
trunk/matml/src/ternary/ChangeLog
r445 r459 3 3 * Overhauled the free energy interface and functions, adding derivative 4 4 implementations. 5 * Added WITH_DERIVATIVES and NO_INFINITY options to free energies(). 6 * Split free energy out into its own library, for use in phase field codes. 5 7 * Added phase_boundary object. 6 8 * Changed hull calculation interface to only hold the qhull variables during … … 9 11 minimization algorithm. 10 12 * Report all phase boundaries in the hull as phase_boundary objects. 11 * Added WITH_DERIVATIVES and NO_INFINITY options to free energies().12 13 * Added spinodal.c with calc_spinodal function returning a phase_boundary. 13 14 * New "square" free energy parameters for pseudo-square representation. 14 15 * Rectangle bookkeeping functions complete square functionality. 16 * Split all non-free-energy functions out into a ternary library. 15 17 * New "square" example program demonstrates these functions. 16 18 -
trunk/matml/src/ternary/configure.in
r413 r459 18 18 AC_C_INLINE 19 19 AM_PROG_CC_C_O 20 AM_PROG_LIBTOOL 20 21 21 22 dnl Geomview check -
trunk/matml/src/ternary/freenergy.c
r454 r459 6 6 7 7 8 #include " ternary.h"8 #include "freenergy.h" 9 9 #include "config.h" /*+ For inline +*/ 10 10 #include <math.h> /*+ For log, various other functions +*/ … … 435 435 int free_energies It returns zero or an error code. 436 436 437 ternary_point *points Ternary point structures holding the compositions where437 energy_point *points Energy point structures holding the compositions where 438 438 we calculate the free energy, and the free energy field where we put the 439 439 return values. … … 460 460 461 461 int free_energies 462 ( ternary_point *points, int n, double T, double P, energy_params *eparams,462 (energy_point *points, int n, double T, double P, energy_params *eparams, 463 463 int efunc, free_energy_flags flags) 464 464 { -
trunk/matml/src/ternary/geomview.c
r423 r459 79 79 int npoints Number of points. 80 80 81 ternary_point *points Point coordinates and colors.81 visual_point *points Point coordinates and colors. 82 82 83 83 int ntriangles Number of triangles. … … 88 88 int GeomviewDisplayTriangleCOFF 89 89 (FILE *geompipe, char *name, char *label, char *appearance, 90 int npoints, ternary_point *points, int ntriangles, int *vertices)90 int npoints, visual_point *points, int ntriangles, int *vertices) 91 91 { 92 92 int i; … … 128 128 int npoints Number of points. 129 129 130 ternary_point *points Point coordinates and colors.130 visual_point *points Point coordinates and colors. 131 131 132 132 int numfacets Number of facet objects to display. … … 139 139 int GeomviewDisplayFacets 140 140 (FILE *geompipe, char *name, char *label, char *appearance, 141 int npoints, ternary_point *points, int numfacets, hull_facet *facets,141 int npoints, visual_point *points, int numfacets, hull_facet *facets, 142 142 facet_type type) 143 143 { … … 189 189 int npoints Number of points. 190 190 191 ternary_point *points Point coordinates and colors.191 visual_point *points Point coordinates and colors. 192 192 193 193 phase_boundary theboundary Phase boundary object to display. … … 196 196 int GeomviewDisplayPhaseBoundary 197 197 (FILE *geompipe, char *name, char *label, char *appearance, 198 int npoints, ternary_point *points, phase_boundary *theboundary)198 int npoints, visual_point *points, phase_boundary *theboundary) 199 199 { 200 200 int i, c=theboundary->compos; -
trunk/matml/src/ternary/Makefile.am
r455 r459 9 9 AUTOMAKE_OPTIONS=1.5 10 10 11 lib_LTLIBRARIES = libfreenergy.la libternary.la 12 13 libfreenergy_la_SOURCES = freenergy.c 14 libfreenergy_la_CFLAGS = -std=c99 #-DDEBUG 15 libfreenergy_la_LDFLAGS = -version-info 0:0:0 16 17 libternary_la_SOURCES = geomview.c qhull.c book.c spinodal.c 18 libternary_la_LIBADD = -lm -lqhull libfreenergy.la 19 libternary_la_CFLAGS = -std=c99 -DGEOMVIEW=\"@GEOMVIEW@\" #-DDEBUG 20 libternary_la_LDFLAGS = -version-info 0:0:0 21 22 include_HEADERS = freenergy.h ternary.h 23 11 24 bin_PROGRAMS = ternary square 12 noinst_HEADERS = ternary.h 13 ternary_SOURCES = ternary.c geomview.c qhull.c book.c freenergy.c spinodal.c 14 ternary_CFLAGS = -std=c99 -DGEOMVIEW=\"@GEOMVIEW@\" #-DDEBUG 15 ternary_LDADD = -lm -lqhull 16 square_SOURCES = square.c geomview.c qhull.c book.c freenergy.c spinodal.c 17 square_CFLAGS = -std=c99 -DGEOMVIEW=\"@GEOMVIEW@\" #-DDEBUG 18 square_LDADD = -lm -lqhull 25 ternary_SOURCES = ternary.c 26 ternary_CFLAGS = #-DDEBUG 27 ternary_LDADD = libternary.la libfreenergy.la 28 square_SOURCES = square.c 29 square_CFLAGS = #-DDEBUG 30 square_LDADD = libternary.la libfreenergy.la 19 31 20 32 EXTRA_DIST = autogen.sh macros/autogen.sh macros/cxref-latex.m4 \ … … 25 37 if HAVE_CXREF 26 38 BUILT_TEXFILES = $(top_srcdir)/ternary.c.tex \ 39 $(top_srcdir)/square.c.tex \ 27 40 $(top_srcdir)/ternary.h.tex \ 28 41 $(top_srcdir)/spinodal.c.tex \ … … 30 43 $(top_srcdir)/qhull.c.tex \ 31 44 $(top_srcdir)/book.c.tex \ 45 $(top_srcdir)/freenergy.h.tex \ 32 46 $(top_srcdir)/freenergy.c.tex \ 33 47 config.h.tex -
trunk/matml/src/ternary/qhull.c
r456 r459 7 7 8 8 9 #include "freenergy.h" 9 10 #include "ternary.h" 10 11 #include <qhull/qset.h> … … 102 103 int dim Number of dimensions (should always be 3 for ternary). 103 104 104 ternary_point *points Point information.105 energy_point *points Point information. 105 106 106 107 int numpoints Number of points of which to calculate the convex hull. … … 121 122 122 123 int hullCalculate 123 (int dim, ternary_point *points, int numpoints, energy_params *eparams,124 (int dim, energy_point *points, int numpoints, energy_params *eparams, 124 125 int nparams, double T, double P, hull_facet **facets, int *numfacets) 125 126 { … … 312 313 int i; 313 314 double distance = 1., G, slope2, slope3; 314 ternary_point current;315 energy_point current; 315 316 316 317 if (globaldims != 3) … … 350 351 351 352 while (distance >= newton_tolerance * newton_tolerance && 352 current.C2>=0. && current.C3>=0. && current.C2<=1. && current.C3<=1.) 353 current.C2>=0. && current.C3>=0. && 354 current.C2<=1. && current.C3<=1.) 353 355 { 354 356 double dC2, dC3, det; … … 389 391 int hullRefine It returns zero or an error code. 390 392 391 ternary_point **points Pointer to point list, which will be modified to393 energy_point **points Pointer to point list, which will be modified to 392 394 accommodate the new points created in the refining process. 393 395 … … 422 424 423 425 int hullRefine 424 ( ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets,426 (energy_point **points, int *numpoints, hull_facet **facets, int *numfacets, 425 427 energy_params *eparams, int nparams, double T,double P, 426 428 double newton_tolerance, double vertex_tolerance, int one_phase_refine) 427 429 { 428 ternary_point *newpoints;430 energy_point *newpoints; 429 431 int newpointsize=100, numnewpoints=0, i; 430 432 431 if (!(newpoints = malloc (100*sizeof(ternary_point))))433 if (!(newpoints = (energy_point *) malloc (100*sizeof(energy_point)))) 432 434 return 1; 433 435 … … 490 492 #endif 491 493 if (numnewpoints >= newpointsize) 492 newpoints = realloc493 (newpoints, (newpointsize+=100)*sizeof( ternary_point));494 newpoints = (energy_point *) realloc 495 (newpoints, (newpointsize+=100)*sizeof(energy_point)); 494 496 newpoints [numnewpoints].C2 = centroid[0]; 495 497 newpoints [numnewpoints].C3 = centroid[1]; … … 588 590 #endif 589 591 if (numnewpoints >= newpointsize) 590 newpoints = realloc591 (newpoints, (newpointsize+=100)*sizeof( ternary_point));592 newpoints = (energy_point *) realloc 593 (newpoints, (newpointsize+=100)*sizeof(energy_point)); 592 594 newpoints [numnewpoints].C2 = newcorners[0]; 593 595 newpoints [numnewpoints].C3 = newcorners[1]; … … 609 611 #endif 610 612 if (numnewpoints >= newpointsize) 611 newpoints = realloc612 (newpoints, (newpointsize+=100)*sizeof( ternary_point));613 newpoints = (energy_point *) realloc 614 (newpoints, (newpointsize+=100)*sizeof(energy_point)); 613 615 newpoints [numnewpoints].C2 = newcorners[3]; 614 616 newpoints [numnewpoints].C3 = newcorners[4]; … … 634 636 #endif 635 637 if (numnewpoints >= newpointsize) 636 newpoints = realloc637 (newpoints, (newpointsize+=100)*sizeof( ternary_point));638 newpoints = (energy_point *) realloc 639 (newpoints, (newpointsize+=100)*sizeof(energy_point)); 638 640 newpoints [numnewpoints].C2 = newcorners[6]; 639 641 newpoints [numnewpoints].C3 = newcorners[7]; … … 653 655 #endif 654 656 655 if (!(*points = realloc656 (*points, (*numpoints + numnewpoints) * sizeof ( ternary_point))))657 if (!(*points = (energy_point *) realloc 658 (*points, (*numpoints + numnewpoints) * sizeof (energy_point)))) 657 659 return 1; 658 660 … … 707 709 int hullReturnPhaseBoundaries It returns zero or an error code. 708 710 709 ternary_point *points Array of points in the ternary system.711 energy_point *points Array of points in the ternary system. 710 712 711 713 int n_points Number of points. … … 729 731 730 732 int hullReturnPhaseBoundaries 731 ( ternary_point *points, int n_points, hull_facet *facets, int n_facets,733 (energy_point *points, int n_points, hull_facet *facets, int n_facets, 732 734 energy_params *eparams, double T, double P, 733 735 phase_boundary **boundaries, int *n_bounds) -
trunk/matml/src/ternary/spinodal.c
r414 r459 6 6 7 7 8 #include "freenergy.h" 8 9 #include "ternary.h" 9 10 #include <stdlib.h> /*+ For malloc() and free() +*/ … … 42 43 int calc_spinodal It returns zero or an error code. 43 44 44 ternary_point **points Points in the array, this function adds points to the45 energy_point **points Points in the array, this function adds points to the 45 46 end of the array. 46 47 … … 59 60 60 61 int calc_spinodal 61 ( ternary_point **points, int *n_points, int *triangle_indices, int n_triangles,62 (energy_point **points, int *n_points, int *triangle_indices, int n_triangles, 62 63 double T, double P, energy_params *eparams, int efunc, 63 64 phase_boundary *spinreturn) … … 65 66 int tri, numsegs=0, thesegs_size=20, *thesegs, numnewpoints=0, 66 67 thenewpoints_size=20; 67 ternary_point *thenewpoints;68 energy_point *thenewpoints; 68 69 69 70 //printf ("Calculating free energies at all points\n"); … … 76 77 printf ("Allocating new points and segments arrays\n"); 77 78 #endif 78 if (!(thenewpoints = malloc (thenewpoints_size * sizeof (ternary_point)))) 79 if (!(thenewpoints = (energy_point *) malloc 80 (thenewpoints_size * sizeof (energy_point)))) 79 81 return 1; 80 82 if (!(thesegs = (int *) malloc (2 * thesegs_size * sizeof (int)))) … … 89 91 double spin[3], A2=-1, A3, B2=-1, B3; 90 92 int total; 91 ternary_point P0=(*points)[triangle_indices[3*tri]],93 energy_point P0=(*points)[triangle_indices[3*tri]], 92 94 P1=(*points)[triangle_indices[3*tri+1]], 93 95 P2=(*points)[triangle_indices[3*tri+2]]; … … 268 270 { 269 271 if (++numnewpoints >= thenewpoints_size) 270 if (!(thenewpoints = ( ternary_point *)271 malloc ((thenewpoints_size*=2)*sizeof ( ternary_point))))272 if (!(thenewpoints = (energy_point *) 273 malloc ((thenewpoints_size*=2)*sizeof (energy_point)))) 272 274 { free (thenewpoints); free (thesegs); return 1; } 273 275 thenewpoints [numnewpoints-1] .C2 = A2; … … 284 286 { 285 287 if (++numnewpoints >= thenewpoints_size) 286 if (!(thenewpoints = ( ternary_point *)287 malloc ((thenewpoints_size*=2)*sizeof ( ternary_point))))288 if (!(thenewpoints = (energy_point *) 289 malloc ((thenewpoints_size*=2)*sizeof (energy_point)))) 288 290 { free (thenewpoints); free (thesegs); return 1; } 289 291 thenewpoints [numnewpoints-1] .C2 = B2; … … 312 314 313 315 // Add new points to old points array 314 if (!(*points = realloc315 (*points, (*n_points+numnewpoints)*sizeof ( ternary_point))))316 if (!(*points = (energy_point *) realloc 317 (*points, (*n_points+numnewpoints)*sizeof (energy_point)))) 316 318 { free (thenewpoints); free (thesegs); return 1; } 317 319 for (tri=0; tri<numnewpoints; tri++) … … 331 333 #endif 332 334 spinreturn->n_edges = numsegs; 333 if (!(spinreturn->phases = malloc (sizeof (int))))335 if (!(spinreturn->phases = (int *) malloc (sizeof (int)))) 334 336 { free (thenewpoints); free (thesegs); return 1; } 335 337 *(spinreturn->phases) = efunc; -
trunk/matml/src/ternary/square.c
r457 r459 33 33 FILE *pfd = NULL; 34 34 double T=0.7, P=1.; 35 ternary_point *points; 35 energy_point *points; 36 visual_point *tpoints=NULL; 36 37 phase_boundary solid_spinodal, *allbounds=NULL; 37 38 /* eparams: R,T0, G1@T0,G2,G3, C1,C2,C3, M1,M2,M3, O12,O13,O23,O123 */ … … 53 54 54 55 /* Allocate array pairs for ternary points and triangle vertices */ 55 if (!(points = malloc (numpoints * sizeof (ternary_point))))56 if (!(points = (energy_point *) malloc (numpoints * sizeof (energy_point)))) 56 57 { printf ("Cannot allocate point coordinate array\n"); exit (1); } 57 if (!(verts = malloc (res2*res3 * 12 * sizeof (int))))58 if (!(verts = (int *) malloc (res2*res3 * 12 * sizeof (int)))) 58 59 { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 59 60 … … 84 85 85 86 /* Calculate the spinodal: first with no return, then more accurate with one 87 Problem: what's the spinodal criterion in a square array? 86 88 if (i=calc_spinodal (&points, &numpoints, verts, res2*res3*4, T, P, 87 89 allparams, 0, &solid_spinodal)) … … 90 92 91 93 /* Scale all free energy values */ 92 if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL, 1)) 94 if (i=energy_to_visual_array (numpoints, points, &tpoints, 0., -.2, 1., .9, 95 NULL, NULL, 1)) 93 96 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 94 97 … … 96 99 if (i=GeomviewDisplayTriangleCOFF 97 100 (pfd, "Ternary Free Energy", "tfe", "shading smooth", 98 numpoints, points, res2*res3*4, verts))101 numpoints, tpoints, res2*res3*4, verts)) 99 102 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 100 101 /*102 if (i=GeomviewDisplayPhaseBoundary103 (pfd, "Spinodal", "spin", "-face +edge",104 numpoints, points, &solid_spinodal))105 { printf ("main: Error %d in Geomview Display\n", i); exit (i); }106 */107 103 108 104 /* Calculate and refine the lower convex hull */ … … 122 118 123 119 /* Scale and display everything */ 124 if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL, 1)) 120 if (i=energy_to_visual_array (numpoints, points, &tpoints, 0., -.2, 1., .9, 121 NULL, NULL, 1)) 125 122 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 126 127 /* No longer needed128 if (i=GeomviewDisplayFacets129 (pfd, "Binodal and Tie Lines", "ech", "-face +edge",130 numpoints, points, hullnumfacets, hullfacets, TWO_PHASE))131 { printf ("main: Error %d in Geomview Display\n", i); exit (i); }132 */133 123 134 124 if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, … … 151 141 152 142 if (ret=GeomviewDisplayPhaseBoundary 153 (pfd, name, label, "-face +edge", numpoints, points, allbounds+i))143 (pfd, name, label, "-face +edge", numpoints, tpoints, allbounds+i)) 154 144 { printf ("main: Error %d in Geomview Display\n", ret); exit (ret); } 155 145 } -
trunk/matml/src/ternary/ternary.c
r457 r459 33 33 FILE *pfd = NULL; 34 34 double T=0.7, P=1.; 35 ternary_point *points; 35 energy_point *points; 36 visual_point *tpoints=NULL; 36 37 phase_boundary solid_spinodal, *allbounds=NULL; 37 38 /* eparams: name, R,T0, G1@T0,G2,G3, C1,C2,C3, S1,S2,S3,S4,S5, … … 49 50 50 51 /* Allocate array pairs for ternary points and triangle vertices */ 51 if (!(points = malloc (numpoints * sizeof (ternary_point))))52 if (!(points = (energy_point *) malloc (numpoints * sizeof (energy_point)))) 52 53 { printf ("Cannot allocate point coordinate array\n"); exit (1); } 53 if (!(verts = malloc (loop_max*loop_max * 6 * sizeof (int))))54 if (!(verts = (int *) malloc (loop_max*loop_max * 6 * sizeof (int)))) 54 55 { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 55 56 … … 85 86 86 87 /* Scale all free energy values */ 87 if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL, 0)) 88 if (i=energy_to_visual_array (numpoints, points, &tpoints, 0., -.2, 1., .9, 89 NULL, NULL, 0)) 88 90 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 89 91 … … 91 93 if (i=GeomviewDisplayTriangleCOFF 92 94 (pfd, "Ternary Free Energy", "tfe", "shading smooth", 93 numpoints, points, loop_max*loop_max*2, verts))95 numpoints, tpoints, loop_max*loop_max*2, verts)) 94 96 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 95 97 96 98 if (i=GeomviewDisplayPhaseBoundary 97 99 (pfd, "Spinodal", "spin", "-face +edge", 98 numpoints, points, &solid_spinodal))100 numpoints, tpoints, &solid_spinodal)) 99 101 { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 100 102 … … 115 117 116 118 /* Scale and display everything */ 117 if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL, 0)) 119 if (i=energy_to_visual_array (numpoints, points, &tpoints, 0., -.2, 1., .9, 120 NULL, NULL, 0)) 118 121 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 119 120 /* No longer needed121 if (i=GeomviewDisplayFacets122 (pfd, "Binodal and Tie Lines", "ech", "-face +edge",123 numpoints, points, hullnumfacets, hullfacets, TWO_PHASE))124 { printf ("main: Error %d in Geomview Display\n", i); exit (i); }125 */126 122 127 123 if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, … … 144 140 145 141 if (ret=GeomviewDisplayPhaseBoundary 146 (pfd, name, label, "-face +edge", numpoints, points, allbounds+i))142 (pfd, name, label, "-face +edge", numpoints, tpoints, allbounds+i)) 147 143 { printf ("main: Error %d in Geomview Display\n", ret); exit (ret); } 148 144 } -
trunk/matml/src/ternary/ternary.h
r454 r459 2 2 $Header$ 3 3 4 This is the header file. 4 This is the ternary.h header file with structures and prototypes for 5 calculating ternary phase diagrams. 5 6 ***************************************/ 6 7 … … 10 11 11 12 #include <stdio.h> 13 #include "freenergy.h" 12 14 13 15 typedef struct { 14 double C2; /*+ Ternary concentration variable15 +latex+$C_2$ ($0\rightarrow1$)16 -latex-2 (0 -> 1)17 +*/18 double C3; /*+ Ternary concentration variable19 +latex+$C_3$ ($0\rightarrow1-C_2$)20 -latex-3 (0 -> 1-C2)21 +*/22 int efunc; /*+ Index indicating which energy surface (phase) this point23 is on; a negative value indicates that energy derivatives24 are not yet calculated. +*/25 double T; /*+ Temperature at which the free energies and derivatives26 are valid +*/27 double P; /*+ Pressure at which the free energies and derivatives are28 valid, -1 if not valid +*/29 double G; /*+ Free energy +*/30 double G2; /*+ Free energy derivative31 +latex+$\partial G/\partial C_2$32 -latex-dG/dC233 +*/34 double G3; /*+ Free energy derivative35 +latex+$\partial G/\partial C_3$36 -latex-dG/dC337 +*/38 double G22; /*+ Free energy second derivative39 +latex+$\partial^2 G/\partial C_2^2$40 +html+ d<sup>2</sup>G/dC2<sup>2</sup>41 +*/42 double G33; /*+ Free energy second derivative43 +latex+$\partial^2 G/\partial C_3^2$44 +html+ d<sup>2</sup>G/dC3<sup>2</sup>45 +*/46 double G23; /*+ Free energy mixed partial second derivative47 +latex+$\partial^2 G/\partial C_2\partial C_3$48 +html+ d<sup>2</sup>G/dC2dC349 +*/50 16 double x; /*+ Visualization 51 17 +latex+$x$-coordinate ($0\rightarrow1$) … … 75 41 -latex-(0 -> 1) 76 42 +*/ 77 } ternary_point; /*+ Ternary "point" structure. +*/ 78 79 typedef struct { 80 char *name; 81 double C2; /*+ Composition at center of this Gaussian term +*/ 82 double C3; /*+ Composition at center of this Gaussian term +*/ 83 double G; /*+ Free energy addition at the Gaussian center +*/ 84 double w; /*+ Width of the Gaussian distribution +*/ 85 double n; /*+ Exponent of the distribution, currently fixed at 2 +*/ 86 } energy_gaussian; 87 88 typedef struct { 89 char *name; /*+ Name of this phase +*/ 90 double R; /*+ Ideal gas law constant +*/ 91 double T0; /*+ Reference temperature +*/ 92 double G1_T0; /*+ Free energy of species 1 at reference temperature +*/ 93 double G2_T0; /*+ Free energy of species 2 at reference temperature +*/ 94 double G3_T0; /*+ Free energy of species 3 at reference temperature +*/ 95 double G1_C; /*+ Species 1 heat capacity +*/ 96 double G2_C; /*+ Species 2 heat capacity +*/ 97 double G3_C; /*+ Species 3 heat capacity +*/ 98 double S1; /*+ Species 1 entropy coefficient (inverse Flory-Huggins relative molar volume) +*/ 99 double S2; /*+ Species 2 entropy coefficient +*/ 100 double S3; /*+ Species 3 entropy coefficient +*/ 101 double S4; /*+ 1-C2 entropy coefficient for square system +*/ 102 double S5; /*+ 1-C3 entropy coefficient for square system +*/ 103 double Omega12; /*+ Species 1-2 regular solution interaction parameter +*/ 104 double Omega13; /*+ Species 1-3 regular solution interaction parameter +*/ 105 double Omega23; /*+ Species 2-3 regular solution interaction parameter +*/ 106 double Omega123; /*+ Species 1-2-3 regular solution interaction parameter +*/ 107 double Omega234; /*+ Species 2-3-4 regular solution interaction parameter +*/ 108 double Omega235; /*+ Species 2-3-5 regular solution interaction parameter +*/ 109 double Omega245; /*+ Species 2-4-5 regular solution interaction parameter +*/ 110 double Omega345; /*+ Species 3-4-5 regular solution interaction parameter +*/ 111 double Omega2345;/*+ Species 2-3-4-5 regular solution interaction parameter+*/ 112 energy_gaussian *gauss; /*+ Array of Gaussian energy parameter structs +*/ 113 int n_gauss; /*+ Number of Gaussian energy terms +*/ 114 } energy_params; /*+ Free energy parameters structure +*/ 115 116 typedef enum { 117 STANDARD=0, 118 WITH_DERIVATIVES=1, 119 NO_INFINITY=2, 120 WITH_DERIVATIVES_NO_INFINITY=3 121 } free_energy_flags; 43 } visual_point; /*+ Ternary "point" structure. +*/ 122 44 123 45 typedef enum { … … 130 52 typedef struct { 131 53 int compos; /*+ Number of points in a boundary edge +*/ 132 int *edges; /*+ Edges with indices of ternary_points comprising a phase54 int *edges; /*+ Edges with indices of energy_points comprising a phase 133 55 boundary; each edge has compos points +*/ 134 56 int n_edges; /*+ Number of edges comprising this boundary +*/ … … 140 62 boundary between a single phase and a multi-phase region, 141 63 or the tie lines/simplices across a multi-phase region +*/ 142 143 #define TERNARY_INFINITY HUGE_VALF144 #define TERNARY_NEGATIVE_INFINITY (-HUGE_VALF)145 64 146 65 typedef enum { … … 157 76 } hull_facet; 158 77 159 /* From freenergy.c */160 double free_energy161 (double C2, double C3, double T, double P, energy_params *eparams);162 int free_energies163 (ternary_point *points, int n, double T, double P, energy_params *eparams,164 int efunc, free_energy_flags flags);165 166 78 /* From spinodal.c */ 167 79 int calc_spinodal 168 ( ternary_point **points, int *n_points, int *triangle_indices, int n_triangles,80 (energy_point **points, int *n_points, int *triangle_indices, int n_triangles, 169 81 double T, double P, energy_params *eparams, int efunc, 170 82 phase_boundary *spinreturn); … … 174 86 int GeomviewDisplayTriangleCOFF 175 87 (FILE *geompipe, char *name, char *label, char *appearance, 176 int npoints, ternary_point *points, int ntriangles, int *vertices);88 int npoints, visual_point *points, int ntriangles, int *vertices); 177 89 int GeomviewDisplayFacets 178 90 (FILE *geompipe, char *name, char *label, char *appearance, 179 int npoints, ternary_point *points, int numfacets, hull_facet *facets,91 int npoints, visual_point *points, int numfacets, hull_facet *facets, 180 92 facet_type type); 181 93 int GeomviewDisplayPhaseBoundary 182 94 (FILE *geompipe, char *name, char *label, char *appearance, 183 int npoints, ternary_point *points, phase_boundary *theboundary);95 int npoints, visual_point *points, phase_boundary *theboundary); 184 96 int GeomviewEnd (FILE **geompipe); 185 97 186 98 /* From qhull.c */ 187 99 int hullCalculate 188 (int dim, ternary_point *points, int numpoints, energy_params *eparams,100 (int dim, energy_point *points, int numpoints, energy_params *eparams, 189 101 int nparams, double T, double P, hull_facet **facets, int *numfacets); 190 102 int hullRefine 191 ( ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets,103 (energy_point **points, int *numpoints, hull_facet **facets, int *numfacets, 192 104 energy_params *eparams, int nparams, double T,double P, 193 105 double newton_tolerance, double vertex_tolerance, int one_phase_refine); 194 106 int hullReturnPhaseBoundaries 195 ( ternary_point *points, int n_points, hull_facet *facets, int n_facets,107 (energy_point *points, int n_points, hull_facet *facets, int n_facets, 196 108 energy_params *eparams, double T, double P, 197 109 phase_boundary **boundaries, int *n_bounds); … … 200 112 /* From book.c */ 201 113 int init_triangle_array 202 (int resolution, ternary_point *points, int efunc,114 (int resolution, energy_point *points, int efunc, 203 115 double A2, double A3, double B2, double B3, double C2, double C3); 204 116 int init_rectangle_array 205 (int res2, int res3, ternary_point *points, int efunc,117 (int res2, int res3, energy_point *points, int efunc, 206 118 double A2, double A3, double B2, double B3); 207 119 int init_triangle_vertices (int resolution, int *vertex_array, int offset); 208 120 int init_rectangle_vertices (int res2, int res3, int *vertex_array, int offset); 209 int scale_energy_array (int num_points, ternary_point *points,210 double y0, double G0, double y1, double G1,211 double *Gmin, double *Gmax, int square);121 int energy_to_visual_array 122 (int num_points, energy_point *epoints, visual_point **tpoints, double y0, 123 double G0, double y1, double G1, double *Gmin, double *Gmax, int square); 212 124 213 125 #endif /* TERNARY_H */ -
trunk/matml/src/ternary/ternary.tex.in
r428 r459 46 46 \section{How it works} 47 47 48 The file {\tt ternary.c} (documentation in appendix \ref{file_ternary.c})49 contains {\tt main()}, which is a simple demonstration of the ternary 50 calculation and visualization functions. It doesthe following:48 The files {\tt ternary.c} and {\tt square.c} (documentation in appendices 49 \ref{file_ternary.c} and \ref{file_square.c}) contain sample front-ends to the 50 free energy and phase diagram libraries. They do the following: 51 51 \begin{itemize} 52 \item Call sfunctions in {\tt book.c} (appendix \ref{file_book.c}) to create a53 triangular array of points and set of triangles connecting them.54 \item Calculate s the free energy function on the triangle verticies using52 \item Call functions in {\tt book.c} (appendix \ref{file_book.c}) to create a 53 triangular or square array of points and set of triangles connecting them. 54 \item Calculate the free energy function on the triangle vertices using 55 55 {\tt free\_energies()} in {\tt freenergy.c} (appendix 56 56 \ref{file_freenergy.c}). 57 \item Display sthe free energy using the functions in {\tt geomview.c}57 \item Display the free energy using the functions in {\tt geomview.c} 58 58 (appendix \ref{file_geomview.c}), which forks and controls a Geomview 59 59 process. 60 \item Calculate sthe spinodal of this free energy function using {\tt60 \item Calculate the spinodal of this free energy function using {\tt 61 61 calc\_spinodal} in {\tt spinodal.c} (appendix \ref{file_spinodal.c}), and 62 62 displays it on the free energy function. 63 \item Use sQhull calls in {\tt qhull.c} (appendix \ref{file_qhull.c}) to63 \item Use Qhull calls in {\tt qhull.c} (appendix \ref{file_qhull.c}) to 64 64 calculate the convex hull of the free energy function. 65 \item Refine sthe multi-phase triangles using Newton iteration ({\tt65 \item Refine the multi-phase triangles using Newton iteration ({\tt 66 66 hullRefine} in {\tt qhull.c}) to find the lowest-energy point starting at 67 67 each corner, smoothing the phase boundaries considerably. 68 \item Add sthe two-phase region facet outlines to the Geomview display.68 \item Add the two-phase region facet outlines to the Geomview display. 69 69 \end{itemize} 70 70 … … 105 105 spinodal.c} calculates the shape of the spinodal curve. 106 106 107 All functions can now accommodate ``rectangle'' ternary spaces, though it's not 108 clear what a spinodal means in this context. The {\tt square} front-end 109 demonstrates this functionality. 110 111 Finally, a major reorganization splits the bulk of the code into two libraries, 112 with front-end codes {\tt ternary} and {\tt square} calling into them. One 113 library calculates free energies and derivatives, and can be re-used in phase 114 field codes. The second calculates phase diagrams. The APIs are relatively 115 immature and bound to change. 116 107 117 \bibliographystyle{unsrturl} 108 118 \bibliography{ternary}