Changeset 424 for trunk

Show
Ignore:
Timestamp:
02/23/2009 07:27:26 PM (3 years ago)
Author:
powell
Message:

Fixed hullRefine.

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

Legend:

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

    r421 r424  
    366366  int hullRefine It returns zero or an error code. 
    367367 
    368   ternary_point **points Pointer to point list. 
    369  
    370   int *numpoints Number of points of which to calculate the convex hull. 
     368  ternary_point **points Pointer to point list, which will be modified to 
     369  accommodate the new points created in the refining process. 
     370 
     371  int *numpoints Pointer to number of points of which to calculate the convex 
     372  hull, which will also be modified. 
     373 
     374  hull_facet **facets Pointer to the array of facets to be refined, which will 
     375  be modified to accommodate new facets created -- and some removed -- in the 
     376  refining process. 
     377 
     378  int *numfacets Pointer to the number of facets comprising the convex hull, 
     379  which will also be modified. 
    371380 
    372381  energy_params *eparams Collection of energy parameter structures. 
     
    390399 
    391400int hullRefine 
    392 (ternary_point **points, int *numpoints, energy_params *eparams, int nparams, 
    393  double T,double P, double newton_tolerance, double vertex_tolerance, 
    394  int one_phase_refine) 
     401(ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
     402 energy_params *eparams, int nparams, double T,double P, 
     403 double newton_tolerance, double vertex_tolerance, int one_phase_refine) 
    395404{ 
    396   facetT *facet; 
    397   facet_type type; 
    398405  ternary_point *newpoints; 
    399406  int newpointsize=100, numnewpoints=0, i; 
     
    410417    +*/ 
    411418 
    412   FORALLfacets 
     419  for (i=0; i<*numfacets; i++) 
    413420    { 
    414421      double corners [9], centroid [3], Gcenter; 
    415       vertexT *vertex, **vertexp; 
    416422      int j=0, eparam [3] = {0,0,0}, thepoint [3]; 
    417423 
     
    423429        +html+ </li> 
    424430        +*/ 
    425       FOREACHvertex_(facet->vertices) 
     431      for (j=0; j<3; j++) 
    426432        { 
    427           if (j<3) 
    428             { 
    429               thepoint [j] = (vertex->point-qh first_point)/3; 
    430  
    431               corners [3*j]   = vertex->point[0]; 
    432               corners [3*j+1] = vertex->point[1]; 
    433               corners [3*j+2] = vertex->point[2]; 
    434  
    435               eparam [j] = (*points)[thepoint[j]].efunc; 
    436             } 
    437           j++; 
     433          thepoint [j] = (*facets) [i].vertex[j]; 
     434 
     435          corners [3*j]   = (*points) [thepoint[j]].C2; 
     436          corners [3*j+1] = (*points) [thepoint[j]].C3; 
     437          corners [3*j+2] = (*points) [thepoint[j]].G; 
     438          eparam [j] = (*points)[thepoint[j]].efunc; 
    438439        } 
    439440 
    440       // Ignore non-simplical side facets and top facet 
    441       if (fabs((corners[3]-corners[0])*(corners[7]-corners[1]) - 
    442                (corners[6]-corners[0])*(corners[4]-corners[1])) < 0.999999 
    443           && j==3) 
    444         { 
    445441          int eparamc=0; 
    446           facet_type facetype; 
    447  
    448 #ifdef DEBUG 
    449           printf ("Facet 0x%lx: %g,%g %g,%g %g,%g\n", facet, 
     442 
     443#ifdef DEBUG 
     444          printf ("Facet %d: %g,%g %g,%g %g,%g\n", i, 
    450445                  corners[0], corners[1], corners[3], 
    451446                  corners[4], corners[6], corners[7]); 
     
    468463          centroid[2] = (corners[2] + corners[5] + corners[8]) / 3.; 
    469464 
    470           facetype = facettype (corners, eparams, nparams, T, P); 
    471  
    472           if (facetype == ONE_PHASE && 
    473               eparam[0] == eparam[1] && eparam[1] == eparam[2]) 
     465          if ((*facets) [i].type == ONE_PHASE && one_phase_refine) 
    474466            { 
    475               if (one_phase_refine) 
    476                 { 
    477 #ifdef DEBUG 
    478                   printf ("  Refining %s-phase triangle at centroid\n", 
    479                     (eparam[0]==eparamc) ? "one" : "multi"); 
     467#ifdef DEBUG 
     468                  printf ("  Refining one-phase triangle at centroid\n"); 
    480469#endif 
    481470                  if (numnewpoints >= newpointsize) 
     
    484473                  newpoints [numnewpoints].C2 = centroid[0]; 
    485474                  newpoints [numnewpoints].C3 = centroid[1]; 
    486                   newpoints [numnewpoints].G  = Gcenter; 
    487                   newpoints [numnewpoints].efunc = eparamc; 
     475                  newpoints [numnewpoints].G  = free_energy 
     476                    (centroid[0], centroid[1], T, P, eparams+eparam [0]); 
     477                  newpoints [numnewpoints].efunc = eparam [0]; 
    488478                  numnewpoints++; 
    489                 } 
    490  
    491               else 
    492                 { 
    493 #ifdef DEBUG 
    494                   printf ("  Not refining one-phase triangle\n"); 
    495 #endif 
    496                 } 
    497479            } 
    498480 
     
    504486            +html+ </li> 
    505487            +*/ 
    506           else 
     488          else if ((*facets) [i].type != ONE_PHASE) 
    507489            { 
    508490              coordT newcorners [9] = { corners[0], corners[1], corners[2], 
     
    541523                } 
    542524 
     525              /*+ 
     526                +latex+\item 
     527                +html+ <li> 
     528                Refine the vertices of the facet using 
     529                +latex+{\tt NewtonRefine()} (section 
     530                +latex+\ref{func_NewtonRefine_qhull.c} page 
     531                +latex+\pageref{func_NewtonRefine_qhull.c}). 
     532                +html+ <a href="#func-NewtonRefine"><tt>NewtonRefine()</tt></a>.</li> 
     533                +*/ 
    543534              for (j=0; j<3; j++) 
    544535                { 
     
    561552                +latex+\item 
    562553                +html+ <li> 
    563                 If any two new candidate vertices are in the same place (closer 
    564                 than vertex_tolerance), eliminate one. 
     554                Add new points, leaving out duplicates in same place (closer 
     555                than vertex_tolerance). 
    565556                +html+ </li> 
    566557                +*/ 
     
    630621                } 
    631622            } 
    632         } 
    633623    } 
    634624  /*+ 
     
    637627    +*/ 
    638628 
    639   /*+ Unfortunately, adding new points can create dissonance between qhull 
    640     indices and Ternary indices.  So this frees the old hull and creates a new 
    641     one around the old points and new refined ones.  This adds an N log N 
    642     process to an otherwise order-N refining algorithm, but can't be 
    643     helped. +*/ 
    644629#ifdef DEBUG 
    645630  printf ("Adding %d new points to hull\n", numnewpoints); 
     
    650635    return 1; 
    651636           
    652   //qh_freeqhull (True); 
    653   //free (qpoints); 
    654  
    655637  for (i=0; i<numnewpoints; i++) 
    656638    { 
     
    662644 
    663645      (*points) [(*numpoints)+i] = newpoints [i]; 
    664       // In case I try to implement this using qh_addpoint someday... 
    665       /*printf ("  Finding best facet for coords %g, %g, %g\n", 
    666               (*points) [(*numpoints)+i].C2,(*points) [(*numpoints)+i].C3, 
    667               (*points) [(*numpoints)+i].G); 
    668       facet = qh_findbestfacet (newcorners, True, &bestdist, &isoutside); 
    669       printf ("  Adding to %d facet 0x%lx: %g, %g, %g\n", isoutside, facet, newcorners[0], newcorners[1], 
    670               newcorners[2]); 
    671       if (isoutside) 
    672         printf ("  Result: %d\n", qh_addpoint (newcorners, facet, True)); 
    673       else 
    674       (*numpoints)--;*/ 
    675646    } 
    676647  *numpoints += numnewpoints; 
    677  
    678 #ifdef DEBUG 
    679   printf ("Done, returning\n"); 
    680 #endif 
    681648  free(newpoints); 
    682649 
    683   //return hullCalculate (3, *points, *numpoints); 
     650#ifdef DEBUG 
     651  printf ("Re-calculating hull using hullCalculate()\n"); 
     652#endif 
     653 
     654  /*+ Finally, after generating the new points and adding them to the hull, it 
     655    re-calculates the convex hull using 
     656    +latex+{\tt hullCalculate()} (section 
     657    +latex+\ref{func_hullCalculate_qhull.c} page 
     658    +latex+\pageref{func_hullCalculate_qhull.c}). 
     659    +html+ <a href="#func-hullCalculate"><tt>hullCalculate()</tt></a>.</li> 
     660    +*/ 
     661   
     662  return hullCalculate (3, *points,*numpoints, eparams,nparams, T,P, facets, 
     663                        numfacets); 
    684664} 
    685665 
  • trunk/matml/src/ternary/ternary.c

    r423 r424  
    101101                       &hullfacets, &hullnumfacets)) 
    102102    { printf ("main: Error %d in hullCalculate\n", i); exit (i); } 
    103   /*if (i=hullRefine (&points, &numpoints, allparams, 2, T, P, 
    104                     1e-10, 1e-7, 0)) 
     103  if (i=hullRefine (&points, &numpoints, &hullfacets, &hullnumfacets, 
     104                    allparams, 2, T, P, 1e-10, 1e-7, 0)) 
    105105    { printf ("main: error %d in hullRefine\n", i); exit (i); } 
    106   if (i=hullRefine (&points, &numpoints, allparams, 2, T, P, 
    107                     1e-10, 1e-7, 0)) 
     106  if (i=hullRefine (&points, &numpoints, &hullfacets, &hullnumfacets, 
     107                    allparams, 2, T, P, 1e-10, 1e-7, 0)) 
    108108    { printf ("main: error %d in hullRefine\n", i); exit (i); } 
    109   if (i=hullRefine (&points, &numpoints, allparams, 2, T, P, 
    110                     1e-10, 1e-7, 0)) 
    111     { printf ("main: error %d in hullRefine\n", i); exit (i); }*/ 
     109  if (i=hullRefine (&points, &numpoints, &hullfacets, &hullnumfacets, 
     110                    allparams, 2, T, P, 1e-10, 1e-7, 0)) 
     111    { printf ("main: error %d in hullRefine\n", i); exit (i); } 
    112112 
     113  /* Scale and display everything */ 
    113114  if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL)) 
    114115    { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } 
  • trunk/matml/src/ternary/ternary.h

    r423 r424  
    171171 int nparams, double T, double P, hull_facet **facets, int *numfacets); 
    172172int hullRefine 
    173 (ternary_point **points, int *numpoints, energy_params *eparams, int nparams, 
    174  double T,double P, double newton_tolerance, double vertex_tolerance, 
    175  int one_phase_refine); 
     173(ternary_point **points, int *numpoints, hull_facet **facets, int *numfacets, 
     174 energy_params *eparams, int nparams, double T,double P, 
     175 double newton_tolerance, double vertex_tolerance, int one_phase_refine); 
    176176char *hullQHullVersion (); 
    177177