56. Chemical equilibrium.
Given the number density of ions in a computational element, determine if any of the ions should go in to/out of solution. Determine the pH and adjust H and OH, accordingly.
⟨Function declarations 23⟩
void chemical_equilibrium (boolean);
57. Minimizing function. This is the function to minimize for the chemical_equilibrium routine. The objective of chemical-equilibrium is to determine how many moles of salt should be leached/precipitated. Therefore, minfunc must adjust for the pore volume. The equation minfunc is minimizing the square of
where is moles salt, and are stoichiometric ratios, and is the pore solution volume,
real minfunc(real, int, int, int); real minfunc(real x,int i,int j,int k) { real C, A; int m, n; m = sol_array[i][j].m n = soLarray[i][j].n C = cation[i].c[k]-, A = anion [j].c[k]-, return SQR(potr(C+m*x/(litre[k] * [k]),m) * pow(A + n * x/(litre[k] * [k]), n) — sol-array [i][j].ksp); }
58. chemical_equilibrium(). Cycle through sol.array and determine if any ions should go in to/out of solution based upon the concentration, the solubility constant, and the presence of solid salt.
#defineTOL void chemical-equilibrium (boolean Change_Porosity) { int i, j, k, n, m, iterations; real w_max ; real xa, xb, xc, fa, fb, fc, moles, tmp; real dsolid; real litre; /* change in pore volume */ real old_cOH; real charge,temp; boolean NEG_FLAG; for (k= FIRST_CELL+1; k< NUM.SURFACES; k++) { iterations = 0; do { w_max = 0.0; for (j=0; j < num-amons j++) { for (i =0; i < num-cations-, i++) { if ((i0j 0)) {