Changeset 316

Show
Ignore:
Timestamp:
03/26/08 09:24:09 (8 months ago)
Author:
powell
Message:

Reorganization: new file geomview.c handles all geomview interactions.

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

Legend:

Unmodified
Added
Removed
  • trunk/matml/src/ternary/Makefile.am

    r310 r316  
    1111bin_PROGRAMS    = ternary 
    1212noinst_HEADERS  = ternary.h 
    13 ternary_SOURCES = ternary.c freenergy.c 
     13ternary_SOURCES = ternary.c geomview.c freenergy.c 
    1414ternary_CFLAGS  = -DGEOMVIEW=\"@GEOMVIEW@\" 
    1515ternary_LDADD   = -lm 
     
    2121BUILT_TEXFILES = $(top_srcdir)/ternary.c.tex \ 
    2222                 $(top_srcdir)/ternary.h.tex \ 
     23                 $(top_srcdir)/geomview.c.tex \ 
    2324                 $(top_srcdir)/freenergy.c.tex 
    2425 
  • trunk/matml/src/ternary/freenergy.c

    r313 r316  
    77 
    88#include "ternary.h" 
     9#include <math.h> 
    910 
    1011 
  • trunk/matml/src/ternary/ternary.c

    r315 r316  
    88 
    99#include "ternary.h" 
     10#include <stdlib.h> 
     11#include <math.h> 
     12 
     13 
     14/*++++++++++++++++++++++++++++++++++++++ 
     15  This program starts Geomview, displays a single ternary phase diagram, waits 
     16  for user interaction, and closes.  Its only argument right now is an optional 
     17  "resolution" of the discretization: "ternary 30" will use a 30x30/2 triangle 
     18  array to display free energy and calculate the phase diagram. 
     19 
     20  int main It returns zero or an error code. 
     21 
     22  int argc Number of arguments. 
     23 
     24  char *argv[] Arguments: right now only the "resolution" of the 
     25  discretization. 
     26  ++++++++++++++++++++++++++++++++++++++*/ 
    1027 
    1128int main (int argc, char *argv[]) 
    1229{ 
    13   int gv_pid,gv_pipe[2], to_gv_pipe[2]; 
     30  int i, j, index, loop_max=50, *verts; 
    1431  char gv_version[100]; 
    1532  FILE *pfd = NULL; 
    16   int i, j, loop_max=50; 
    17   coordT Gmin=REALmax, Gmax=-REALmax; 
    18  
    19   pipe (gv_pipe); /* from geomview stdout */ 
    20   pipe (to_gv_pipe); /* to geomview stdin */ 
    21   gv_pid = fork (); 
    22  
    23   if(gv_pid==0) /* child */ 
    24     { 
    25       close (0); 
    26       dup (to_gv_pipe[0]); 
    27       close (to_gv_pipe[0]); 
    28       close (to_gv_pipe[1]); 
    29       close (1); 
    30       dup (gv_pipe[1]); 
    31       close (gv_pipe[0]); 
    32       close (gv_pipe[1]); 
    33       /* signal(SIGINT,SIG_IGN); */ 
    34       execlp (GEOMVIEW,GEOMVIEW,"-c","(interest (pick world))","-",NULL); 
    35       perror (GEOMVIEW); /* only error gets here */ 
    36     } 
    37  
    38   /* Program execution resumes here */ 
    39   close (gv_pipe[1]); 
    40   close (to_gv_pipe[0]); 
    41   pfd = fdopen (to_gv_pipe[1], "w"); /* hooked to stdin of geomview */ 
    42   fprintf (pfd, "(echo (geomview-version) \"\n\")\n"); 
    43   fflush (pfd); 
    44   read (gv_pipe[0], gv_version, sizeof (gv_version)); 
    45   printf("Geomview version: %s\n", gv_version); 
     33  coordT Gmin, Gmax, *points; 
    4634 
    4735  if (argc>1) 
    4836    sscanf (argv[1], "%d", &loop_max); 
    4937 
    50   fprintf (pfd, "(geometry \"Ternary Phase Diagram\" { : tpd })"); 
    51   fprintf (pfd, "(read geometry { define tpd \n"); 
    52   fprintf (pfd, "appearance {}\nCOFF\n"); 
    53   fprintf (pfd, "%d %d 0\n", (loop_max+1)*(loop_max+2)/2, loop_max*loop_max); 
     38  /* Allocate arrays for point coordinates and colors and triangle vertices */ 
     39  if (!(points = calloc ((loop_max+1)*(loop_max+2)/2 * 7, sizeof (coordT)))) 
     40    { printf ("Cannot allocate point coordinate array\n"); exit (1); } 
    5441 
    55   /* Calculate upper and lower free energy bounds for coloring */ 
     42  if (!(verts = calloc (loop_max*loop_max * 3, sizeof (int)))) 
     43    { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 
     44 
     45  /* Start Geomview process */ 
     46  if (i=GeomviewBegin (&pfd, gv_version)) 
     47    { printf ("main: Error %d in Geomview Begin\n", i); exit (i); } 
     48  printf("Geomview version: %s\n", gv_version); 
     49 
     50#define ROWSTART(row) ((row)*(loop_max+1) - ((row)*((row)-1))/2) 
     51 
     52  /* Calculate free energies, including upper and lower bounds for coloring */ 
     53  Gmin = Gmax = free_energy (0., 0., 0.); 
    5654  for (i=0; i<=loop_max; i++) 
    5755    for (j=0; j<=loop_max-i; j++) 
    5856      { 
    59         coordT C2=(coordT)i/loop_max, C3=(coordT)j/loop_max, G; 
    60         G = free_energy (C2, C3, 0.); 
    61         Gmin = (G<Gmin) ? G : Gmin; 
    62         Gmax = (G>Gmax) ? G : Gmax; 
     57        index = 7 * (ROWSTART (i) + j); 
     58 
     59        points [index] = (coordT)i/loop_max; 
     60        points [index+1] = (coordT)j/loop_max; 
     61        points [index+2] = free_energy (points[index], points[index+1], 0.); 
     62        Gmin = (points [index+2]<Gmin) ? points [index+2] : Gmin; 
     63        Gmax = (points [index+2]>Gmax) ? points [index+2] : Gmax; 
    6364      } 
    6465 
     
    6869#define BLUE(G) (((G)<.5) ? 0. : (((G)<.75) ? 4.*(G)-2. : 1.)) 
    6970 
    70   /* Send vertex points and colors to Geomview */ 
     71  /* Rescale points from C2,C3 to x,y and calculate colors */ 
    7172  for (i=0; i<=loop_max; i++) 
    7273    for (j=0; j<=loop_max-i; j++) 
    7374      { 
    74         coordT C2=(coordT)i/loop_max, C3=(coordT)j/loop_max, G, x,y,z; 
     75        index = 7 * (ROWSTART (i) + j); 
    7576 
    76         G = free_energy (C2, C3, 0.); 
     77        points [index] += 0.5 * points [index+1]; 
     78        points [index+1] *= sqrt(3)/2.; 
    7779 
    78         x = C2 + 0.5*C3; 
    79         y = sqrt(3)/2. * C3; 
    80         z = G; 
    81  
    82         fprintf (pfd, "%g %g %g %g %g %g 1\n", x, z, 1.-y, 
    83                  RED(Grel(G)), GREEN(Grel(G)), BLUE(Grel(G))); 
     80        points [index+3] = RED   (Grel (points [index+2])); 
     81        points [index+4] = GREEN (Grel (points [index+2])); 
     82        points [index+5] = BLUE  (Grel (points [index+2])); 
     83        points [index+6] = 1.; 
    8484      } 
    8585 
    86 #define ROWSTART(row) ((row)*(loop_max+1) - ((row)*((row)-1))/2) 
    87   /* Send triangle vertices to Geomview */ 
    88   for (i=0; i<loop_max-1; i++) 
     86  /* Calculate triangle vertex indices */ 
     87  for (i=0, index=0; i<loop_max-1; i++) 
    8988    { 
    9089      for (j=0; j<loop_max-1-i; j++) 
    9190        { 
    92           fprintf (pfd, "3 %d %d %d\n", 
    93                    ROWSTART(i)+j, ROWSTART(i)+j+1, ROWSTART(i+1)+j); 
    94           fprintf (pfd, "3 %d %d %d\n", 
    95                    ROWSTART(i)+j+1, ROWSTART(i+1)+j, ROWSTART(i+1)+j+1); 
     91          verts [3*index]   = ROWSTART(i)+j; 
     92          verts [3*index+1] = ROWSTART(i)+j+1; 
     93          verts [3*index+2] = ROWSTART(i+1)+j; 
     94          index++; 
     95 
     96          verts [3*index]   = ROWSTART(i)+j+1; 
     97          verts [3*index+1] = ROWSTART(i+1)+j+1; 
     98          verts [3*index+2] = ROWSTART(i+1)+j; 
     99          index++; 
    96100        } 
    97       fprintf (pfd, "3 %d %d %d\n", 
    98                ROWSTART(i)+j, ROWSTART(i)+j+1, ROWSTART(i+1)+j); 
     101      verts [3*index]   = ROWSTART(i)+j; 
     102      verts [3*index+1] = ROWSTART(i)+j+1; 
     103      verts [3*index+2] = ROWSTART(i+1)+j; 
     104      index++; 
    99105    } 
    100   fprintf (pfd, "3 %d %d %d\n", 
    101            ROWSTART(i), ROWSTART(i)+1, ROWSTART(i+1)); 
    102   fprintf (pfd, "})\n"); 
    103   fflush (pfd); 
     106  verts [3*index]   = ROWSTART(i); 
     107  verts [3*index+1] = ROWSTART(i)+1; 
     108  verts [3*index+2] = ROWSTART(i+1); 
     109 
     110  /* Send points and triangle vertex data to Geomview */ 
     111  if (i=GeomviewDisplayTriangleCOFF (pfd, (loop_max+1)*(loop_max+2)/2, points, 
     112                                     loop_max*loop_max, verts)) 
     113    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    104114 
    105115  { 
     
    110120  } 
    111121 
    112   fprintf (pfd, "(exit)"); 
    113   fclose (pfd); 
     122  GeomviewEnd (&pfd); 
     123  free (points); 
     124  free (verts); 
    114125 
    115126  return 0; 
  • trunk/matml/src/ternary/ternary.h

    r313 r316  
    1010 
    1111#include <stdio.h> 
    12 #include <math.h> 
    13 #include <unistd.h> 
    1412#include <qhull/qhull.h> 
    1513 
    1614coordT free_energy (coordT C2, coordT C3, realT T); 
    1715 
     16int GeomviewBegin (FILE **geompipe, char *version); 
     17int GeomviewDisplayTriangleCOFF 
     18(FILE *geompipe, int npoints, coordT *points, int ntriangles, int *vertices); 
     19int GeomviewEnd (FILE **geompipe); 
     20 
    1821#endif /* TERNARY_H */