- Timestamp:
- 02/23/2009 07:27:26 PM (3 years ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/qhull.c
r421 r424 366 366 int hullRefine It returns zero or an error code. 367 367 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. 371 380 372 381 energy_params *eparams Collection of energy parameter structures. … … 390 399 391 400 int 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) 395 404 { 396 facetT *facet;397 facet_type type;398 405 ternary_point *newpoints; 399 406 int newpointsize=100, numnewpoints=0, i; … … 410 417 +*/ 411 418 412 FORALLfacets419 for (i=0; i<*numfacets; i++) 413 420 { 414 421 double corners [9], centroid [3], Gcenter; 415 vertexT *vertex, **vertexp;416 422 int j=0, eparam [3] = {0,0,0}, thepoint [3]; 417 423 … … 423 429 +html+ </li> 424 430 +*/ 425 FOREACHvertex_(facet->vertices)431 for (j=0; j<3; j++) 426 432 { 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; 438 439 } 439 440 440 // Ignore non-simplical side facets and top facet441 if (fabs((corners[3]-corners[0])*(corners[7]-corners[1]) -442 (corners[6]-corners[0])*(corners[4]-corners[1])) < 0.999999443 && j==3)444 {445 441 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, 450 445 corners[0], corners[1], corners[3], 451 446 corners[4], corners[6], corners[7]); … … 468 463 centroid[2] = (corners[2] + corners[5] + corners[8]) / 3.; 469 464 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) 474 466 { 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"); 480 469 #endif 481 470 if (numnewpoints >= newpointsize) … … 484 473 newpoints [numnewpoints].C2 = centroid[0]; 485 474 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]; 488 478 numnewpoints++; 489 }490 491 else492 {493 #ifdef DEBUG494 printf (" Not refining one-phase triangle\n");495 #endif496 }497 479 } 498 480 … … 504 486 +html+ </li> 505 487 +*/ 506 else 488 else if ((*facets) [i].type != ONE_PHASE) 507 489 { 508 490 coordT newcorners [9] = { corners[0], corners[1], corners[2], … … 541 523 } 542 524 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 +*/ 543 534 for (j=0; j<3; j++) 544 535 { … … 561 552 +latex+\item 562 553 +html+ <li> 563 If any two new candidate vertices are in thesame place (closer564 than vertex_tolerance) , eliminate one.554 Add new points, leaving out duplicates in same place (closer 555 than vertex_tolerance). 565 556 +html+ </li> 566 557 +*/ … … 630 621 } 631 622 } 632 }633 623 } 634 624 /*+ … … 637 627 +*/ 638 628 639 /*+ Unfortunately, adding new points can create dissonance between qhull640 indices and Ternary indices. So this frees the old hull and creates a new641 one around the old points and new refined ones. This adds an N log N642 process to an otherwise order-N refining algorithm, but can't be643 helped. +*/644 629 #ifdef DEBUG 645 630 printf ("Adding %d new points to hull\n", numnewpoints); … … 650 635 return 1; 651 636 652 //qh_freeqhull (True);653 //free (qpoints);654 655 637 for (i=0; i<numnewpoints; i++) 656 638 { … … 662 644 663 645 (*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 else674 (*numpoints)--;*/675 646 } 676 647 *numpoints += numnewpoints; 677 678 #ifdef DEBUG679 printf ("Done, returning\n");680 #endif681 648 free(newpoints); 682 649 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); 684 664 } 685 665 -
trunk/matml/src/ternary/ternary.c
r423 r424 101 101 &hullfacets, &hullnumfacets)) 102 102 { 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)) 105 105 { 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)) 108 108 { 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); } 112 112 113 /* Scale and display everything */ 113 114 if (i=scale_energy_array (numpoints, points, 0., -.2, 1., .9, NULL, NULL)) 114 115 { printf ("main: Error %d in scale_triangle_array\n", i); exit (i); } -
trunk/matml/src/ternary/ternary.h
r423 r424 171 171 int nparams, double T, double P, hull_facet **facets, int *numfacets); 172 172 int 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); 176 176 char *hullQHullVersion (); 177 177