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

Issue 939 sim defaults #952

Merged
merged 6 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

## Bug fixes

- Changed simulation attributes to assign copies rather than the objects themselves ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)
- Added default values to base model so that it works with the `Simulation` class ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)
- Reformatted thermal submodels ([#938](https://github.com/pybamm-team/PyBaMM/pull/938)
- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Reformatted convection submodels ([#635](https://github.com/pybamm-team/PyBaMM/pull/635))
Expand All @@ -21,6 +23,7 @@

- Removed some inputs like `T_inf`, `R_g` and activation energies to some of the standard function parameters. This is because each of those inputs is specific to a particular function (e.g. the reference temperature at which the function was measured). To change a property such as the activation energy, users should create a new function, specifying the relevant property as a `Parameter` or `InputParameter` ([#942](https://github.com/pybamm-team/PyBaMM/pull/942))
- The thermal option 'xyz-lumped' has been removed. The option 'thermal current collector' has also been removed ([#938](https://github.com/pybamm-team/PyBaMM/pull/938)
- The 'C-rate' parameter has been deprecated. Use 'Current function [A]' instead. The cell capacity can be accessed as 'Cell capacity [A.h]', and used to calculate current from C-rate ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)

# [v0.2.1](https://github.com/pybamm-team/PyBaMM/tree/v0.2.1) - 2020-03-31

Expand Down
20 changes: 11 additions & 9 deletions examples/notebooks/compare-ecker-data.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Positive tab centre z-coordinate [m],0.114,Tab at top,
# Electrical,,,
Cell capacity [A.h],17,Manufacturer,
Typical current [A],1,,

Current function [A],1,default current function,
,,,
# Density,,,
Negative current collector density [kg.m-3],11300, same as electrode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Number of electrodes connected in parallel to make a cell,8,Manufacturer,
Number of cells connected in series to make a battery,6,Manufacturer,
Lower voltage cut-off [V],1.73,(just under) 10.5V across 6-cell battery,
Upper voltage cut-off [V],2.44,(just over) 14.5V across 6-cell battery,
C-rate,0.1,,
,,,
# Initial conditions
Initial State of Charge,1,-,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Positive current collector thermal conductivity [W.m-1.K-1],158.079, 237 * 0.667
# Electrical,,,
Cell capacity [A.h],0.43,trial and error,
Typical current [A],0.43,0.2857,1C current
Current function [A],0.43,default current function,
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Positive current collector thermal conductivity [W.m-1.K-1],237,CRC Handbook,alu
,,,
# Electrical,,,
Cell capacity [A.h],5,Chen 2020,
Typical current [A],5,Chen 2020,
Typical current [A],5,Chen 2020,
Current function [A],5,default current function,
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Positive current collector thermal conductivity [W.m-1.K-1],237,,
# Electrical,,,
Cell capacity [A.h],5,Peyman MPM,
Typical current [A],5,,1C current
Current function [A],5,default current function,
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Electrode width [m],8.50E-02,,
# Electrical,,,
Cell capacity [A.h], 0.15625, 7.5/48 (parameter set for a single layer cell),
Typical current [A], 0.15652,,
Current function [A],0.15652,default current function,
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Positive current collector thermal conductivity [W.m-1.K-1],237,,
# Electrical,,,
Cell capacity [A.h],0.680616,,24 Ah/m2 * 0.137m * 0.207m
Typical current [A],0.680616,,1C current
Current function [A],0.680616,default current function,
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Number of electrodes connected in parallel to make a cell,1,,
Number of cells connected in series to make a battery,1,,
Lower voltage cut-off [V],2.5,,
Upper voltage cut-off [V],4.2,,
C-rate,-1,,
,,,
# Initial conditions
Initial concentration in negative electrode [mol.m-3],48.8682,Peyman MPM, x0 (0.0017) * Csmax_n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Number of electrodes connected in parallel to make a cell,1,,
Number of cells connected in series to make a battery,1,,
Lower voltage cut-off [V],2.5,,
Upper voltage cut-off [V],4.4,,
C-rate,1,,
,,,
# Initial conditions
Initial concentration in negative electrode [mol.m-3],30086,Chen 2020,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Number of electrodes connected in parallel to make a cell,1,,
Number of cells connected in series to make a battery,1,,
Lower voltage cut-off [V],2.5,,
Upper voltage cut-off [V],4.2,,
C-rate,1,,
,,,
# Initial conditions
Initial concentration in negative electrode [mol.m-3], 26120.05,,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Number of electrodes connected in parallel to make a cell,1,,
Number of cells connected in series to make a battery,1,,
Lower voltage cut-off [V],2.7,,
Upper voltage cut-off [V],4.5,,
C-rate,1,,
,,,
# Initial conditions
Initial concentration in negative electrode [mol.m-3],18081,0.63*2.84E4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Number of electrodes connected in parallel to make a cell,1,,
Number of cells connected in series to make a battery,1,,
Lower voltage cut-off [V],3.105,,
Upper voltage cut-off [V],4.7,,
C-rate,1,,
,,,
# Initial conditions
Initial concentration in negative electrode [mol.m-3],19986.609595075,Scott Moura FastDFN,
Expand Down
20 changes: 20 additions & 0 deletions pybamm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,26 @@ def info(self, symbol_name):

print(div)

@property
def default_parameter_values(self):
return pybamm.ParameterValues({})

@property
def default_var_pts(self):
return {}

@property
def default_geometry(self):
return {}

@property
def default_submesh_types(self):
return {}

@property
def default_spatial_methods(self):
return {}

@property
def default_solver(self):
"Return default solver based on whether model is ODE model or DAE model"
Expand Down
97 changes: 19 additions & 78 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pandas as pd
import os
import numbers
import numpy as np
from pprint import pformat


Expand Down Expand Up @@ -86,6 +85,13 @@ def __init__(self, values=None, chemistry=None):
def __getitem__(self, key):
return self._dict_items[key]

def get(self, key, default=None):
"Return item correspoonding to key if it exists, otherwise return default"
try:
return self._dict_items[key]
except KeyError:
return default

def __setitem__(self, key, value):
"Call the update functionality when doing a setitem"
self.update({key: value})
Expand All @@ -108,6 +114,11 @@ def items(self):
"Get the items of the dictionary"
return self._dict_items.items()

def copy(self):
"""Returns a copy of the parameter values. Makes sure to copy the internal
dictionary."""
return ParameterValues(values=self._dict_items.copy())

def search(self, key, print_values=True):
"""
Search dictionary for keys containing 'key'.
Expand Down Expand Up @@ -206,6 +217,8 @@ def update(self, values, check_conflict=False, check_already_exists=True, path="
path : string, optional
Path from which to load functions
"""
# check parameter values
self.check_parameter_values(values)
# update
for name, value in values.items():
# check for conflicts
Expand Down Expand Up @@ -265,64 +278,22 @@ def update(self, values, check_conflict=False, check_already_exists=True, path="
values[name] = float(value)
else:
self._dict_items[name] = value
# check parameter values
self.check_and_update_parameter_values(values)
# reset processed symbols
self._processed_symbols = {}

def check_and_update_parameter_values(self, values):
def check_parameter_values(self, values):
# Make sure typical current is non-zero
if "Typical current [A]" in values and values["Typical current [A]"] == 0:
raise ValueError(
"'Typical current [A]' cannot be zero. A possible alternative is to "
"set 'Current function [A]' to `0` instead."
)
if "C-rate" in values and "Current function [A]" in values:
if "C-rate" in values:
raise ValueError(
"Cannot provide both 'C-rate' and 'Current function [A]' simultaneously"
"The 'C-rate' parameter has been deprecated, "
"use 'Current function [A]' instead. The cell capacity can be accessed "
"as 'Cell capacity [A.h]', and used to calculate current from C-rate."
)
# If the capacity of the cell has been provided, make sure "C-rate" and current
# match with the stated capacity
if "Cell capacity [A.h]" in values or "Cell capacity [A.h]" in self._dict_items:
# Capacity from values takes precedence
if "Cell capacity [A.h]" in values:
capacity = values["Cell capacity [A.h]"]
else:
capacity = self._dict_items["Cell capacity [A.h]"]
# Make sure they match if both provided
# Update the other if only one provided
if "C-rate" in values:
# Can't provide C-rate as a function
if callable(values["C-rate"]):
value = CrateToCurrent(values["C-rate"], capacity)
elif isinstance(values["C-rate"], tuple):
data = values["C-rate"][1]
current_data = np.stack([data[:, 0], data[:, 1] * capacity], axis=1)
value = (values["C-rate"][0] + "_to_current", current_data)
elif values["C-rate"] == "[input]":
value = CrateToCurrent(values["C-rate"], capacity, typ="input")
else:
value = values["C-rate"] * capacity
self._dict_items["Current function [A]"] = value
elif "Current function [A]" in values:
if callable(values["Current function [A]"]):
value = CurrentToCrate(values["Current function [A]"], capacity)
elif isinstance(values["Current function [A]"], tuple):
data = values["Current function [A]"][1]
c_rate_data = np.stack([data[:, 0], data[:, 1] / capacity], axis=1)
value = (
values["Current function [A]"][0] + "_to_Crate",
c_rate_data,
)
elif values["Current function [A]"] == "[input]":
value = CurrentToCrate(
values["Current function [A]"], capacity, typ="input"
)
else:
value = values["Current function [A]"] / capacity
self._dict_items["C-rate"] = value

return values

def process_model(self, unprocessed_model, inplace=True):
"""Assign parameter values to a model.
Expand Down Expand Up @@ -598,33 +569,3 @@ def evaluate(self, symbol):

def _ipython_key_completions_(self):
return list(self._dict_items.keys())


class CurrentToCrate:
"Convert a current function to a C-rate function"

def __init__(self, current, capacity, typ="function"):
self.current = current
self.capacity = capacity
self.type = typ

def __call__(self, t):
if self.type == "function":
return self.current(t) / self.capacity
elif self.type == "input":
return pybamm.InputParameter("Current function [A]") / self.capacity


class CrateToCurrent:
"Convert a C-rate function to a current function"

def __init__(self, Crate, capacity, typ="function"):
self.Crate = Crate
self.capacity = capacity
self.type = typ

def __call__(self, t):
if self.type == "function":
return self.Crate(t) * self.capacity
elif self.type == "input":
return pybamm.InputParameter("C-rate") * self.capacity
6 changes: 5 additions & 1 deletion pybamm/parameters/print_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def print_parameters(parameters, parameter_values, output_file=None):
# Calculate parameters for each C-rate
for Crate in [1, 10]:
# Update Crate
parameter_values.update({"C-rate": Crate}, check_already_exists=False)
capacity = parameter_values.get("Cell capacity [A.h]")
if capacity is not None:
parameter_values.update(
{"Current function [A]": Crate * capacity}, check_already_exists=False
)
for name, symbol in parameters.items():
if not callable(symbol):
proc_symbol = parameter_values.process_symbol(symbol)
Expand Down
Loading