Skip to content

Commit

Permalink
#692 added an get_external_variables method to submodels
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Nov 6, 2019
1 parent fb69f96 commit eb0685e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,19 @@ def build_model(self):
)
self.variables.update(submodel.get_fundamental_variables())

# Get any external variables
self.external_variables = []
for submodel_name, submodel in self.submodels.items():
pybamm.logger.debug(
"Getting external variables for {} submodel ({})".format(
submodel_name, self.name
)
)
variables, external_variables = submodel.get_external_variables()

self.variables.update(variables)
self.external_variables += external_variables

# Get coupled variables
# Note: pybamm will try to get the coupled variables for the submodels in the
# order they are set by the user. If this fails for a particular submodel,
Expand Down Expand Up @@ -454,6 +467,7 @@ def build_model(self):
pybamm.logger.debug(
"Setting rhs for {} submodel ({})".format(submodel_name, self.name)
)

submodel.set_rhs(self.variables)
pybamm.logger.debug(
"Setting algebraic for {} submodel ({})".format(
Expand Down
15 changes: 15 additions & 0 deletions pybamm/models/submodels/base_submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ def get_fundamental_variables(self):
"""
return {}

def set_external_variables(self):
"""
A public method that creates and returns the variables in a submodel which are
suppled external to the model.
Returns
-------
dict :
The variables created by the submodel which are independent of variables in
other submodels.
list :
A list of the external variables in the model.
"""
return {}, []

def get_coupled_variables(self, variables):
"""
A public method that creates and returns the variables in a submodel which
Expand Down
Empty file.
32 changes: 32 additions & 0 deletions pybamm/models/submodels/thermal/external/full.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# A class for full external thermal models
#
import pybamm

from ..base_thermal import BaseThermal


class Full(BaseThermal):
"""Class to link full external thermal submodels.
Parameters
----------
param : parameter class
The parameters to use for this submodel
**Extends:** :class:`pybamm.thermal.BaseModel`
"""

def __init__(self, param):
super().__init__(param)

def get_external_variables(self):
T = pybamm.standard_variables.T
T_cn = pybamm.BoundaryValue(T, "left")
T_cp = pybamm.BoundaryValue(T, "right")

variables = self._get_standard_fundamental_variables(T, T_cn, T_cp)
external_variables = [T]

return variables, external_variables
39 changes: 39 additions & 0 deletions pybamm/models/submodels/thermal/external/lumped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# A class for external lumped thermal models
#
import pybamm

from ..base_thermal import BaseThermal


class Full(BaseThermal):
"""Class to link external lumped thermal submodels.
Parameters
----------
param : parameter class
The parameters to use for this submodel
**Extends:** :class:`pybamm.thermal.BaseModel`
"""

def __init__(self, param):
super().__init__(param)

def get_external_variables(self):
T_x_av = pybamm.standard_variables.T_av
T_n = pybamm.PrimaryBroadcast(T_x_av, "negative electrode")
T_s = pybamm.PrimaryBroadcast(T_x_av, "separator")
T_p = pybamm.PrimaryBroadcast(T_x_av, "positive electrode")
T = pybamm.Concatenation(T_n, T_s, T_p)

T_cn = T_x_av
T_cp = T_x_av

variables = self._get_standard_fundamental_variables(T, T_cn, T_cp)
variables = self._get_standard_fundamental_variables(T, T_cn, T_cp)

external_variables = [T_x_av]

return variables, external_variables

0 comments on commit eb0685e

Please sign in to comment.