ISLEC  Version 4.2
rkg_model.c
Go to the documentation of this file.
1 /* src/rkg_model.c
2  *
3  * Copyright (C) 2011-2018 Dongdong Li
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundataion; either version 3 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABLITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
32 //Redlich-Kister-Guggenheim formula
33 static double rkg_ai (SOLIDSOLUTION_PHASE ss, int index, double *n, double T, double P)
34 {
35  double lnri = 0.0;
36  double A0[ss.species_num][ss.species_num];
37  double A1[ss.species_num][ss.species_num];
38  double x[ss.species_num];
39  int i, j, k, l;
40  double sumn;
41 
42  for (i = 0; i < ss.species_num; i ++)
43  {
44  for (j = 0; j < ss.species_num; j ++)
45  {
46  A0[i][j] = 0.0;
47  A1[i][j] = 0.0;
48  }
49  }
50 
51  sumn = 0.0;
52  for (k = 0; k < ss.species_num; k ++)
53  {
54  sumn += n[k];
55  }
56 
57  for (k = 0; k < ss.species_num; k ++)
58  {
59  x[k] = n[k] / sumn;
60  }
61 
62  for (l = 0; l < ss.param_num; l ++)
63  {
64  for (k = 0; k < ss.species_num; k ++)
65  {
66  if (strcmp (ss.params[l].species_a, ss.solidsolution_species[k].species_symbol) == 0)
67  {
68  i = k;
69  }
70  }
71 
72  for (k = 0; k < ss.species_num; k ++)
73  {
74  if (strcmp (ss.params[l].species_b, ss.solidsolution_species[k].species_symbol) == 0)
75  {
76  j = k;
77  }
78  }
79 
80  A0[i][j] = ss.params[l].A0;
81  A0[j][i] = A0[i][j];
82  A1[i][j] = ss.params[l].A1;
83  A1[j][i] = A1[i][j];
84  }
85 
86  for (j = 0; j < ss.species_num; j++)
87  {
88  lnri += ((1 - x[index]) * x[j] * A0[index][j]/(R * T) +
89  x[index] * x[j] * (1.0 - 2.0 * x[j]) * A1[index][j]/(R * T));
90  }
91 
92  if (sumn == 0 || x[index] == 0
93  || x[index] * exp(lnri) < 1.0e-15
94  || x[index] * exp(lnri) > 1.0e+15) {return 1.0E-10;}
95 
96  return x[index] * exp(lnri);
97 }
98 
99 extern double rkg_a (SOLIDSOLUTION_PHASE ss, int index, double *n, double T, double P)
100 {
101  rkg_ai (ss, index, n, T, P);
102 }
char species_a[64]
Definition: islec.h:142
double A0
Definition: islec.h:144
double A1
Definition: islec.h:145
double rkg_a(SOLIDSOLUTION_PHASE ss, int index, double *n, double T, double P)
Definition: rkg_model.c:99
#define R
Definition: islec.h:37
char species_b[64]
Definition: islec.h:143
SUBRPARAM * params
Definition: islec.h:183
char species_symbol[64]
Definition: islec.h:79
SPECIES * solidsolution_species
Definition: islec.h:181