Skip to content

Commit

Permalink
Merge branch 'develop' into black_action
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshuone6 committed Sep 12, 2022
2 parents 390b654 + b25ce8c commit 5ff3370
Show file tree
Hide file tree
Showing 41 changed files with 1,221 additions and 1,839 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/validation_benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Alert validation repository
on:
release:
types:
- published
push:
branches:
- develop

jobs:
build:
name: Dispatch to `pybamm-validation`
runs-on: ubuntu-latest
steps:
- uses: mvasigh/dispatch-action@main
with:
token: ${{ secrets.BENCHMARKS_ACCESS_TOKEN }}
repo: pybamm-validation
owner: pybamm-team
event_type: ${{ github.event_name }}
message: |
{
"commit_hash": "$GITHUB_SHA"
}
2 changes: 1 addition & 1 deletion .github/workflows/work_precision_sets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Generate work precision sets

on:
release:
types: [created]
types: [published]
workflow_dispatch:

jobs:
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Features

- For experiments, the simulation now automatically checks and skips steps that cannot be performed (e.g. "Charge at 1C until 4.2V" from 100% SOC) ([#2212](https://github.com/pybamm-team/PyBaMM/pull/2212))

## Breaking changes

- Events must now be defined in such a way that they are positive at the initial conditions (events will be triggered when they become negative, instead of when they change sign in either direction) ([#2212](https://github.com/pybamm-team/PyBaMM/pull/2212))

# [v22.8](https://github.com/pybamm-team/PyBaMM/tree/v22.8) - 2022-08-31

## Features
Expand Down Expand Up @@ -294,7 +302,7 @@ example notebook ([#1602](https://github.com/pybamm-team/PyBaMM/pull/1602))
## Breaking changes

- Refactored the `particle` submodel module, with the models having no size distribution now found in `particle.no_distribution`, and those with a size distribution in `particle.size_distribution`. Renamed submodels to indicate the transport model (Fickian diffusion, polynomial profile) and if they are "x-averaged". E.g., `FickianManyParticles` and `FickianSingleParticle` are now `no_distribution.FickianDiffusion` and `no_distribution.XAveragedFickianDiffusion` ([#1602](https://github.com/pybamm-team/PyBaMM/pull/1602))
- Changed sensitivity API. Removed `ProcessedSymbolicVariable`, all sensitivity now handled within the solvers and `ProcessedVariable` () ([#1552](https://github.com/pybamm-team/PyBaMM/pull/1552))
- Changed sensitivity API. Removed `ProcessedSymbolicVariable`, all sensitivity now handled within the solvers and `ProcessedVariable` ([#1552](https://github.com/pybamm-team/PyBaMM/pull/1552),[#2276](https://github.com/pybamm-team/PyBaMM/pull/2276))
- The `Yang2017` parameter set has been removed as the complete parameter set is not publicly available in the literature ([#1577](https://github.com/pybamm-team/PyBaMM/pull/1577))
- Changed how options are specified for the "loss of active material" and "particle cracking" submodels. "loss of active material" can now be one of "none", "stress-driven", or "reaction-driven", or a 2-tuple for different options in negative and positive electrode. Similarly "particle cracking" (now called "particle mechanics") can now be "none", "swelling only", "swelling and cracking", or a 2-tuple ([#1490](https://github.com/pybamm-team/PyBaMM/pull/1490))
- Changed the variable in the full diffusion model from "Electrolyte concentration" to "Porosity times concentration" ([#1476](https://github.com/pybamm-team/PyBaMM/pull/1476))
Expand Down
3 changes: 1 addition & 2 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@
#
# Solver classes
#
from .solvers.solution import Solution, make_cycle_solution
from .solvers.solution import Solution, EmptySolution, make_cycle_solution
from .solvers.processed_variable import ProcessedVariable
from .solvers.processed_symbolic_variable import ProcessedSymbolicVariable
from .solvers.base_solver import BaseSolver
from .solvers.dummy_solver import DummySolver
from .solvers.algebraic_solver import AlgebraicSolver
Expand Down
3 changes: 2 additions & 1 deletion pybamm/expression_tree/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class SolverError(Exception):
Solver error: a solution to the model could not be found with the chosen settings
"""

pass
def __init__(self, *args):
self.message = args[0]


class SolverWarning(UserWarning):
Expand Down
24 changes: 14 additions & 10 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,19 @@ def __init__(self, extra_options):

super().__init__(options.items())

def phase_number_to_names(self, number):
"""
Converts number of phases to a list ["primary", "secondary", ...]
"""
number = int(number)
phases = ["primary"]
if number >= 2:
phases.append("secondary")
return phases
@property
def phases(self):
try:
return self._phases
except AttributeError:
self._phases = {}
for domain in ["negative", "positive"]:
number = int(getattr(self, domain)["particle phases"])
phases = ["primary"]
if number >= 2:
phases.append("secondary")
self._phases[domain] = phases
return self._phases

def print_options(self):
"""
Expand Down Expand Up @@ -1340,7 +1344,7 @@ def x_not_zero(x):
self.events.append(
pybamm.Event(
"Maximum voltage",
V - self.param.voltage_high_cut,
self.param.voltage_high_cut - V,
pybamm.EventType.TERMINATION,
)
)
Expand Down
6 changes: 3 additions & 3 deletions pybamm/models/full_battery_models/lead_acid/basic_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ def __init__(self, name="Basic full model"):
"Zero negative electrode porosity cut-off", pybamm.min(eps_n)
),
pybamm.Event(
"Max negative electrode porosity cut-off", pybamm.max(eps_n) - 1
"Max negative electrode porosity cut-off", 1 - pybamm.max(eps_n)
),
pybamm.Event(
"Zero positive electrode porosity cut-off", pybamm.min(eps_p)
),
pybamm.Event(
"Max positive electrode porosity cut-off", pybamm.max(eps_p) - 1
"Max positive electrode porosity cut-off", 1 - pybamm.max(eps_p)
),
]
)
Expand Down Expand Up @@ -294,6 +294,6 @@ def __init__(self, name="Basic full model"):
self.events.extend(
[
pybamm.Event("Minimum voltage", voltage - param.voltage_low_cut),
pybamm.Event("Maximum voltage", voltage - param.voltage_high_cut),
pybamm.Event("Maximum voltage", param.voltage_high_cut - voltage),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ def __init__(self, options=None, name="Unnamed lithium-ion model", build=False):
)

# Add relevant secondary length scales
phases_p = int(getattr(self.options, "positive")["particle phases"])
if phases_p >= 2:
if len(self.options.phases["positive"]) >= 2:
self._length_scales["positive secondary particle"] = self.param.p.sec.R_typ
phases_n = int(getattr(self.options, "negative")["particle phases"])
if not self.half_cell and phases_n >= 2:
if not self.half_cell and len(self.options.phases["negative"]) >= 2:
self._length_scales["negative secondary particle"] = self.param.n.sec.R_typ

self.set_standard_output_variables()
Expand Down Expand Up @@ -134,14 +132,11 @@ def set_degradation_variables(self):
else:
domains = ["negative", "positive"]
for domain in domains:
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
self.variables[f"Total lithium in {domain} electrode [mol]"] = sum(
self.variables[
f"Total lithium in {phase} phase in {domain} electrode [mol]"
]
for phase in phases
for phase in self.options.phases[domain]
)

# LAM
Expand Down Expand Up @@ -255,10 +250,7 @@ def set_summary_variables(self):
def set_open_circuit_potential_submodel(self):
for domain in ["negative", "positive"]:
domain_options = getattr(self.options, domain)
phases = self.options.phase_number_to_names(
domain_options["particle phases"]
)
for phase in phases:
for phase in self.options.phases[domain]:
ocp_option = getattr(domain_options, phase)["open circuit potential"]
ocp_submodels = pybamm.open_circuit_potential
if ocp_option == "single":
Expand Down Expand Up @@ -345,9 +337,7 @@ def set_crack_submodel(self):
def set_active_material_submodel(self):
for domain in ["negative", "positive"]:
lam = getattr(self.options, domain)["loss of active material"]
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
phases = self.options.phases[domain]
for phase in phases:
if lam == "none":
submod = pybamm.active_material.Constant(
Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/lithium_ion/basic_dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,5 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
# Events specify points at which a solution should terminate
self.events += [
pybamm.Event("Minimum voltage", voltage - param.voltage_low_cut),
pybamm.Event("Maximum voltage", voltage - param.voltage_high_cut),
pybamm.Event("Maximum voltage", param.voltage_high_cut - voltage),
]
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __init__(self, options=None, name="Doyle-Fuller-Newman half cell model"):
self.events.append(
pybamm.Event(
"Maximum voltage",
voltage_dim - self.param.voltage_high_cut_dimensional,
self.param.voltage_high_cut_dimensional - voltage_dim,
pybamm.EventType.TERMINATION,
)
)
Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/lithium_ion/basic_spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,5 @@ def __init__(self, name="Single Particle Model"):
}
self.events += [
pybamm.Event("Minimum voltage", V - param.voltage_low_cut),
pybamm.Event("Maximum voltage", V - param.voltage_high_cut),
pybamm.Event("Maximum voltage", param.voltage_high_cut - V),
]
25 changes: 6 additions & 19 deletions pybamm/models/full_battery_models/lithium_ion/dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,12 @@ def set_convection_submodel(self):
] = pybamm.convection.through_cell.NoConvection(self.param, self.options)

def set_intercalation_kinetics_submodel(self):
for domain in ["Negative", "Positive"]:
for domain in ["negative", "positive"]:
intercalation_kinetics = self.get_intercalation_kinetics(domain)
phases = self.options.phase_number_to_names(
getattr(self.options, domain.lower())["particle phases"]
)
for phase in ["primary", "secondary"]:
# Add kinetics for each phase included in the options
# If a phase is not included, add "NoReaction"
if phase in phases:
submod = intercalation_kinetics(
self.param, domain, "lithium-ion main", self.options, phase
)
else:
submod = pybamm.kinetics.NoReaction(
self.param, domain, "lithium-ion main", self.options, phase
)
for phase in self.options.phases[domain]:
submod = intercalation_kinetics(
self.param, domain, "lithium-ion main", self.options, phase
)
self.submodels[f"{domain.lower()} {phase} interface"] = submod

self.submodels[
Expand All @@ -84,10 +74,7 @@ def set_intercalation_kinetics_submodel(self):
def set_particle_submodel(self):
for domain in ["negative", "positive"]:
particle = getattr(self.options, domain)["particle"]
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
for phase in phases:
for phase in self.options.phases[domain]:
if particle == "Fickian diffusion":
submod = pybamm.particle.FickianDiffusion(
self.param, domain, self.options, phase=phase, x_average=False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ def __init__(self, options=None, name="Newman-Tobias model", build=True):
def set_particle_submodel(self):
for domain in ["negative", "positive"]:
particle = getattr(self.options, domain)["particle"]
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
for phase in phases:
for phase in self.options.phases[domain]:
if particle == "Fickian diffusion":
submod = pybamm.particle.FickianDiffusion(
self.param, domain, self.options, phase=phase, x_average=True
Expand Down
23 changes: 5 additions & 18 deletions pybamm/models/full_battery_models/lithium_ion/spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,10 @@ def set_intercalation_kinetics_submodel(self):
)
else:
intercalation_kinetics = self.get_intercalation_kinetics(domain)
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
for phase in ["primary", "secondary"]:
# Add kinetics for each phase included in the options
# If a phase is not included, add "NoReaction"
if phase in phases:
submod = intercalation_kinetics(
self.param, domain, "lithium-ion main", self.options, phase
)
else:
submod = pybamm.kinetics.NoReaction(
self.param, domain, "lithium-ion main", self.options, phase
)
for phase in self.options.phases[domain]:
submod = intercalation_kinetics(
self.param, domain, "lithium-ion main", self.options, phase
)
self.submodels[f"{domain} {phase} interface"] = submod
self.submodels[
f"total {domain} interface"
Expand All @@ -119,10 +109,7 @@ def set_intercalation_kinetics_submodel(self):
def set_particle_submodel(self):
for domain in ["negative", "positive"]:
particle = getattr(self.options, domain)["particle"]
phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
for phase in phases:
for phase in self.options.phases[domain]:
if particle == "Fickian diffusion":
submod = pybamm.particle.FickianDiffusion(
self.param, domain, self.options, phase=phase, x_average=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def get_coupled_variables(self, variables):
Domain = self.domain
domain = Domain.lower()

phases = self.options.phase_number_to_names(
getattr(self.options, domain)["particle phases"]
)
phases = self.options.phases[domain]
eps_solid = sum(
variables[f"{Domain} electrode {phase} active material volume fraction"]
for phase in phases
Expand Down
19 changes: 8 additions & 11 deletions pybamm/models/submodels/base_submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,20 @@ def __init__(
# Error checks for phase and domain
self.set_phase(phase)

def set_phase(self, phase, check_phases=True):
def set_phase(self, phase):
if phase is not None:
if self.domain is None:
raise ValueError("Phase must be None if domain is None")
options_phase = getattr(self.options, self.domain.lower())[
"particle phases"
]
if check_phases:
if options_phase == "1" and phase != "primary":
raise ValueError(
"Phase must be 'primary' if there is only one phase"
)
elif options_phase == "2" and phase not in ["primary", "secondary"]:
raise ValueError(
"Phase must be either 'primary' or 'secondary' "
"if there are two phases"
)
if options_phase == "1" and phase != "primary":
raise ValueError("Phase must be 'primary' if there is only one phase")
elif options_phase == "2" and phase not in ["primary", "secondary"]:
raise ValueError(
"Phase must be either 'primary' or 'secondary' "
"if there are two phases"
)

if options_phase == "1" and phase == "primary":
# Only one phase, no need to distinguish between
Expand Down
6 changes: 0 additions & 6 deletions pybamm/models/submodels/interface/kinetics/no_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ def __init__(self, param, domain, reaction, options, phase="primary"):
}
super().__init__(param, domain, reaction, options, phase)

def set_phase(self, phase):
"""
Bypass the phase checks from BaseSubmodel
"""
super().set_phase(phase, check_phases=False)

def get_fundamental_variables(self):
zero = pybamm.Scalar(0)
variables = self._get_standard_interfacial_current_variables(zero)
Expand Down
Loading

0 comments on commit 5ff3370

Please sign in to comment.