Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow 3D process variables #4804

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
Draft

Conversation

rtimms
Copy link
Contributor

@rtimms rtimms commented Jan 27, 2025

Description

Allow 3D (in space) processed variables. There is a lot of code duplication in the processed variables code, but we can fix that in a separate PR.

This currently covers the case of variables that are 3D and have a tertiary domain (e.g. particle -> particle size -> electrode) but doesn't work for the special case of 3D variables that only have a primary and secondary domain (e.g. electrode -> current collector, when using the 2D current collector mesh).

Still needs tests.

Fixes #4776 and #2394.

Also, see #1549

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python -m pytest (or $ nox -s tests)
  • The documentation builds: $ python -m pytest --doctest-plus src (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@rtimms
Copy link
Contributor Author

rtimms commented Jan 27, 2025

All these cases work now

import pybamm

# Process variable in 3D
model = pybamm.lithium_ion.DFN(
    options={"current collector": "potential pair", "dimensionality": 1}
)
sim = pybamm.Simulation(model)
sol = sim.solve([0, 100])
sol["Negative particle concentration [mol.m-3]"].entries

# Experiment with 3D vars (particle size distribution)
model = pybamm.lithium_ion.DFN(
    {
        "working electrode": "positive",
        "surface form": "differential",
        "contact resistance": "true",
        "particle size": "distribution",
    }
)

parameter_values = model.default_parameter_values


def f_a_dist_p_dim(R):
    return pybamm.lognormal(R, 8e-6, 1e-6)


distribution_params = {
    "Positive minimum particle radius [m]": 0,
    "Positive maximum particle radius [m]": 3e-5,
    "Positive area-weighted " + "particle-size distribution [m-1]": f_a_dist_p_dim,
}
parameter_values.update(distribution_params, check_already_exists=False)


def D_p(sto, T):
    return 8e-15 + 3e-15 * sto


parameter_values.update(
    {"Positive particle diffusivity [m2.s-1]": D_p}, check_already_exists=False
)

experiment = pybamm.Experiment(["Charge at C/100 for 20 hours", "Rest for 2 hours"])

sim = pybamm.Simulation(
    model,
    parameter_values=parameter_values,
    experiment=experiment,
    solver=pybamm.IDAKLUSolver(),
)
sim.solve(initial_soc=0)

# Experiment with 3D vars (current collector)
options = {"cell geometry": "pouch", "thermal": "x-lumped", "dimensionality": 2}
model = pybamm.lithium_ion.SPMe(options=options)
experiment = pybamm.Experiment(
    [
        "Discharge at 5 C for 10 seconds",
        "Charge at 1 C for 10 seconds",
    ]
)
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.IDAKLUSolver())
sol = sim.solve(calc_esoh=False)
sol["Negative electrode potential [V]"].entries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: DFN + MPM + stoichiometry-dependent diffusivity with string experiments
1 participant