Changeset 360

Show
Ignore:
Timestamp:
04/17/08 17:08:26 (7 months ago)
Author:
powell
Message:

Overhaul of freenergy interface, with implementation stubs.

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

Legend:

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

    r349 r360  
    1111 
    1212/*++++++++++++++++++++++++++++++++++++++ 
    13   This calculates the free energy. 
    14  
    15   double free_energy It returns the free energy. 
    16  
    17   double C2 Concentration of species 2. 
    18  
    19   double C3 Concentration of species 3. 
    20  
    21   double T Temperature. 
    22  
    23   energy_params *eparams Free energy function parameters. 
    24   ++++++++++++++++++++++++++++++++++++++*/ 
    25  
    26 double free_energy (double C2, double C3, double T, energy_params *eparams) 
     13  This local function calculates the free energy as a function of composition, 
     14  temperature, pressure, and the specified parameters. 
     15 
     16  inline double _G It returns the free energy. 
     17 
     18  double C2 Concentration of species 2. 
     19 
     20  double C3 Concentration of species 3. 
     21 
     22  double T Temperature. 
     23 
     24  double P Pressure (ignored for now). 
     25 
     26  energy_params *eparams Free energy function parameters. 
     27  ++++++++++++++++++++++++++++++++++++++*/ 
     28 
     29static inline double _G 
     30(double C2, double C3, double T, double P, energy_params *eparams) 
    2731{ 
    2832  double C1 = (1.-C2-C3 < 0.) ? 0. : 1.-C2-C3, 
     
    4650    +*/ 
    4751  return G1 + (G2-G1)*C2 + (G3-G2)*C3 
    48     + eparams->R*T*(((C1==0.)?0.:C1/eparams->M1*log(C1)) 
    49                     + ((C2==0.)?0.:C2/eparams->M2*log(C2)) 
    50                     + ((C3==0.)?0.:C3/eparams->M3*log(C3))) 
     52    + eparams->R*T*(((C1<=0.)?0.:C1/eparams->M1*log(C1)) 
     53                    + ((C2<=0.)?0.:C2/eparams->M2*log(C2)) 
     54                    + ((C3<=0.)?0.:C3/eparams->M3*log(C3))) 
    5155    + eparams->Omega12*C2*C1 + eparams->Omega13*C3*C1 + eparams->Omega23*C2*C3 
    5256    + eparams->Omega123*C1*C2*C3; 
    5357} 
     58 
     59 
     60/*++++++++++++++++++++++++++++++++++++++ 
     61  This local function calculates the derivative of free energy with respect to 
     62  +latex+$C_2$: $\partial G/\partial C_2$ 
     63  +html+ <i>C</i><sub>2</sub>: <i>dG</i>/<i>DC</i><sub>2</sub> 
     64  as a function of composition, temperature, pressure, and the specified 
     65  parameters. 
     66 
     67  inline double _G2 It returns the free energy derivative. 
     68 
     69  double C2 Concentration of species 2. 
     70 
     71  double C3 Concentration of species 3. 
     72 
     73  double T Temperature. 
     74 
     75  double P Pressure (ignored for now). 
     76 
     77  energy_params *eparams Free energy function parameters. 
     78  ++++++++++++++++++++++++++++++++++++++*/ 
     79 
     80static inline double _G2 
     81(double C2, double C3, double T, double P, energy_params *eparams) 
     82{ 
     83  return 0.; 
     84} 
     85 
     86 
     87/*++++++++++++++++++++++++++++++++++++++ 
     88  This local function calculates the derivative of free energy with respect to 
     89  +latex+$C_3$: $\partial G/\partial C_3$ 
     90  +html+ <i>C</i><sub>3</sub>: <i>dG</i>/<i>DC</i><sub>3</sub> 
     91  as a function of composition, temperature, pressure, and the specified 
     92  parameters. 
     93 
     94  inline double _G3 It returns the free energy derivative. 
     95 
     96  double C2 Concentration of species 2. 
     97 
     98  double C3 Concentration of species 3. 
     99 
     100  double T Temperature. 
     101 
     102  double P Pressure (ignored for now). 
     103 
     104  energy_params *eparams Free energy function parameters. 
     105  ++++++++++++++++++++++++++++++++++++++*/ 
     106 
     107static inline double _G3 
     108(double C2, double C3, double T, double P, energy_params *eparams) 
     109{ 
     110  return 0.; 
     111} 
     112 
     113 
     114/*++++++++++++++++++++++++++++++++++++++ 
     115  This local function calculates the second derivative of free energy with 
     116  respect to  
     117  +latex+$C_2$: $\partial^2G/\partial C_2^2$ 
     118  +html+ <i>C</i><sub>2</sub>: 
     119  +html+ <i>d</i><sup>2</sup><i>G</i>/<i>DC</i><sub>2</sub><sup>2</sup> 
     120  as a function of composition, temperature, pressure, and the specified 
     121  parameters. 
     122 
     123  inline double _G22 It returns the free energy derivative. 
     124 
     125  double C2 Concentration of species 2. 
     126 
     127  double C3 Concentration of species 3. 
     128 
     129  double T Temperature. 
     130 
     131  double P Pressure (ignored for now). 
     132 
     133  energy_params *eparams Free energy function parameters. 
     134  ++++++++++++++++++++++++++++++++++++++*/ 
     135 
     136static inline double _G22 
     137(double C2, double C3, double T, double P, energy_params *eparams) 
     138{ 
     139  return 0.; 
     140} 
     141 
     142 
     143/*++++++++++++++++++++++++++++++++++++++ 
     144  This local function calculates the second derivative of free energy with 
     145  respect to  
     146  +latex+$C_3$: $\partial^2G/\partial C_3^2$ 
     147  +html+ <i>C</i><sub>3</sub>: 
     148  +html+ <i>d</i><sup>2</sup><i>G</i>/<i>DC</i><sub>3</sub><sup>2</sup> 
     149  as a function of composition, temperature, pressure, and the specified 
     150  parameters. 
     151 
     152  inline double _G33 It returns the free energy derivative. 
     153 
     154  double C2 Concentration of species 2. 
     155 
     156  double C3 Concentration of species 3. 
     157 
     158  double T Temperature. 
     159 
     160  double P Pressure (ignored for now). 
     161 
     162  energy_params *eparams Free energy function parameters. 
     163  ++++++++++++++++++++++++++++++++++++++*/ 
     164 
     165static inline double _G33 
     166(double C2, double C3, double T, double P, energy_params *eparams) 
     167{ 
     168  return 0.; 
     169} 
     170 
     171 
     172/*++++++++++++++++++++++++++++++++++++++ 
     173  This local function calculates the mixed second derivative of free energy 
     174  with respect to  
     175  +latex+$C_2$ and $C_3$: $\partial^2G/\partial C_2\partial C_3$ 
     176  +html+ <i>C</i><sub>2</sub> and <i>C</i><sub>3</sub>: 
     177  +html+ <i>d</i><sup>2</sup><i>G</i>/<i>DC</i><sub>2</sub><i>DC</i><sub>3</sub> 
     178  as a function of composition, temperature, pressure, and the specified 
     179  parameters. 
     180 
     181  inline double _G23 It returns the free energy derivative. 
     182 
     183  double C2 Concentration of species 2. 
     184 
     185  double C3 Concentration of species 3. 
     186 
     187  double T Temperature. 
     188 
     189  double P Pressure (ignored for now). 
     190 
     191  energy_params *eparams Free energy function parameters. 
     192  ++++++++++++++++++++++++++++++++++++++*/ 
     193 
     194static inline double _G23 
     195(double C2, double C3, double T, double P, energy_params *eparams) 
     196{ 
     197  return 0.; 
     198} 
     199 
     200 
     201/*++++++++++++++++++++++++++++++++++++++ 
     202  This returns the free energy at a single composition. 
     203 
     204  double free_energy It returns the free energy. 
     205 
     206  double C2 Concentration of species 2. 
     207 
     208  double C3 Concentration of species 3. 
     209 
     210  double T Temperature. 
     211 
     212  double P Pressure (ignored for now). 
     213 
     214  energy_params *eparams Free energy function parameters. 
     215  ++++++++++++++++++++++++++++++++++++++*/ 
     216 
     217double free_energy 
     218(double C2, double C3, double T, double P, energy_params *eparams) 
     219{ 
     220  return _G (C2, C3, T, P, eparams); 
     221} 
     222 
     223 
     224/*++++++++++++++++++++++++++++++++++++++ 
     225  This calculates free energy at a bunch of compositions. 
     226 
     227  int free_energies It returns zero or an error code. 
     228 
     229  ternary_point *points Ternary point structures holding the compositions where 
     230  we calculate the free energy, and the free energy field where we put the 
     231  return values. 
     232 
     233  int n Number of points to calculate. 
     234 
     235  double T Temperature. 
     236 
     237  double P Pressure (ignored for now). 
     238 
     239  energy_params *eparams Free energy function parameters. 
     240  ++++++++++++++++++++++++++++++++++++++*/ 
     241 
     242int free_energies 
     243(ternary_point *points, int n, double T, double P, energy_params *eparams) 
     244{ 
     245  int i; 
     246 
     247  for (i=0; i<n; i++) 
     248    points[i].G = _G (points[i].C2, points[i].C3, T, P, eparams); 
     249 
     250  return 0; 
     251} 
     252 
     253 
     254/*++++++++++++++++++++++++++++++++++++++ 
     255  This calculates free energy and its derivatives at a bunch of compositions. 
     256 
     257  int free_energy_derivatives It returns zero or an error code. 
     258 
     259ternary_point *points Ternary point structures holding the compositions where 
     260  we calculate the free energy, and the free energy and derivative fields where 
     261  we put the return values. 
     262 
     263  int n Number of points to calculate. 
     264 
     265  double T Temperature. 
     266 
     267  double P Pressure (ignored for now). 
     268 
     269  energy_params *eparams Free energy function parameters. 
     270  ++++++++++++++++++++++++++++++++++++++*/ 
     271 
     272int free_energy_derivatives 
     273(ternary_point *points, int n, double T, double P, energy_params *eparams) 
     274{ 
     275  int i; 
     276 
     277  for (i=0; i<n; i++) 
     278    { 
     279      points[i].G   = _G   (points[i].C2, points[i].C3, T, P, eparams); 
     280      points[i].G2  = _G2  (points[i].C2, points[i].C3, T, P, eparams); 
     281      points[i].G3  = _G3  (points[i].C2, points[i].C3, T, P, eparams); 
     282      points[i].G22 = _G22 (points[i].C2, points[i].C3, T, P, eparams); 
     283      points[i].G33 = _G33 (points[i].C2, points[i].C3, T, P, eparams); 
     284      points[i].G23 = _G23 (points[i].C2, points[i].C3, T, P, eparams); 
     285    } 
     286 
     287  return 0; 
     288} 
  • trunk/matml/src/ternary/geomview.c

    r352 r360  
    88#include "ternary.h" /*+ Ternary prototypes, typedefs, etc. +*/ 
    99#include <unistd.h>  /*+ For execlp() +*/ 
     10#define _POSIX_C_SOURCE /*+ For fdopen(). +*/ 
    1011#include <stdio.h>   /*+ For FILE, fdopen(), etc. +*/ 
    1112 
  • trunk/matml/src/ternary/ternary.c

    r355 r360  
    6868  for (index=0; index<(loop_max+1)*(loop_max+2)/2; index++) 
    6969    points[index].G = 
    70       free_energy (points[index].C2, points[index].C3, T, &eparams1); 
     70      free_energy (points[index].C2, points[index].C3, T, 1., &eparams1); 
    7171  for (index=(loop_max+1)*(loop_max+2)/2; 
    7272       index<(loop_max+1)*(loop_max+2); index++) 
    7373    points[index].G = 
    74       free_energy (points[index].C2, points[index].C3, T, &eparams2); 
     74      free_energy (points[index].C2, points[index].C3, T, 1., &eparams2); 
    7575 
    7676  /* Scale all free energy values to (0->1) */ 
     
    111111      /* Test whether hull facet is in one-phase region: free energy at 
    112112         centroid is below facet; if so, remove it */ 
    113       if (fmin (free_energy (C2av, C3av, T, &eparams1), 
    114                 free_energy (C2av, C3av, T, &eparams2)) < Gav) 
     113      if (fmin (free_energy (C2av, C3av, T, 1., &eparams1), 
     114                free_energy (C2av, C3av, T, 1., &eparams2)) < Gav) 
    115115        { 
    116116          for (j=i; j<hullnumverts-1; j++) 
  • trunk/matml/src/ternary/ternary.h

    r359 r360  
    8989 
    9090/* From freenergy.c */ 
    91 double free_energy (double C2, double C3, double T, energy_params *eparams); 
     91double free_energy 
     92(double C2, double C3, double T, double P, energy_params *eparams); 
     93int free_energies 
     94(ternary_point *points, int n, double T, double P, energy_params *eparams); 
     95int free_energy_derivatives 
     96(ternary_point *points, int n, double T, double P, energy_params *eparams); 
    9297 
    9398/* From geomview.c */