Skip to content

Commit 2cd3f44

Browse files
committedDec 3, 2019
#492 fix easy tests
1 parent 194c707 commit 2cd3f44

11 files changed

+55
-25
lines changed
 

‎examples/scripts/compare_lead_acid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
models = [
2020
pybamm.lead_acid.LOQS(),
2121
# pybamm.lead_acid.FOQS(),
22-
# pybamm.lead_acid.Composite(),
22+
pybamm.lead_acid.Composite(),
2323
pybamm.lead_acid.Full(),
2424
]
2525

‎pybamm/parameters/parameter_values.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,21 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
285285
elif processing == "update":
286286
processing_function = self.update_scalars
287287

288-
for variable, equation in unprocessed_model.rhs.items():
288+
for variable, equation in model.rhs.items():
289289
pybamm.logger.debug(
290290
"{} parameters for {!r} (rhs)".format(processing.capitalize(), variable)
291291
)
292292
model.rhs[variable] = processing_function(equation)
293293

294-
for variable, equation in unprocessed_model.algebraic.items():
294+
for variable, equation in model.algebraic.items():
295295
pybamm.logger.debug(
296296
"{} parameters for {!r} (algebraic)".format(
297297
processing.capitalize(), variable
298298
)
299299
)
300300
model.algebraic[variable] = processing_function(equation)
301301

302-
for variable, equation in unprocessed_model.initial_conditions.items():
302+
for variable, equation in model.initial_conditions.items():
303303
pybamm.logger.debug(
304304
"{} parameters for {!r} (initial conditions)".format(
305305
processing.capitalize(), variable
@@ -313,7 +313,7 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
313313
# "positive tab": pos. tab bc "no tab": no tab bc}.
314314
new_boundary_conditions = {}
315315
sides = ["left", "right", "negative tab", "positive tab", "no tab"]
316-
for variable, bcs in unprocessed_model.boundary_conditions.items():
316+
for variable, bcs in model.boundary_conditions.items():
317317
processed_variable = processing_function(variable)
318318
new_boundary_conditions[processed_variable] = {}
319319
for side in sides:
@@ -337,14 +337,14 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
337337

338338
model.boundary_conditions = new_boundary_conditions
339339

340-
for variable, equation in unprocessed_model.variables.items():
340+
for variable, equation in model.variables.items():
341341
pybamm.logger.debug(
342342
"{} parameters for {!r} (variables)".format(
343343
processing.capitalize(), variable
344344
)
345345
)
346346
model.variables[variable] = processing_function(equation)
347-
for event, equation in unprocessed_model.events.items():
347+
for event, equation in model.events.items():
348348
pybamm.logger.debug(
349349
"{} parameters for event '{}''".format(processing.capitalize(), event)
350350
)

‎tests/unit/test_models/test_submodels/test_current_collector/test_composite_potential_pair.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_public_functions(self):
1414
variables = {
1515
"Positive current collector potential": pybamm.PrimaryBroadcast(
1616
0, "current collector"
17-
)
17+
),
18+
"Total current density": 0,
1819
}
1920
std_tests = tests.StandardSubModelTests(submodel, variables)
2021

‎tests/unit/test_models/test_submodels/test_current_collector/test_homogeneous_current_collector.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def test_public_functions(self):
1515
variables = {
1616
"Positive current collector potential": pybamm.PrimaryBroadcast(
1717
0, "current collector"
18-
)
18+
),
19+
"Total current density": 0,
1920
}
2021
std_tests = tests.StandardSubModelTests(submodel, variables)
2122
std_tests.test_all()

‎tests/unit/test_models/test_submodels/test_current_collector/test_potential_pair.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def test_public_functions(self):
1313
variables = {
1414
"Positive current collector potential": pybamm.PrimaryBroadcast(
1515
0, "current collector"
16-
)
16+
),
17+
"Total current density": 0,
1718
}
1819
submodel = pybamm.current_collector.PotentialPair1plus1D(param)
1920
std_tests = tests.StandardSubModelTests(submodel, variables)

‎tests/unit/test_models/test_submodels/test_current_collector/test_set_potential_spm_1plus1d.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_public_functions(self):
2020
"X-averaged negative electrode reaction overpotential": val,
2121
"X-averaged electrolyte overpotential": val,
2222
"X-averaged positive electrode ohmic losses": val,
23-
"X-averaged negative electrode ohmic losses": val
23+
"X-averaged negative electrode ohmic losses": val,
24+
"Total current density": 0,
2425
}
2526
std_tests = tests.StandardSubModelTests(submodel, variables)
2627

@@ -39,7 +40,8 @@ def test_public_functions(self):
3940
"X-averaged negative electrode reaction overpotential": val,
4041
"X-averaged electrolyte overpotential": val,
4142
"X-averaged positive electrode ohmic losses": val,
42-
"X-averaged negative electrode ohmic losses": val
43+
"X-averaged negative electrode ohmic losses": val,
44+
"Total current density": 0,
4345
}
4446
std_tests = tests.StandardSubModelTests(submodel, variables)
4547

