Skip to content

Commit d44f526

Browse files
authored
Merge pull request #1510 from pybamm-team/issue-1507-check_algebraic_equations
#1507 remove algebraic equation check
2 parents c8f2174 + e133009 commit d44f526

File tree

5 files changed

+11
-44
lines changed

5 files changed

+11
-44
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
## Bug fixes
2828

29+
- Removed the overly-restrictive check "each variable in the algebraic eqn keys must appear in the eqn" ([#1510](https://github.com/pybamm-team/PyBaMM/pull/1510))
2930
- Made parameters importable through pybamm ([#1475](https://github.com/pybamm-team/PyBaMM/pull/1475))
3031

3132
## Breaking changes

pybamm/models/base_model.py

+8-28
Original file line numberDiff line numberDiff line change
@@ -639,40 +639,20 @@ def check_well_determined(self, post_discretisation):
639639

640640
def check_algebraic_equations(self, post_discretisation):
641641
"""
642-
Check that the algebraic equations are well-posed.
643-
Before discretisation, each algebraic equation key must appear in the equation
644-
After discretisation, there must be at least one StateVector in each algebraic
645-
equation
642+
Check that the algebraic equations are well-posed. After discretisation,
643+
there must be at least one StateVector in each algebraic equation.
646644
"""
647-
vars_in_bcs = set()
648-
unpacker = pybamm.SymbolUnpacker(pybamm.Variable)
649-
for side_eqn in self.boundary_conditions.values():
650-
all_vars = unpacker.unpack_list_of_symbols(
651-
[eqn for eqn, _ in side_eqn.values()]
652-
)
653-
vars_in_bcs.update(all_vars.keys())
654-
if not post_discretisation:
655-
# After the model has been defined, each algebraic equation key should
656-
# appear in that algebraic equation, or in the boundary conditions
657-
# this has been relaxed for concatenations for now
658-
for var, eqn in self.algebraic.items():
659-
if not (
660-
any(x.id == var.id for x in eqn.pre_order())
661-
or var.id in vars_in_bcs
662-
or isinstance(var, pybamm.Concatenation)
663-
):
664-
raise pybamm.ModelError(
665-
"each variable in the algebraic eqn keys must appear in the eqn"
666-
)
667-
else:
668-
# variables in keys don't get discretised so they will no longer match
669-
# with the state vectors in the algebraic equations. Instead, we check
670-
# that each algebraic equation contains some StateVector
645+
if post_discretisation:
646+
# Check that each algebraic equation contains some StateVector
671647
for eqn in self.algebraic.values():
672648
if not eqn.has_symbol_of_classes(pybamm.StateVector):
673649
raise pybamm.ModelError(
674650
"each algebraic equation must contain at least one StateVector"
675651
)
652+
else:
653+
# We do not perfom any checks before discretisation (most problematic
654+
# cases should be caught by `check_well_determined`)
655+
pass
676656

677657
def check_ics_bcs(self):
678658
"""Check that the initial and boundary conditions are well-posed."""

pybamm/models/submodels/current_collector/effective_resistance_current_collector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(self):
350350
f_p: pybamm.laplacian(f_p)
351351
- pybamm.source(1, f_p)
352352
+ c * pybamm.DefiniteIntegralVector(f_p, vector_type="column"),
353-
c: pybamm.yz_average(f_p) + pybamm.NotConstant(0) * c,
353+
c: pybamm.yz_average(f_p),
354354
}
355355

356356
# Boundary conditons

pybamm/models/submodels/current_collector/quite_conductive_potential_pair.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def set_algebraic(self, variables):
6767
* pybamm.laplacian(phi_s_cp)
6868
+ pybamm.source(i_boundary_cc_0, phi_s_cp)
6969
+ c * pybamm.PrimaryBroadcast(cc_area, "current collector"),
70-
c: pybamm.Integral(i_boundary_cc, z)
71-
- applied_current / cc_area
72-
+ pybamm.Multiplication(0, c),
70+
c: pybamm.Integral(i_boundary_cc, z) - applied_current / cc_area,
7371
}
7472

7573
def set_initial_conditions(self, variables):

tests/unit/test_models/test_base_model.py

-12
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,6 @@ def test_check_well_posedness_variables(self):
342342
with self.assertRaisesRegex(pybamm.ModelError, "extra algebraic keys"):
343343
model.check_well_posedness()
344344

345-
# before discretisation, fail if the algebraic eqn keys don't appear in the eqns
346-
model = pybamm.BaseModel()
347-
model.algebraic = {c: d - 2, d: d - c}
348-
with self.assertRaisesRegex(
349-
pybamm.ModelError,
350-
"each variable in the algebraic eqn keys must appear in the eqn",
351-
):
352-
model.check_well_posedness()
353-
# passes when we switch the equations around
354-
model.algebraic = {c: d - c, d: d - 2}
355-
model.check_well_posedness()
356-
357345
# after discretisation, algebraic equation without a StateVector fails
358346
model = pybamm.BaseModel()
359347
model.algebraic = {

0 commit comments

Comments
 (0)