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

[Bug]: DFN + MPM + stoichiometry-dependent diffusivity with string experiments #4776

Open
Daniel-Nicolae23 opened this issue Jan 20, 2025 · 3 comments · May be fixed by #4804
Open

[Bug]: DFN + MPM + stoichiometry-dependent diffusivity with string experiments #4776

Daniel-Nicolae23 opened this issue Jan 20, 2025 · 3 comments · May be fixed by #4804
Labels
bug Something isn't working

Comments

@Daniel-Nicolae23
Copy link

PyBaMM Version

25.1.0

Python Version

3.12.7

Describe the bug

Reviving bug #3549

DFN + MPM + stoichiometry-dependent diffusivity works with a pybamm.Experiment containing only one string but fails when using multiple steps/cycles.

Steps to Reproduce

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"]) # this fails
# experiment = pybamm.Experiment(["Charge at C/100 for 20 hours"]) # this is fine

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

Relevant log output

Shape not recognized for 48230.0 * y[2:12002](note processing of 3D variables is not yet implemented)
@Daniel-Nicolae23 Daniel-Nicolae23 added the bug Something isn't working label Jan 20, 2025
@rtimms
Copy link
Contributor

rtimms commented Jan 20, 2025

This will be the same issue as #1549

@rtimms
Copy link
Contributor

rtimms commented Jan 20, 2025

IMO we should do the second fix suggested below

Yes, there are two possible fixes, either

edit processed variable so that 3D variables are allowed
or

add a hack to set_initial_conditions_from to avoid needing to call processed variable in 3D
The latter is probably easier. If the 3D variable is already a state in the system (which it will be in most cases), we can just directly call solution.y[slice] instead of solution[var.name]. The reason set_initial_conditions_from calls solution[var.name] by default is so you can initialize a model using a different model which does not have all the same states

@kratman
Copy link
Contributor

kratman commented Jan 20, 2025

Part of #2394

rtimms added a commit that referenced this issue Jan 27, 2025
@rtimms rtimms linked a pull request Jan 27, 2025 that will close this issue
8 tasks
rtimms added a commit that referenced this issue Jan 27, 2025
rtimms added a commit that referenced this issue Jan 30, 2025
rtimms added a commit that referenced this issue Jan 30, 2025
rtimms added a commit that referenced this issue Feb 4, 2025
rtimms added a commit that referenced this issue Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants