Changeset 353

Show
Ignore:
Timestamp:
03/27/08 16:54:31 (8 months ago)
Author:
powell
Message:

One more O(N) function from main() to book.c.

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

Legend:

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

    r349 r353  
    44  * Check for qhull library in configure.in. 
    55  * Parameterized free energy function with temperature support. 
     6  * Moved many O(N) functions from main() out to new book.c file. 
    67  * TODO: better single-phase check in ternary.c, 
    78    multiple free energy functions; later refine qhull concave facets. 
  • trunk/matml/src/ternary/Makefile.am

    r350 r353  
    1212noinst_HEADERS  = ternary.h 
    1313ternary_SOURCES = ternary.c geomview.c qhull.c book.c freenergy.c 
    14 ternary_CFLAGS  = -DGEOMVIEW=\"@GEOMVIEW@\" # -DDEBUG 
     14ternary_CFLAGS  = -std=c99 -DGEOMVIEW=\"@GEOMVIEW@\" # -DDEBUG 
    1515ternary_LDADD   = -lm -lqhull 
    1616 
  • trunk/matml/src/ternary/book.c

    r351 r353  
    99 
    1010#include "ternary.h" /*+ Ternary prototypes, typedefs, etc. +*/ 
    11 #include <math.h>    /*+ For sqrt() +*/ 
     11#include <math.h>    /*+ For sqrt(), fmin()/fmax() +*/ 
    1212 
    1313 
     
    7474 
    7575/*++++++++++++++++++++++++++++++++++++++ 
     76  This function fills an array with vertex indices. 
     77 
     78  int init_triangle_vertices It returns zero or an error code. 
     79 
     80  int resolution Resolution of the discretization (number of points on a side). 
     81 
     82  int *vertex_array Array of triangle indices of size 
     83  +latex+$N^2$, where $N$ is the resolution. 
     84  +html+ <i>N</i><sup>2</sup>, where <i>N</i> is the resolution. 
     85  ++++++++++++++++++++++++++++++++++++++*/ 
     86 
     87int init_triangle_vertices (int resolution, int *vertex_array) 
     88{ 
     89  int i,j, index; 
     90 
     91  for (i=0, index=0; i<resolution-1; i++) 
     92    { 
     93      for (j=0; j<resolution-i-1; j++) 
     94        { 
     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; 
     98          index++; 
     99 
     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; 
     103          index++; 
     104        } 
     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; 
     108      index++; 
     109    } 
     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); 
     113 
     114  return 0; 
     115} 
     116 
     117 
     118/*++++++++++++++++++++++++++++++++++++++ 
    76119  This scales the free energy of an array of ternary points to the 
    77120  +latex+$y$-coordinate 
     
    79122  and colors the points according to free energy as well. 
    80123 
    81   int scale_triangle_array It returns zero or an error code. 
     124  int scale_energy_array It returns zero or an error code. 
    82125 
    83126  int num_points Number of points in the array 
     
    110153  ++++++++++++++++++++++++++++++++++++++*/ 
    111154 
    112 int scale_triangle_array (int num_points, ternary_point *points, 
     155int scale_energy_array (int num_points, ternary_point *points, 
    113156                          double y0, double G0, double y1, double G1, 
    114157                          double *Gmin, double *Gmax) 
  • trunk/matml/src/ternary/ternary.c

    r351 r353  
    5252  printf("Geomview version: %s\n", gv_version); 
    5353 
    54   /* Calculate free energies, including upper and lower bounds for coloring */ 
     54  /* Initialize coordinates of triangle array */ 
    5555  if (i=init_triangle_array (loop_max, points)) 
    5656    { printf ("main: Error %d in init_triangle_array\n", i); exit (i); } 
    5757 
    58 #define ROWSTART(row) ((row)*(loop_max+1) - ((row)*((row)-1))/2) 
     58  /* Calculate triangle vertex indices */ 
     59  if (i=init_triangle_vertices (loop_max, verts)) 
     60    { printf ("main: Error %d in init_triangle_vertices\n", i); exit (i); } 
    5961 
     62  /* Calculate free energies */ 
    6063  for (index=0; index<(loop_max+1)*(loop_max+2)/2; index++) 
    6164    points[index].G = 
    6265      free_energy (points[index].C2, points[index].C3, T, &eparams1); 
    6366 
    64   if (i=scale_triangle_array ((loop_max+1)*(loop_max+2)/2, points, 
     67  /* Scale free energy values to (0->1) */ 
     68  if (i=scale_energy_array ((loop_max+1)*(loop_max+2)/2, points, 
    6569                              0., 0., 1., 0., NULL, NULL)) 
    6670    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    67  
    68   /* Calculate triangle vertex indices */ 
    69   for (i=0, index=0; i<loop_max-1; i++) 
    70     { 
    71       for (j=0; j<loop_max-1-i; j++) 
    72         { 
    73           verts [3*index]   = ROWSTART(i)+j; 
    74           verts [3*index+1] = ROWSTART(i)+j+1; 
    75           verts [3*index+2] = ROWSTART(i+1)+j; 
    76           index++; 
    77  
    78           verts [3*index]   = ROWSTART(i)+j+1; 
    79           verts [3*index+1] = ROWSTART(i+1)+j+1; 
    80           verts [3*index+2] = ROWSTART(i+1)+j; 
    81           index++; 
    82         } 
    83       verts [3*index]   = ROWSTART(i)+j; 
    84       verts [3*index+1] = ROWSTART(i)+j+1; 
    85       verts [3*index+2] = ROWSTART(i+1)+j; 
    86       index++; 
    87     } 
    88   verts [3*index]   = ROWSTART(i); 
    89   verts [3*index+1] = ROWSTART(i)+1; 
    90   verts [3*index+2] = ROWSTART(i+1); 
    9171 
    9272  /* Send points and triangle vertex data to Geomview */ 
  • trunk/matml/src/ternary/ternary.h

    r351 r353  
    104104/* From book.c */ 
    105105int 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); 
     106int init_triangle_vertices (int resolution, int *vertex_array); 
     107int scale_energy_array (int num_points, ternary_point *points, 
     108                        double y0, double G0, double y1, double G1, 
     109                        double *Gmin, double *Gmax); 
    109110 
    110111#endif /* TERNARY_H */