Description Usage Arguments Details Value Examples
View source: R/chemsolve_generic.R
Mass balance and charge balance solver for chemical equilibria. This is the workhorse for chemsolve and requires the prods function
1 2 3 |
solvent |
Symbols for solvent species (should not be changed for water) |
solvcharge |
Charges for solvent species (should not be changed for water) |
solva |
Ion size parameters (should not be changed for water) |
Ksoln |
log K of the solvent |
species |
Chemical symbols of the basis species |
conc |
Total concentrations of the basis species (mol/kg) |
a |
Ion size parameters for the basis species |
prod |
Dataframe detailing the derived species (Output from prods function) |
A |
A value |
B |
B value |
Bdot |
Bdot value is zero by default |
start |
Initial guess for the calculated equilibrium concentration of the basis species (in the same order as the solvent and then the species vectors) |
maxitr |
Maximum number of iterations |
bal |
The species to charge balance against (e.g. the default of "Cl") or NULL for none |
A generic function to add any basis species, product species or if the log K/temperature range need to be extended. Requires all parameters (e.g. log K at the given temperature). The temperature is indirectly set through the log K, A, B & Bdot values. These parameters need to be reinitialised each time, together with reactants and products, if a calculation across a range of temperatures is required. A useful upgrade would be to carry over defaults and use a lookup table and interpolation to initialise the parameters across a range of temperatures. This is similar to the wrapper function except that there the defaults are built in and cannot be changed by the casual user. For more details see chemsolve documentation.
A list containing the concentrations, gamma values, and pH at equilibrium
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## Define all the product species including KHSO4° FeSO4° and FeCl+
## which are not included as default species in chemsolve
## LogK are at 400°C and 0.5kb. Firsly parameters for the products are defined
prd=c("NaSO4","HSO4","KSO4","NaCl","KCl","HCl","KOH","NaOH","CaSO4",
"MgSO4","MgCl","CaCl","CaCl2","MgOH","CaOH","FeCl","FeSO4","KHSO4")
prdnms=c(2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,3)
prdconstit=c("Na","SO4","H","SO4","K",
"SO4","Na","Cl","K","Cl","H","Cl","K","OH","Na","OH","Ca","SO4","Mg","SO4","Mg","Cl",
"Ca","Cl","Ca","Cl","Cl","Mg","OH","Ca","OH","Fe","Cl","Fe","SO4","K","H","SO4")
prdK=c(-3.549,-7.444,-3.899,-1.737,-1.236,-2.689,-1.446,-1.164,-6.173,-6.014,-3.18,
-3.692,-4.783,-6.149,-5.635,-5.745,-3.814, -8.701)
prda=c(4,4,4,0,0,0,0,0,0,0,8,6,0,8,6,6,0,0)
## product input is created with the prods function
products <- prods(names=prd,number=prdnms,species=prdconstit,K=prdK,a=prda)
## Starting species are defined for chemsolve
chspec=c("Na", "K", "Cl", "SO4", "Ca", "Mg", "Fe")
chconc=c(0.4, 0.2, 0.8, 0.2, 0.1, 0.1,0.1)
cha=c(4, 3,3.5, 4, 6, 8,6)
chc=c(1, 1, -1, -2, 2, 2,2)
## chemsolve is now run with the previously defined products
## Defaults include water as the solvent and a charge balance against Cl
## A & B are at 400°C and 0.5kb
chemsolve_generic(species = chspec, conc = chconc, a = cha, charges = chc, A = 1.8789,B = 0.423, Bdot = 0,
start = c(1e-06, 1e-05, 0.3, 0.1, 0.3,0.01, 0.001, 0.02,1e-8), prod = products)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.