Skip to content

Commit

Permalink
#492 passes voltage function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Jul 25, 2019
1 parent 78c563e commit 37903e6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pybamm/expression_tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def _function_simplify(self, simplified_children):
elif isinstance(self.function, pybamm.GetConstantCurrent):
# If self.function() is a constant current then simplify to scalar
return pybamm.Scalar(self.function.parameters_eval["Current [A]"])
elif isinstance(self.function, pybamm.GetConstantVoltage):
return pybamm.Scalar(self.function.parameters_eval["Cell voltage [V]"])
else:
return pybamm.Function(self.function, *simplified_children)

Expand Down
6 changes: 4 additions & 2 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,17 @@ def update_scalars(self, symbol):
continue
elif isinstance(x, pybamm.Function):
# Need to update values in parameters_eval dict of current functions
if isinstance(x.function, pybamm.GetCurrent):
if isinstance(x.function, (pybamm.GetCurrent, pybamm.GetVoltage)):
for param, sym in x.function.parameters.items():
if isinstance(sym, pybamm.Scalar):
try:
x.function.parameters_eval[param] = self[sym.name]
except KeyError:
# KeyError -> name not in parameter dict, don't update
continue
if isinstance(x.function, pybamm.GetCurrentData):
if isinstance(
x.function, (pybamm.GetCurrentData, pybamm.GetVoltageData)
):
# update interpolant
x.function.interpolate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class GetCurrent(object):
"""
The base class for setting the input current for a simulation. The parameters
dictionary holds the symbols of any paramters required to evaluate the current.
dictionary holds the symbols of any parameters required to evaluate the current.
During processing, the evaluated parameters are stored in parameters_eval.
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_parameters/test_voltage_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_constant_voltage(self):
voltage = pybamm.electrical_parameters.voltage_with_time
parameter_values = pybamm.ParameterValues(
{
"Typical voltage [A]": 2,
"Typical voltage [V]": 2,
"Typical timescale [s]": 1,
"Voltage function": pybamm.GetConstantVoltage(),
}
Expand Down

0 comments on commit 37903e6

Please sign in to comment.