Skip to content

Conversation

@DrSOKane
Copy link
Contributor

Edited BasicDFN2D to make the porosity and active material fractions into FunctionParameters. However, it doesn't seem to have any effect:

import pybamm
import numpy as np

model = pybamm.lithium_ion.BasicDFN2D()
param = pybamm.ParameterValues("Ecker2015")
Lz = param["Electrode height [m]"]


def sigmoid(arg):
    return (1 + np.tanh(arg)) / 2


def top_hat(arg, a, b, k=2025):
    return sigmoid(k * (arg - a)) * sigmoid(k * (b - arg))


def eps_sep(x_s, z_s):
    return 0.508 - 0.458 * (
        top_hat(arg=z_s, a=Lz*0.45, b=Lz*0.55)
    )


param_defect = param.copy()
param_defect.update({"Separator porosity": eps_sep})

Ls = param_defect["Separator thickness [m]"]
param_defect["Separator porosity"](Ls/2,0.5*Lz)

The output is np.float64(0.05000000120084669), as expected.

exp = pybamm.Experiment(["Discharge at 1C until 2.7 V", "Charge at 1C until 4.2 V", "Hold at 4.2 V until C/20"])
sim = pybamm.Simulation(model, parameter_values=param_defect, experiment=exp)
sol = sim.solve()
output_variables = [
    "Negative electrolyte potential [V]",
    "Negative electrode potential [V]",
    "Negative electrode ocp [V]",
    "Electrolyte flux X-component [mol.m-2.s-1]",
    "Electrolyte flux Z-component [mol.m-2.s-1]",
    "Voltage [V]",
]
plot = sol.plot(output_variables, variable_limits="tight", shading="auto")
plot.plot(2.35)
plot.fig.savefig("defect_test_basic2d.png")

yields this figure, in which the z-component of the electrolyte flux is zero plus noise.
defect_test_basic2d

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (154b192) to head (55da99a).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5266      +/-   ##
===========================================
- Coverage    98.66%   98.64%   -0.03%     
===========================================
  Files          323      323              
  Lines        28062    28065       +3     
===========================================
- Hits         27687    27684       -3     
- Misses         375      381       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DrSOKane DrSOKane marked this pull request as ready for review December 19, 2025 15:32
@DrSOKane DrSOKane requested a review from a team as a code owner December 19, 2025 15:32
aabills
aabills previously approved these changes Dec 19, 2025
Copy link
Contributor

@aabills aabills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@DrSOKane
Copy link
Contributor Author

Thanks @aabills! I'm in a mind to add an example before merging.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@DrSOKane
Copy link
Contributor Author

Example failed due to taking too long. How do I change var_pts for the BasicDFN2D class without altering the code?

@aabills
Copy link
Contributor

aabills commented Dec 19, 2025

It should be the same as the standard models, except that you'll need to add var_pts for both the X and Z directions. And you'll need to directly create the spatial variables x and z or use the ones from the model.

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.

5 participants