ISLEC  Version 4.2
gsl_reg.c
Go to the documentation of this file.
1 /* src/gsl_reg.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 #include <gsl/gsl_rng.h>
33 #include <gsl/gsl_randist.h>
34 #include <gsl/gsl_vector.h>
35 #include <gsl/gsl_blas.h>
36 #include <gsl/gsl_multifit_nlin.h>
37 
38 struct DATA_POINT {
39  size_t n;
43 };
44 
45 void
46 print_state (size_t iter, gsl_multifit_fdfsolver *s)
47 {
48  int i;
49  printf ("iter: %4lu |f(x)| = %g\n",
50  iter, gsl_blas_dnrm2 (s->f));
51 
52  for (i = 0; i < fitted_param_num; i ++)
53  {
54  printf ("%0.10E\n", gsl_vector_get (s->x, i));
55  }
56 }
57 
59 {
60  int species_num_index = 0;
61 
62  int i;
63  for (i = 0; i < gas_phase_num; i ++)
64  {
65  species_num_index += phases.gas[i].species_num;
66  }
67 
68  for (i = 0; i < aqueous_phase_num; i ++)
69  {
70  int j;
71 
72  for (j = 0; j < phases.aqueous[i].species_num; j++)
73  {
74  naq_eq[i][j] = n_eq[j + species_num_index];
75  }
76 
77  species_num_index += phases.aqueous[i].species_num;
78  }
79 }
80 
82 {
83  int i, j, k;
84 
85  fitted_param = (FITPARAM *)malloc (sizeof (FITPARAM) * fitted_param_num);
86 
87  int index = 0;
88 
89  for (i = 0; i < aqueous_phase_num; i ++)
90  {
91  for (j = 0; j < phases.aqueous[i].ii_bin_param_num; j ++)
92  {
93  if (phases.aqueous[i].ii_bin_params[j].alpha > 0 &&
94  phases.aqueous[i].ii_bin_params[j].alpha < 1.0E-20)
95  {
96  fitted_param[index].value = 0.0;
97  fitted_param[index].aq_index = i;
98  fitted_param[index].param_type = 0;
99  fitted_param[index].param_index = j;
100  fitted_param[index].param_sub_type = 0;
101  fitted_param[index].coeff_index = 0;
102 
103  index ++;
104  }
105  if (phases.aqueous[i].ii_bin_params[j].alpha1 > 0 &&
106  phases.aqueous[i].ii_bin_params[j].alpha1 < 1.0E-20)
107  {
108  fitted_param[index].value = 0.0;
109  fitted_param[index].aq_index = i;
110  fitted_param[index].param_type = 0;
111  fitted_param[index].param_index = j;
112  fitted_param[index].param_sub_type = 1;
113  fitted_param[index].coeff_index = 0;
114 
115  index ++;
116  }
117 
118  for (k = 0; k < 6; k ++)
119  {
120  if (phases.aqueous[i].ii_bin_params[j].B0ss[k] > 0 &&
121  phases.aqueous[i].ii_bin_params[j].B0ss[k] < 1.0E-20)
122  {
123  fitted_param[index].value = 0.0;
124  fitted_param[index].aq_index = i;
125  fitted_param[index].param_type = 0;
126  fitted_param[index].param_index = j;
127  fitted_param[index].param_sub_type = 2;
128  fitted_param[index].coeff_index = k;
129 
130  index ++;
131  }
132  if (phases.aqueous[i].ii_bin_params[j].B1ss[k] > 0 &&
133  phases.aqueous[i].ii_bin_params[j].B1ss[k] < 1.0E-20)
134  {
135  fitted_param[index].value = 0.0;
136  fitted_param[index].aq_index = i;
137  fitted_param[index].param_type = 0;
138  fitted_param[index].param_index = j;
139  fitted_param[index].param_sub_type = 3;
140  fitted_param[index].coeff_index = k;
141 
142  index ++;
143  }
144  }
145  }
146 
147  for (j = 0; j < phases.aqueous[i].nn_bin_param_num; j ++)
148  {
149  for (k = 0; k < 6; k ++)
150  {
151  if (phases.aqueous[i].nn_bin_params[j].Wss[k] > 0 &&
152  phases.aqueous[i].nn_bin_params[j].Wss[k] < 1.0E-20)
153  {
154  fitted_param[index].value = 0.0;
155  fitted_param[index].aq_index = i;
156  fitted_param[index].param_type = 1;
157  fitted_param[index].param_index = j;
158  fitted_param[index].param_sub_type = 0;
159  fitted_param[index].coeff_index = k;
160 
161  index ++;
162  }
163  if (phases.aqueous[i].nn_bin_params[j].Uss[k] > 0 &&
164  phases.aqueous[i].nn_bin_params[j].Uss[k] < 1.0E-20)
165  {
166  fitted_param[index].value = 0.0;
167  fitted_param[index].aq_index = i;
168  fitted_param[index].param_type = 1;
169  fitted_param[index].param_index = j;
170  fitted_param[index].param_sub_type = 1;
171  fitted_param[index].coeff_index = k;
172 
173  index ++;
174  }
175  }
176  }
177 
178  for (j = 0; j < phases.aqueous[i].nii_ter_param_num; j ++)
179  {
180  for (k = 0; k < 6; k ++)
181  {
182  if (phases.aqueous[i].nii_ter_params[j].Wsss[k] > 0 &&
183  phases.aqueous[i].nii_ter_params[j].Wsss[k] < 1.0E-20)
184  {
185  fitted_param[index].value = 0.0;
186  fitted_param[index].aq_index = i;
187  fitted_param[index].param_type = 2;
188  fitted_param[index].param_index = j;
189  fitted_param[index].param_sub_type = 0;
190  fitted_param[index].coeff_index = k;
191 
192  index ++;
193  }
194  if (phases.aqueous[i].nii_ter_params[j].Usss[k] > 0 &&
195  phases.aqueous[i].nii_ter_params[j].Usss[k] < 1.0E-20)
196  {
197  fitted_param[index].value = 0.0;
198  fitted_param[index].aq_index = i;
199  fitted_param[index].param_type = 2;
200  fitted_param[index].param_index = j;
201  fitted_param[index].param_sub_type = 1;
202  fitted_param[index].coeff_index = k;
203 
204  index ++;
205  }
206 
207  if (phases.aqueous[i].nii_ter_params[j].Vsss[k] > 0 &&
208  phases.aqueous[i].nii_ter_params[j].Vsss[k] < 1.0E-20)
209  {
210  fitted_param[index].value = 0.0;
211  fitted_param[index].aq_index = i;
212  fitted_param[index].param_type = 2;
213  fitted_param[index].param_index = j;
214  fitted_param[index].param_sub_type = 2;
215  fitted_param[index].coeff_index = k;
216 
217  index ++;
218  }
219  }
220  }
221 
222  for (j = 0; j < phases.aqueous[i].iii_ter_param_num; j ++)
223  {
224  for (k = 0; k < 6; k ++)
225  {
226  if (phases.aqueous[i].iii_ter_params[j].Wsss[k] > 0 &&
227  phases.aqueous[i].iii_ter_params[j].Wsss[k] < 1.0E-20)
228  {
229  fitted_param[index].value = 0.0;
230  fitted_param[index].aq_index = i;
231  fitted_param[index].param_type = 3;
232  fitted_param[index].param_index = j;
233  fitted_param[index].param_sub_type = 0;
234  fitted_param[index].coeff_index = k;
235 
236  index ++;
237  }
238  }
239  }
240 
241  for (j = 0; j < phases.aqueous[i].niii_qua_param_num; j ++)
242  {
243  for (k = 0; k < 6; k ++)
244  {
245  if (phases.aqueous[i].niii_qua_params[j].Qssss[k] > 0 &&
246  phases.aqueous[i].niii_qua_params[j].Qssss[k] < 1.0E-20)
247  {
248  fitted_param[index].value = 0.0;
249  fitted_param[index].aq_index = i;
250  fitted_param[index].param_type = 4;
251  fitted_param[index].param_index = j;
252  fitted_param[index].param_sub_type = 0;
253  fitted_param[index].coeff_index = k;
254 
255  index ++;
256  }
257 
258  if (phases.aqueous[i].niii_qua_params[j].Yssss[k] > 0 &&
259  phases.aqueous[i].niii_qua_params[j].Yssss[k] < 1.0E-20)
260  {
261  fitted_param[index].value = 0.0;
262  fitted_param[index].aq_index = i;
263  fitted_param[index].param_type = 4;
264  fitted_param[index].param_index = j;
265  fitted_param[index].param_sub_type = 1;
266  fitted_param[index].coeff_index = k;
267 
268  index ++;
269  }
270  }
271  }
272 
273  for (j = 0; j < phases.aqueous[i].nnii_qua_param_num; j ++)
274  {
275  for (k = 0; k < 6; k ++)
276  {
277  if (phases.aqueous[i].nnii_qua_params[j].Yssss[k] > 0 &&
278  phases.aqueous[i].nnii_qua_params[j].Yssss[k] < 1.0E-20)
279  {
280  fitted_param[index].value = 0.0;
281  fitted_param[index].aq_index = i;
282  fitted_param[index].param_type = 5;
283  fitted_param[index].param_index = j;
284  fitted_param[index].param_sub_type = 0;
285  fitted_param[index].coeff_index = k;
286 
287  index ++;
288  }
289  }
290  }
291  }
292 
293  if (index != fitted_param_num)
294  {
295  printf ("Inconsistent Fitted Parameter Number!!!\n");
296  exit (0);
297  }
298 }
299 
300 void renew_fitted_params (const gsl_vector *x)
301 {
302  int i;
303 
304  for (i = 0; i < fitted_param_num; i ++)
305  {
306  fitted_param[i].value = gsl_vector_get(x, i);
307  }
308 
309  for (i = 0; i < fitted_param_num; i ++)
310  {
311  switch (fitted_param[i].param_type)
312  {
313  case 0: // ii
314  {
315  if (fitted_param[i].param_sub_type == 0)
316  {
318  }
319  if (fitted_param[i].param_sub_type == 1)
320  {
322  }
323  if (fitted_param[i].param_sub_type == 2)
324  {
326  }
327  if (fitted_param[i].param_sub_type == 3)
328  {
330  }
331 
332  break;
333  }
334  case 1: // nn
335  {
336  if (fitted_param[i].param_sub_type == 0)
337  {
339  }
340  if (fitted_param[i].param_sub_type == 1)
341  {
343  }
344 
345  break;
346  }
347  case 2: // nii
348  {
349  if (fitted_param[i].param_sub_type == 0)
350  {
352  }
353  if (fitted_param[i].param_sub_type == 1)
354  {
356  }
357  if (fitted_param[i].param_sub_type == 2)
358  {
360  }
361 
362  break;
363  }
364  case 3: // iii
365  {
366  if (fitted_param[i].param_sub_type == 0)
367  {
369  }
370 
371  break;
372  }
373  case 4: // niii
374  {
375  if (fitted_param[i].param_sub_type == 0)
376  {
378  }
379  if (fitted_param[i].param_sub_type == 1)
380  {
382  }
383 
384  break;
385  }
386  case 5: // nnii
387  {
388  if (fitted_param[i].param_sub_type == 0)
389  {
391  }
392 
393  break;
394  }
395  }
396  }
397 }
398 
399 double objfun (const gsl_vector *x, void *data_point, int i)
400 {
401  int exp_sum = 0;
402  double OF = 0;
403 
405 
406  if (i < total_exp_aw_num)
407  {
408  EXPAW *expaw = ((struct DATA_POINT *)data_point)->expaw;
409 
410  int j, k;
411 
412  n_eq = (double *)malloc (sizeof(double) * total_species_num);
413  for (k = 0; k < total_species_num; k ++)
414  {
415  n_eq[k] = 1.0e-10;
416  }
417 
418  system_T = expaw[i].T;
419  system_P = expaw[i].P;
420  system_charge = 0;
421 
422  for (j = 0; j < total_comp_num; j ++)
423  {
424  total_components[j] = expaw[i].component[j];
425  }
426 
427  // speciation equilibrium
428  gem_ipopt ();
429  if (!successed) {return 0.0;}
430 
432 
433  for (k = 0; k < phases.aqueous[expaw[i].index].species_num; k ++)
434  {
435  if (phases.aqueous[expaw[i].index].aqueous_species[k].charge == 0 &&
436  strcmp (phases.aqueous[expaw[i].index].aqueous_species[k].species_symbol, WATER_SYMBOL) == 0)
437  {
438  break;
439  }
440  }
441 
442  double aw = psc_a (phases.aqueous[expaw[i].index], k, naq_eq[expaw[i].index], expaw[i].T, expaw[i].P);
443 
444  OF = 1.0/expaw[i].sigma * (log(aw) - log(expaw[i].value));
445  }
446 
447  exp_sum += total_exp_aw_num;
448  if (i >= exp_sum && i < exp_sum + total_exp_ph_num)
449  {
450  EXPPH *expph = ((struct DATA_POINT *)data_point)->expph;
451 
452  int j, k;
453 
454  n_eq = (double *)malloc (sizeof(double) * total_species_num);
455  for (k = 0; k < total_species_num; k ++)
456  {
457  n_eq[k] = 1.0e-10;
458  }
459 
460  system_T = expph[i - exp_sum].T;
461  system_P = expph[i - exp_sum].P;
462  system_charge = 0;
463 
464  for (j = 0; j < total_comp_num; j ++)
465  {
466  total_components[j] = expph[i - exp_sum].component[j];
467  }
468 
469  // speciation equilibrium
470  gem_ipopt ();
471  if (!successed) {return 0.0;}
472 
474 
475  for (k = 0; k < phases.aqueous[expph[i - exp_sum].index].species_num; k ++)
476  {
477  if (phases.aqueous[expph[i - exp_sum].index].aqueous_species[k].charge != 0 &&
478  strcmp (phases.aqueous[expph[i - exp_sum].index].aqueous_species[k].species_symbol, H_SYMBOL) == 0)
479  {
480  break;
481  }
482  }
483 
484  double ah = psc_a (phases.aqueous[expph[i - exp_sum].index], k, naq_eq[expph[i - exp_sum].index], expph[i - exp_sum].T, expph[i - exp_sum].P);
485 
486  OF = 1.0/expph[i].sigma * (-log(ah)/log(10) - expph[i - exp_sum].value);
487  }
488 
489  exp_sum += total_exp_ph_num;
490  if (i >= exp_sum && i < exp_sum + total_exp_sol_num)
491  {
492  EXPSOL *expsol = ((struct DATA_POINT *)data_point)->expsol;
493 
494  int j, k;
495 
496  n_eq = (double *)malloc (sizeof(double) * total_species_num);
497  for (k = 0; k < total_species_num; k ++)
498  {
499  n_eq[k] = 1.0e-10;
500  }
501 
502  system_T = expsol[i - exp_sum].T;
503  system_P = expsol[i - exp_sum].P;
504  system_charge = 0;
505 
506  for (j = 0; j < total_comp_num; j ++)
507  {
508  total_components[j] = expsol[i - exp_sum].component[j];
509  }
510 
511  // speciation equilibrium
512  gem_ipopt ();
513  if (!successed) {return 0.0;}
514 
516 
517  double *ai = (double *)malloc(sizeof (double) * phases.aqueous[expsol[i - exp_sum].index].species_num);
518 
519  for (k = 0; k < phases.aqueous[expsol[i - exp_sum].index].species_num; k ++)
520  {
521  ai[k] = psc_a (phases.aqueous[expsol[i - exp_sum].index], k,
522  naq_eq[expsol[i - exp_sum].index],
523  expsol[i - exp_sum].T,
524  expsol[i - exp_sum].P);
525 
526  OF += (log(ai[k])) * expsol[i - exp_sum].species[k];
527  }
528 
529  OF = 1.0/expsol[i - exp_sum].sigma * (OF - expsol[i - exp_sum].lnk);
530  }
531 
532  return OF;
533 }
534 
535 int objfun_f (const gsl_vector *x, void *data_point, gsl_vector *f)
536 {
537  EXPAW *expaw = ((struct DATA_POINT *)data_point)->expaw;
538  EXPPH *expph = ((struct DATA_POINT *)data_point)->expph;
539  EXPSOL *expsol = ((struct DATA_POINT *)data_point)->expsol;
540 
541  double Pi;
542  int i, j, k;
543  int exp_sum = 0;
544 
545  n_eq = (double *)malloc (sizeof(double) * total_species_num);
546  for (k = 0; k < total_species_num; k ++)
547  {
548  n_eq[k] = 1.0e-10;
549  }
550 
552 
553  for (i = 0; i < total_exp_aw_num; i ++)
554  {
555  Pi = 0;
556  system_T = expaw[i].T;
557  system_P = expaw[i].P;
558  system_charge = 0;
559 
560  for (j = 0; j < total_comp_num; j ++)
561  {
562  total_components[j] = expaw[i].component[j];
563  }
564 
565  // speciation equilibrium
566  gem_ipopt ();
567  //print_results ();
568 
570 
571  for (k = 0; k < phases.aqueous[expaw[i].index].species_num; k ++)
572  {
573  if (phases.aqueous[expaw[i].index].aqueous_species[k].charge == 0 &&
574  strcmp (phases.aqueous[expaw[i].index].aqueous_species[k].species_symbol, WATER_SYMBOL) == 0)
575  {
576  break;
577  }
578  }
579 
580  double aw = psc_a (phases.aqueous[expaw[i].index], k, naq_eq[expaw[i].index], expaw[i].T, expaw[i].P);
581 
582  Pi = 1.0/expaw[i].sigma * (log(aw) - log(expaw[i].value));
583 
584  if (!successed) {Pi = 0.0;}
585 
586  gsl_vector_set (f, i+exp_sum, Pi);
587  }
588 
589  exp_sum += total_exp_aw_num;
590  for (i = 0; i < total_exp_ph_num; i ++)
591  {
592  Pi = 0;
593  system_T = expph[i].T;
594  system_P = expph[i].P;
595  system_charge = 0;
596 
597  for (j = 0; j < total_comp_num; j ++)
598  {
599  total_components[j] = expph[i].component[j];
600  }
601 
602  // speciation equilibrium
603  gem_ipopt ();
604  //print_results ();
605 
607 
608  for (k = 0; k < phases.aqueous[expph[i].index].species_num; k ++)
609  {
610  if (phases.aqueous[expph[i].index].aqueous_species[k].charge != 0 &&
611  strcmp (phases.aqueous[expph[i].index].aqueous_species[k].species_symbol, H_SYMBOL) == 0)
612  {
613  break;
614  }
615  }
616 
617  double ah = psc_a (phases.aqueous[expph[i].index], k, naq_eq[expph[i].index], expph[i].T, expph[i].P);
618 
619  Pi = 1.0/expph[i].sigma * (-log(ah)/log(10) - expph[i].value);
620 
621  gsl_vector_set (f, i + exp_sum, Pi);
622  }
623 
624  exp_sum += total_exp_ph_num;
625  for (i = 0; i < total_exp_sol_num; i ++)
626  {
627  Pi = 0;
628  system_T = expsol[i].T;
629  system_P = expsol[i].P;
630  system_charge = 0;
631 
632  for (j = 0; j < total_comp_num; j ++)
633  {
634  total_components[j] = expsol[i].component[j];
635  }
636 
637  // speciation equilibrium
638  gem_ipopt ();
639 
641 
642  double *ai = (double *)malloc(sizeof (double) * phases.aqueous[expsol[i].index].species_num);
643 
644  for (k = 0; k < phases.aqueous[expsol[i].index].species_num; k ++)
645  {
646  ai[k] = psc_a (phases.aqueous[expsol[i].index], k,
647  naq_eq[expsol[i].index],
648  expsol[i].T,
649  expsol[i].P);
650 
651  Pi += (log(ai[k])) * expsol[i].species[k];
652  }
653 
654  Pi = 1.0/expsol[i].sigma * (Pi - expsol[i].lnk);
655 
656  if (!successed) {Pi = 0.0;}
657 
658  gsl_vector_set (f, i + exp_sum, Pi);
659  }
660 
661  return GSL_SUCCESS;
662 }
663 
664 int objfun_df (const gsl_vector *x, void *data_point, gsl_matrix *J)
665 {
666  double h = 1.0e-6;
667  double F1, F2;
668  int i, j;
669 
670  for (i = 0; i < total_exp_aw_num + total_exp_ph_num + total_exp_sol_num; i ++)
671  {
672  for (j = 0; j < fitted_param_num; j ++)
673  {
674  F1 = objfun (x, data_point, i);
675 
676  x->data[j] = x->data[j] + h;
677  F2 = objfun (x, data_point, i);
678 
679  double Jij = (F2 - F1) / h;
680 
681  if (F2 == 0 || F1 == 0) {Jij = 0;}
682 
683  gsl_matrix_set (J, i, j, Jij);
684 
685  //printf ("%d\t%d\t%lf\n", i, j, Jij);
686  }
687  }
688 
689  return GSL_SUCCESS;
690 }
691 
692 int objfun_fdf (const gsl_vector *x, void *data_point, gsl_vector *f, gsl_matrix *J)
693 {
694  objfun_f (x, data_point, f);
695  objfun_df (x, data_point, J);
696 
697  return GSL_SUCCESS;
698 }
699 
700 void gsl_reg()
701 {
703 
704  const gsl_multifit_fdfsolver_type *T = gsl_multifit_fdfsolver_lmsder;
705  gsl_multifit_fdfsolver *s;
706 
707  int iter = 1;
708  int status;
709  size_t i;
711  const size_t P = fitted_param_num;
712  double chi, chi0, dof;
713 
714  total_components = (double *)malloc(sizeof (double) * total_comp_num);
715  naq_eq = (double **)malloc(sizeof(double*) * aqueous_phase_num);
716 
717  for (i = 0; i < aqueous_phase_num; i ++)
718  {
719  naq_eq[i] = (double *)malloc(sizeof(double) * phases.aqueous[i].species_num);
720  }
721 
722  struct DATA_POINT d = {N, expaw, expph, expsol};
723 
724  double *x_init = (double *)malloc(sizeof (double) * P);
725 
726  for(i = 0; i < fitted_param_num; i ++)
727  {
728  x_init[i] = 1.0;
729  }
730 
731  gsl_vector_view x = gsl_vector_view_array (x_init, P);
732 
733  gsl_matrix *J = gsl_matrix_alloc (N, P);
734  gsl_multifit_function_fdf f;
735 
736  f.f = &objfun_f;
737  f.df = &objfun_df;
738  f.fdf = &objfun_fdf;
739  f.n = N;
740  f.p = P;
741  f.params = &d;
742 
743  s = gsl_multifit_fdfsolver_alloc (T, N, P);
744  gsl_multifit_fdfsolver_set (s, &f, &x.vector);
745  print_state (iter, s);
746 
747  do
748  {
749  iter ++;
750  status = gsl_multifit_fdfsolver_iterate (s);
751 
752  printf ("status = %s\n", gsl_strerror (status));
753 
754  print_state (iter, s);
755 
756  if (status)
757  break;
758 
759  status = gsl_multifit_test_delta (s->dx, s->x, 1.0e-4, 1.0e-4);
760  }
761  while (status == GSL_CONTINUE && iter < 1000);
762 
763  printf ("status = %s\n", gsl_strerror (status));
764 
765  chi = gsl_blas_dnrm2 (s->f); // 2 norm
766  dof = N - P; // degree of freedom
767 
768  printf ("OF = %g\n", sqrt(chi / dof));
769 
770  renew_fitted_params (s->x);
771 }
int param_sub_type
Definition: islre.h:240
int ii_bin_param_num
Definition: islec.h:158
size_t n
Definition: gsl_reg.c:39
AQUEOUS_PHASE * aqueous
Definition: islec.h:189
int index
Definition: islre.h:218
double B0ss[6]
Definition: islec.h:91
int objfun_fdf(const gsl_vector *x, void *data_point, gsl_vector *f, gsl_matrix *J)
Definition: gsl_reg.c:692
int index
Definition: islre.h:207
double sigma
Definition: islre.h:221
double T
Definition: islre.h:215
int species_num
Definition: islec.h:150
IIBINPARAM * ii_bin_params
Definition: islec.h:159
void renew_fitted_params(const gsl_vector *x)
Definition: gsl_reg.c:300
int param_type
Definition: islre.h:238
double Qssss[6]
Definition: islec.h:127
EXPSOL * expsol
Definition: gsl_reg.c:42
int species_num
Definition: islec.h:156
double * total_components
Definition: islec.h:213
double psc_a(AQUEOUS_PHASE aq, int index, double *n, double T, double P)
Definition: psc_model.c:3496
double value
Definition: islre.h:209
bool successed
Definition: islec.h:217
SPECIES * aqueous_species
Definition: islec.h:157
int param_index
Definition: islre.h:239
double Usss[6]
Definition: islec.h:109
int niii_qua_param_num
Definition: islec.h:166
double alpha
Definition: islec.h:89
double system_T
Definition: islec.h:210
NNBINPARAM * nn_bin_params
Definition: islec.h:161
double T
Definition: islre.h:195
Definition: islre.h:213
double ** naq_eq
Definition: islre.h:266
double lnk
Definition: islre.h:220
int objfun_f(const gsl_vector *x, void *data_point, gsl_vector *f)
Definition: gsl_reg.c:535
int charge
Definition: islec.h:80
double * component
Definition: islre.h:208
#define WATER_SYMBOL
Definition: islec.h:47
NIITERPARAM * nii_ter_params
Definition: islec.h:163
int gem_ipopt()
Perform Gibbs energy minimization (GEM) using the IPOPT algrithium.
Definition: gem_ipopt.c:180
void print_state(size_t iter, gsl_multifit_fdfsolver *s)
Definition: gsl_reg.c:46
double Wsss[6]
Definition: islec.h:118
double * n_eq
Definition: islec.h:215
GAS_PHASE * gas
Definition: islec.h:188
double sigma
Definition: islre.h:200
int nn_bin_param_num
Definition: islec.h:160
int total_exp_sol_num
Definition: islre.h:280
double system_P
Definition: islec.h:211
void set_aqueous_species()
Definition: gsl_reg.c:58
#define H_SYMBOL
Definition: islre.h:47
double P
Definition: islre.h:196
double objfun(const gsl_vector *x, void *data_point, int i)
Definition: gsl_reg.c:399
int aq_index
Definition: islre.h:237
double value
Definition: islre.h:236
int fitted_param_num
Definition: islre.h:282
double * component
Definition: islre.h:217
double sigma
Definition: islre.h:210
int objfun_df(const gsl_vector *x, void *data_point, gsl_matrix *J)
Definition: gsl_reg.c:664
double Wsss[6]
Definition: islec.h:108
double * component
Definition: islre.h:198
int aqueous_phase_num
Definition: islec.h:196
EXPPH * expph
Definition: gsl_reg.c:41
double Vsss[6]
Definition: islec.h:110
int init_fitted_params()
Definition: gsl_reg.c:81
EXPAW * expaw
Definition: gsl_reg.c:40
int total_exp_aw_num
Definition: islre.h:272
int index
Definition: islre.h:197
int total_species_num
Definition: islec.h:200
double B1ss[6]
Definition: islec.h:92
double Yssss[6]
Definition: islec.h:128
int nii_ter_param_num
Definition: islec.h:162
double Yssss[6]
Definition: islec.h:137
Definition: islre.h:203
IIITERPARAM * iii_ter_params
Definition: islec.h:165
double T
Definition: islre.h:205
void gsl_reg()
Definition: gsl_reg.c:700
NNIIQUAPARAM * nnii_qua_params
Definition: islec.h:169
PHASES phases
Definition: islec.h:206
int coeff_index
Definition: islre.h:241
char species_symbol[64]
Definition: islec.h:79
FITPARAM * fitted_param
Definition: islre.h:283
int total_comp_num
Definition: islec.h:194
double alpha1
Definition: islec.h:90
double system_charge
Definition: islec.h:212
int total_exp_ph_num
Definition: islre.h:273
NIIIQUAPARAM * niii_qua_params
Definition: islec.h:167
int iii_ter_param_num
Definition: islec.h:164
double P
Definition: islre.h:216
Definition: islre.h:193
int gas_phase_num
Definition: islec.h:195
int nnii_qua_param_num
Definition: islec.h:168
double P
Definition: islre.h:206
double Uss[6]
Definition: islec.h:100
double Wss[6]
Definition: islec.h:99