ORR.jl
Demonstration of oxygen reduction reaction
$$ 4(H^+⋅κH_2O) + O_2 + 4e^- \leftrightharpoons (2+4κ)H_2O$$
Negative potential: electrons available, protons attracted, water produced
Positive potential: electrons sucked away, protons pushed away, water destroyed
using GridVisualize
import CairoMakie
default_plotter!(CairoMakie)
CairoMakie.activate!(type="svg")
begin
using PlutoUI, HypertextLiteral
using LiquidElectrolytes
using Printf
using LessUnitful
using ExtendableGrids
using VoronoiFVM
using StaticArrays
using Interpolations
using Test
end
pkgdir(LiquidElectrolytes)
"/home/runner/work/LiquidElectrolytes.jl/LiquidElectrolytes.jl"
begin
mylog = RLog()
end
RLog{Float64}(2.4308653429145085e-63)
Setup
Units
begin
LessUnitful.@phconstants R N_A e
@unitfactors nm cm μF mol dm s V
const F = N_A * e
end;
Data
begin
const vmin = -1V
const vmax = 1V
const vdelta = 0.025 * V
const molarity = 0.1
const nref = 0
const κ = 10.0
const vfac = 1
const upwindflux! = LiquidElectrolytes.μex_flux!
const R0 = 5.0e-16mol / (cm^2 * s)
const Δg = 0.0
const β = 0.5
const ϕ_we = 0.0
const ihplus = 1
const iso4 = 2
const io2 = 3
const z = [1, -2, 0]
const allκ = [κ, κ, 0]
end;
Solver control
solver_control = (
max_round = 4,
tol_round = 1.0e-8,
reltol = 1.0e-8,
abstol = 1.0e-9,
verbose = "",
maxiters = 20,
damp_initial = 0.1,
)
(max_round = 4, tol_round = 1.0e-8, reltol = 1.0e-8, abstol = 1.0e-9, verbose = "", maxiters = 20, damp_initial = 0.1)
Reaction description
In the following reaction function, the balance with the solvent is fulfilled automatically via the incompressibility constraint. Any material which is removed via the boundary reaction is automatically replaced by solvent with the corresponding volume. So "ignoring the solvent" here is correct.
function halfcellbc(f, u, bnode, data)
bulkbcondition(f, u, bnode, data)
(; iϕ, eneutral, ϕ_we, Γ_we, RT, κ) = data
return if bnode.region == Γ_we
f .= 0.0
if !eneutral
boundary_dirichlet!(
f, u, bnode; species = iϕ, region = Γ_we,
value = ϕ_we
)
end
μh2o, μ = chemical_potentials!(MVector{4, eltype(u)}(undef), u, data)
A = (
4 * μ[ihplus] + μ[io2] - (2 + 4κ[ihplus]) * μh2o + Δg +
4 * eneutral * F * (u[iϕ] - ϕ_we)
) / (RT)
r = rrate(R0, β, A)
f[ihplus] -= 4 * r
f[io2] -= r
end
end
halfcellbc (generic function with 1 method)
Nernst-Planck halfcell
grid = let
hmin = 1.0e-1 * nm * 2.0^(-nref)
hmax = 1.0 * nm * 2.0^(-nref)
L = 20.0 * nm
X = geomspace(0, L, hmin, hmax)
simplexgrid(X)
end
ExtendableGrids.ExtendableGrid{Float64, Int32} dim = 1 nnodes = 52 ncells = 51 nbfaces = 2
begin
celldata = ElectrolyteData(;
nc = 3,
z,
κ = allκ,
Γ_we = 1,
Γ_bulk = 2,
eneutral = false,
upwindflux!,
rlog = mylog
)
celldata.v .*= vfac
celldata.weights[celldata.ip] = 0
celldata.weights[1:(celldata.nc)] .= 0
c_bulk = celldata.c_bulk
c_bulk[io2] = 0.001 * mol / dm^3
c_bulk[iso4] = molarity * mol / dm^3
c_bulk[ihplus] = 2.0 * molarity * mol / dm^3
#celldata.pscale=1
end
199.99999999999997
@test isincompressible(celldata.c_bulk, celldata)
�[32m�[1mTest Passed�[22m�[39m
@test iselectroneutral(celldata.c_bulk, celldata)
�[32m�[1mTest Passed�[22m�[39m
cell = PNPSystem(grid; bcondition = halfcellbc, celldata)
PNPSystem(VoronoiFVM.System{Float64, Float64, Int32, Int64, Matrix{Int32}}( grid = ExtendableGrids.ExtendableGrid{Float64, Int32}(dim=1, nnodes=52, ncells=51, nbfaces=2), physics = Physics(data=LiquidElectrolytes.ElectrolyteData{typeof(LiquidElectrolytes.DG ML_gamma!), PreallocationTools.DiffCache{Vector{Float64}, Vector{Float64}}, typeof(exp), LiquidElectrolytes.RLog{Float64}, typeof(LiquidElectrolytes.μex_flux!)}, flux=pnpflux!, storage=pnpstorage!, reaction=_pnpreaction!, breaction=halfcellbc, ), num_species = 5))
result = LiquidElectrolytes.ivsweep(
cell; store_solutions = true,
voltages = vmin:vdelta:vmax,
solver_control...
)
IVSweepResult([-1.0, -0.9985343042859195, -0.997068608571839, -0.9941372171436781, -0.9912058257155171, -0.9868087385732757, -0.9821371496871446, -0.9782441589487021, -0.975, -0.9717558410512979 … 0.9717558410512979, 0.975, 0.9782441589487021, 0.9821371496871446, 0.9868087385732757, 0.9912058257155171, 0.9941372171436781, 0.997068608571839, 0.9985343042859195, 1.0], Any[[-0.10592034819181619, -0.0, -0.026480087047954046, -0.0, -0.0], [-0.10630852567727113, -0.0, -0.026577131419317782, -0.0, -0.0], [-0.10669776722177376, -0.0, -0.02667444180544344, -0.0, -0.0], [-0.10747944383611141, -0.0, -0.026869860959027853, -0.0, -0.0], [-0.10826538052078134, -0.0, -0.027066345130195336, -0.0, -0.0], [-0.10945227778053847, -0.0, -0.027363069445134617, -0.0, -0.0], [-0.11072378381969693, -0.0, -0.027680945954924232, -0.0, -0.0], [-0.11179164946704773, -0.0, -0.02794791236676193, -0.0, -0.0], [-0.11268728686948287, -0.0, -0.028171821717370718, -0.0, -0.0], [-0.11358815128943965, -0.0, -0.028397037822359913, -0.0, -0.0] … [2.4848567647950406e-22, -0.0, 6.212141911987601e-23, -0.0, -0.0], [2.577027480299421e-22, -0.0, 6.442568700748553e-23, -0.0, -0.0], [-2.8875568602870774e-22, -0.0, -7.218892150717694e-23, -0.0, -0.0], [-2.697331247247803e-22, -0.0, -6.743328118119507e-23, -0.0, -0.0], [-2.6988189461008007e-22, -0.0, -6.747047365252002e-23, -0.0, -0.0], [-2.379496599758113e-22, -0.0, -5.948741499395283e-23, -0.0, -0.0], [4.802114261792668e-22, -0.0, 1.200528565448167e-22, -0.0, -0.0], [1.2776446567386302e-22, -0.0, 3.1941116418465755e-23, -0.0, -0.0], [-1.8045120953047445e-22, -0.0, -4.5112802382618614e-23, -0.0, -0.0], [2.306088653369898e-22, -0.0, 5.765221633424745e-23, -0.0, -0.0]], Any[[0.10592034828330556, -5.189738966551716e-15, 0.02648008704796319, 0.7617236380571555, -5.493201231969652e-10], [0.10630852570598393, -5.558098750895099e-15, 0.026577131419320495, 0.7610760434265902, 2.789926494937378e-9], [0.10669776723472636, 1.0248074074583856e-14, 0.026674441805444937, 0.7604279126882699, 7.674323052043394e-10], [0.10747944383664391, 1.0668825727431072e-16, 0.026869860959028533, 0.7591300377543568, 3.9915491628289337e-10], [0.10826538058185518, 5.7533878775271914e-15, 0.027066345130200994, 0.757830002937571, 6.736632187910435e-10], [0.10945227769520899, -8.696450645820857e-15, 0.027363069445125475, 0.7558758781637875, 3.686713074057075e-10], [0.11072378379225255, 5.998170907189168e-15, 0.02768094595492117, 0.7537943715406009, 4.509347866147855e-10], [0.11179164957038949, -2.3306118525317243e-15, 0.027947912366773284, 0.7520555106527625, -7.344621681084562e-10], [0.11268728683498921, 1.7374919851261794e-14, 0.02817182171736687, 0.7506034737924483, -6.245521690807505e-10], [0.11358815122926844, 3.816101686099079e-15, 0.028397037822353678, 0.7491487065914347, 1.0729165948872988e-9] … [-4.254409553125285e-15, 1.5307307421605825e-9, -7.286380700188876e-17, -1.0981730294897594, 4.0181041439001077e-10], [2.7322718940939824e-14, 1.5961418853292347e-9, -5.416131952651575e-17, -1.1001672039222903, -2.314254286974763e-9], [3.9689604070890106e-15, -1.98535730078196e-9, -6.693322111839485e-17, -1.1021577789016828, 5.543963960925906e-9], [1.1318422380532363e-15, -1.8306593574376778e-9, 3.686287386450002e-18, -1.104541744799221, 1.6824554221519932e-9], [1.830792415734866e-14, -1.8114619138028643e-9, -6.646159317334874e-18, -1.1073957452608345, -3.459892164656282e-10], [-1.0486717643097307e-14, -1.5854283219593821e-9, -1.4717502390404416e-16, -1.1100753568669308, -1.3260207719113105e-9], [-1.2684341752733477e-14, 3.1424775670525717e-9, -3.6732769603812016e-17, -1.1118581848317535, -4.5437455320232004e-10], [-1.498773960199146e-14, 8.152525765580302e-10, -5.027987574901912e-18, -1.1136381648564977, -2.450084996242805e-9], [-1.4372172833587583e-14, -1.2001748928013622e-9, -4.586988341243052e-17, -1.114527091107805, -2.2301527851620783e-9], [-2.4094354818044745e-14, 1.4987847407609579e-9, 4.482633882141543e-17, -1.1154153104193993, -7.073775291222934e-10]], Any[[-0.10592034828330554, 5.1897389665523e-15, -0.026480087047963192, -1.5762274325654155e-6, 5.493201231970043e-10], [-0.10630852570598393, 5.5580987508956415e-15, -0.0265771314193205, -1.5820046667675694e-6, -2.789926494937618e-9], [-0.1066977672347264, -1.0248074074583826e-14, -0.02667444180544494, -1.587797742249132e-6, -7.674323052043941e-10], [-0.10747944383664389, -1.066882572743831e-16, -0.026869860959028543, -1.5994314372074897e-6, -3.9915491628301357e-10], [-0.10826538058185521, -5.753387877526359e-15, -0.027066345130201, -1.6111285546735284e-6, -6.7366321879119e-10], [-0.10945227769520899, 8.696450645821434e-15, -0.02736306944512548, -1.628793217449658e-6, -3.6867130740577194e-10], [-0.11072378379225256, -5.998170907189556e-15, -0.027680945954921172, -1.6477171682614957e-6, -4.5093478661488153e-10], [-0.11179164957038946, 2.3306118525313433e-15, -0.02794791236677328, -1.6636103592420986e-6, 7.344621681086405e-10], [-0.1126872868349892, -1.7374919851262006e-14, -0.028171821717366877, -1.6769402820887303e-6, 6.24552169080815e-10], [-0.11358815122926841, -3.816101686098817e-15, -0.02839703782235367, -1.6903480256755564e-6, -1.072916594887412e-9] … [4.254409553124579e-15, -1.530730742160821e-9, 7.286380700188847e-17, 8.632601246020149e-16, -4.018104143902157e-10], [-2.7322718940938656e-14, -1.5961418853294251e-9, 5.416131952651369e-17, 8.866563757054553e-16, 2.314254286974939e-9], [-3.968960407090036e-15, 1.9853573007822087e-9, 6.693322111839235e-17, 8.585659706200432e-16, -5.5439639609268325e-9], [-1.1318422380547758e-15, 1.8306593574379905e-9, -3.686287386450934e-18, 8.486470565622538e-16, -1.682455422152028e-9], [-1.8307924157350823e-14, 1.8114619138032246e-9, 6.646159317336131e-18, 8.852985729327398e-16, 3.4598921646581164e-10], [1.0486717643096114e-14, 1.5854283219596342e-9, 1.4717502390404532e-16, 8.765421701900025e-16, 1.3260207719114666e-9], [1.2684341752733007e-14, -3.1424775670530092e-9, 3.673276960380908e-17, 8.97754046086895e-16, 4.543745532022696e-10], [1.4987739601991973e-14, -8.152525765581278e-10, 5.027987574901283e-18, 9.048731598342034e-16, 2.450084996243226e-9], [1.4372172833587103e-14, 1.2001748928014482e-9, 4.586988341243073e-17, 8.733784807017347e-16, 2.230152785162323e-9], [2.4094354818046083e-14, -1.4987847407610468e-9, -4.482633882141254e-17, 8.928562204794191e-16, 7.073775291224386e-10]], [[5013.512456603281 5002.471499893383 … 199.9693095061514 199.99999999999997; 4.904845300789068e-48 1.178575701789473e-42 … 99.98465374550244 99.99999999999999; … ; -1.0 -0.8938742377576455 … -2.252107131725821e-6 -1.576227432560113e-36; 0.41642130041703646 0.36514156883710036 … 2.1894093698134468e-16 8.779981737320839e-50], [5013.388748399885 5002.296468460925 … 199.96919703273693 199.99999999999997; 5.820338985516533e-48 1.3834227960400318e-42 … 99.98459750139602 99.99999999999999; … ; -0.9985343042859195 -0.8925016399178014 … -2.2603616197076636e-6 -1.5820046667846447e-36; 0.41571262070177306 0.3644794019493807 … 2.2135710550540237e-16 -1.942394512465061e-49], [5013.26434407968 5002.120491398198 … 199.96908425102268 199.99999999999997; 6.906709749620412e-48 1.6238594002502546e-42 … 99.98454110309224 99.99999999999999; … ; -0.997068608571839 -0.8911291187364002 … -2.268638741606663e-6 -1.587797742263185e-36; 0.4150039582839259 0.36381729510525046 … 2.2379768643522847e-16 2.1408717281483038e-49], [5013.013430252607 5001.765678102597 … 199.96885776230815 199.99999999999997; 9.725611985993658e-48 2.2372964389403197e-42 … 99.98442784369828 99.99999999999999; … ; -0.9941372171436781 -0.8883843070759821 … -2.285260916052513e-6 -1.5994314372065834e-36; 0.4135866857391171 0.36249326239530166 … 2.287529394187059e-16 5.9701287409023435e-49], [5012.759681163874 5001.4070150716025 … 199.9686300392879 199.99999999999997; 1.3695014987455638e-47 3.08235551475885e-42 … 99.9843139669588 99.99999999999999; … ; -0.9912058257155171 -0.8856398042374749 … -2.301973708384938e-6 -1.6111285547095414e-36; 0.4121694835860335 0.361169472412996 … 2.3380842184483754e-16 6.54170109566823e-50], [5012.3736659923015 5000.861702475192 … 199.96828613910236 199.99999999999997; 2.28839275355409e-47 4.984154756501275e-42 … 99.98414199365666 99.99999999999999; … ; -0.9868087385732757 -0.8815236322446071 … -2.3272129042755527e-6 -1.628793217450545e-36; 0.4100438141228597 0.3591842463275495 … 2.415834098943321e-16 -1.233652832460102e-48], [5011.95634632836 5000.272569830177 … 199.96791772385424 199.99999999999997; 3.9483684303426076e-47 8.30404864520454e-42 … 99.98395776088778 99.99999999999999; … ; -0.9821371496871446 -0.877151266018488 … -2.3542513656571825e-6 -1.6477171682535794e-36; 0.40778562182636874 0.35707569555478286 … 2.501018836355742e-16 8.710832999846495e-49], [5011.602806324615 4999.773795998033 … 199.967608312907 199.99999999999997; 6.220470838806784e-47 1.2705946927186798e-41 … 99.98380303407193 99.99999999999999; … ; -0.9782441589487021 -0.8735082382009284 … -2.3769594901711134e-6 -1.6636103592552976e-36; 0.4059039379161467 0.355319054409018 … 2.5740892652870724e-16 -1.1607178503936057e-48], [5011.3041143246155 4999.352626521528 … 199.96734880464425 199.99999999999997; 9.085057424882628e-47 1.8109897192791146e-41 … 99.98367326188237 99.99999999999999; … ; -0.975 -0.87047280853644 … -2.396005227891896e-6 -1.6769402820844292e-36; 0.4043359688473798 0.3538555264944463 … 2.6364613095394816e-16 -7.615068841489057e-49], [5011.001663899878 4998.926363791582 … 199.967087781919 199.99999999999997; 1.3268806900798042e-46 2.58109983387119e-41 … 99.98354273221072 99.99999999999999; … ; -0.9717558410512979 -0.8674377691373997 … -2.4151621555860407e-6 -1.690348025672515e-36; 0.40276809272355935 0.35239231003564275 … 2.700205860449239e-16 -1.4075317489772885e-48] … [5.341290029961905e-26 5.900380583721773e-26 … 199.99999999999034 199.99999999999997; 5035.532775727444 5033.937449802622 … 100.00000000000958 99.99999999999999; … ; 0.9717558410512979 0.8207284914650587 … 1.2333807910228848e-15 8.63230976100671e-46; 0.8642225020752435 0.7174909473843158 … 1.403311532645322e-27 1.4115294614472564e-48], [4.149343856552204e-26 4.5827621101238304e-26 … 199.99999999999034 199.99999999999997; 5035.551660589028 5033.987909279231 … 100.00000000000962 99.99999999999999; … ; 0.975 0.8236857306921367 … 1.2382516374095e-15 8.666400331504952e-46; 0.8673719760745565 0.7203606503550813 … -2.681707789260852e-28 -2.718108917020597e-49], [3.223388389439795e-26 3.5593855973170334e-26 … 199.9999999999903 199.99999999999997; 5035.57011560381 5034.037323519708 … 100.00000000000966 99.99999999999999; … ; 0.9782441589487021 0.8266434872552975 … 1.243112303977866e-15 8.700419654465469e-46; 0.8705214692355923 0.7232308928525599 … 4.649454344625483e-28 4.664865276107587e-49], [2.3807424688821067e-26 2.6282875622835744e-26 … 199.99999999999025 199.99999999999997; 5035.591708022074 5034.095271284932 … 100.0000000000097 99.99999999999999; … ; 0.9821371496871446 0.8301934741199517 … 1.2506930228778207e-15 8.753476353768573e-46; 0.8743008859587152 0.7266758914157995 … 8.124542545933151e-28 8.16440318006778e-49], [1.6549773599091872e-26 1.8265480572505793e-26 … 199.9999999999902 199.99999999999997; 5035.616843742334 5034.162914159937 … 100.00000000000976 99.99999999999999; … ; 0.9868087385732757 0.8344544297926609 … 1.2543993504571667e-15 8.779416572696535e-46; 0.8788362212781804 0.7308109010703772 … 1.2765303855927523e-27 1.2837897264864998e-48], [1.1753060448319135e-26 1.296810851846233e-26 … 199.99999999999014 199.99999999999997; 5035.6397532965 5034.224746049451 … 100.0000000000098 99.99999999999999; … ; 0.9912058257155171 0.8384659738088577 … 1.2611054677094277e-15 8.826352021859108e-46; 0.8831050954530569 0.7347039380766746 … -8.912652861335739e-28 -8.99386479619041e-49], [9.355281506584569e-27 1.0320658774517838e-26 … 199.99999999999014 199.99999999999997; 5035.654634046563 5034.26500319146 … 100.00000000000985 99.99999999999999; … ; 0.9941372171436781 0.8411408510426746 … 1.2655115430822464e-15 8.85718970615365e-46; 0.8859510296688072 0.7372998306433484 … -1.3300373559737076e-27 -1.3412794966403955e-48], [7.446680320740556e-27 8.213694441929679e-27 … 199.9999999999901 199.99999999999997; 5035.669208516396 5034.304505845642 … 100.00000000000988 99.99999999999999; … ; 0.997068608571839 0.8438161376473374 … 1.2718383905049056e-15 8.90147068341593e-46; 0.8887969780618713 0.7398961480898992 … -3.108477810505418e-28 -3.1488217641230266e-49], [6.643785777227657e-27 7.327473067413164e-27 … 199.99999999999005 199.99999999999997; 5035.6763828761805 5034.323978657083 … 100.00000000000988 99.99999999999999; … ; 0.9985343042859195 0.8451539338597688 … 1.2729395691625965e-15 8.909177723564915e-46; 0.8902199574901141 0.741194465403441 … -5.167415677958252e-28 -5.2224022776620805e-49], [5.92745848607142e-27 6.53687233268759e-27 … 199.99999999999005 199.99999999999997; 5035.683483025372 5034.343268114123 … 100.0000000000099 99.99999999999999; … ; 1.0 0.8464918316922079 … 1.2747151805964272e-15 8.921605051786314e-46; 0.8916429403594364 0.742492888050262 … -6.206462714568729e-28 -6.268871338848222e-49]])
Results
@bind vshow PlutoUI.Slider(range(extrema(result.voltages)...; length = 101),
show_value = true)
plot1d(result, celldata, vshow)
plot1d(result, celldata)
cplot(cell, result)
Plotting functions
curr (generic function with 1 method)
curr_h2o (generic function with 1 method)
function plotcurr(result)
scale = 1 / (mol / dm^3)
volts = result.voltages
vis = GridVisualizer(;
size = (600, 300),
tilte = "IV Curve",
xlabel = "Φ_WE/V",
ylabel = "I",
legend = :lt)
scalarplot!(vis,
volts,
curr(result.j_bulk, ihplus);
linestyle = :dash,
label = "H+, bulk",
color = :red)
scalarplot!(vis,
volts,
curr(result.j_we, ihplus);
color = :red,
clear = false,
linestyle = :solid,
label = "H+, we")
scalarplot!(vis,
volts,
curr(result.j_bulk, io2);
linestyle = :dash,
label = "O2, bulk",
color = :green,
clear = false)
scalarplot!(vis,
volts,
curr(result.j_we, io2);
color = :green,
clear = false,
linestyle = :solid,
label = "O2, we")
scalarplot!(vis,
volts,
curr(result.j_bulk, io2);
linestyle = :dash,
label = "O2, bulk",
color = :green,
clear = false)
scalarplot!(vis,
volts,
curr(result.j_we, io2);
color = :green,
clear = false,
linestyle = :solid,
label = "O2, we")
scalarplot!(vis,
volts,
curr_h2o(result.j_bulk) / 100;
linestyle = :dash,
label = "H2O/100, bulk",
color = :blue,
clear = false)
scalarplot!(vis,
volts,
curr_h2o(result.j_we) / 100;
color = :blue,
clear = false,
linestyle = :solid,
label = "H2O/100, we")
reveal(vis)
end
plotcurr (generic function with 1 method)
function plot1d!(vis,result, celldata, vshow)
vinter = linear_interpolation(result.voltages, [j[io2] for j in result.j_we])
tsol=LiquidElectrolytes.voltages_solutions(result)
sol = tsol(vshow)
c0 = solventconcentration(sol, celldata)
scale = 1.0 / (mol / dm^3)
ishow=vinter(vshow)
title = "Φ_we=$(round(vshow,digits=4)), I=$(round(vinter(vshow),sigdigits=4))"
scalarplot!(vis, grid, sol[io2, :] * scale.|>abs; color = :green, label = "O_2",title)
scalarplot!(vis,
grid,
sol[iso4, :] * scale .|>abs;
color = :gray,
clear = false,
label = "SO4--")
scalarplot!(vis,
grid,
sol[ihplus, :] * scale .|>abs;
color = :red,
clear = false,
label = "H+")
scalarplot!(vis, grid, c0 * scale.|>abs; color = :blue, clear = false,
label = "H2O")
end
plot1d! (generic function with 1 method)
function plot1d(result,celldata, vshow)
vis = GridVisualizer(;
size = (600, 250),
yscale = :log,
limits = (1.0e-6, 100),
legend = :rt)
plot1d!(vis,result,celldata,vshow)
reveal(vis)
end
plot1d (generic function with 1 method)
function plot1d(result,celldata)
vinter = linear_interpolation(result.voltages, [j[io2] for j in result.j_we])
tsol=LiquidElectrolytes.voltages_solutions(result)
vis = GridVisualizer(;
size = (600, 250),
yscale = :log,
limits = (1.0e-6, 100),
legend = :rt)
video="orr.gif"
vrange=range(extrema(result.voltages)...; length = 101)
movie(vis,file="orr.mp4") do vis
for vshow in vrange
plot1d!(vis,result,celldata,vshow)
reveal(vis)
end
end
isdefined(Main,:PlutoRunner) && LocalResource("orr.mp4")
end
plot1d (generic function with 2 methods)
function cplot(cell, result)
scale = 1.0 / (mol / dm^3)
tsol = LiquidElectrolytes.voltages_solutions(result)
j_we = result.j_we
currs = curr(j_we, io2)
vis = GridVisualizer(;
resolution = (1200, 400), layout = (1, 3),
gridscale = 1.0e9
)
xmax = 10 * nm
xlimits = [0, xmax]
aspect = 2 * xmax / (tsol.t[end] - tsol.t[begin])
scalarplot!(
vis[1, 1],
cell.vfvmsys,
tsol;
scale,
species = io2,
aspect,
xlimits,
title = "O2",
colormap = :summer
)
scalarplot!(
vis[1, 2],
cell.vfvmsys,
tsol;
species = ihplus,
aspect,
scale,
xlimits,
title = "H+",
colormap = :summer
)
scalarplot!(
vis[1, 3],
1000 * tsol[io2, 1, :] * scale,
tsol.t;
label = "1000*O2",
xlabel = "c",
color = :green,
clear = false
)
scalarplot!(
vis[1, 3],
tsol[ihplus, 1, :] * scale,
tsol.t;
title = "c(0)",
xlabel = "c",
ylabel = "V",
label = "H+",
color = :red,
clear = false
)
scalarplot!(
vis[1, 3],
tsol[iso4, 1, :] * scale,
tsol.t;
label = "SO4--",
color = :blue,
clear = false,
legend = :ct
)
return reveal(vis)
end
cplot (generic function with 1 method)
Electroneutral case
begin
ncelldata = deepcopy(celldata)
ncelldata.eneutral = true
ncell = PNPSystem(grid; bcondition = halfcellbc, celldata = ncelldata)
end
PNPSystem(VoronoiFVM.System{Float64, Float64, Int32, Int64, Matrix{Int32}}( grid = ExtendableGrids.ExtendableGrid{Float64, Int32}(dim=1, nnodes=52, ncells=51, nbfaces=2), physics = Physics(data=LiquidElectrolytes.ElectrolyteData{typeof(LiquidElectrolytes.DG ML_gamma!), PreallocationTools.DiffCache{Vector{Float64}, Vector{Float64}}, typeof(exp), LiquidElectrolytes.RLog{Float64}, typeof(LiquidElectrolytes.μex_flux!)}, flux=pnpflux!, storage=pnpstorage!, reaction=_pnpreaction!, breaction=halfcellbc, ), num_species = 5))
nresult = LiquidElectrolytes.ivsweep(
ncell;
store_solutions = true,
voltages = vmin:vdelta:vmax,
solver_control...
)
IVSweepResult([-1.0, -0.9985343042859195, -0.997068608571839, -0.9941372171436781, -0.9912058257155171, -0.9868087385732757, -0.9821371496871446, -0.9782441589487021, -0.975, -0.9717558410512979 … 0.9717558410512979, 0.975, 0.9782441589487021, 0.9821371496871446, 0.9868087385732757, 0.9912058257155171, 0.9941372171436781, 0.997068608571839, 0.9985343042859195, 1.0], Any[[-5249.685546551648, -0.0, -1312.421386637912, -0.0, -0.0], [-1.3858026655368272e7, -0.0, -3.464506663842068e6, -0.0, -0.0], [-1.748499877064077e7, -0.0, -4.371249692660193e6, -0.0, -0.0], [-1.7045497768666912e7, -0.0, -4.261374442166728e6, -0.0, -0.0], [-1.5666699416686188e7, -0.0, -3.916674854171547e6, -0.0, -0.0], [-1.2438849159185234e7, -0.0, -3.1097122897963086e6, -0.0, -0.0], [-9.66724692013483e6, -0.0, -2.4168117300337073e6, -0.0, -0.0], [-7.98265733235097e6, -0.0, -1.9956643330877426e6, -0.0, -0.0], [-6.933096048717949e6, -0.0, -1.7332740121794872e6, -0.0, -0.0], [-6.219010724129453e6, -0.0, -1.5547526810323633e6, -0.0, -0.0] … [5899.268971504578, -0.0, 1474.8172428761445, -0.0, -0.0], [5933.402033664381, -0.0, 1483.3505084160952, -0.0, -0.0], [5967.547185830642, -0.0, 1491.8867964576605, -0.0, -0.0], [6008.537076746199, -0.0, 1502.1342691865498, -0.0, -0.0], [6057.747164150195, -0.0, 1514.4367910375488, -0.0, -0.0], [6104.0873896149305, -0.0, 1526.0218474037326, -0.0, -0.0], [6134.992362058512, -0.0, 1533.748090514628, -0.0, -0.0], [6165.906385236967, -0.0, 1541.4765963092418, -0.0, -0.0], [6181.366753882021, -0.0, 1545.3416884705052, -0.0, -0.0], [6196.8293410885935, -0.0, 1549.2073352721484, -0.0, -0.0]], Any[[0.40015182141465, 9.947598300641314e-15, 0.10003795535677329, -0.0, 1.9359026867449625e-27], [0.4001518214146501, 9.947598300641314e-15, 0.10003795535677329, -0.0, 2.3231276170494617e-27], [0.40015182141465, 8.526512829121112e-15, 0.10003795535677329, -0.0, 2.7103525473539588e-27], [0.4001518214146472, 9.947598300641317e-15, 0.10003795535677329, -0.0, 3.0975774776584562e-27], [0.40015182141465006, 5.684341886080957e-15, 0.10003795535677329, -0.0, 3.4848024079629536e-27], [0.4001518214146614, -1.2789769243681916e-14, 0.10003795535677328, -0.0, 3.872027338267455e-27], [0.4001518214146558, 5.684341886080457e-15, 0.10003795535677328, -0.0, 4.302171924768622e-27], [0.4001518214146387, 5.6843418860810945e-15, 0.10003795535677328, -0.0, 4.7801271122238136e-27], [0.4001518214146671, 2.8421709430400885e-15, 0.10003795535677328, -0.0, 5.3130318126577064e-27], [0.40015182141466715, 1.421085471519965e-15, 0.10003795535677329, -0.0, 5.977352823179731e-27] … [-5899.268971504498, 1.5120349416973905e-12, -1474.8172428761243, -0.0, -1.0960064281447605e-14], [-5933.402033664505, -1.0572875908108662e-12, -1483.3505084161252, -0.0, -2.196424236792516e-14], [-5967.547185830557, 1.4210854715197466e-14, -1491.886796457639, -0.0, 6.003240001034121e-15], [-6008.537076746094, 6.025402399246128e-13, -1502.1342691865239, -0.0, 1.7108836679586088e-14], [-6057.747164150122, 7.673861546220134e-14, -1514.4367910375304, -0.0, 1.2137452764128688e-14], [-6104.087389614743, 2.344791028008186e-12, -1526.0218474036856, -0.0, -3.0976212034771056e-14], [-6134.992362058518, 5.400124791786659e-14, -1533.748090514629, -0.0, 7.7704845276865e-15], [-6165.9063852368745, -8.526512829072371e-15, -1541.4765963092186, -0.0, -3.861193640083473e-15], [-6181.36675388208, -6.792788553866278e-13, -1545.341688470521, -0.0, -1.3792778386655844e-15], [-6196.829341088559, 7.332801033042426e-13, -1549.2073352721395, -0.0, -3.8676321508833833e-16]], Any[[-0.40015182141465, -9.94759830064135e-15, -0.10003795535677328, -0.0, -1.935902686744989e-27], [-0.40015182141465, -9.94759830064135e-15, -0.10003795535677328, -0.0, -2.3231276170494922e-27], [-0.40015182141465, -8.52651282912114e-15, -0.10003795535677328, -0.0, -2.710352547353996e-27], [-0.4001518214146472, -9.94759830064135e-15, -0.10003795535677328, -0.0, -3.0975774776584996e-27], [-0.40015182141465006, -5.684341886080728e-15, -0.10003795535677328, -0.0, -3.484802407963003e-27], [-0.40015182141466143, 1.2789769243681916e-14, -0.10003795535677328, -0.0, -3.872027338267507e-27], [-0.4001518214146558, -5.6843418860808065e-15, -0.10003795535677328, -0.0, -4.302171924768682e-27], [-0.4001518214146387, -5.684341886080538e-15, -0.10003795535677328, -0.0, -4.7801271122238774e-27], [-0.40015182141466715, -2.8421709430402802e-15, -0.10003795535677328, -0.0, -5.31303181265778e-27], [-0.4001518214146672, -1.4210854715201748e-15, -0.10003795535677328, -0.0, -5.9773528231798105e-27] … [5899.268971504498, -1.5120349416975159e-12, 1474.817242876124, -0.0, 1.096006428144757e-14], [5933.402033664504, 1.0572875908110273e-12, 1483.350508416126, -0.0, 2.1964242367925084e-14], [5967.5471858305555, -1.4210854715212177e-14, 1491.8867964576389, -0.0, -6.003240001034103e-15], [6008.537076746095, -6.025402399245655e-13, 1502.1342691865234, -0.0, -1.7108836679586028e-14], [6057.747164150123, -7.673861546208237e-14, 1514.436791037531, -0.0, -1.2137452764128638e-14], [6104.087389614744, -2.344791028008331e-12, 1526.0218474036856, -0.0, 3.0976212034770955e-14], [6134.99236205852, -5.40012479177641e-14, 1533.7480905146292, -0.0, -7.77048452768648e-15], [6165.906385236875, 8.52651282910466e-15, 1541.4765963092188, -0.0, 3.861193640083458e-15], [6181.366753882081, 6.792788553866536e-13, 1545.3416884705207, -0.0, 1.3792778386655798e-15], [6196.829341088559, -7.33280103304435e-13, 1549.2073352721393, -0.0, 3.8676321508833656e-16]], [[197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020001 -0.00017149082108389453 … -8.509624387662797e-6 -1.9168552632958413e-66; -3.871805373489954e-35 -3.893632764303802e-35 … 2.1522282282326336e-36 0.0], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.0001723576702002014 -0.0001714908210838959 … -8.509624387662865e-6 -1.9168552632958413e-66; -4.646255234098957e-35 -4.6724491996991245e-35 … 2.5829405732160852e-36 0.0], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020278 -0.00017149082108389724 … -8.509624387662932e-6 -1.9168552632958413e-66; -5.42070509470796e-35 -5.451265635094447e-35 … 3.013652918199537e-36 0.0], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020416 -0.0001714908210838986 … -8.509624387663e-6 -1.9168552632958413e-66; -6.195154955316962e-35 -6.23008207048977e-35 … 3.4443652631829885e-36 0.0], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020554 -0.00017149082108389995 … -8.509624387663068e-6 -1.9168552632958413e-66; -6.969604815925965e-35 -7.008898505885092e-35 … 3.87507760816644e-36 0.0], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020693 -0.0001714908210839013 … -8.509624387663136e-6 -1.916855263295913e-66; -7.744054676534967e-35 -7.787714941280415e-35 … 4.305789953149892e-36 -4.978412222288915e-61], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020581 -0.0001714908210839002 … -8.509624387663173e-6 -1.9168552632958418e-66; -8.604343849537311e-35 -8.652849396235385e-35 … 4.7846265824890366e-36 2.489206111144457e-60], [197.66277647227292 197.6744719453475 … 199.8840497949761 199.99999999999997; 98.83138823613646 98.83723597267375 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020462 -0.00017149082108389898 … -8.50962438766324e-6 -1.9168552632953906e-66; -9.560254224447699e-35 -9.614153982779069e-35 … 5.313993710401659e-36 1.4935236666866742e-59], [197.66277647227287 197.67447194534745 … 199.8840497949761 199.99999999999997; 98.83138823613643 98.83723597267372 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020020899 -0.0001714908210839033 … -8.509624387663508e-6 -1.9168552632958693e-66; -1.0626063625315493e-34 -1.0685969731993298e-34 … 5.887875801343297e-36 0.0], [197.66277647227287 197.67447194534745 … 199.8840497949761 199.99999999999997; 98.83138823613643 98.83723597267372 … 99.94202489748805 99.99999999999999; … ; -0.00017235767020021012 -0.0001714908210839044 … -8.509624387663564e-6 -1.9168552632958693e-66; -1.1954705646359552e-34 -1.2022095386023078e-34 … 6.624177351985399e-36 0.0] … [2672.0573577292566 2671.77095755586 … 1159.089554269213 199.99999999999997; 1336.0286788646283 1335.88547877793 … 579.5447771346065 99.99999999999999; … ; 0.23567602875839352 0.23473059365876964 … 0.03489352482213156 2.825938599416833e-61; 2.1920128562895144e-22 2.1920128562355883e-22 … 1.1271621985891687e-23 1.135152292169287e-44], [2672.376006204458 2672.0945766661953 … 1162.3850571628116 199.99999999999997; 1336.188003102229 1336.0472883330976 … 581.1925285814058 99.99999999999999; … ; 0.23675670629801168 0.2358059151914379 … 0.034990599087868564 2.8422894283653285e-61; 4.392848473585018e-22 4.392848473351017e-22 … 2.2624619599542498e-23 2.2784985585196905e-44], [2672.687404200772 2672.4108656673698 … 1165.6679834859654 199.99999999999997; 1336.343702100386 1336.2054328336849 … 582.8339917429827 99.99999999999999; … ; 0.2378376163000449 0.23688146592829568 … 0.03508738525240399 2.8586460488135748e-61; -1.200648000206821e-22 -1.2006480003878585e-22 … -6.16803030500318e-24 -6.211725796278821e-45], [2673.0517439376467 2672.780971074316 … 1169.5909917307 199.99999999999997; 1336.5258719688234 1336.390485537158 … 584.79549586535 99.99999999999999; … ; 0.23913501151742794 0.23817242579072306 … 0.035203152016657024 2.8782815181375935e-61; -3.421767335917207e-22 -3.4217673357323177e-22 … -1.7635578626943946e-23 -1.7760531257848786e-44], [2673.475876210935 2673.2118756090777 … 1174.274996072459 199.99999999999997; 1336.7379381054675 1336.6059378045388 … 587.1374980362295 99.99999999999999; … ; 0.24069231655377388 0.23972200240350966 … 0.03534153569469017 2.901854724605622e-61; -2.427490552825728e-22 -2.427490553126173e-22 … -1.2673874317758463e-23 -1.2763719894431903e-44], [2673.862449391445 2673.604679813751 … 1178.6604161451532 199.99999999999997; 1336.9312246957224 1336.8023399068754 … 589.3302080725766 99.99999999999999; … ; 0.24215853765952314 0.24118094334006898 … 0.03547125970753953 2.9240531753761705e-61; 6.195242406954193e-22 6.195242407063971e-22 … 3.1850284671430055e-23 3.207609206400552e-44], [2674.113547850972 2673.859856440625 … 1181.5715342688925 199.99999999999997; 1337.056773925486 1336.9299282203126 … 590.7857671344462 99.99999999999999; … ; 0.24313624322465166 0.24215379235300105 … 0.035557460917880535 2.938857646059677e-61; -1.5540969055372962e-22 -1.554096906342335e-22 … -7.908068909572455e-24 -7.964106705212805e-45], [2674.35947998951 2674.1098069808513 … 1184.472714634686 199.99999999999997; 1337.179739994755 1337.0549034904257 … 592.236357317343 99.99999999999999; … ; 0.24411412658018342 0.24312681670809347 … 0.03564343906931918 2.9536664523346533e-61; 7.722387280166918e-23 7.722387277008393e-23 … 4.0128383174492646e-24 4.041287601357844e-45], [2674.4805420689736 2674.232856091185 … 1185.9195937463282 199.99999999999997; 1337.2402710344868 1337.1164280455926 … 592.9597968731641 99.99999999999999; … ; 0.24460313438160014 0.24361339410088076 … 0.035686345057875525 2.961072463609396e-61; 2.758555677331161e-23 2.7585556777259765e-23 … 1.4248337222010024e-24 1.4349282284323437e-45], [2674.6003523460245 2674.3546387472747 … 1187.3640070966605 199.99999999999997; 1337.3001761730122 1337.1773193736374 … 593.6820035483303 99.99999999999999; … ; 0.24509218597617205 0.24410001468633039 … 0.03572919595122062 2.9684795376459773e-61; 7.735264301766732e-24 7.735264298974134e-24 … 4.0738741580915556e-25 4.102775593534894e-46]])
Results
plotcurr(nresult)
plot1d(nresult,ncelldata, nvshow)
Comparison
let vis = GridVisualizer(;
size = (600, 400),
title = "IV Curve",
xlabel = "Φ_WE/V",
ylabel = "I/(A/m^2)",
legend = :lt,
)
scalarplot!(vis,
nresult.voltages,
currents(nresult,io2);
label = "O2,electroneutral",
color = :green,
clear = false,
limits= [-5.0e4, 5.0e4])
scalarplot!(vis, result.voltages, currents(result, io2); label = "O2,PNP", color = :red,
clear = false)
reveal(vis)
end