TransWikia.com

ParametricNDSolveValue - Acid-Base equilibrium kinetics

Mathematica Asked by MSM on January 27, 2021

So Im trying to model the concentration profile of a diffusing species into a sphere in an acid-base equilibrium system. Although im getting a solution, Its not the values or the trends I expect. Is there a possibility that there is something wrong with the code that makes these results inaccurate. I cant find what’s wrong with the code.

Clear["Global`*"] 
(*constants*)
V = 1.4137*10^-8;(* volume*)  
S = 2.827*10^-5; (* surface area*)
pH = 7.5;



kc1 = 7.12*10^5;
pkc1 = 9.26;
c1out = 0.5;
c1rout = c1out*(10^(pH - pkc1)); 

kc2 = 8.45*10^6; 
pkc2 = 6.5; 
c2tot = 0.000190;

kw = 2.5*10^-5;
pkw = 14;

cPout = 10^-pH;


(*--------------------*)


eqns =
  {
   c1'[t] == -kc1*c1[t] + kc1*(10^pkc1)*c1r[t]*cP[t] ,
   c1r'[t] == 
    kc1*c1[t] - 
     kc1*(10^pkc1)*c1r[t]*cP[t] - (S/V)*pm*(c1r[t] - c1rout),
   
   
   c2'[t] == -kc2*c2[t] + kc2*(10^pkc2)*c2r[t]*cP[t],
   c2r'[t] == kc2*c2[t] - kc2*(10^pkc2)*c2r[t]*cP[t],
   
   cw'[t] == -kw*cw[t] + kw*(10^pkw)*cwr[t]*cP[t],
   cwr'[t] == kw*cw[t] - kw*(10^pkw)*cwr[t]*cP[t],
   
   cP'[t] == 
    kw*cw[t] - kw*(10^pkw)*cwr[t]*cP[t] + kc1*c1[t] - 
     kc1*(10^pkc1)*c1r[t]*cP[t] + kc2*c2[t] - 
     kc2*(10^pkc2)*c2r[t]*cP[t]};


init = {c1[0] == 0, c1r[0] == 0, 
   c2[0] == (c2tot)/(1 + 10^(pH - pkc2)), 
   c2r[0] == c2tot - ((c2tot)/(1 + 10^(pH - pkc2))), cw[0] == 55.5556,
    cwr[0] == 10^-(14 - pH), cP[0] == 10^-pH}; 

vars = {c1[t], c1r[t], c2[t], c2r[t], cw[t], cwr[t], cP[t]};


tmax = 2;
sol = ParametricNDSolveValue[{eqns, init}, vars, {t, 0, tmax}, {pm}]
sol[0.05]


Plot[Evaluate[sol[0.05][[1]]], {t, 0, tmax}, 
  AxesLabel -> {"t [s]", "c(t) [M]"}, 
  PlotLabel -> "c1 Concentration Profile", 
  PlotLegends -> "Expressions"] Plot[
  Evaluate[sol[0.05][[2]]], {t, 0, tmax}, 
  AxesLabel -> {"t [s]", "c(t) [M]"}, 
  PlotLabel -> "c1r Concentration Profile", 
  PlotLegends -> "Expressions"] Plot[
  Evaluate[sol[0.05][[3]]], {t, 0, tmax}, 
  AxesLabel -> {"t [s]", "c(t) [M]"}, 
  PlotLabel -> "c2 Concentration Profile", 
  PlotLegends -> "Expressions"] Plot[
  Evaluate[sol[0.05][[4]]], {t, 0, tmax}, 
  AxesLabel -> {"t [s]", "c(t) [M]"}, 
  PlotLabel -> "c2r Concentration Profile", 
  PlotLegends -> "Expressions"]

Plot[Evaluate[sol[0.05][[7]]], {t, 0, tmax}, 
 AxesLabel -> {"t [s]", "c(t) [M]"}, 
 PlotLabel -> "cP Concentration Profile", 
 PlotLegends -> "Expressions"]

One Answer

The system seems to be stiff.

Try Method -> "StiffnessSwitching"

sol = ParametricNDSolveValue[{eqns, init}, vars, {t, 0, tmax}, {pm}, Method -> "StiffnessSwitching", AccuracyGoal -> 5, PrecisionGoal -> 4 ]

Plot[Evaluate[sol[0.05][[7]]], {t, 0, tmax}, AxesLabel -> {"t [s]", "c(t) [M]"},PlotLabel -> "cP Concentration Profile",PlotLegends -> "Expressions", PlotRange -> All]

enter image description here

Answered by Ulrich Neumann on January 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP