Skip to content

Commit

Permalink
change _process_symbol() to use create_copy() not _binary_create_copy().
Browse files Browse the repository at this point in the history
  • Loading branch information
pipliggins committed May 9, 2024
1 parent 0578ce2 commit 31e65a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 5 additions & 3 deletions pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,12 @@ def new_copy(
Optionally gives the copied symbol new children.
If `perform_simplifications` = True, some classes (e.g. `BinaryOperator`,
`UnaryOperator`, `Concatenation`) will perform simplifications and checks
`UnaryOperator`, `Concatenation`) will perform simplifications and error checks
based on the new children before copying the symbol. This may result in a
different symbol being returned than the one copied. This behaviour can be
turned off if the symbol is required to remain unchanged.
different symbol being returned than the one copied.
Turning off this behaviour to ensure the symbol remains unchanged is
discouraged.
"""
obj = self.create_copy(new_children, perform_simplifications)
obj._print_name = self.print_name
Expand Down
12 changes: 5 additions & 7 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,6 @@ def _process_symbol(self, symbol):
# Process again just to be sure
return self.process_symbol(function_out)

elif isinstance(symbol, pybamm.BinaryOperator):
new_children = [self.process_symbol(child) for child in symbol.children]
return symbol._binary_new_copy(new_children[0], new_children[1])

# Unary operators
elif isinstance(symbol, pybamm.UnaryOperator):
new_child = self.process_symbol(symbol.child)
Expand All @@ -740,9 +736,11 @@ def _process_symbol(self, symbol):
new_symbol.position = new_symbol_position
return new_symbol

# Functions & Concatenations
elif isinstance(symbol, pybamm.Function) or isinstance(
symbol, pybamm.Concatenation
# Functions, BinaryOperators & Concatenations
elif (
isinstance(symbol, pybamm.Function)
or isinstance(symbol, pybamm.Concatenation)
or isinstance(symbol, pybamm.BinaryOperator)
):
new_children = [self.process_symbol(child) for child in symbol.children]
return symbol.create_copy(new_children)
Expand Down

0 comments on commit 31e65a4

Please sign in to comment.