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

#1110 fix bug #1111

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion examples/scripts/DFN.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# solve model
t_eval = np.linspace(0, 3600, 100)
solver = pybamm.CasadiSolver(atol=1e-6, rtol=1e-3)
solution = solver.solve(model, t_eval)
solution = solver.solve(model, t_eval, inputs={"eps_n": 0.3})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep the DFN example without inputs, we can have a separate example for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, forgot to remove this


# plot
plot = pybamm.QuickPlot(
Expand Down
4 changes: 1 addition & 3 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,13 @@ def _process_symbol(self, symbol):
function = pybamm.Scalar(
function_name, name=symbol.name
) * pybamm.ones_like(*new_children)
elif isinstance(function_name, pybamm.InputParameter):
# Replace the function with an input parameter
function = function_name
elif (
isinstance(function_name, pybamm.Symbol)
and function_name.evaluates_to_number()
):
# If the "function" provided is a pybamm scalar-like, use ones_like to
# get the right shape
# This also catches input parameters
function = function_name * pybamm.ones_like(*new_children)
elif callable(function_name):
# otherwise evaluate the function to create a new PyBaMM object
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,28 @@ def test_process_function_parameter(self):
processed_func = parameter_values.process_symbol(func)
self.assertEqual(processed_func.evaluate(inputs={"vec": 13}), 13)

# make sure function keeps the domain of the original function

def my_func(x):
return 2 * x

x = pybamm.standard_spatial_vars.x_n
func = pybamm.FunctionParameter("func", {"x": x})

parameter_values = pybamm.ParameterValues({"func": my_func})
func1 = parameter_values.process_symbol(func)

parameter_values = pybamm.ParameterValues({"func": pybamm.InputParameter("a")})
func2 = parameter_values.process_symbol(func)

parameter_values = pybamm.ParameterValues(
{"func": pybamm.InputParameter("a", "negative electrode")}
)
func3 = parameter_values.process_symbol(func)

self.assertEqual(func1.domains, func2.domains)
self.assertEqual(func1.domains, func3.domains)

def test_process_inline_function_parameters(self):
def D(c):
return c ** 2
Expand Down