Skip to content

Commit

Permalink
Merge pull request #713 from pybamm-team/issue-711-thermal-bc-bug
Browse files Browse the repository at this point in the history
#711 fix bc bug in 1plus1D
  • Loading branch information
rtimms authored Nov 11, 2019
2 parents 7d31c68 + 28e690a commit 14681fb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

## Bug fixes

- Fixed a bug where boundary conditions were sometimes handled incorrectly in 1+1D models ([#713](https://github.com/pybamm-team/PyBaMM/pull/713))
- Corrected a sign error in Dirichlet boundary conditions in the Finite Element Method ([#706](https://github.com/pybamm-team/PyBaMM/pull/706))
- Passed the correct dimensional temperature to open circuit potential ([#702](https://github.com/pybamm-team/PyBaMM/pull/702))
- Added missing temperature dependence in electrolyte and interface submodels ([#698](https://github.com/pybamm-team/PyBaMM/pull/698))
Expand Down
23 changes: 15 additions & 8 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,26 @@ def check_tab_conditions(self, symbol, bcs):
symbol, domain
)
)

# Replace keys with "left" and "right" as appropriate for 1D meshes
if isinstance(mesh, pybamm.SubMesh1D):
# replace negative and/or positive tab
# send boundary conditions applied on the tabs to "left" or "right"
# depending on the tab location stored in the mesh
for tab in ["negative tab", "positive tab"]:
if any(tab in side for side in list(bcs.keys())):
bcs[mesh.tabs[tab]] = bcs.pop(tab)
# replace no tab
if any("no tab" in side for side in list(bcs.keys())):
if "left" in list(bcs.keys()):
bcs["right"] = bcs.pop("no tab") # tab at bottom
else:
bcs["left"] = bcs.pop("no tab") # tab at top
# if there was a tab at either end, then the boundary conditions
# have now been set on "left" and "right" as required by the spatial
# method, so there is no need to further modify the bcs dict
if all(side in list(bcs.keys()) for side in ["left", "right"]):
pass
# if both tabs are located at z=0 then the "right" boundary condition
# (at z=1) is the condition for "no tab"
elif "left" in list(bcs.keys()):
bcs["right"] = bcs.pop("no tab")
# else if both tabs are located at z=1, the "left" boundary condition
# (at z=0) is the condition for "no tab"
else:
bcs["left"] = bcs.pop("no tab")

return bcs

Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_spatial_methods/test_finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,41 @@ def test_grad_div_with_bcs_on_tab(self):
div_eqn_disc = disc.process_symbol(div_eqn)
div_eqn_disc.evaluate(None, y_test)

def test_neg_pos_bcs(self):
# 2d macroscale
mesh = get_1p1d_mesh_for_testing()
spatial_methods = {
"macroscale": pybamm.FiniteVolume,
"negative particle": pybamm.FiniteVolume,
"positive particle": pybamm.FiniteVolume,
"current collector": pybamm.FiniteVolume,
}
disc = pybamm.Discretisation(mesh, spatial_methods)

# var
var = pybamm.Variable("var", domain="current collector")
disc.set_variable_slices([var])
# grad
grad_eqn = pybamm.grad(var)

# bcs (on each tab)
boundary_conditions = {
var.id: {
"negative tab": (pybamm.Scalar(1), "Dirichlet"),
"positive tab": (pybamm.Scalar(0), "Neumann"),
"no tab": (pybamm.Scalar(8), "Dirichlet"),
}
}
disc.bcs = boundary_conditions

# check after disc that negative tab goes to left and positive tab goes
# to right
disc.process_symbol(grad_eqn)
self.assertEqual(disc.bcs[var.id]["left"][0].id, pybamm.Scalar(1).id)
self.assertEqual(disc.bcs[var.id]["left"][1], "Dirichlet")
self.assertEqual(disc.bcs[var.id]["right"][0].id, pybamm.Scalar(0).id)
self.assertEqual(disc.bcs[var.id]["right"][1], "Neumann")


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

0 comments on commit 14681fb

Please sign in to comment.