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

#1722 store first states #1759

Merged
merged 2 commits into from
Oct 27, 2021
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 @@ -2,6 +2,7 @@

## Features

- Added `all_first_states` to the `Solution` object for a simulation with experiment ([#1759](https://github.com/pybamm-team/PyBaMM/pull/1759))
- Added a new method (`create_gif`) in `QuickPlot`, `Simulation` and `BatchStudy` to create a GIF of a simulation ([#1754](https://github.com/pybamm-team/PyBaMM/pull/1754))
- SEI models can now be included in the half-cell model ([#1705](https://github.com/pybamm-team/PyBaMM/pull/1705))

Expand Down
13 changes: 12 additions & 1 deletion pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,15 +781,20 @@ def solve(
if starting_solution is None:
starting_solution_cycles = []
starting_solution_summary_variables = []
starting_solution_first_states = []
else:
starting_solution_cycles = starting_solution.cycles.copy()
starting_solution_summary_variables = (
starting_solution.all_summary_variables.copy()
)
starting_solution_first_states = (
starting_solution.all_first_states.copy()
)

cycle_offset = len(starting_solution_cycles)
all_cycle_solutions = starting_solution_cycles
all_summary_variables = starting_solution_summary_variables
all_first_states = starting_solution_first_states
current_solution = starting_solution

# Set up eSOH model (for summary variables)
Expand Down Expand Up @@ -894,13 +899,18 @@ def solve(
self._solution = self._solution + cycle_solution

# At the final step of the inner loop we save the cycle
cycle_solution, cycle_summary_variables = pybamm.make_cycle_solution(
(
cycle_solution,
cycle_summary_variables,
cycle_first_state,
) = pybamm.make_cycle_solution(
steps,
esoh_sim,
save_this_cycle=save_this_cycle,
)
all_cycle_solutions.append(cycle_solution)
all_summary_variables.append(cycle_summary_variables)
all_first_states.append(cycle_first_state)

# Calculate capacity_start using the first cycle
if cycle_num == 1:
Expand Down Expand Up @@ -935,6 +945,7 @@ def solve(
if self.solution is not None and len(all_cycle_solutions) > 0:
self.solution.cycles = all_cycle_solutions
self.solution.set_summary_variables(all_summary_variables)
self.solution.all_first_states = all_first_states
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't this whole PR be a one-liner with

self.solution.all_first_states = [cycle.first_state for cycle in self.solution.cycles]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried and it doesn't work because if the cycle is not stored cycle is None so you can't pull the first state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah makes sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that's why we were doing this in the first place haha


pybamm.logger.notice(
"Finish experiment simulation, took {}".format(timer.time())
Expand Down
4 changes: 3 additions & 1 deletion pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,14 @@ def make_cycle_solution(step_solutions, esoh_sim=None, save_this_cycle=True):

cycle_summary_variables = get_cycle_summary_variables(cycle_solution, esoh_sim)

cycle_first_state = cycle_solution.first_state

if save_this_cycle:
cycle_solution.cycle_summary_variables = cycle_summary_variables
else:
cycle_solution = None

return cycle_solution, cycle_summary_variables
return cycle_solution, cycle_summary_variables, cycle_first_state


def get_cycle_summary_variables(cycle_solution, esoh_sim):
Expand Down