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 790 param not recognized #796

Merged
merged 10 commits into from
Jan 28, 2020
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 .requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ scikit-fem>=0.2.0
casadi>=3.5.0
guzzle-sphinx-theme
sphinx>=1.5
python-Levenshtein>=0.12.0
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Features

- Added fuzzy string matching for parameters and variables ([#796](https://github.com/pybamm-team/PyBaMM/pull/796))
- Changed ParameterValues to raise an error when a parameter that wasn't previously defined is updated ([#796](https://github.com/pybamm-team/PyBaMM/pull/796))
- Added some basic models (BasicSPM and BasicDFN) in order to clearly demonstrate the PyBaMM model structure for battery models ([#795](https://github.com/pybamm-team/PyBaMM/pull/795))
- Added the harmonic mean to the Finite Volume method, which is now used when computing fluxes ([#783](https://github.com/pybamm-team/PyBaMM/pull/783))
- Refactored `Solution` to make it a dictionary that contains all of the solution variables. This automatically creates `ProcessedVariable` objects when required, so that the solution can be obtained much more easily. ([#781](https://github.com/pybamm-team/PyBaMM/pull/781))
Expand Down
58 changes: 39 additions & 19 deletions examples/notebooks/change-settings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<bound method ParameterValues.items of <pybamm.parameters.parameter_values.ParameterValues object at 0x1113519e8>>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.default_parameter_values.items"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -155,8 +175,8 @@
"Typical current [A] 0.680616\n",
"Negative electrode conductivity [S.m-1] 100.0\n",
"Maximum concentration in negative electrode [mol.m-3] 24983.2619938437\n",
"Negative electrode diffusivity [m2.s-1] <function graphite_mcmb2528_diffusivity_Dualfoil1998 at 0x13e6f9840>\n",
"Negative electrode OCP [V] <function graphite_mcmb2528_ocp_Dualfoil1998 at 0x13e6f96a8>\n",
"Negative electrode diffusivity [m2.s-1] <function graphite_mcmb2528_diffusivity_Dualfoil1998 at 0x13dad4400>\n",
"Negative electrode OCP [V] <function graphite_mcmb2528_ocp_Dualfoil1998 at 0x13dad4598>\n",
"Negative electrode porosity 0.3\n",
"Negative electrode active material volume fraction 0.7\n",
"Negative particle radius [m] 1e-05\n",
Expand All @@ -173,15 +193,15 @@
"Negative electrode density [kg.m-3] 1657.0\n",
"Negative electrode specific heat capacity [J.kg-1.K-1] 700.0\n",
"Negative electrode thermal conductivity [W.m-1.K-1] 1.7\n",
"Negative electrode OCP entropic change [V.K-1] <function graphite_entropic_change_Moura2016 at 0x13e6f9730>\n",
"Negative electrode OCP entropic change [V.K-1] <function graphite_entropic_change_Moura2016 at 0x13dad4488>\n",
"Reference temperature [K] 298.15\n",
"Negative electrode reaction rate <function graphite_electrolyte_reaction_rate_Dualfoil1998 at 0x13e6f98c8>\n",
"Negative electrode reaction rate <function graphite_electrolyte_reaction_rate_Dualfoil1998 at 0x13dad4620>\n",
"Negative reaction rate activation energy [J.mol-1] 37480.0\n",
"Negative solid diffusion activation energy [J.mol-1] 42770.0\n",
"Positive electrode conductivity [S.m-1] 10.0\n",
"Maximum concentration in positive electrode [mol.m-3] 51217.9257309275\n",
"Positive electrode diffusivity [m2.s-1] <function lico2_diffusivity_Dualfoil1998 at 0x13e6f97b8>\n",
"Positive electrode OCP [V] <function lico2_ocp_Dualfoil1998 at 0x13e6f9950>\n",
"Positive electrode diffusivity [m2.s-1] <function lico2_diffusivity_Dualfoil1998 at 0x13dad4510>\n",
"Positive electrode OCP [V] <function lico2_ocp_Dualfoil1998 at 0x13dad46a8>\n",
"Positive electrode porosity 0.3\n",
"Positive electrode active material volume fraction 0.7\n",
"Positive particle radius [m] 1e-05\n",
Expand All @@ -198,8 +218,8 @@
"Positive electrode density [kg.m-3] 3262.0\n",
"Positive electrode specific heat capacity [J.kg-1.K-1] 700.0\n",
"Positive electrode thermal conductivity [W.m-1.K-1] 2.1\n",
"Positive electrode OCP entropic change [V.K-1] <function lico2_entropic_change_Moura2016 at 0x13e6f9a60>\n",
"Positive electrode reaction rate <function lico2_electrolyte_reaction_rate_Dualfoil1998 at 0x13e6f9ae8>\n",
"Positive electrode OCP entropic change [V.K-1] <function lico2_entropic_change_Moura2016 at 0x13dad47b8>\n",
"Positive electrode reaction rate <function lico2_electrolyte_reaction_rate_Dualfoil1998 at 0x13dad4840>\n",
"Positive reaction rate activation energy [J.mol-1] 39570.0\n",
"Positive solid diffusion activation energy [J.mol-1] 18550.0\n",
"Separator porosity 1.0\n",
Expand All @@ -210,8 +230,8 @@
"Separator thermal conductivity [W.m-1.K-1] 0.16\n",
"Typical electrolyte concentration [mol.m-3] 1000.0\n",
"Cation transference number 0.4\n",
"Electrolyte diffusivity [m2.s-1] <function electrolyte_diffusivity_Capiglia1999 at 0x13e6f9c80>\n",
"Electrolyte conductivity [S.m-1] <function electrolyte_conductivity_Capiglia1999 at 0x13e6f99d8>\n",
"Electrolyte diffusivity [m2.s-1] <function electrolyte_diffusivity_Capiglia1999 at 0x13dad49d8>\n",
"Electrolyte conductivity [S.m-1] <function electrolyte_conductivity_Capiglia1999 at 0x13dad4730>\n",
"Electrolyte diffusion activation energy [J.mol-1] 37040.0\n",
"Electrolyte conductivity activation energy [J.mol-1] 34700.0\n",
"Heat transfer coefficient [W.m-2.K-1] 10.0\n",
Expand Down Expand Up @@ -250,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -282,7 +302,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -298,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -314,7 +334,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -352,7 +372,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -384,7 +404,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -408,7 +428,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -453,7 +473,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -477,7 +497,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down
16 changes: 8 additions & 8 deletions examples/notebooks/parameter-values.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"parameter values are {'a': 1, 'b': 2, 'c': 3}\n"
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e0f0>\n"
]
}
],
Expand All @@ -73,7 +73,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"parameter values are {'a': 4, 'b': 5, 'c': 6}\n"
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
]
}
],
Expand Down Expand Up @@ -126,7 +126,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can input functions into the parameter values, either directly"
"We can input functions into the parameter values, either directly (note we bypass the check that the parameter already exists)"
]
},
{
Expand All @@ -138,14 +138,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"parameter values are {'a': 4, 'b': 5, 'c': 6, 'cube function': <function cubed at 0x136260a60>}\n"
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
]
}
],
"source": [
"def cubed(x):\n",
" return x ** 3\n",
"parameter_values.update({\"cube function\": cubed})\n",
"parameter_values.update({\"cube function\": cubed}, check_already_exists=False)\n",
"print(\"parameter values are {}\".format(parameter_values))"
]
},
Expand All @@ -165,7 +165,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"parameter values are {'a': 4, 'b': 5, 'c': 6, 'cube function': <function cubed at 0x136260a60>, 'square function': <function squared at 0x136260ae8>}\n"
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
]
}
],
Expand All @@ -178,7 +178,7 @@
"\"\"\"\n",
")\n",
"f.close()\n",
"parameter_values.update({\"square function\": pybamm.load_function(\"squared.py\")})\n",
"parameter_values.update({\"square function\": pybamm.load_function(\"squared.py\")}, check_already_exists=False)\n",
"print(\"parameter values are {}\".format(parameter_values))"
]
},
Expand Down Expand Up @@ -405,7 +405,7 @@
{
"data": {
"text/plain": [
"{Variable(-0x53753a8d5f6f95de, u, children=[], domain=[], auxiliary_domains={}): Multiplication(0x3e1bde14593f44cc, *, children=['-a', 'y[0:1]'], domain=[], auxiliary_domains={})}"
"{Variable(0x1b4aef6f668c631, u, children=[], domain=[], auxiliary_domains={}): Multiplication(-0x36caade7fdf02dac, *, children=['-a', 'y[0:1]'], domain=[], auxiliary_domains={})}"
]
},
"execution_count": 12,
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/DFN.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# load parameter values and process model and geometry
param = model.default_parameter_values
param["Voltage function [V]"] = 4.1
param.update({"Voltage function [V]": 4.1}, check_already_exists=False)
param.process_model(model)
param.process_geometry(geometry)

Expand Down
1 change: 0 additions & 1 deletion examples/scripts/compare_lead_acid_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
param.update(
{
"Current function [A]": 1,
"Bruggeman coefficient": 0.001,
"Initial State of Charge": 1,
"Typical electrolyte concentration [mol.m-3]": 5600,
"Negative electrode reference exchange-current density [A.m-2]": 0.08,
Expand Down
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def version(formatted=False):
#
# Utility classes and methods
#
from .util import Timer
from .util import Timer, FuzzyDict
from .util import root_dir, load_function, rmse, get_infinite_nested_dict, load
from .logger import logger, set_logging_level
from .settings import settings
Expand Down
4 changes: 2 additions & 2 deletions pybamm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, name="Unnamed model"):
self._algebraic = {}
self._initial_conditions = {}
self._boundary_conditions = {}
self._variables = {}
self._variables = pybamm.FuzzyDict()
self._events = {}
self._concatenated_rhs = None
self._concatenated_algebraic = None
Expand Down Expand Up @@ -208,7 +208,7 @@ def variables(self):

@variables.setter
def variables(self, variables):
self._variables = variables
self._variables = pybamm.FuzzyDict(variables)

def variable_names(self):
return list(self._variables.keys())
Expand Down
Loading