Changeset 459 for trunk/matml

Show
Ignore:
Timestamp:
06/17/2009 03:52:54 PM (3 years ago)
Author:
powell
Message:

Major update splitting out two libraries and updating documentation.

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

Legend:

Unmodified
Added
Removed
  • trunk/matml/src/ternary/book.c

    r443 r459  
    88 
    99 
     10#include "freenergy.h" /*+ Free energy prototypes, typedefs, etc. +*/ 
    1011#include "ternary.h" /*+ Ternary prototypes, typedefs, etc. +*/ 
    1112#include <math.h>    /*+ For sqrt(), fmin()/fmax() +*/ 
     13#include <stdlib.h>  /*+ For malloc and free +*/ 
    1214 
    1315 
     
    3234  side). 
    3335 
    34   ternary_point *points Array of ternary points of size 
     36  energy_point *points Array of energy points of size 
    3537  +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 
    3638  -latex-(N+1)(N+2)/2, where N is the resolution. 
     
    5355 
    5456int init_triangle_array 
    55 (int resolution, ternary_point *points, int efunc, 
     57(int resolution, energy_point *points, int efunc, 
    5658 double A2, double A3, double B2, double B3, double C2, double C3) 
    5759{ 
     
    107109  -latex-C3-direction. 
    108110 
    109   ternary_point *points Array of ternary points of size 
     111  energy_point *points Array of energy points of size 
    110112  +latex+({\tt res2}+1)$\times$({\tt res3}+1). 
    111113  -latex-(res2+1) * (res3+1). 
     
    132134 
    133135int init_rectangle_array 
    134 (int res2, int res3, ternary_point *points, int efunc, 
     136(int res2, int res3, energy_point *points, int efunc, 
    135137 double A2, double A3, double B2, double B3) 
    136138{ 
     
    243245  and colors the points according to free energy as well. 
    244246 
    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. 
    246248 
    247249  int num_points Number of points in the array 
    248250 
    249   ternary_point *points Array of ternary points of size 
     251  energy_point *epoints Array of energy points of size 
    250252  +latex+$(N+1)(N+2)/2$, where $N$ is the resolution. 
    251253  -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. 
    252259 
    253260  double y0 Reference (minimum) 
     
    277284  ++++++++++++++++++++++++++++++++++++++*/ 
    278285 
    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) 
     286int 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) 
    282289{ 
    283290  int i; 
    284291 
     292  if (*tpoints) 
     293    free (*tpoints); 
     294 
     295  if (!(*tpoints = (visual_point *) malloc (num_points * sizeof (visual_point)))) 
     296    return -1; 
     297 
    285298  if (G0==0. && G1==0.) 
    286299    { 
    287       G0 = G1 = points[0].G; 
     300      G0 = G1 = epoints[0].G; 
    288301      for (i=0; i<num_points; i++) 
    289302        { 
    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); 
    292305        } 
    293306      if (Gmin) 
     
    300313      if (Gmin) 
    301314        { 
    302           *Gmin = points[0].G; 
     315          *Gmin = epoints[0].G; 
    303316          for (i=0; i<num_points; i++) 
    304             *Gmin = fmin (points[i].G, *Gmin); 
     317            *Gmin = fmin (epoints[i].G, *Gmin); 
    305318        } 
    306319      if (Gmax) 
    307320        { 
    308           *Gmax = points[0].G; 
     321          *Gmax = epoints[0].G; 
    309322          for (i=0; i<num_points; i++) 
    310             *Gmax = fmax (points[i].G, *Gmax); 
     323            *Gmax = fmax (epoints[i].G, *Gmax); 
    311324        } 
    312325    } 
     
    321334      if (square) 
    322335        { 
    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; 
    325338        } 
    326339      else 
    327340        { 
    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  
    33  * Overhauled the free energy interface and functions, adding derivative 
    44    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. 
    57  * Added phase_boundary object. 
    68  * Changed hull calculation interface to only hold the qhull variables during 
     
    911    minimization algorithm. 
    1012  * Report all phase boundaries in the hull as phase_boundary objects. 
    11   * Added WITH_DERIVATIVES and NO_INFINITY options to free energies(). 
    1213  * Added spinodal.c with calc_spinodal function returning a phase_boundary. 
    1314  * New "square" free energy parameters for pseudo-square representation. 
    1415  * Rectangle bookkeeping functions complete square functionality. 
     16  * Split all non-free-energy functions out into a ternary library. 
    1517  * New "square" example program demonstrates these functions. 
    1618 
  • trunk/matml/src/ternary/configure.in

    r413 r459  
    1818AC_C_INLINE 
    1919AM_PROG_CC_C_O 
     20AM_PROG_LIBTOOL 
    2021 
    2122dnl Geomview check 
  • trunk/matml/src/ternary/freenergy.c

    r454 r459  
    66 
    77 
    8 #include "ternary.h" 
     8#include "freenergy.h" 
    99#include "config.h" /*+ For inline +*/ 
    1010#include <math.h> /*+ For log, various other functions +*/ 
     
    435435  int free_energies It returns zero or an error code. 
    436436 
    437   ternary_point *points Ternary point structures holding the compositions where 
     437  energy_point *points Energy point structures holding the compositions where 
    438438  we calculate the free energy, and the free energy field where we put the 
    439439  return values. 
     
    460460 
    461461int 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, 
    463463 int efunc, free_energy_flags flags) 
    464464{ 
  • trunk/matml/src/ternary/geomview.c

    r423 r459  
    7979  int npoints Number of points. 
    8080 
    81   ternary_point *points Point coordinates and colors. 
     81  visual_point *points Point coordinates and colors. 
    8282 
    8383  int ntriangles Number of triangles. 
     
    8888int GeomviewDisplayTriangleCOFF 
    8989(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) 
    9191{ 
    9292  int i; 
     
    128128  int npoints Number of points. 
    129129 
    130   ternary_point *points Point coordinates and colors. 
     130  visual_point *points Point coordinates and colors. 
    131131 
    132132  int numfacets Number of facet objects to display. 
     
    139139int GeomviewDisplayFacets 
    140140(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, 
    142142 facet_type type) 
    143143{ 
     
    189189  int npoints Number of points. 
    190190 
    191   ternary_point *points Point coordinates and colors. 
     191  visual_point *points Point coordinates and colors. 
    192192 
    193193  phase_boundary theboundary Phase boundary object to display. 
     
    196196int GeomviewDisplayPhaseBoundary 
    197197(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) 
    199199{ 
    200200  int i, c=theboundary->compos; 
  • trunk/matml/src/ternary/Makefile.am

    r455 r459  
    99AUTOMAKE_OPTIONS=1.5 
    1010 
     11lib_LTLIBRARIES = libfreenergy.la libternary.la 
     12 
     13libfreenergy_la_SOURCES = freenergy.c 
     14libfreenergy_la_CFLAGS  = -std=c99 #-DDEBUG 
     15libfreenergy_la_LDFLAGS = -version-info 0:0:0 
     16 
     17libternary_la_SOURCES = geomview.c qhull.c book.c spinodal.c 
     18libternary_la_LIBADD  = -lm -lqhull libfreenergy.la 
     19libternary_la_CFLAGS  = -std=c99 -DGEOMVIEW=\"@GEOMVIEW@\" #-DDEBUG 
     20libternary_la_LDFLAGS = -version-info 0:0:0 
     21 
     22include_HEADERS = freenergy.h ternary.h 
     23 
    1124bin_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 
     25ternary_SOURCES = ternary.c 
     26ternary_CFLAGS  = #-DDEBUG 
     27ternary_LDADD   = libternary.la libfreenergy.la 
     28square_SOURCES = square.c 
     29square_CFLAGS  = #-DDEBUG 
     30square_LDADD   = libternary.la libfreenergy.la 
    1931 
    2032EXTRA_DIST = autogen.sh macros/autogen.sh macros/cxref-latex.m4 \ 
     
    2537if HAVE_CXREF 
    2638BUILT_TEXFILES = $(top_srcdir)/ternary.c.tex \ 
     39                 $(top_srcdir)/square.c.tex \ 
    2740                 $(top_srcdir)/ternary.h.tex \ 
    2841                 $(top_srcdir)/spinodal.c.tex \ 
     
    3043                 $(top_srcdir)/qhull.c.tex \ 
    3144                 $(top_srcdir)/book.c.tex \ 
     45                 $(top_srcdir)/freenergy.h.tex \ 
    3246                 $(top_srcdir)/freenergy.c.tex \ 
    3347                 config.h.tex 
  • trunk/matml/src/ternary/qhull.c

    r456 r459  
    77 
    88 
     9#include "freenergy.h" 
    910#include "ternary.h" 
    1011#include <qhull/qset.h> 
     
    102103  int dim Number of dimensions (should always be 3 for ternary). 
    103104 
    104   ternary_point *points Point information. 
     105  energy_point *points Point information. 
    105106 
    106107  int numpoints Number of points of which to calculate the convex hull. 
     
    121122 
    122123int hullCalculate 
    123 (int dim, ternary_point *points, int numpoints, energy_params *eparams, 
     124(int dim, energy_point *points, int numpoints, energy_params *eparams, 
    124125 int nparams, double T, double P, hull_facet **facets, int *numfacets) 
    125126{ 
     
    312313  int i; 
    313314  double distance = 1., G, slope2, slope3; 
    314   ternary_point current; 
     315  energy_point current; 
    315316 
    316317  if (globaldims != 3) 
     
    350351 
    351352  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.) 
    353355    { 
    354356      double dC2, dC3, det; 
     
    389391  int hullRefine It returns zero or an error code. 
    390392 
    391   ternary_point **points Pointer to point list, which will be modified to 
     393  energy_point **points Pointer to point list, which will be modified to 
    392394  accommodate the new points created in the refining process. 
    393395 
     
    422424 
    423425int hullRefine 
    424 (ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
     426(energy_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
    425427 energy_params *eparams, int nparams, double T,double P, 
    426428 double newton_tolerance, double vertex_tolerance, int one_phase_refine) 
    427429{ 
    428   ternary_point *newpoints; 
     430  energy_point *newpoints; 
    429431  int newpointsize=100, numnewpoints=0, i; 
    430432 
    431   if (!(newpoints = malloc (100*sizeof(ternary_point)))) 
     433  if (!(newpoints = (energy_point *) malloc (100*sizeof(energy_point)))) 
    432434    return 1; 
    433435 
     
    490492#endif 
    491493          if (numnewpoints >= newpointsize) 
    492             newpoints = realloc 
    493               (newpoints, (newpointsize+=100)*sizeof(ternary_point)); 
     494            newpoints = (energy_point *) realloc 
     495              (newpoints, (newpointsize+=100)*sizeof(energy_point)); 
    494496          newpoints [numnewpoints].C2 = centroid[0]; 
    495497          newpoints [numnewpoints].C3 = centroid[1]; 
     
    588590#endif 
    589591              if (numnewpoints >= newpointsize) 
    590                 newpoints = realloc 
    591                   (newpoints, (newpointsize+=100)*sizeof(ternary_point)); 
     592                newpoints = (energy_point *) realloc 
     593                  (newpoints, (newpointsize+=100)*sizeof(energy_point)); 
    592594              newpoints [numnewpoints].C2 = newcorners[0]; 
    593595              newpoints [numnewpoints].C3 = newcorners[1]; 
     
    609611#endif 
    610612              if (numnewpoints >= newpointsize) 
    611                 newpoints = realloc 
    612                   (newpoints, (newpointsize+=100)*sizeof(ternary_point)); 
     613                newpoints = (energy_point *) realloc 
     614                  (newpoints, (newpointsize+=100)*sizeof(energy_point)); 
    613615              newpoints [numnewpoints].C2 = newcorners[3]; 
    614616              newpoints [numnewpoints].C3 = newcorners[4]; 
     
    634636#endif 
    635637              if (numnewpoints >= newpointsize) 
    636                 newpoints = realloc 
    637                   (newpoints, (newpointsize+=100)*sizeof(ternary_point)); 
     638                newpoints = (energy_point *) realloc 
     639                  (newpoints, (newpointsize+=100)*sizeof(energy_point)); 
    638640              newpoints [numnewpoints].C2 = newcorners[6]; 
    639641              newpoints [numnewpoints].C3 = newcorners[7]; 
     
    653655#endif 
    654656 
    655   if (!(*points = realloc 
    656         (*points, (*numpoints + numnewpoints) * sizeof (ternary_point)))) 
     657  if (!(*points = (energy_point *) realloc 
     658        (*points, (*numpoints + numnewpoints) * sizeof (energy_point)))) 
    657659    return 1; 
    658660           
     
    707709  int hullReturnPhaseBoundaries It returns zero or an error code. 
    708710 
    709   ternary_point *points Array of points in the ternary system. 
     711  energy_point *points Array of points in the ternary system. 
    710712 
    711713  int n_points Number of points. 
     
    729731 
    730732int 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, 
    732734 energy_params *eparams, double T, double P, 
    733735 phase_boundary **boundaries, int *n_bounds) 
  • trunk/matml/src/ternary/spinodal.c

    r414 r459  
    66 
    77 
     8#include "freenergy.h" 
    89#include "ternary.h" 
    910#include <stdlib.h>  /*+ For malloc() and free() +*/ 
     
    4243  int calc_spinodal It returns zero or an error code. 
    4344 
    44   ternary_point **points Points in the array, this function adds points to the 
     45  energy_point **points Points in the array, this function adds points to the 
    4546  end of the array. 
    4647 
     
    5960 
    6061int 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, 
    6263 double T, double P, energy_params *eparams, int efunc, 
    6364 phase_boundary *spinreturn) 
     
    6566  int tri, numsegs=0, thesegs_size=20, *thesegs, numnewpoints=0, 
    6667    thenewpoints_size=20; 
    67   ternary_point *thenewpoints; 
     68  energy_point *thenewpoints; 
    6869 
    6970  //printf ("Calculating free energies at all points\n"); 
     
    7677  printf ("Allocating new points and segments arrays\n"); 
    7778#endif 
    78   if (!(thenewpoints = malloc (thenewpoints_size * sizeof (ternary_point)))) 
     79  if (!(thenewpoints = (energy_point *) malloc 
     80        (thenewpoints_size * sizeof (energy_point)))) 
    7981    return 1; 
    8082  if (!(thesegs = (int *) malloc (2 * thesegs_size * sizeof (int)))) 
     
    8991      double spin[3], A2=-1, A3, B2=-1, B3; 
    9092      int total; 
    91       ternary_point P0=(*points)[triangle_indices[3*tri]], 
     93      energy_point P0=(*points)[triangle_indices[3*tri]], 
    9294        P1=(*points)[triangle_indices[3*tri+1]], 
    9395        P2=(*points)[triangle_indices[3*tri+2]]; 
     
    268270        { 
    269271          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)))) 
    272274              { free (thenewpoints); free (thesegs); return 1; } 
    273275          thenewpoints [numnewpoints-1] .C2 = A2; 
     
    284286        { 
    285287          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)))) 
    288290              { free (thenewpoints); free (thesegs); return 1; } 
    289291          thenewpoints [numnewpoints-1] .C2 = B2; 
     
    312314 
    313315  // Add new points to old points array 
    314   if (!(*points = realloc 
    315         (*points, (*n_points+numnewpoints)*sizeof (ternary_point)))) 
     316  if (!(*points = (energy_point *) realloc 
     317        (*points, (*n_points+numnewpoints)*sizeof (energy_point)))) 
    316318    { free (thenewpoints); free (thesegs); return 1; } 
    317319  for (tri=0; tri<numnewpoints; tri++) 
     
    331333#endif 
    332334      spinreturn->n_edges = numsegs; 
    333       if (!(spinreturn->phases = malloc (sizeof (int)))) 
     335      if (!(spinreturn->phases = (int *) malloc (sizeof (int)))) 
    334336        { free (thenewpoints); free (thesegs); return 1; } 
    335337      *(spinreturn->phases) = efunc; 
  • trunk/matml/src/ternary/square.c

    r457 r459  
    3333  FILE *pfd = NULL; 
    3434  double T=0.7, P=1.; 
    35   ternary_point *points; 
     35  energy_point *points; 
     36  visual_point *tpoints=NULL; 
    3637  phase_boundary solid_spinodal, *allbounds=NULL; 
    3738  /* eparams: R,T0, G1@T0,G2,G3, C1,C2,C3, M1,M2,M3, O12,O13,O23,O123 */ 
     
    5354 
    5455  /* 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)))) 
    5657    { 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)))) 
    5859    { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 
    5960 
     
    8485 
    8586  /* Calculate the spinodal: first with no return, then more accurate with one 
     87     Problem: what's the spinodal criterion in a square array? 
    8688  if (i=calc_spinodal (&points, &numpoints, verts, res2*res3*4, T, P, 
    8789                       allparams, 0, &solid_spinodal)) 
     
    9092 
    9193  /* 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)) 
    9396    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    9497 
     
    9699  if (i=GeomviewDisplayTriangleCOFF 
    97100      (pfd, "Ternary Free Energy", "tfe", "shading smooth", 
    98        numpoints, points, res2*res3*4, verts)) 
     101       numpoints, tpoints, res2*res3*4, verts)) 
    99102    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    100  
    101   /* 
    102   if (i=GeomviewDisplayPhaseBoundary 
    103       (pfd, "Spinodal", "spin", "-face +edge", 
    104        numpoints, points, &solid_spinodal)) 
    105     { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    106   */ 
    107103 
    108104  /* Calculate and refine the lower convex hull */ 
     
    122118 
    123119  /* 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)) 
    125122    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    126  
    127   /* No longer needed 
    128   if (i=GeomviewDisplayFacets 
    129       (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   */ 
    133123 
    134124  if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, 
     
    151141 
    152142      if (ret=GeomviewDisplayPhaseBoundary 
    153           (pfd, name, label, "-face +edge", numpoints, points, allbounds+i)) 
     143          (pfd, name, label, "-face +edge", numpoints, tpoints, allbounds+i)) 
    154144        { printf ("main: Error %d in Geomview Display\n", ret); exit (ret); } 
    155145    } 
  • trunk/matml/src/ternary/ternary.c

    r457 r459  
    3333  FILE *pfd = NULL; 
    3434  double T=0.7, P=1.; 
    35   ternary_point *points; 
     35  energy_point *points; 
     36  visual_point *tpoints=NULL; 
    3637  phase_boundary solid_spinodal, *allbounds=NULL; 
    3738  /* eparams: name, R,T0, G1@T0,G2,G3, C1,C2,C3, S1,S2,S3,S4,S5, 
     
    4950 
    5051  /* 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)))) 
    5253    { 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)))) 
    5455    { printf ("Cannot allocate triangle vertex array\n"); exit (1); } 
    5556 
     
    8586 
    8687  /* 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)) 
    8890    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    8991 
     
    9193  if (i=GeomviewDisplayTriangleCOFF 
    9294      (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)) 
    9496    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    9597 
    9698  if (i=GeomviewDisplayPhaseBoundary 
    9799      (pfd, "Spinodal", "spin", "-face +edge", 
    98        numpoints, points, &solid_spinodal)) 
     100       numpoints, tpoints, &solid_spinodal)) 
    99101    { printf ("main: Error %d in Geomview Display\n", i); exit (i); } 
    100102 
     
    115117 
    116118  /* 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)) 
    118121    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
    119  
    120   /* No longer needed 
    121   if (i=GeomviewDisplayFacets 
    122       (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   */ 
    126122 
    127123  if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, 
     
    144140 
    145141      if (ret=GeomviewDisplayPhaseBoundary 
    146           (pfd, name, label, "-face +edge", numpoints, points, allbounds+i)) 
     142          (pfd, name, label, "-face +edge", numpoints, tpoints, allbounds+i)) 
    147143        { printf ("main: Error %d in Geomview Display\n", ret); exit (ret); } 
    148144    } 
  • trunk/matml/src/ternary/ternary.h

    r454 r459  
    22  $Header$ 
    33 
    4   This is the header file. 
     4  This is the ternary.h header file with structures and prototypes for 
     5  calculating ternary phase diagrams. 
    56  ***************************************/ 
    67 
     
    1011 
    1112#include <stdio.h> 
     13#include "freenergy.h" 
    1214 
    1315typedef struct { 
    14   double C2;     /*+ Ternary concentration variable 
    15                    +latex+$C_2$ ($0\rightarrow1$) 
    16                    -latex-2 (0 -> 1) 
    17                    +*/ 
    18   double C3;     /*+ Ternary concentration variable 
    19                    +latex+$C_3$ ($0\rightarrow1-C_2$) 
    20                    -latex-3 (0 -> 1-C2) 
    21                    +*/ 
    22   int efunc;     /*+ Index indicating which energy surface (phase) this point 
    23                    is on; a negative value indicates that energy derivatives 
    24                    are not yet calculated. +*/ 
    25   double T;      /*+ Temperature at which the free energies and derivatives 
    26                    are valid +*/ 
    27   double P;      /*+ Pressure at which the free energies and derivatives are 
    28                    valid, -1 if not valid +*/ 
    29   double G;      /*+ Free energy +*/ 
    30   double G2;     /*+ Free energy derivative 
    31                    +latex+$\partial G/\partial C_2$ 
    32                    -latex-dG/dC2 
    33                    +*/ 
    34   double G3;     /*+ Free energy derivative 
    35                    +latex+$\partial G/\partial C_3$ 
    36                    -latex-dG/dC3 
    37                    +*/ 
    38   double G22;    /*+ Free energy second derivative 
    39                    +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 derivative 
    43                    +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 derivative 
    47                    +latex+$\partial^2 G/\partial C_2\partial C_3$ 
    48                    +html+ d<sup>2</sup>G/dC2dC3 
    49                    +*/ 
    5016  double x;      /*+ Visualization 
    5117                   +latex+$x$-coordinate ($0\rightarrow1$) 
     
    7541                   -latex-(0 -> 1) 
    7642                   +*/ 
    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. +*/ 
    12244 
    12345typedef enum { 
     
    13052typedef struct { 
    13153  int compos;   /*+ Number of points in a boundary edge +*/ 
    132   int *edges;   /*+ Edges with indices of ternary_points comprising a phase 
     54  int *edges;   /*+ Edges with indices of energy_points comprising a phase 
    13355                  boundary; each edge has compos points +*/ 
    13456  int n_edges;  /*+ Number of edges comprising this boundary +*/ 
     
    14062                    boundary between a single phase and a multi-phase region, 
    14163                    or the tie lines/simplices across a multi-phase region +*/ 
    142  
    143 #define TERNARY_INFINITY HUGE_VALF 
    144 #define TERNARY_NEGATIVE_INFINITY (-HUGE_VALF) 
    14564 
    14665typedef enum { 
     
    15776} hull_facet; 
    15877 
    159 /* From freenergy.c */ 
    160 double free_energy 
    161 (double C2, double C3, double T, double P, energy_params *eparams); 
    162 int free_energies 
    163 (ternary_point *points, int n, double T, double P, energy_params *eparams, 
    164  int efunc, free_energy_flags flags); 
    165  
    16678/* From spinodal.c */ 
    16779int 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, 
    16981 double T, double P, energy_params *eparams, int efunc, 
    17082 phase_boundary *spinreturn); 
     
    17486int GeomviewDisplayTriangleCOFF 
    17587(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); 
    17789int GeomviewDisplayFacets 
    17890(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, 
    18092 facet_type type); 
    18193int GeomviewDisplayPhaseBoundary 
    18294(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); 
    18496int GeomviewEnd (FILE **geompipe); 
    18597 
    18698/* From qhull.c */ 
    18799int hullCalculate 
    188 (int dim, ternary_point *points, int numpoints, energy_params *eparams, 
     100(int dim, energy_point *points, int numpoints, energy_params *eparams, 
    189101 int nparams, double T, double P, hull_facet **facets, int *numfacets); 
    190102int hullRefine 
    191 (ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
     103(energy_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
    192104 energy_params *eparams, int nparams, double T,double P, 
    193105 double newton_tolerance, double vertex_tolerance, int one_phase_refine); 
    194106int 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, 
    196108 energy_params *eparams, double T, double P, 
    197109 phase_boundary **boundaries, int *n_bounds); 
     
    200112/* From book.c */ 
    201113int init_triangle_array 
    202 (int resolution, ternary_point *points, int efunc, 
     114(int resolution, energy_point *points, int efunc, 
    203115 double A2, double A3, double B2, double B3, double C2, double C3); 
    204116int init_rectangle_array 
    205 (int res2, int res3, ternary_point *points, int efunc, 
     117(int res2, int res3, energy_point *points, int efunc, 
    206118 double A2, double A3, double B2, double B3); 
    207119int init_triangle_vertices (int resolution, int *vertex_array, int offset); 
    208120int 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); 
     121int 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); 
    212124 
    213125#endif /* TERNARY_H */ 
  • trunk/matml/src/ternary/ternary.tex.in

    r428 r459  
    4646\section{How it works} 
    4747 
    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 does the following: 
     48The 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 
     50free energy and phase diagram libraries.  They do the following: 
    5151\begin{itemize} 
    52 \item Calls functions in {\tt book.c} (appendix \ref{file_book.c}) to create a 
    53   triangular array of points and set of triangles connecting them. 
    54 \item Calculates the free energy function on the triangle verticies using 
     52\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 
    5555  {\tt free\_energies()} in {\tt freenergy.c} (appendix 
    5656  \ref{file_freenergy.c}). 
    57 \item Displays the free energy using the functions in {\tt geomview.c} 
     57\item Display the free energy using the functions in {\tt geomview.c} 
    5858  (appendix \ref{file_geomview.c}), which forks and controls a Geomview 
    5959  process. 
    60 \item Calculates the spinodal of this free energy function using {\tt 
     60\item Calculate the spinodal of this free energy function using {\tt 
    6161    calc\_spinodal} in {\tt spinodal.c} (appendix \ref{file_spinodal.c}), and 
    6262  displays it on the free energy function. 
    63 \item Uses Qhull calls in {\tt qhull.c} (appendix \ref{file_qhull.c}) to 
     63\item Use Qhull calls in {\tt qhull.c} (appendix \ref{file_qhull.c}) to 
    6464  calculate the convex hull of the free energy function. 
    65 \item Refines the multi-phase triangles using Newton iteration ({\tt 
     65\item Refine the multi-phase triangles using Newton iteration ({\tt 
    6666    hullRefine} in {\tt qhull.c}) to find the lowest-energy point starting at 
    6767  each corner, smoothing the phase boundaries considerably. 
    68 \item Adds the two-phase region facet outlines to the Geomview display. 
     68\item Add the two-phase region facet outlines to the Geomview display. 
    6969\end{itemize} 
    7070 
     
    105105  spinodal.c} calculates the shape of the spinodal curve. 
    106106 
     107All functions can now accommodate ``rectangle'' ternary spaces, though it's not 
     108clear what a spinodal means in this context.  The {\tt square} front-end 
     109demonstrates this functionality. 
     110 
     111Finally, a major reorganization splits the bulk of the code into two libraries, 
     112with front-end codes {\tt ternary} and {\tt square} calling into them.  One 
     113library calculates free energies and derivatives, and can be re-used in phase 
     114field codes.  The second calculates phase diagrams.  The APIs are relatively 
     115immature and bound to change. 
     116 
    107117\bibliographystyle{unsrturl} 
    108118\bibliography{ternary}