Skip to content

Commit

Permalink
Merge branch 'nbmake' of https://github.com/arjxn-py/PyBaMM into nbmake
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Sep 16, 2023
2 parents 565a1f2 + 2a944e8 commit 22fb645
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 48 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@
"bug"
]
},
{
"login": "bobonice",
"name": "bobonice",
"avatar_url": "https://avatars.githubusercontent.com/u/22030806?v=4",
"profile": "https://github.com/bobonice",
"contributions": [
"bug",
"code"
]
},
{
"login": "kratman",
"name": "Eric G. Kratz",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lychee_url_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
--accept 200,429
--exclude-path ./CHANGELOG.md
--exclude-path ./scripts/update_version.py
--exclude-path docs/conf.py
'./**/*.rst'
'./**/*.md'
'./**/*.py'
Expand Down
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
- Implement the MSMR model ([#3116](https://github.com/pybamm-team/PyBaMM/pull/3116))

## Bug fixes

- Fixed a bug that caused incorrect results of “{Domain} electrode thickness change [m]” due to the absence of dimension for the variable `electrode_thickness_change`([#3329](https://github.com/pybamm-team/PyBaMM/pull/3329)).
- Fixed a bug that occured in `check_ys_are_not_too_large` when trying to reference `y-slice` where the referenced variable was not a `pybamm.StateVector` ([#3313](https://github.com/pybamm-team/PyBaMM/pull/3313)
- Fixed a bug with `_Heaviside._evaluate_for_shape` which meant some expressions involving heaviside function and subtractions did not work ([#3306](https://github.com/pybamm-team/PyBaMM/pull/3306))
- The `OneDimensionalX` thermal model has been updated to account for edge/tab cooling and account for the current collector volumetric heat capacity. It now gives the correct behaviour compared with a lumped model with the correct total heat transfer coefficient and surface area for cooling. ([#3042](https://github.com/pybamm-team/PyBaMM/pull/3042))
- Fixed a bug where the "basic" lithium-ion models gave incorrect results when using nonlinear particle diffusivity ([#3207](https://github.com/pybamm-team/PyBaMM/pull/3207))
- Particle size distributions now work with SPMe and NewmanTobias models ([#3207](https://github.com/pybamm-team/PyBaMM/pull/3207))
- Fix to simulate c_rate steps with drive cycles ([#3186](https://github.com/pybamm-team/PyBaMM/pull/3186))
- Parameters in `Prada2013` have been updated to better match those given in the paper, which is a 2.3 Ah cell, instead of the mix-and-match with the 1.1 Ah cell from Lain2019.
- Error generated when invalid parameter values are passed. ([#3132](https://github.com/pybamm-team/PyBaMM/pull/3132))
- Thevenin() model is now constructed with standard variables: `Time [s], Time [min], Time [h]` ([#3143](https://github.com/pybamm-team/PyBaMM/pull/3143))
- Always save last cycle in experiment, to fix issues with `starting_solution` and `last_state` ([#3177](https://github.com/pybamm-team/PyBaMM/pull/3177))
- Fix simulations with `starting_solution` to work with `start_time` experiments ([#3177](https://github.com/pybamm-team/PyBaMM/pull/3177))
- Fix SEI Example Notebook ([#3166](https://github.com/pybamm-team/PyBaMM/pull/3166))
- Thevenin() model is now constructed with standard variables: `Time [s]`, `Time [min]`, `Time [h]` ([#3143](https://github.com/pybamm-team/PyBaMM/pull/3143))
- Error generated when invalid parameter values are passed ([#3132](https://github.com/pybamm-team/PyBaMM/pull/3132))
- Parameters in `Prada2013` have been updated to better match those given in the paper, which is a 2.3 Ah cell, instead of the mix-and-match with the 1.1 Ah cell from Lain2019 ([#3096](https://github.com/pybamm-team/PyBaMM/pull/3096))



## Breaking changes

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://batterycontrolgroup.engin.umich.edu/"><img src="https://avatars.githubusercontent.com/u/633873?v=4?s=100" width="100px;" alt="Jason Siegel"/><br /><sub><b>Jason Siegel</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=js1tr3" title="Code">💻</a> <a href="#ideas-js1tr3" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tommaull"><img src="https://avatars.githubusercontent.com/u/101814207?v=4?s=100" width="100px;" alt="Tom Maull"/><br /><sub><b>Tom Maull</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=tommaull" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=tommaull" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ejfdickinson"><img src="https://avatars.githubusercontent.com/u/116663050?v=4?s=100" width="100px;" alt="ejfdickinson"/><br /><sub><b>ejfdickinson</b></sub></a><br /><a href="#ideas-ejfdickinson" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Aejfdickinson" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bobonice"><img src="https://avatars.githubusercontent.com/u/22030806?v=4?s=100" width="100px;" alt="bobonice"/><br /><sub><b>bobonice</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Abobonice" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=bobonice" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kratman"><img src="https://avatars.githubusercontent.com/u/10170302?v=4?s=100" width="100px;" alt="Eric G. Kratz"/><br /><sub><b>Eric G. Kratz</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=kratman" title="Documentation">📖</a> <a href="#infra-kratman" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
</tbody>
Expand Down
46 changes: 42 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,52 @@
# a conflict with the sphinx-docsearch extension for Algolia search

nbsphinx_requirejs_path = ""

# For notebook downloads (23.5 onwards), we get the version from the environment
# variable READTHEDOCS_VERSION and set it accordingly.

# If the version is set to "latest", then we are on the develop branch, and we
# point to the notebook in the develop blob
# If we are on "stable", we point to the notebook in the relevant release tree
# for the PyBaMM version
# On a PR build, we use READTHEDOCS_GIT_COMMIT_HASH which will always point to changes
# made to a notebook, if any.
# On local builds, the version is not set, so we use "latest".

if (os.environ.get("READTHEDOCS_VERSION") == "latest") or (
os.environ.get("READTHEDOCS_VERSION") is None
):
notebooks_version = "develop"
append_to_url = f"blob/{notebooks_version}"

if os.environ.get("READTHEDOCS_VERSION") == "stable":
notebooks_version = version
append_to_url = f"tree/v{notebooks_version}"

if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external":
notebooks_version = os.environ.get("READTHEDOCS_GIT_COMMIT_HASH")
append_to_url = f"blob/{notebooks_version}"

github_download_url = f"https://github.com/pybamm-team/PyBaMM/{append_to_url}"
google_colab_url = github_download_url.replace("github.com", "githubtocolab.com")

html_context.update(
{
"notebooks_version": notebooks_version,
"github_download_url": github_download_url,
"google_colab_url": google_colab_url,
}
)

nbsphinx_prolog = r"""
{% set github_docname =
'github/pybamm-team/pybamm/blob/develop/docs/' +
env.doc2path(env.docname, base=None) %}
{% set readthedocs_download_url =
'https://docs.pybamm.org/en/latest/' %}
{% set notebooks_version = env.config.html_context.notebooks_version %}
{% set github_download_url = env.config.html_context.github_download_url %}
{% set google_colab_url = env.config.html_context.google_colab_url %}
{% set doc_path = env.doc2path(env.docname, base=None) %}
Expand All @@ -323,15 +361,15 @@
<p>
An interactive online version of this notebook is available, which can be
accessed via
<a href="https://colab.research.google.com/{{ github_docname | e }}"
<a href="{{ google_colab_url | e }}/docs/{{ doc_path | e }}"
target="_blank">
<img src="https://colab.research.google.com/assets/colab-badge.svg"
alt="Open this notebook in Google Colab"/></a>
</p>
<hr>
<p>
Alternatively, you may
<a href="{{ readthedocs_download_url | e }}{{ doc_path | e }}"
<a href="{{ github_download_url | e }}/docs/{{ doc_path | e }}"
target="_blank" download>
download this notebook</a> and run it offline.
</p>
Expand Down

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pybamm/models/submodels/particle_mechanics/base_mechanics.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def _get_mechanical_results(self, variables):
c_0 = domain_param.c_0
E0 = domain_param.E
nu = domain_param.nu
L0 = domain_param.L
sto_init = pybamm.r_average(domain_param.prim.c_init / domain_param.prim.c_max)
v_change = pybamm.x_average(
eps_s * domain_param.prim.t_change(sto_rav)
) - pybamm.x_average(eps_s * domain_param.prim.t_change(sto_init))

electrode_thickness_change = self.param.n_electrodes_parallel * v_change
electrode_thickness_change = self.param.n_electrodes_parallel * v_change * L0
# Ai2019 eq [10]
disp_surf = Omega * R0 / 3 * (c_s_rav - c_0)
# c0 reference concentration for no deformation
Expand Down
118 changes: 92 additions & 26 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,21 @@ def solve(
starting_solution.all_first_states.copy()
)

# set simulation initial_start_time
if starting_solution is None:
initial_start_time = self.experiment.initial_start_time
else:
initial_start_time = starting_solution.initial_start_time

if (
initial_start_time is None
and self.experiment.initial_start_time is not None
):
raise ValueError(
"When using experiments with `start_time`, the starting_solution "
"must have a `start_time` too."
)

cycle_offset = len(starting_solution_cycles)
all_cycle_solutions = starting_solution_cycles
all_summary_variables = starting_solution_summary_variables
Expand All @@ -660,6 +675,49 @@ def solve(
idx = 0
num_cycles = len(self.experiment.cycle_lengths)
feasible = True # simulation will stop if experiment is infeasible

# Add initial padding rest if current time is earlier than first start time
# This could be the case when using a starting solution
if starting_solution is not None:
op_conds = self.experiment.operating_conditions_steps[0]
if op_conds.start_time is not None:
rest_time = (
op_conds.start_time
- (
initial_start_time
+ timedelta(seconds=float(current_solution.t[-1]))
)
).total_seconds()
if rest_time > pybamm.settings.step_start_offset:
# logs["step operating conditions"] = "Initial rest for padding"
# callbacks.on_step_start(logs)

kwargs["inputs"] = {
**user_inputs,
"Ambient temperature [K]": (
op_conds.temperature or self._original_temperature
),
"start time": current_solution.t[-1],
}
steps = current_solution.cycles[-1].steps
step_solution = current_solution.cycles[-1].steps[-1]

step_solution_with_rest = self.run_padding_rest(
kwargs, rest_time, step_solution
)
steps[-1] = step_solution + step_solution_with_rest

cycle_solution, _, _ = pybamm.make_cycle_solution(
steps, esoh_solver=esoh_solver, save_this_cycle=True
)
old_cycles = current_solution.cycles.copy()
old_cycles[-1] = cycle_solution
current_solution += step_solution_with_rest
current_solution.cycles = old_cycles

# Update _solution
self._solution = current_solution

for cycle_num, cycle_length in enumerate(
# tqdm is the progress bar.
tqdm.tqdm(
Expand All @@ -683,6 +741,8 @@ def solve(
save_this_cycle = (
# always save cycle 1
cycle_num == 1
# always save last cycle
or cycle_num == num_cycles
# None: save all cycles
or save_at_cycles is None
# list: save all cycles in the list
Expand Down Expand Up @@ -710,7 +770,7 @@ def solve(
(
op_conds.end_time
- (
self.experiment.initial_start_time
initial_start_time
+ timedelta(seconds=float(start_time))
)
).total_seconds(),
Expand Down Expand Up @@ -765,41 +825,25 @@ def solve(
rest_time = (
op_conds.next_start_time
- (
self.experiment.initial_start_time
initial_start_time
+ timedelta(seconds=float(step_solution.t[-1]))
)
).total_seconds()
if rest_time > pybamm.settings.step_start_offset:
start_time = step_solution.t[-1]
# Let me know if you have a better name
op_conds_str = "Rest for padding"
model = self.op_conds_to_built_models[op_conds_str]
solver = self.op_conds_to_built_solvers[op_conds_str]

logs["step number"] = (step_num, cycle_length)
logs["step operating conditions"] = op_conds_str
logs["step operating conditions"] = "Rest for padding"
callbacks.on_step_start(logs)

ambient_temp = (
op_conds.temperature or self._original_temperature
)
kwargs["inputs"] = {
**user_inputs,
"Ambient temperature [K]": ambient_temp,
"start time": start_time,
"Ambient temperature [K]": (
op_conds.temperature or self._original_temperature
),
"start time": step_solution.t[-1],
}
# Make sure we take at least 2 timesteps
# The period is hardcoded to 10 minutes, the user can
# always override it by adding a rest step
npts = max(int(round(rest_time / 600)) + 1, 2)

step_solution_with_rest = solver.step(
step_solution,
model,
rest_time,
npts=npts,
save=False,
**kwargs,

step_solution_with_rest = self.run_padding_rest(
kwargs, rest_time, step_solution
)
step_solution += step_solution_with_rest

Expand Down Expand Up @@ -903,8 +947,30 @@ def solve(

callbacks.on_experiment_end(logs)

# record initial_start_time of the solution
self.solution.initial_start_time = initial_start_time

return self.solution

def run_padding_rest(self, kwargs, rest_time, step_solution):
model = self.op_conds_to_built_models["Rest for padding"]
solver = self.op_conds_to_built_solvers["Rest for padding"]

# Make sure we take at least 2 timesteps. The period is hardcoded to 10
# minutes,the user can always override it by adding a rest step
npts = max(int(round(rest_time / 600)) + 1, 2)

step_solution_with_rest = solver.step(
step_solution,
model,
rest_time,
npts=npts,
save=False,
**kwargs,
)

return step_solution_with_rest

def step(
self, dt, solver=None, npts=2, save=True, starting_solution=None, **kwargs
):
Expand Down
12 changes: 12 additions & 0 deletions pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def __init__(
# Initialize empty summary variables
self._summary_variables = None

# Initialise initial start time
self.initial_start_time = None

# Solution now uses CasADi
pybamm.citations.register("Andersson2019")

Expand Down Expand Up @@ -434,6 +437,15 @@ def cycles(self, cycles):
def summary_variables(self):
return self._summary_variables

@property
def initial_start_time(self):
return self._initial_start_time

@initial_start_time.setter
def initial_start_time(self, value):
"""Updates the reason for termination"""
self._initial_start_time = value

def set_summary_variables(self, all_summary_variables):
summary_variables = {var: [] for var in all_summary_variables[0]}
for sum_vars in all_summary_variables:
Expand Down
Loading

0 comments on commit 22fb645

Please sign in to comment.