11

I've asked similar questions before about Mathematica's Mass Transport model. My aim is to model these systems and show how they change by manipulating various parameters.

This time it's the following system.

Edit:

The reaction that the system is modeling and the equilibrium constants are given below (My apologies for not uploading them from the start but my question was predominantly about those boundary conditions):

enter image description here

End of Edit

enter image description here enter image description here

The system above should yield a voltammogram like this:

enter image description here enter image description here enter image description here

I tried implementing the model using the following code (excluding the plotting of results).

Needs["NDSolve`FEM`"]
ClearAll["Global`*"]
(*Experimental Parameters*)
k1 := 0; k2 := 0 (*10^8*);
ef0AB := 0; ef0BC = -0.4; 
α1 := 0.5; α2 := 0.5; 
k10 := 1; k20 := 1; 
ar := 1; cAbulk := 10^-3; 
dA := 10^-5; dB = 10^-5; dC := 10^-5;
rtbyf := 25.7 10^-3(*volt*);
f := 96485.33;

ts := 1; tmax = 2 ts; ν := -1; e1 := -0.3; ef0 := 0; e[t_] := Piecewise[{{e1 + ν t, 0 <= t <= ts}, {e1 + 2 ν ts - ν t, ts <= t <= 2 ts}}]

large = 6 Sqrt[dA tmax];

i[t_, x_] := far ( D[2 dA cA[t, x] + dB cB[t, x]]) /. x -> 0

vars = {{cA[t, x], cB[t, x], cC[t, x]}, t, {x}}; pars = <| "DiffusionCoefficient" -> {{dA, 0, 0}, {0, dB, 0}, {0, 0, dC}}, "MassReactionRate" -> {{Subscript[k, 2] cC[t, x], 0, 0}, {0, 2 Subscript[k, 1] cB[t, x], 0}, {0, 0, Subscript[k, 2] cA[t, x]}}, "MassSource" -> {{Subscript[k, 1] cB[t, x]^2}, {2 Subscript[k, 2] cA[t, x] cC[t, x]}, {Subscript[k, 1] cB[t, x]^2}},

"BoundaryConditionMassFlux" -> <|"MassFlux" -> {D[-dB cB[t, x] - dC cC[t, x], x] , D[-dA cA[t, x] - dC cC[t, x], x], D[-dA cA[t, x] - dB cB[t, x], x]}|>,

"BoundaryConditionConcentration" -> <|"MassConcentration" -> {cB[t, x] Exp[rtbyf^-1 (e[t] - ef0AB)], cA[t, x] /Exp[rtbyf^-1 (e[t] - ef0AB)], cA[t, x] /Exp[rtbyf^-1 (e[t] - ef0BC)]}|>,

"BoundaryConditionInf" -> <|"MassConcentration" -> {cAbulk, 0, 0}|>|>;

ops = MassTransportPDEComponent[vars, pars]; TableForm[%] // TraditionalForm;

ics = {cA[0, x] == cAbulk, cB[0, x] == 0, cC[0, x] == 0}; Γflux = MassFluxValue[x == 0, vars, pars, "BoundaryConditionMassFlux"]; Γcond = MassConcentrationCondition[x == 0, vars, pars, "BoundaryConditionConcentration"]; Γcondinf = MassConcentrationCondition[x == large, vars, pars, "BoundaryConditionInf"];

{cAfun, cBfun, cCfun} = NDSolveValue[{ops == Γflux, Γcond,
Γcondinf, ics}, {cA, cB, cC}, {t, 0, tmax}, {x, 0, large}, Method -> {"MethodOfLines", "TemporalVariable" -> t, "SpatialDiscretization" -> {"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> large/1000}}}];

I get two errors; one of which says:

NDSolveValue::fembcdepderiv: Derivatives of dependent variables in boundary conditions are not supported with the Finite Element Method in this version of NDSolve.

The other one says that the lists are not the same shape which again has me confused because NDSolveValue should return a list with three elements.

I tried to test it with a different model by removing the derivatives but then it returned similar errors with DirichletCondition. So I think I'm doing something wrong here.

Thank you to everyone in advance.

user21
  • 39,710
  • 8
  • 110
  • 167
Walser
  • 351
  • 1
  • 8
  • 2
  • "NDSolveValue should return a list with three elements." No, NDSolveValue already fails after the first warning, what's returned is an unevaluated NDSolveValue[…]. Just execute the NDSolveValue[…] separately and observe. 2. As indicated by the description of NDSolveValue::fembcdepderiv, you can not have derivatives in NeumannValue. (Please observe what's inside Γflux.) Do notice MassTransportPDEComponent, etc. are no more than generator of PDEs and b.c.s, in other words, if NeumannValue isn't able to do something, MassTransportPDEComponent, etc. won't help either.
  • – xzczd Mar 29 '21 at 05:34
  • 2
  • As I've said for several times, if the domain is always regular, consider using the old good TensorProductGrid instead of FiniteElement.
  • – xzczd Mar 29 '21 at 05:43
  • 1
    Can you share where this model comes from? I see a few issue to be tackled. Everything seems clear, except the last BC. There you have a relation of Dirichlet values - that might work if Dirichlet cross coupling were implemented but even then I am not sure this is what is needed. Additionally you have a constraint that the sum of Neumann values is 0. This might be doable with an integral constraint. All in all the FEM version is not doable from an NDSolve level right now. It might be doable with the low level FEM code but would requite considerable work. Do you want to go there? – user21 Apr 02 '21 at 06:55
  • In any case if you could send me the link to the paper/book where you found that, I might be able to do this in future versions of Mathematica. You are also welcome to add this request here – user21 Apr 02 '21 at 06:57
  • One last thing, I have seen that you have collected various mass transport examples. Would you be willing to share them, such that they can be included in the documentation? – user21 Apr 02 '21 at 06:58
  • 1
    Yes I'll be happy to share them. My next target was to solve problems involving second order reactions. The models come from Understanding Voltammetry by R.G. Compton. This one is page 145 (chapter 4).

    I don't want anything too complicated just yet. But if you can point to some basic literature and examples regarding it, that would be helpful.

    – Walser Apr 04 '21 at 10:57
  • 1
    Thanks for the reference. Unfortunately. I do not have any literature to point you to, but this post has an integral constraint. But again, I am very unsure if this would work. This would need some time to tackle. – user21 Apr 05 '21 at 06:41
  • 1
  • You haven't converted the units of parameters to SI units, is it correct? 5. What's the definition of $k_2$? It's different from $k_2^0$, right? 6. $\alpha_1, \alpha_2, k_1^0, k_2^0$ are never used? 7. Are you sure e[t] is the function used for generating the curve in the screenshot?
  • – xzczd Apr 06 '21 at 10:08