Tip

An interactive online version of this notebook is available, which can be accessed via Open this notebook in Google Colab


Alternatively, you may download this notebook and run it offline.

Tutorial 4b: Parameter Introspection and Comparison#

This tutorial introduces the parameter introspection features in PyBaMM’s ParameterValues class. These features help you:

  1. Understand parameters - Get metadata like units and categories

  2. Browse by category - Find parameters related to electrodes, thermal, etc.

  3. Compare parameter sets - See differences between parameter sets

[1]:
import pybamm

pybamm.set_logging_level("WARNING")

1. Getting Parameter Information#

The get_info() method returns metadata about a parameter including its value, units, and category.

[2]:
# Load the Chen2020 parameter set
params = pybamm.ParameterValues("Chen2020")

# Get information about a specific parameter
info = params.get_info("Maximum concentration in negative electrode [mol.m-3]")

print(f"Parameter: {info.name}")
print(f"Value: {info.value}")
print(f"Units: {info.units}")
print(f"Category: {info.category}")
print(f"Is function: {info.is_function}")
print(f"Is input parameter: {info.is_input}")
Parameter: Maximum concentration in negative electrode [mol.m-3]
Value: 33133.0
Units: mol.m-3
Category: negative electrode
Is function: False
Is input parameter: False

2. Browsing Parameters by Category#

Use list_by_category() to find all parameters in a specific category, or categories() to see all parameters grouped by category.

[3]:
# List all negative electrode parameters
neg_electrode_params = params.list_by_category("negative electrode")
print(f"Found {len(neg_electrode_params)} negative electrode parameters:")
for p in neg_electrode_params[:5]:  # Show first 5
    print(f"  - {p}")
print("  ...")
Found 19 negative electrode parameters:
  - Negative electrode reaction-driven LAM factor [m3.mol-1]
  - Negative electrode thickness [m]
  - Negative electrode conductivity [S.m-1]
  - Maximum concentration in negative electrode [mol.m-3]
  - Negative particle diffusivity [m2.s-1]
  ...
[4]:
# Get all categories and their counts
all_categories = params.categories()
print("Parameters by category:")
for category, param_list in all_categories.items():
    print(f"  {category}: {len(param_list)} parameters")
Parameters by category:
  other: 14 parameters
  geometric: 7 parameters
  kinetic: 2 parameters
  thermal: 13 parameters
  electrolyte: 4 parameters
  negative electrode: 19 parameters
  positive electrode: 19 parameters
  separator: 6 parameters
  electrical: 9 parameters
[5]:
neg_electrode_params
[5]:
['Negative electrode reaction-driven LAM factor [m3.mol-1]',
 'Negative electrode thickness [m]',
 'Negative electrode conductivity [S.m-1]',
 'Maximum concentration in negative electrode [mol.m-3]',
 'Negative particle diffusivity [m2.s-1]',
 'Negative electrode OCP [V]',
 'Negative electrode porosity',
 'Negative electrode active material volume fraction',
 'Negative particle radius [m]',
 'Negative electrode Bruggeman coefficient (electrolyte)',
 'Negative electrode Bruggeman coefficient (electrode)',
 'Negative electrode charge transfer coefficient',
 'Negative electrode double-layer capacity [F.m-2]',
 'Negative electrode exchange-current density [A.m-2]',
 'Negative electrode density [kg.m-3]',
 'Negative electrode specific heat capacity [J.kg-1.K-1]',
 'Negative electrode thermal conductivity [W.m-1.K-1]',
 'Negative electrode OCP entropic change [V.K-1]',
 'Initial concentration in negative electrode [mol.m-3]']

3. Comparing Parameter Sets#

Use diff() to compare two parameter sets and see what’s different.

[6]:
# Load another parameter set
chen = pybamm.ParameterValues("Chen2020")
marquis = pybamm.ParameterValues("Marquis2019")

# Compare them
diff = chen.diff(marquis)

print(f"Parameters only in Chen2020: {len(diff.removed)}")
print(f"Parameters only in Marquis2019: {len(diff.added)}")
print(f"Parameters with different values: {len(diff.changed)}")
Parameters only in Chen2020: 1
Parameters only in Marquis2019: 12
Parameters with different values: 46
[7]:
# Show some changed parameters
print("\nSome parameters with different values:")
for key, (chen_val, marquis_val) in list(diff.changed.items())[:5]:
    if not callable(chen_val) and not callable(marquis_val):
        print(f"  {key}:")
        print(f"    Chen2020: {chen_val}")
        print(f"    Marquis2019: {marquis_val}")

Some parameters with different values:
  Positive electrode Bruggeman coefficient (electrode):
    Chen2020: 0
    Marquis2019: 1.5
  Current function [A]:
    Chen2020: 5.0
    Marquis2019: 0.680616
  Electrode width [m]:
    Chen2020: 1.58
    Marquis2019: 0.207