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

#1075 update default var pts #1081

Merged
merged 2 commits into from
Jun 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 @@ -12,6 +12,7 @@

## Bug fixes

- Update the default variable points to better capture behaviour in the solid particles in li-ion models ([#1081](https://github.com/pybamm-team/PyBaMM/pull/1081))
- Fix `QuickPlot` to display variables discretised by FEM (in y-z) properly ([#1078](https://github.com/pybamm-team/PyBaMM/pull/1078))
- Add length scales to `EffectiveResistance` models ([#1071](https://github.com/pybamm-team/PyBaMM/pull/1071))
- Allowed for pybamm functions exp, sin, cos, sqrt to be used in expression trees that
Expand Down
10 changes: 7 additions & 3 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ def default_geometry(self):
@property
def default_var_pts(self):
var = pybamm.standard_spatial_vars
return {
base_var_pts = {
var.x_n: 20,
var.x_s: 20,
var.x_p: 20,
var.r_n: 10,
var.r_p: 10,
var.r_n: 30,
var.r_p: 30,
var.y: 10,
var.z: 10,
}
# Reduce the default points for 2D current collectors
if self.options["dimensionality"] == 2:
base_var_pts.update({var.x_n: 10, var.x_s: 10, var.x_p: 10})
return base_var_pts

@property
def default_submesh_types(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/test_solvers/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def test_append_external_variables(self):
# solve model
solver = model.default_solver

var = pybamm.standard_spatial_vars
Nr = model.default_var_pts[var.r_n]

T_av = 0
c_s_n_av = np.ones((10, 1)) * 0.6
c_s_n_av = np.ones((Nr, 1)) * 0.6
external_variables = {
"Volume-averaged cell temperature": T_av,
"X-averaged negative particle concentration": c_s_n_av,
Expand All @@ -111,7 +114,7 @@ def test_append_external_variables(self):
t_eval = np.linspace(0, 3600)
sol = solver.solve(model, t_eval, external_variables=external_variables)
np.testing.assert_array_equal(
sol.inputs["Volume-averaged cell temperature"], np.zeros((1, len(sol.t))),
sol.inputs["Volume-averaged cell temperature"], np.zeros((1, len(sol.t)))
)
np.testing.assert_array_equal(
sol.inputs["X-averaged negative particle concentration"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ def test_default_submesh_types(self):
)
)

def test_default_var_pts(self):
var = pybamm.standard_spatial_vars
var_pts = {
var.x_n: 20,
var.x_s: 20,
var.x_p: 20,
var.r_n: 30,
var.r_p: 30,
var.y: 10,
var.z: 10,
}
model = pybamm.BaseBatteryModel({"dimensionality": 0})
self.assertDictEqual(var_pts, model.default_var_pts)

var_pts.update({var.x_n: 10, var.x_s: 10, var.x_p: 10})
model = pybamm.BaseBatteryModel({"dimensionality": 2})
self.assertDictEqual(var_pts, model.default_var_pts)

def test_default_spatial_methods(self):
model = pybamm.BaseBatteryModel({"dimensionality": 0})
self.assertTrue(
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ def test_set_external_variable(self):
model = pybamm.lithium_ion.SPMe(model_options)
sim = pybamm.Simulation(model)

var = pybamm.standard_spatial_vars
Nr = model.default_var_pts[var.r_n]

T_av = 0
c_s_n_av = np.ones((10, 1)) * 0.5
c_s_n_av = np.ones((Nr, 1)) * 0.5
external_variables = {
"Volume-averaged cell temperature": T_av,
"X-averaged negative particle concentration": c_s_n_av,
Expand Down