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

#851 fix scaling bug in current data #852

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

## Bug fixes

- Fixed a bug where current loaded from data was incorrectly scaled with the cell capacity ([#852](https://github.com/pybamm-team/PyBaMM/pull/852))
- Moved evaluation of initial conditions to solver ([#839](https://github.com/pybamm-team/PyBaMM/pull/839))
- Fixed a bug where the first line of the data wasn't loaded when parameters are loaded from data ([#819](https://github.com/pybamm-team/PyBaMM/pull/819))
- Made `graphviz` an optional dependency ([#810](https://github.com/pybamm-team/PyBaMM/pull/810))
Expand Down
12 changes: 8 additions & 4 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
import os
import numbers
import numpy as np


class ParameterValues:
Expand Down Expand Up @@ -276,8 +277,8 @@ def check_and_update_parameter_values(self, values):
value = CrateToCurrent(values["C-rate"], capacity)
elif isinstance(values["C-rate"], tuple):
data = values["C-rate"][1]
data[:, 1] = data[:, 1] * capacity
value = (values["C-rate"][0] + "_to_Crate", data)
current_data = np.stack([data[:, 0], data[:, 1] * capacity], axis=1)
value = (values["C-rate"][0] + "_to_current", current_data)
elif values["C-rate"] == "[input]":
value = CrateToCurrent(values["C-rate"], capacity, typ="input")
else:
Expand All @@ -288,8 +289,11 @@ def check_and_update_parameter_values(self, values):
value = CurrentToCrate(values["Current function [A]"], capacity)
elif isinstance(values["Current function [A]"], tuple):
data = values["Current function [A]"][1]
data[:, 1] = data[:, 1] / capacity
value = (values["Current function [A]"][0] + "_to_current", data)
c_rate_data = np.stack([data[:, 0], data[:, 1] / capacity], axis=1)
value = (
values["Current function [A]"][0] + "_to_Crate",
c_rate_data,
)
elif values["Current function [A]"] == "[input]":
value = CurrentToCrate(
values["Current function [A]"], capacity, typ="input"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_check_and_update_parameter_values(self):
linear = np.hstack([x, 2 * x])
values = {"C-rate": ("linear", linear), "Cell capacity [A.h]": 10}
param = pybamm.ParameterValues(values)
self.assertEqual(param["Current function [A]"][0], "linear_to_Crate")
self.assertEqual(param["Current function [A]"][0], "linear_to_current")
np.testing.assert_array_equal(
param["Current function [A]"][1], np.hstack([x, 20 * x])
)
Expand All @@ -110,7 +110,7 @@ def test_check_and_update_parameter_values(self):
linear = np.hstack([x, 2 * x])
values = {"Current function [A]": ("linear", linear), "Cell capacity [A.h]": 10}
param = pybamm.ParameterValues(values)
self.assertEqual(param["C-rate"][0], "linear_to_current")
self.assertEqual(param["C-rate"][0], "linear_to_Crate")
np.testing.assert_array_almost_equal(
param["C-rate"][1], np.hstack([x, 0.2 * x])
)
Expand Down