# Blend\_electode modelling

**URL:** <https://pybamm.discourse.group/t/blend-electode-modelling/247>\
**Category:** General\
**Created:** [19 March 2025 15:55 UTC](https://pybamm.discourse.group/t/blend-electode-modelling/247 "2025-03-19T15:55:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Anfal](https://pybamm.discourse.group/u/Anfal)\
**Post date:** [19 March 2025 15:55 UTC](https://pybamm.discourse.group/t/blend-electode-modelling/247/1 "2025-03-19T15:55:18Z")

</div>

Hi everyone,

I’m running a PyBaMM simulation and trying to define a custom exchange current density function for the **secondary positive electrode**. The function works when I input values manually, but when I pass it as a parameter to PyBaMM, I get the error:

```auto
TypeError: exchange_current_density_secondary() takes 2 positional arguments but 4 were given.

```

Here’s my function:

def exchange\_current\_density\_secondary(x, T): if x \< 0.85: return ((-4098733 \* x) + 3804998) \* np.exp(-(35418) / (298.15 \* 8.3145)) else: return ((-4098733 \* 0.85) + 3804998) \* np.exp(-(35418) / (298.15 \* 8.3145))

And I’m passing it to PyBaMM like this:

custom\_parameters = { … “Secondary: Positive electrode exchange-current density [A.m-2]”: exchange\_current\_density\_secondary, … }

When I replace `exchange_current_density_secondary` with a constant value, everything runs fine. But when I use the function, PyBaMM seems to call it with four arguments instead of two.

### **What I’ve Tried:**

- Checking if PyBaMM expects a function with a different signature.
- Adding `*args, **kwargs` to capture extra arguments, but the error persists.
- Printing the arguments passed to the function—PyBaMM does seem to pass extra arguments, but I don’t know why.

### **Questions:**

1. How does PyBaMM internally handle functions passed as parameters?
2. Does the exchange current density function need a different signature for PyBaMM to use it correctly?
3. Has anyone faced a similar issue, and how did you solve it?

Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![DrSOKane](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DrSOKane](https://pybamm.discourse.group/u/DrSOKane)\
**Post date:** [25 March 2025 15:37 UTC](https://pybamm.discourse.group/t/blend-electode-modelling/247/2 "2025-03-25T15:37:58Z")

</div>

Hi Anfal,

PyBaMM requires function parameters to be in a specific format. For example, the exchange current density requires four arguments: electrolyte concentration, surface concentration, maximum surface concentration and temperature. Here is an example:

```auto
def graphite_electrolyte_exchange_current_density_Ecker2015(c_e, c_s_surf, c_s_max, T):
    """
    Exchange-current density for Butler-Volmer reactions between graphite and LiPF6 in
    EC:DMC.

    References
    ----------
    .. [1] Ecker, Madeleine, et al. "Parameterization of a physico-chemical model of
    a lithium-ion battery i. determination of parameters." Journal of the
    Electrochemical Society 162.9 (2015): A1836-A1848.
    .. [2] Ecker, Madeleine, et al. "Parameterization of a physico-chemical model of
    a lithium-ion battery ii. model validation." Journal of The Electrochemical
    Society 162.9 (2015): A1849-A1857.
    .. [3] Richardson, Giles, et. al. "Generalised single particle models for
    high-rate operation of graded lithium-ion electrodes: Systematic derivation
    and validation." Electrochemica Acta 339 (2020): 135862

    Parameters
    ----------
    c_e : :class:`pybamm.Symbol`
        Electrolyte concentration [mol.m-3]
    c_s_surf : :class:`pybamm.Symbol`
        Particle concentration [mol.m-3]
    c_s_max : :class:`pybamm.Symbol`
        Maximum particle concentration [mol.m-3]
    T : :class:`pybamm.Symbol`
        Temperature [K]

    Returns
    -------
    :class:`pybamm.Symbol`
        Exchange-current density [A.m-2]
    """

    k_ref = 1.11 * 1e-10

    # multiply by Faraday's constant to get correct units
    m_ref = (
        pybamm.constants.F * k_ref
    ) # (A/m2)(m3/mol)**1.5 - includes ref concentrations
    E_r = 53400

    arrhenius = pybamm.exp(-E_r / (pybamm.constants.R * T)) * pybamm.exp(
        E_r / (pybamm.constants.R * 296.15)
    )

    return m_ref * arrhenius * c_e **0.5 * c_s_surf** 0.5 * (c_s_max - c_s_surf) ** 0.5

```

It doesn’t matter if your function only takes two inputs; PyBaMM will reject any function that does not accept all four inputs. If there is no dependence on `c_e` or `c_s_max`, then you need to put them as inputs but then leave them unused. Many functions in PyBaMM’s ready-made parameter sets do exactly this.

---

<div class="post-metadata">

**Author:** ![Anfal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Anfal](https://pybamm.discourse.group/u/Anfal)\
**Post date:** [28 March 2025 07:59 UTC](https://pybamm.discourse.group/t/blend-electode-modelling/247/3 "2025-03-28T07:59:43Z")

</div>

Hi DrSOKane,  
Thanks alot for your response, I was able to run it properly by providing for arguments as above.
