Changeset 432 for trunk/matml

Show
Ignore:
Timestamp:
03/06/2009 04:49:33 PM (3 years ago)
Author:
powell
Message:

Major overhaul of phase boundary return code including miscibility gap.

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

Legend:

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

    r430 r432  
    705705  int numfacets Number of facets. 
    706706 
     707  energy_params *eparams Collection of energy parameter structures. 
     708 
     709  double T Temperature. 
     710 
     711  double P Pressure. 
     712 
    707713  phase_boundary **boundaries Pointer to array of phase_boundary objects.  This 
    708714  is changed by realloc() each time the function is called, so it should be 
     
    714720int hullReturnPhaseBoundaries 
    715721(ternary_point *points, int n_points, hull_facet *facets, int n_facets, 
     722 energy_params *eparams, double T, double P, 
    716723 phase_boundary **boundaries, int *n_bounds) 
    717724{ 
     
    731738        v2 = facets[f].vertex[2]; 
    732739 
    733       printf ("Last facet %d vertices %d, %d, %d\n", n_facets-1, 
    734               facets[n_facets-1].vertex[0], facets[n_facets-1].vertex[1], 
    735               facets[n_facets-1].vertex[2]); 
    736  
    737740      printf ("Facet %d: type %d, vertices %d ",f, facets [f].type, v0); 
    738       fflush (stdout); 
    739741      printf ("(%d), %d (%d), %d(%d)\n", 
    740742              points[v0].efunc, v1, 
     
    745747        { 
    746748        case ONE_PHASE: 
    747           { 
    748             printf ("Type 0 facet\n"); fflush (stdout); 
    749             // Totally uninteresting 
    750             break; 
    751           } 
     749          // Totally uninteresting 
     750          break; 
    752751 
    753752        case THREE_PHASE: 
     
    795794                (*boundaries) [bound].edges [2] = MAX3 (v0, v1, v2); 
    796795                (*n_bounds) ++; 
     796                printf ("  Corners for bound %d edge 0: %d, %d, %d\n", bound, 
     797                        (*boundaries) [bound].edges [0], 
     798                        (*boundaries) [bound].edges [1], 
     799                        (*boundaries) [bound].edges [2]); 
    797800              } 
    798801            else 
     
    811814                (*boundaries) [bound].edges [3*e+2] = MAX3 (v0, v1, v2); 
    812815                (*boundaries) [bound].n_edges += 1; 
     816                printf ("  Corners for bound %d edge %d: %d, %d, %d\n", bound,e, 
     817                        (*boundaries) [bound].edges [3*e], 
     818                        (*boundaries) [bound].edges [3*e+1], 
     819                        (*boundaries) [bound].edges [3*e+2]); 
    813820              } 
    814821 
     
    820827        case TWO_PHASE: 
    821828          { 
    822             int b=0, bound=-1, p0, p1, p2, 
     829            int b=0, bound=-1, p0, p1, p2, nphases=2, e=0, 
    823830              phase0 = MIN3 (points [v0].efunc, points [v1].efunc, 
    824831                             points [v2].efunc), 
     
    833840                p1 = MAX (v0, v1); 
    834841                p2 = v2; 
    835                 // If all three are on the same phase, need to check midpoint 
    836                 // energies to determine which are one- and two-phase segments. 
    837                 // Punt for the default case later! 
     842 
     843                // If all three are on the same phase, this is a miscibility 
     844                // gap facet, set nphases to 1 and figure out which vertex is 
     845                // across from the other two 
    838846                if (points [v0].efunc == points [v2].efunc) 
    839                   { printf ("Miscibility gap!\n"); break; } 
     847                  { 
     848                    double C02 = points [v0].C2, C03 = points [v0].C3, 
     849                      C12 = points [v1].C2, C13 = points [v1].C3, 
     850                      C22 = points [v2].C2, C23 = points [v2].C3, 
     851                      G0 = points [v0].G, G1 = points [v1].G, 
     852                      G2 = points [v2].G; 
     853 
     854                    printf ("Misc gap: "); 
     855                    nphases=1; 
     856 
     857                    if (free_energy ((C02+C12)/2,(C03,C13)/2,T,P,eparams+phase0) < 
     858                        G0+G1/2) 
     859                      { 
     860                        printf ("v2 alone, Gav=%g, Gmid=%g\n", 
     861                                G0+G1/2, free_energy ((C02+C12)/2,(C03,C13)/2,T,P,eparams+phase0)); 
     862                        p0 = MIN (v0, v1); 
     863                        p1 = MAX (v0, v1); 
     864                        p2 = v2; 
     865                      } 
     866                    else if (free_energy ((C02+C22)/2,(C03,C23)/2,T,P,eparams+phase0) < 
     867                        G0+G2/2) 
     868                      { 
     869                        printf ("v1 alone, Gav=%g, Gmid=%g\n", 
     870                                G0+G2/2, free_energy ((C02+C22)/2,(C03,C23)/2,T,P,eparams+phase0)); 
     871                        p0 = MIN (v0, v2); 
     872                        p1 = MAX (v0, v2); 
     873                        p2 = v1; 
     874                      } 
     875                    else 
     876                      { 
     877                        printf ("v0 alone, Gav=%g, Gmid=%g\n", 
     878                                G1+G2/2, free_energy ((C22+C12)/2,(C23,C13)/2,T,P,eparams+phase0)); 
     879                        p0 = MIN (v1, v2); 
     880                        p1 = MAX (v1, v2); 
     881                        p2 = v0; 
     882                      } 
     883                  } 
    840884              } 
    841885            else if (points [v0].efunc == points [v2].efunc) 
     
    854898            // Check for a boundary with tie lines between these two phases 
    855899            for (b=0; b<*n_bounds; b++) 
    856               if ((*boundaries) [b].n_phases == 2 && 
     900              if ((*boundaries) [b].n_phases == nphases && 
    857901                  (*boundaries) [b].flags == TIE_SIMPLICES && 
    858902                  (*boundaries) [b].phases[0] == phase0 && 
    859                   (*boundaries) [b].phases[1] == phase1) 
     903                  (*boundaries) [b].phases[nphases-1] == phase1) 
    860904                bound = b; 
    861905 
     
    870914 
    871915                (*boundaries) [bound].compos = 2; 
    872                 (*boundaries) [bound].n_phases = 2; 
     916                (*boundaries) [bound].n_phases = nphases; 
    873917                if (!((*boundaries) [bound].phases = 
    874                       malloc (2*sizeof (int)))) 
     918                      malloc (nphases*sizeof (int)))) 
    875919                  return 1; 
    876920                (*boundaries) [bound].phases [0] = phase0; 
    877                 (*boundaries) [bound].phases [1] = phase1; 
    878                 (*boundaries) [bound].n_edges = 2; 
    879                 if (!((*boundaries) [bound].edges = 
    880                       malloc (4*sizeof (int)))) 
    881                   return 1; 
    882                 (*boundaries) [bound].edges [0] = MIN (p0, p2); 
    883                 (*boundaries) [bound].edges [1] = MAX (p0, p2); 
    884                 (*boundaries) [bound].edges [2] = MIN (p1, p2); 
    885                 (*boundaries) [bound].edges [3] = MAX (p1, p2); 
     921                (*boundaries) [bound].phases [nphases-1] = phase1; 
     922                (*boundaries) [bound].n_edges = 0; 
     923                (*boundaries) [bound].edges = NULL; 
    886924                (*boundaries) [bound].flags = TIE_SIMPLICES; 
    887925                (*n_bounds) ++; 
     926                e=0; 
    888927              } 
    889928            else 
    890               { 
    891                 int e = (*boundaries) [bound].n_edges; 
    892                 printf ("Tie-line boundary %d adding edges %d,%d\n",bound,e,e+1); 
    893                 // All of these reallocs are pretty expensive... 
    894                 // Later use compos to store size of array, sort out later 
    895                 if (!((*boundaries) [bound].edges = realloc 
    896                       ((*boundaries) [bound].edges, (2*e+4)*sizeof (int)))) 
    897                   return 1; 
    898                 (*boundaries) [bound].edges [2*e]   = MIN (p0, p2); 
    899                 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p2); 
    900                 (*boundaries) [bound].edges [2*e+2] = MIN (p1, p2); 
    901                 (*boundaries) [bound].edges [2*e+3] = MAX (p1, p2); 
    902                 (*boundaries) [bound].n_edges += 2; 
    903               } 
     929              e = (*boundaries) [bound].n_edges; 
     930 
     931            // All of these reallocs are pretty expensive... 
     932            // Later use compos to store size of array, sort out later 
     933            if (!((*boundaries) [bound].edges = realloc 
     934                  ((*boundaries) [bound].edges, (2*e+4) * sizeof (int)))) 
     935              return 1; 
     936            (*boundaries) [bound].n_edges += 2; 
     937 
     938            (*boundaries) [bound].edges [2*e]   = MIN (p0, p2); 
     939            (*boundaries) [bound].edges [2*e+1] = MAX (p0, p2); 
     940            (*boundaries) [bound].edges [2*e+2] = MIN (p1, p2); 
     941            (*boundaries) [bound].edges [2*e+3] = MAX (p1, p2); 
     942            printf ("  Corners for bound %d edges %d,%d: %d,%d, %d,%d\n", 
     943                    bound, e, e+1, (*boundaries) [bound].edges [2*e], 
     944                    (*boundaries) [bound].edges [2*e+1], 
     945                    (*boundaries) [bound].edges [2*e+2], 
     946                    (*boundaries) [bound].edges [2*e+3]); 
    904947 
    905948            // Check for a boundary with an edge on the "majority" phase 
    906949            for (b=0, bound=-1; b<*n_bounds; b++) 
    907               if ((*boundaries) [b].n_phases == 2 && 
     950              if ((*boundaries) [b].n_phases == nphases && 
    908951                  (*boundaries) [b].flags == ONE_PHASE_EDGE && 
    909952                  (*boundaries) [b].phases[0] == points[p0].efunc && 
    910                   (*boundaries) [b].phases[1] == points[p2].efunc) 
     953                  (*boundaries) [b].phases[nphases-1] == points[p2].efunc) 
    911954                bound = b; 
    912955 
     
    921964 
    922965                (*boundaries) [bound].compos = 2; 
    923                 (*boundaries) [bound].n_phases = 2; 
     966                (*boundaries) [bound].n_phases = nphases; 
    924967                if (!((*boundaries) [bound].phases = 
    925                       malloc (2*sizeof (int)))) 
     968                      malloc (nphases*sizeof (int)))) 
    926969                  return 1; 
    927970                (*boundaries) [bound].phases [0] = points[p0].efunc; 
    928                 (*boundaries) [bound].phases [1] = points[p2].efunc; 
    929                 (*boundaries) [bound].n_edges = 1; 
    930                 if (!((*boundaries) [bound].edges = 
    931                       malloc (2*sizeof (int)))) 
    932                   return 1; 
    933                 (*boundaries) [bound].edges [0] = MIN (p0, p1); 
    934                 (*boundaries) [bound].edges [1] = MAX (p0, p1); 
     971                (*boundaries) [bound].phases [nphases-1] = points[p2].efunc; 
     972                (*boundaries) [bound].n_edges = 0; 
     973                (*boundaries) [bound].edges = NULL; 
    935974                (*boundaries) [bound].flags = ONE_PHASE_EDGE; 
    936975                (*n_bounds) ++; 
     976                e=0; 
    937977              } 
    938978            else 
    939               { 
    940                 int e = (*boundaries) [bound].n_edges; 
    941                 printf ("Phase edge boundary %d adding edge %d\n",bound,e); 
    942                 // All of these reallocs are pretty expensive... 
    943                 if (!((*boundaries) [bound].edges = realloc 
    944                       ((*boundaries) [bound].edges, (2*e+2)*sizeof (int)))) 
    945                   return 1; 
    946                 (*boundaries) [bound].edges [2*e]   = MIN (p0, p1); 
    947                 (*boundaries) [bound].edges [2*e+1] = MAX (p0, p1); 
    948                 (*boundaries) [bound].n_edges += 1; 
    949               } 
    950  
     979              e = (*boundaries) [bound].n_edges; 
     980 
     981            // All of these reallocs are pretty expensive... 
     982            if (!((*boundaries) [bound].edges = realloc 
     983                  ((*boundaries) [bound].edges, (2*e+2)*sizeof (int)))) 
     984              return 1; 
     985            (*boundaries) [bound].edges [2*e]   = MIN (p0, p1); 
     986            (*boundaries) [bound].edges [2*e+1] = MAX (p0, p1); 
     987            (*boundaries) [bound].n_edges += 1; 
     988            printf ("  Corners for bound %d edge %d: %d,%d\n", 
     989                    bound, e, (*boundaries) [bound].edges [2*e], 
     990                    (*boundaries) [bound].edges [2*e+1]); 
     991 
     992            break; 
     993          } 
     994 
     995        case CRITICAL_POINT: 
     996          { 
     997            printf ("Critical point case\n"); 
    951998            break; 
    952999          } 
     
    9621009                    points [facets[f].vertex[1]].efunc, 
    9631010                    points [facets[f].vertex[2]].efunc); 
     1011            printf ("  Coords: %d %g,%g, %d %g,%g, %d %g,%g\n", 
     1012                    facets[f].vertex[0], points [facets[f].vertex[0]].C2, 
     1013                    points [facets[f].vertex[0]].C3, 
     1014                    facets[f].vertex[1], points [facets[f].vertex[1]].C2, 
     1015                    points [facets[f].vertex[1]].C3, 
     1016                    facets[f].vertex[2], points [facets[f].vertex[2]].C2, 
     1017                    points [facets[f].vertex[2]].C3); 
    9641018          } 
    9651019        } 
  • trunk/matml/src/ternary/ternary.c

    r431 r432  
    121121 
    122122  if (i=hullReturnPhaseBoundaries (points,numpoints, hullfacets,hullnumfacets, 
    123                                    &allbounds, &numbounds)) 
     123                                   allparams, T, P, &allbounds, &numbounds)) 
    124124    { printf ("main: error %d in hullReturnPhaseBoundaries\n", i); exit (i); } 
    125125 
     
    144144    { printf ("main: Error %d in Geomview Display\n", i); exit (i); }   
    145145 
     146  if (i=GeomviewDisplayPhaseBoundary 
     147      (pfd, "Boundary 4", "bd4", "-face +edge", 
     148       numpoints, points, allbounds+4)) 
     149    { printf ("main: Error %d in Geomview Display\n", i); exit (i); }   
     150 
     151  if (i=GeomviewDisplayPhaseBoundary 
     152      (pfd, "Boundary 5", "bd5", "-face +edge", 
     153       numpoints, points, allbounds+5)) 
     154    { printf ("main: Error %d in Geomview Display\n", i); exit (i); }   
     155 
    146156  printf ("Press <return> to close up... "); 
    147157  fflush (stdout);