Changeset 354

Show
Ignore:
Timestamp:
03/27/08 17:22:53 (8 months ago)
Author:
powell
Message:

Multiple free energy functions work!

Location:
trunk/matml/src/ternary
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/matml/src/ternary/ChangeLog

    r353 r354  
    55  * Parameterized free energy function with temperature support. 
    66  * 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. 
    910 
    1011 -- 
  • trunk/matml/src/ternary/book.c

    r353 r354  
    8383  +latex+$N^2$, where $N$ is the resolution. 
    8484  +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. 
    8587  ++++++++++++++++++++++++++++++++++++++*/ 
    8688 
    87 int init_triangle_vertices (int resolution, int *vertex_array) 
     89int init_triangle_vertices (int resolution, int *vertex_array, int offset) 
    8890{ 
    8991  int i,j, index; 
     
    9395      for (j=0; j<resolution-i-1; j++) 
    9496        { 
    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; 
    98100          index++; 
    99101 
    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; 
    103105          index++; 
    104106        } 
    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; 
    108110      index++; 
    109111    } 
    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); 
    113115 
    114116  return 0; 
  • trunk/matml/src/ternary/ternary.c

    r353 r354  
    88 
    99#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() +*/ 
    1112 
    1213 
     
    3031  char gv_version[100], *qh_version; 
    3132  FILE *pfd = NULL; 
    32   double T=1.; 
     33  double T=1.5; 
    3334  ternary_point *points; 
    3435  /* eparams: R,T0, G1@T0,G2,G3, C1,C2,C3, M1,M2,M3, O12,O13,O23,O123 */ 
    3536  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}; 
    3839 
    3940  if (argc>1) 
    4041    sscanf (argv[1], "%d", &loop_max); 
    4142 
    42   /* Allocate arrays 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)))) 
    4445    { 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)))) 
    4747    { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 
    4848 
     
    5252  printf("Geomview version: %s\n", gv_version); 
    5353 
    54   /* Initialize coordinates of triangle array */ 
     54  /* Initialize coordinates of both triangle array halves */ 
    5555  if (i=init_triangle_array (loop_max, points)) 
    5656    { 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); } 
    5759 
    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)) 
    6065    { printf ("main: Error %d in init_triangle_vertices\n", i); exit (i); } 
    6166 
     
    6469    points[index].G = 
    6570      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); 
    6675 
    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)) 
    7079    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    7180 
     
    7382  if (i=GeomviewDisplayTriangleCOFF 
    7483      (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)) 
    7685    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    7786 
    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, 
    7989                       &hullverts, &qh_version)) 
    8090    { printf ("main: qhullCalcHull returned %d\n", i); exit (i); } 
     
    113123  if (i=GeomviewDisplayTriangleCOFF 
    114124      (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)) 
    116126    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    117127 
  • trunk/matml/src/ternary/ternary.h

    r353 r354  
    104104/* From book.c */ 
    105105int init_triangle_array (int resolution, ternary_point *points); 
    106 int init_triangle_vertices (int resolution, int *vertex_array); 
     106int init_triangle_vertices (int resolution, int *vertex_array, int offset); 
    107107int scale_energy_array (int num_points, ternary_point *points, 
    108108                        double y0, double G0, double y1, double G1,