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

Add BaseParameters and SymPy #1495

Merged
merged 5 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ matplotlib >= 2.0
#
guzzle-sphinx-theme
sphinx>=1.5
sympy==1.8
12 changes: 12 additions & 0 deletions pybamm/parameters/base_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pybamm


class BaseParameters:
"""
Overload the `__setattr__` method to record what the variable was called
"""

def __setattr__(self, name, value):
if isinstance(value, pybamm.Symbol):
value.print_name = name
super().__setattr__(name, value)
3 changes: 2 additions & 1 deletion pybamm/parameters/electrical_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#
import pybamm
import numpy as np
from .base_parameters import BaseParameters


class ElectricalParameters:
class ElectricalParameters(BaseParameters):
"""
Standard electrical parameters

Expand Down
3 changes: 2 additions & 1 deletion pybamm/parameters/geometric_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Geometric Parameters
#
import pybamm
from .base_parameters import BaseParameters


class GeometricParameters:
class GeometricParameters(BaseParameters):
"""
Standard geometric parameters

Expand Down
3 changes: 2 additions & 1 deletion pybamm/parameters/lead_acid_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import pybamm
import numpy as np
from .base_parameters import BaseParameters


class LeadAcidParameters:
class LeadAcidParameters(BaseParameters):
"""
Standard Parameters for lead-acid battery models

Expand Down
3 changes: 2 additions & 1 deletion pybamm/parameters/lithium_ion_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#
import pybamm
import numpy as np
from .base_parameters import BaseParameters


class LithiumIonParameters:
class LithiumIonParameters(BaseParameters):
"""
Standard parameters for lithium-ion battery models

Expand Down
2 changes: 1 addition & 1 deletion pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def export_csv(self, filename):

df = pd.DataFrame(parameter_output)
df = df.transpose()
df.to_csv(filename, header=['Value'], index_label="Name [units]")
df.to_csv(filename, header=["Value"], index_label="Name [units]")

def print_parameters(self, parameters, output_file=None):
"""
Expand Down
63 changes: 17 additions & 46 deletions pybamm/parameters/thermal_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Standard thermal parameters
#
import pybamm
from .base_parameters import BaseParameters


class ThermalParameters:
class ThermalParameters(BaseParameters):
"""
Standard thermal parameters

Expand Down Expand Up @@ -67,39 +68,29 @@ def T_amb_dim(self, t):

def rho_cn_dim(self, T):
"""Negative current collector density [kg.m-3]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Negative current collector density [kg.m-3]", inputs
)

def rho_n_dim(self, T):
"""Negative electrode density [kg.m-3]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter("Negative electrode density [kg.m-3]", inputs)

def rho_s_dim(self, T):
"""Separator density [kg.m-3]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter("Separator density [kg.m-3]", inputs)

def rho_p_dim(self, T):
"""Positive electrode density [kg.m-3]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter("Positive electrode density [kg.m-3]", inputs)

def rho_cp_dim(self, T):
"""Positive current collector density [kg.m-3]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Positive current collector density [kg.m-3]", inputs
)
Expand All @@ -116,90 +107,70 @@ def rho_eff_dim(self, T):

def c_p_cn_dim(self, T):
"""Negative current collector specific heat capacity [J.kg-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Negative current collector specific heat capacity [J.kg-1.K-1]", inputs
)

def c_p_n_dim(self, T):
"""Negative electrode specific heat capacity [J.kg-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Negative electrode specific heat capacity [J.kg-1.K-1]", inputs
)

def c_p_s_dim(self, T):
"""Separator specific heat capacity [J.kg-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Separator specific heat capacity [J.kg-1.K-1]", inputs
)

def c_p_p_dim(self, T):
"""Positive electrode specific heat capacity [J.kg-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Positive electrode specific heat capacity [J.kg-1.K-1]", inputs
)

def c_p_cp_dim(self, T):
"""Positive current collector specific heat capacity [J.kg-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Positive current collector specific heat capacity [J.kg-1.K-1]", inputs
)

def lambda_cn_dim(self, T):
"""Negative current collector thermal conductivity [W.m-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Negative current collector thermal conductivity [W.m-1.K-1]", inputs
)

def lambda_n_dim(self, T):
"""Negative electrode thermal conductivity [W.m-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Negative electrode thermal conductivity [W.m-1.K-1]", inputs
)

def lambda_s_dim(self, T):
"""Separator thermal conductivity [W.m-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Separator thermal conductivity [W.m-1.K-1]", inputs
)

def lambda_p_dim(self, T):
"""Positive electrode thermal conductivity [W.m-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Positive electrode thermal conductivity [W.m-1.K-1]", inputs
)

def lambda_cp_dim(self, T):
"""Positive current collector thermal conductivity [W.m-1.K-1]"""
inputs = {
"Temperature [K]": T,
}
inputs = {"Temperature [K]": T}
return pybamm.FunctionParameter(
"Positive current collector thermal conductivity [W.m-1.K-1]", inputs
)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jax==0.1.75
jaxlib==0.1.52
jupyter # For example notebooks
pybtex
sympy==1.8
# Note: Matplotlib is loaded for debug plots but to ensure pybamm runs
# on systems without an attached display it should never be imported
# outside of plot() methods.
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ def compile_KLU():

jax_dependencies = []
if system() != "Windows":
jax_dependencies = [
"jax==0.2.12",
"jaxlib==0.1.65",
]
jax_dependencies = ["jax==0.2.12", "jaxlib==0.1.65"]


# Load text for description and license
Expand Down Expand Up @@ -202,6 +199,7 @@ def compile_KLU():
*jax_dependencies,
"jupyter", # For example notebooks
"pybtex",
"sympy==1.8",
# Note: Matplotlib is loaded for debug plots, but to ensure pybamm runs
# on systems without an attached display, it should never be imported
# outside of plot() methods.
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_parameters/test_base_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Tests for the base_parameters.py
"""
import pybamm
import unittest


class TestBaseParameters(unittest.TestCase):
def test__setattr__(self):
param = pybamm.ElectricalParameters()
self.assertEqual(param.I_typ.print_name, "I_typ")


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()