Skip to content

Commit

Permalink
solve for bulk concentrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tlroy committed May 14, 2024
1 parent 1e44722 commit a4f264e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/catalyst_layer_Cu_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from echemfem import EchemSolver
import numpy as np
import csv
from scipy.optimize import fsolve
"""
1D model for the CO2 electrolysis in a copper catalyst layer of a gas diffusion
electrode (GDE). The model uses electroneutral Nernst-Planck in a porous
Expand Down Expand Up @@ -87,6 +88,7 @@
kwb = kwf/Kw

# Bulk Electrolyte concentrations
# These are the values from Corral et al.
pH0 = 7.9
cKb = 1000 # mol/m3
c0Hb = pow(10, -pH0+3) # mol/m3
Expand All @@ -96,6 +98,34 @@
c0CO2b = H_CO2
cb = np.array([c0CO2b, c0OHb, c0Hb, c0CO3b, c0HCO3b, cKb])

## Solving the bicarbonate bulk reaction system + electroneutrality
# The above values don't solve this system with very high accuracy, which is
# problematic since this causes a discontinuity at the boundary condition.
# Instead, we fix CO2 and K+ concentrations and solve for the others using law
# of mass action and electroneutrality. Note that two of the reactions are
# linearly dependent on the others (see above how K3 and K4 are obtained from
# the others.
def reaction_system(u):
C_CO2 = H_CO2
C_K = cKb
C_OH = u[0]
C_HCO3 = u[1]
C_CO3 = u[2]
C_H = u[3]
r3 = 1. - C_HCO3 / (K3 * C_OH * C_CO2)
r4 = 1. - C_CO3 / (K4 * C_HCO3 * C_OH)
rw = 1. - (C_OH * C_H)/Kw
electro = C_K + C_H - C_OH - C_HCO3 - 2 * C_CO3
return [r3, r4, rw, electro]

Ci = [c0OHb, c0HCO3b, c0CO3b, c0Hb]
Copt = fsolve(reaction_system, Ci, xtol=1e-16, maxfev=1000, diag=None)
C_OH_bulk = Copt[0]
C_HCO3_bulk = Copt[1]
C_CO32_bulk = Copt[2]
C_H_bulk = Copt[3]
cb = np.array([c0CO2b, C_OH_bulk, C_H_bulk, C_CO32_bulk, C_HCO3_bulk, cKb])


class PorousSolver(EchemSolver):
def __init__(self):
Expand Down

0 comments on commit a4f264e

Please sign in to comment.