Changeset 369

Show
Ignore:
Timestamp:
05/09/08 12:58:25 (6 months ago)
Author:
powell
Message:

New code for doing the Newton refining; completely untested.

Files:
1 modified

Legend:

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

    r367 r369  
    8484 
    8585  double *corners Coordinates (including energies) of the corners of this 
    86   facet, used for the facet normal. 
     86  facet, used for the facet normal: C21,C31,G1, C22,C32,G2, C23,C33,G3. 
    8787 
    8888  energy_params *eparams Collection of energy parameter structures. 
    8989 
    9090  int nparams Number of energy parameter structures in eparams. 
     91 
     92  double T Temperature. 
     93 
     94  double P Pressure. 
    9195 
    9296  int globaldims Dimensionality of the global space. 
     
    103107static inline void NewtonRefine 
    104108(coordT *point, coordT *corners, energy_params *eparams, int nparams, 
    105  int globaldims, int localdims, int side, double newton_tolerance) 
    106 { 
    107   double distance = 0.; 
     109 double T, double P, int globaldims, int localdims, int side, 
     110 double newton_tolerance) 
     111{ 
     112  int i, minfunc=0; 
     113  double distance = 1., G, slope2, slope3; 
     114  ternary_point current; 
     115 
     116  if (globaldims != 3) 
     117    { printf ("qhullCalcHull: Non-ternaries not yet supported\n"); return; } 
     118  current.C2 = point[0]; 
     119  current.C3 = point[1]; 
    108120 
    109121  /*+ Determine which is the lowest energy function at this point +*/ 
     122  G = free_energy (current.C2, current.C3, T, P, eparams); 
     123  for (i=1; i<nparams; i++) 
     124    if (slope2 = free_energy (current.C2, current.C3, T, P, eparams+i) < G) 
     125      { 
     126        G = slope2; 
     127        minfunc = i; 
     128      } 
     129 
     130  /*+ Determine the slope(s) of the facet +*/ 
     131  if (localdims==3) 
     132    { 
     133      double x2=corners[3]-corners[0], y2=corners[6]-corners[0], 
     134        x3=corners[4]-corners[1], y3=corners[7]-corners[1], 
     135        xG=corners[5]-corners[2], yG=corners[8]-corners[2]; 
     136      double vG=x2*y3-x3*y2; 
     137      slope2 = (x3*yG-xG*y3)/vG; 
     138      slope3 = (xG*y2-x2*yG)/vG; 
     139    } 
     140  else 
     141    { 
     142      /*+ Slope for the binary case +*/ 
     143      if (side==0 || side==2) // C3=0 or C2+C3=1 sides: dG/dC2 
     144        slope2 = (corners[5]-corners[2])/(corners[3]-corners[0]); 
     145      else if (side==1) // C2=0 side: dG/dC3 
     146        slope2 = (corners[5]-corners[2])/(corners[4]-corners[1]); 
     147    } 
    110148 
    111149  while (distance >= newton_tolerance) 
    112150    { 
     151      double dC2, dC3; 
     152 
    113153      /*+ Calculate the energy derivatives +*/ 
     154      free_energy_derivatives (&current, 1, T, P, eparams+minfunc); 
    114155 
    115156      /*+ Subtract the facet slopes from the energy derivatives +*/ 
    116  
    117       /*+ Solve the linear system to estimate the distance to the minimum +*/ 
    118  
    119       /*+ Add that distance to the point +*/ 
    120     } 
     157      current.G2 -= slope2; 
     158      current.G3 -= slope3; 
     159 
     160      /*+ Solve the linear system to estimate the vector to the minimum +*/ 
     161      dC3 = current.G22*current.G33 - current.G23*current.G23; 
     162      dC2 = (current.G3*current.G23 - current.G2*current.G33) / dC3; 
     163      dC3 = (current.G2*current.G23 - current.G3*current.G22) / dC3; 
     164 
     165      /*+ Add that vector to the point +*/ 
     166      current.C2 += dC2; 
     167      current.C3 += dC3; 
     168      distance = dC2*dC2 + dC3*dC3; 
     169    } 
     170 
     171  /* Return the current point */ 
     172  point[0] = current.C2; 
     173  point[1] = current.C3; 
    121174} 
    122175 
     
    132185 
    133186  int nparams Number of energy parameter structures in eparams. 
     187 
     188  double T Temperature. 
     189 
     190  double P Pressure. 
    134191 
    135192  double newton_tolerance Stop Newton iterations when the vertex motion falls 
     
    142199  ++++++++++++++++++++++++++++++++++++++*/ 
    143200 
    144 int hullRefine (energy_params *eparams, int nparams, double newton_tolerance, 
    145                 double vertex_tolerance) 
     201int hullRefine (energy_params *eparams, int nparams, double T, double P, 
     202                double newton_tolerance, double vertex_tolerance) 
    146203{ 
    147204  facetT *facet;