ISLEC  Version 4.2
islre.h
Go to the documentation of this file.
1 /* src/islre.h
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 
30 #define PROGRAM_NAME "ISLRE" // program name
31 #define PROGRAM_COMMAND "islre" // command name
32 #define PROGRAM_SITE "http://www.islec.net" // program website
33 #define COPYRIGHT "2011-2015" // copyright year
34 #define AUTHOR "Dongdong Li" // author
35 #define AUTHOR_EMAIL "ddong_li@hotmail.com" // author email
36 
37 #define R 8.314
38 #define PRESSURE 1.0
39 #define TEMP_FILE "temp.db"
40 
41 #define C1 4.5810 // higher order constants
42 #define C2 0.7237 //
43 #define C3 0.0120 //
44 #define C4 0.5280 //
45 
46 #define WATER_SYMBOL "H2O(aq)"
47 #define H_SYMBOL "H+(aq)"
48 
49 #define AW 1 // water activity
50 #define GA 2 // mean activity coefficient
51 #define SOL 3 // solubilities
52 
53 char BLOCK_KEYWORDS[2][64] = {"COMPONENTS",
54  "PHASES"
55 };
56 
57 char PHASE_KEYWORDS[4][64] = {"GAS",
58  "LIQUID",
59  "SOLID",
60  "SOLIDSOLUTION"
61 };
62 
63 char PROCESS[5][64] = {"EQUILIBRIUM",
64  "EVAPORATION",
65  "FREEZING",
66  "HEATING",
67  "MIXING"};
68 
69 typedef struct ELEMENT
70 {
71  char element_symbol[2];
72  int element_number;
73  double element_mass;
74 }ELEMENT;
75 
76 typedef struct SPECIES
77 {
78  char species_symbol[64];
79  int charge;
80  double *elements;
81  double thermo_coeff[7];
82 }SPECIES;
83 
84 typedef struct IIBINPARAM
85 {
86  char species_s1[64];
87  char species_s2[64];
88  double alpha;
89  double alpha1;
90  double B0ss[6];
91  double B1ss[6];
92 }IIBINPARAM;
93 
94 typedef struct NNBINPARAM
95 {
96  char species_s1[64];
97  char species_s2[64];
98  double Wss[6];
99  double Uss[6];
100 }NNBINPARAM;
101 
102 typedef struct NIITERPARAM
103 {
104  char species_s1[64];
105  char species_s2[64];
106  char species_s3[64];
107  double Wsss[6];
108  double Usss[6];
109  double Vsss[6];
110 }NIITERPARAM;
111 
112 typedef struct IIITERPARAM
113 {
114  char species_s1[64];
115  char species_s2[64];
116  char species_s3[64];
117  double Wsss[6];
118 }IIITERPARAM;
119 
120 typedef struct NIIIQUAPARAM
121 {
122  char species_s1[64];
123  char species_s2[64];
124  char species_s3[64];
125  char species_s4[64];
126  double Qssss[6];
127  double Yssss[6];
128 }NIIIQUAPARAM;
129 
130 typedef struct NNIIQUAPARAM
131 {
132  char species_s1[64];
133  char species_s2[64];
134  char species_s3[64];
135  char species_s4[64];
136  double Yssss[6];
137 }NNIIQUAPARAM;
138 
139 typedef struct SUBRPARAM
140 {
141  char species_a[64];
142  char species_b[64];
143  double A0;
144  double A1;
145 }SUBRPARAM;
146 
147 typedef struct GAS_PHASE
148 {
149  int species_num;
150  SPECIES *gas_species;
151 }GAS_PHASE;
152 
153 typedef struct AQUEOUS_PHASE
154 {
155  int species_num;
156  SPECIES *aqueous_species;
157  int ii_bin_param_num;
158  IIBINPARAM *ii_bin_params;
159  int nn_bin_param_num;
160  NNBINPARAM *nn_bin_params;
161  int nii_ter_param_num;
162  NIITERPARAM *nii_ter_params;
163  int iii_ter_param_num;
164  IIITERPARAM *iii_ter_params;
165  int niii_qua_param_num;
166  NIIIQUAPARAM *niii_qua_params;
167  int nnii_qua_param_num;
168  NNIIQUAPARAM *nnii_qua_params;
170 
171 typedef struct SOLID_PHASE
172 {
173  int species_num;
174  SPECIES *solid_species;
175 }SOLID_PHASE;
176 
177 typedef struct SOLIDSOLUTION_PHASE
178 {
179  int species_num;
180  SPECIES *solidsolution_species;
181  int param_num;
182  SUBRPARAM *params;
184 
185 typedef struct PHASES
186 {
187  GAS_PHASE *gas;
188  AQUEOUS_PHASE *aqueous;
189  SOLID_PHASE *solids;
190  SOLIDSOLUTION_PHASE *solidsolution;
191 }PHASES;
192 
193 typedef struct EXPAW
194 {
195  double T;
196  double P;
197  int index;
198  double *component;
199  double value;
200  double sigma;
201 }EXPAW;
202 
203 typedef struct EXPPH
204 {
205  double T;
206  double P;
207  int index;
208  double *component;
209  double value;
210  double sigma;
211 }EXPPH;
212 
213 typedef struct EXPSOL
214 {
215  double T;
216  double P;
217  double *component;
218  int index;
219  double *species;
220  double lnk;
221  double sigma;
222 }EXPSOL;
223 
224 typedef struct EXPSP
225 {
226  double T;
227  double P;
228  int index;
229  double *species;
230  double value;
231  double sigma;
232 }EXPSP;
233 
234 typedef struct FITPARAM
235 {
236  double value;
237  int aq_index;
242 }FITPARAM;
243 
244 int total_comp_num; // component number
248 int solidsolution_phase_num; // solid solution phase number
249 int total_phase_num; // solid phase number
250 int total_species_num; // total species number
251 
252 char block_keyword[32]; //
253 char phase_keyword[32]; //
254 
257 
258 double **coeff_matrix; // coeffcients matrix
259 
260 double system_T; // temperature system
261 double system_P; // system pressure
262 double system_charge; // system total charge
263 double *total_components; // total components given initally
264 
265 double *n_eq; // molal number of species in equilibrium
266 double **naq_eq;
267 double gibbs_eq; // Total Gibbs energy of the whole system in equilibrium
268 bool successed; // Gibbs energy minimization successed flag
269 
270 int total_param_num; // total parameter number
271 
272 int total_exp_aw_num; // water activity experimental data number
273 int total_exp_ph_num; // ph experimental data number
274 int total_exp_sp_num; // species experimental data number
275 int total_exp_r_num; // mean ionic activity coefficient experimental data number
276 int total_exp_l_num; // apparent relative molar enthalpy experimental data number
277 int total_exp_dilh_num; // enthalpy of dilution experimental data number
278 int total_exp_cp_num; // apparent molar heat capacity experimental data number
279 int total_exp_alpha_num; // degree of dissociation experimental data number
280 int total_exp_sol_num; // solubility experimental data number
281 
284 
289 
290 /*
291  * load databank
292  * input: databank file name
293  * temp: temp file name
294  */
295 extern bool load_db (char *input, char *temp);
296 
297 extern bool load_exp (char *exp);
298 
299 extern bool test_load ();
300 
301 extern bool test_models ();
302 
303 extern double psc_r (AQUEOUS_PHASE aq, int index, double *n, double T, double P);
304 
305 extern double psc_a (AQUEOUS_PHASE aq, int index, double *n, double T, double P);
306 
307 extern double rkg_a (SOLIDSOLUTION_PHASE ss, int index, double *n, double T, double P);
308 
316 extern int gem_ipopt ();
double system_T
Definition: islre.h:260
int param_sub_type
Definition: islre.h:240
double sigma
Definition: islre.h:231
struct SOLIDSOLUTION_PHASE SOLIDSOLUTION_PHASE
struct EXPAW EXPAW
char PHASE_KEYWORDS[4][64]
Definition: islre.h:57
int total_species_num
Definition: islre.h:250
struct ELEMENT ELEMENT
int index
Definition: islre.h:218
char block_keyword[32]
Definition: islre.h:252
struct EXPSOL EXPSOL
double rkg_a(SOLIDSOLUTION_PHASE ss, int index, double *n, double T, double P)
Definition: rkg_model.c:99
int index
Definition: islre.h:207
EXPSP * expsp
Definition: islre.h:288
double sigma
Definition: islre.h:221
double T
Definition: islre.h:215
double system_charge
Definition: islre.h:262
bool test_models()
Definition: test_models.c:30
int param_type
Definition: islre.h:238
struct FITPARAM FITPARAM
double T
Definition: islre.h:226
int solidsolution_phase_num
Definition: islre.h:248
int element_number
Definition: islec.h:73
struct GAS_PHASE GAS_PHASE
double value
Definition: islre.h:209
double value
Definition: islre.h:199
double * species
Definition: islre.h:219
int param_index
Definition: islre.h:239
struct PHASES PHASES
bool load_exp(char *exp)
Definition: load_exp.c:32
struct SOLID_PHASE SOLID_PHASE
int total_exp_alpha_num
Definition: islre.h:279
double psc_a(AQUEOUS_PHASE aq, int index, double *n, double T, double P)
Definition: psc_model.c:3496
int total_phase_num
Definition: islre.h:249
double ** coeff_matrix
Definition: islre.h:258
double T
Definition: islre.h:195
int total_exp_l_num
Definition: islre.h:276
struct NIITERPARAM NIITERPARAM
double * n_eq
Definition: islre.h:265
Definition: islre.h:213
double * species
Definition: islre.h:229
double ** naq_eq
Definition: islre.h:266
double lnk
Definition: islre.h:220
bool load_db(char *input, char *temp)
Definition: load_db.c:718
double P
Definition: islre.h:227
bool test_load()
Definition: test_load.c:31
double * component
Definition: islre.h:208
double sigma
Definition: islre.h:200
int total_exp_sol_num
Definition: islre.h:280
struct EXPSP EXPSP
char BLOCK_KEYWORDS[2][64]
Definition: islre.h:53
Definition: islec.h:186
char phase_keyword[32]
Definition: islre.h:253
double P
Definition: islre.h:196
bool successed
Definition: islre.h:268
struct IIBINPARAM IIBINPARAM
Definition: islec.h:77
PHASES phases
Definition: islre.h:256
double * total_components
Definition: islre.h:263
int total_exp_sp_num
Definition: islre.h:274
struct NNIIQUAPARAM NNIIQUAPARAM
int aq_index
Definition: islre.h:237
double value
Definition: islre.h:236
struct SPECIES SPECIES
int fitted_param_num
Definition: islre.h:282
int gem_ipopt()
Perform Gibbs energy minimization (GEM) using the IPOPT algrithium.
Definition: gem_ipopt.c:180
double * component
Definition: islre.h:217
double sigma
Definition: islre.h:210
int solid_phase_num
Definition: islre.h:247
struct NIIIQUAPARAM NIIIQUAPARAM
double * component
Definition: islre.h:198
int total_comp_num
Definition: islre.h:244
EXPAW * expaw
Definition: islre.h:285
EXPSOL * expsol
Definition: islre.h:286
double element_mass
Definition: islec.h:74
Definition: islec.h:70
int total_exp_aw_num
Definition: islre.h:272
double psc_r(AQUEOUS_PHASE aq, int index, double *n, double T, double P)
Definition: psc_model.c:3483
char PROCESS[5][64]
Definition: islre.h:63
char element_symbol[2]
Definition: islec.h:72
int aqueous_phase_num
Definition: islre.h:246
int index
Definition: islre.h:197
Definition: islre.h:203
double system_P
Definition: islre.h:261
double T
Definition: islre.h:205
struct AQUEOUS_PHASE AQUEOUS_PHASE
struct SUBRPARAM SUBRPARAM
int coeff_index
Definition: islre.h:241
FITPARAM * fitted_param
Definition: islre.h:283
int total_param_num
Definition: islre.h:270
int total_exp_cp_num
Definition: islre.h:278
double value
Definition: islre.h:230
int gas_phase_num
Definition: islre.h:245
int total_exp_ph_num
Definition: islre.h:273
int total_exp_r_num
Definition: islre.h:275
struct IIITERPARAM IIITERPARAM
EXPPH * expph
Definition: islre.h:287
int total_exp_dilh_num
Definition: islre.h:277
ELEMENT * components
Definition: islre.h:255
struct EXPPH EXPPH
double P
Definition: islre.h:216
double gibbs_eq
Definition: islre.h:267
Definition: islre.h:193
double P
Definition: islre.h:206
struct NNBINPARAM NNBINPARAM
int index
Definition: islre.h:228
Definition: islre.h:224