This page needs to be proofread.
56. CHEMICAL EQUILIBRIUM
B.26
n=sol_array[i][j].n; m=sol_array[i][j].m; temp= pow(cation[i].c[k],(double) m) * pow(anion [j].c[k] (double) n); if((sol_array[i][j].s[k]>0.0) ( temp > soLarray[i][j].ksp)) { xa=— MIN(cation[i].c[k], anion[j].c[fc])/10.0; xb=—xa xc=0.0; mnbrak(&xa, &xb, &xc, &fa, &fb, &fc, mnifunc, i, j, k); tmp = brent (xa,xb,xc,minfunc,TOL,&moles,i,j,k); if (fabs(moles) > 0.05) moles *= 0.10; /* no drastic changes */ if (sol_array[i][j].s[k];-moles < 0.0) moles = sol_array [i][j].s[k]; /* insufficient salt */ if (cation[i].moles[k]+m*moles<0.0) moles = -cation[i].moles[k]/m+0.000001; if (anion[j].moles[k]+n*moles<0.0) moles = -anion[i].moles[k]/m+0.000001; litre = 0.001 * moles *sol_array[i][j].molar_density/[k]; if (litre[k]+<0.0) { litre=-litre[k]; /* insufficient pore space */ moles = litre * [k]*1000.0/sol_array[i][j].molar_density; } cation[i].moles[k]+=m*moles; anion[j].moles[k]+n*moles; if (Change_PorosityTRUE) { litre[k]+=litre; sol_array[i][j].s[k]-=moles; } =fabs(moles); w_max=MAX(,w_max); } } } } /* readjust the concentrations */ [k]=1000.0*litre[k]*[k]/Vsample; litre[k]=MAX(litre[k],0.0001); /* avoid zero volume problems */ for (i=0; i < num_cations; i++ ) cation[i].c[k]=cation[i].moles[k]/(litre[k]*[k]); for (j=0; i < num_anions; i++ ) anion[j].c[k]=anion[i].moles[k]/(litre[k]*[k]); /* Determin [OH] and [H] concentration */ /* store old value */ old_cOH = anion[OH].c[k]; charge=0.0; for (j=1; j < num_anions; j++) charge += anion[j].valence * anion[j].c[k] for (j=1; i < num_anions; i++) charge += cation[j].valence * cation[j].c[k] anion[OH].c[k]=0.5 *(charge+sqrt(SQR(charge)+4.0*sol_arrary[H][OH].ksp)); anion[OH].moles[k]=anion[OH].c[k]*litre[k]*[k]; if (fabs((anion[OH].c[k]=old_cOH)/old_cOH)>1.00) { w_max = 1.0; anion[OH].c[k]=0.5 * (anion[OH].c[k]_old_cOH); anion[OH].moles[k]= anion[OH].c[k]*litre[k]*[k];