‎tests/unit/test_models/test_submodels/test_external_circuit/test_current_control.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class TestCurrentControl(unittest.TestCase):
1111
def test_public_functions(self):
1212
param = pybamm.standard_parameters_lithium_ion
1313
submodel = pybamm.external_circuit.CurrentControl(param)
14-
std_tests = tests.StandardSubModelTests(submodel)
14+
variables = {
15+
"Positive current collector potential": pybamm.Scalar(0),
16+
"Positive current collector potential [V]": pybamm.Scalar(0),
17+
}
18+
std_tests = tests.StandardSubModelTests(submodel, variables)
1519
std_tests.test_all()
1620

1721

‎tests/unit/test_models/test_submodels/test_external_circuit/test_function_control.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class TestFunctionControl(unittest.TestCase):
2121
def test_public_functions(self):
2222
param = pybamm.standard_parameters_lithium_ion
2323
submodel = pybamm.external_circuit.FunctionControl(
24-
param, ExternalCircuitFunction
24+
param, ExternalCircuitFunction()
2525
)
26-
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
26+
variables = {
27+
"Positive current collector potential": pybamm.Scalar(0),
28+
"Positive current collector potential [V]": pybamm.Scalar(0),
29+
}
2730
std_tests = tests.StandardSubModelTests(submodel, variables)
2831
std_tests.test_all()
2932

‎tests/unit/test_models/test_submodels/test_external_circuit/test_power_control.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class TestPowerControl(unittest.TestCase):
1111
def test_public_functions(self):
1212
param = pybamm.standard_parameters_lithium_ion
1313
submodel = pybamm.external_circuit.PowerFunctionControl(param)
14-
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
14+
variables = {
15+
"Positive current collector potential": pybamm.Scalar(0),
16+
"Positive current collector potential [V]": pybamm.Scalar(0),
17+
}
1518
std_tests = tests.StandardSubModelTests(submodel, variables)
1619
std_tests.test_all()
1720

‎tests/unit/test_models/test_submodels/test_external_circuit/test_voltage_control.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ class TestVoltageControl(unittest.TestCase):
1111
def test_public_functions(self):
1212
param = pybamm.standard_parameters_lithium_ion
1313
submodel = pybamm.external_circuit.VoltageFunctionControl(param)
14-
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
14+
variables = {
15+
"Positive current collector potential": pybamm.Scalar(0),
16+
"Positive current collector potential [V]": pybamm.Scalar(0),
17+
}
1518
std_tests = tests.StandardSubModelTests(submodel, variables)
1619
std_tests.test_all()
1720

1821
def test_public_functions_direct(self):
1922
param = pybamm.standard_parameters_lithium_ion
2023
submodel = pybamm.external_circuit.VoltageControl(param)
21-
std_tests = tests.StandardSubModelTests(submodel)
24+
a = pybamm.FullBroadcast(
25+
0,
26+
"positive electrode",
27+
auxiliary_domains={"secondary": "current collector"},
28+
)
29+
variables = {
30+
"Positive electrode potential": a,
31+
"Positive electrode tortuosity": a,
32+
}
33+
std_tests = tests.StandardSubModelTests(submodel, variables)
2234
std_tests.test_all()
2335

2436

‎tests/unit/test_simulation.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def test_basic_ops(self):
3131
self.assertFalse(sim._disc is None)
3232
for val in list(sim.built_model.rhs.values()):
3333
self.assertFalse(val.has_symbol_of_classes(pybamm.Parameter))
34-
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
34+
# skip test for scalar variables (e.g. discharge capacity)
35+
if val.size > 1:
36+
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
3537

3638
sim.reset()
3739
sim.set_parameters()
@@ -60,7 +62,9 @@ def test_solve(self):
6062
self.assertFalse(sim._solution is None)
6163
for val in list(sim.built_model.rhs.values()):
6264
self.assertFalse(val.has_symbol_of_classes(pybamm.Parameter))
63-
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
65+
# skip test for scalar variables (e.g. discharge capacity)
66+
if val.size > 1:
67+
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
6468

6569
sim.reset()
6670
self.assertEqual(sim.model_with_set_params, None)
@@ -76,7 +80,9 @@ def test_solve(self):
7680
sim.solve(check_model=False)
7781
for val in list(sim.built_model.rhs.values()):
7882
self.assertFalse(val.has_symbol_of_classes(pybamm.Parameter))
79-
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
83+
# skip test for scalar variables (e.g. discharge capacity)
84+
if val.size > 1:
85+
self.assertTrue(val.has_symbol_of_classes(pybamm.Matrix))
8086

8187
def test_reuse_commands(self):
8288

@@ -185,10 +191,7 @@ def test_get_variable_array(self):
185191
self.assertIsInstance(c_e, np.ndarray)
186192

187193
def test_set_external_variable(self):
188-
model_options = {
189-
"thermal": "x-lumped",
190-
"external submodels": ["thermal"],
191-
}
194+
model_options = {"thermal": "x-lumped", "external submodels": ["thermal"]}
192195
model = pybamm.lithium_ion.SPMe(model_options)
193196
sim = pybamm.Simulation(model)
194197

0 commit comments

Comments
 (0)
Please sign in to comment.