Battery Pack 18650 Series Parallel
Source: examples/grammar/battery_pack_18650_series_parallel.py
Introduction
Build and evaluate a feasible constrained rectangular 4S4P battery pack.
Technical Implementation
This page is generated from the top-of-file module docstring and the example source code. The full script is included below for direct inspection.
1from __future__ import annotations
2
3import design_research_problems as derp
4
5
6def main() -> None:
7 """Build the constrained feasible 4S4P case and evaluate it when ``pybamm`` is installed.
8
9 Raises:
10 RuntimeError: If the constructed example pack evaluates as infeasible.
11 """
12
13 # Load the constrained rectangular battery grammar and start from its 1S1P seed pack.
14 problem = derp.get_problem("battery_pack_18650_series_parallel")
15 state = problem.initial_state()
16
17 # Add three more series stages. In this grammar each add_series_stage call must
18 # provide one placement for every existing parallel branch, which is one cell at
19 # a time while the pack is still 1P.
20 state = problem.add_series_stage(state, placements=((1, 0, 0),))
21 state = problem.add_series_stage(state, placements=((2, 0, 0),))
22 state = problem.add_series_stage(state, placements=((3, 0, 0),))
23
24 # Add three more parallel branches. Once the pack is 4S, each add_parallel_branch
25 # call must provide one placement for every series stage, so each edit adds a
26 # full new branch of four cells.
27 state = problem.add_parallel_branch(state, placements=((0, 1, 0), (1, 1, 0), (2, 1, 0), (3, 1, 0)))
28 state = problem.add_parallel_branch(state, placements=((0, 2, 0), (1, 2, 0), (2, 2, 0), (3, 2, 0)))
29 state = problem.add_parallel_branch(state, placements=((0, 3, 0), (1, 3, 0), (2, 3, 0), (3, 3, 0)))
30
31 print(problem.metadata.problem_id)
32 print(f"{state.series_count}S{state.parallel_count}P with {len(state.cells)} cells")
33 try:
34 # The packaged evaluator checks the rectangular topology, translates it into
35 # the shared explicit circuit backend, and then runs the battery simulation.
36 evaluation = problem.evaluate(state)
37 except derp.MissingOptionalDependencyError as exc:
38 print(exc)
39 return
40 if not evaluation.is_feasible:
41 raise RuntimeError("The constrained battery example should evaluate to a feasible design.")
42 print(evaluation.is_feasible, round(evaluation.design_volume, 2))
43
44
45if __name__ == "__main__":
46 main()
Expected Results
Run Command
PYTHONPATH=src python3 examples/grammar/battery_pack_18650_series_parallel.py
Run the command shown below from repository root. Output should summarize the problem setup, a baseline solution, or diagnostic values relevant to this example.