Skip to content

Commit

Permalink
#2376 add a bpx test
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Oct 18, 2022
1 parent 326d5cf commit 7feb92e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion pybamm/parameters/bpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def bpx_to_param_dict(bpx: BPX) -> dict:
domain.pre_name + 'reaction rate [mol.m-2.s-1]'
]
k = k_norm * F / (c_n_max * c_e ** 0.5)

def exchange_current_density(c_e, c_s_surf, c_s_max, T):
k_ref = k # (A/m2)(mol/m3)**1.5 - includes ref concentrations
E_r = 53400
Expand Down
70 changes: 70 additions & 0 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,76 @@ def test_export_python_script(self):
os.remove(filename)
shutil.rmtree("data")

def test_bpx(self):
bpx_obj = {
"Header": {
"BPX": 1.0,
"Model": "Newman",
},
"Parameterisation": {
"Cell": {
"Initial temperature [K]": 299.0,
"Reference temperature [K]": 299.0,
"Electrode area [m2]": 2.0,
"Number of electrodes connected in parallel to make a cell": 1,
},
"Electrolyte": {
"Initial concentration [mol.m-3]": 1000,
"Cation transference number": 0.259,
"Conductivity [S.m-1]": 1.0,
"Diffusivity [m2.s-1]": (
"8.794e-7 * x * x - 3.972e-6 * x + 4.862e-6"
),
},
"Anode": {
"Particle radius [m]": 5.86e-6,
"Thickness [m]": 85.2e-6,
"Diffusivity [m2.s-1]": 3.3e-14,
"OCP [V]": {"x": [0, 0.1, 1], "y": [1.72, 1.2, 0.06]},
"Conductivity [S.m-1]": 215.0,
"Surface area per unit volume": 383959,
"Porosity": 0.25,
"Transport efficiency": 0.125,
"Reaction rate [mol.m-2.s-1]": 1e-10,
"Initial concentration [mol.m-3]": 29866.1,
"Maximum concentration [mol.m-3]": 33133,
},
"Cathode": {
"Particle radius [m]": 5.22e-6,
"Thickness [m]": 75.6e-6,
"Diffusivity [m2.s-1]": 4.0e-15,
"OCP [V]": {"x": [0, 0.1, 1], "y": [1.72, 1.2, 0.06]},
"Conductivity [S.m-1]": 0.18,
"Surface area per unit volume": 382184,
"Porosity": 0.335,
"Transport efficiency": 0.1939,
"Reaction rate [mol.m-2.s-1]": 1e-10,
"Initial concentration [mol.m-3]": 167920,
"Maximum concentration [mol.m-3]": 631040,
},
"Separator": {
"Thickness [m]": 1.2e-5,
"Porosity": 0.47,
"Transport efficiency": 0.3222,
},
},
}

import json
import tempfile
filename = 'tmp.json'
with tempfile.NamedTemporaryFile(
suffix=filename, delete=False
) as tmp:
# write to a tempory file so we can
# get the source later on using inspect.getsource
# (as long as the file still exists)
json.dump(bpx_obj, tmp)
tmp.flush()

pv = pybamm.ParameterValues.create_from_bpx(tmp.name)
print('got pv', pv)


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down

0 comments on commit 7feb92e

Please sign in to comment.