Skip to content

Commit

Permalink
Apply user_functions to vecFcode too
Browse files Browse the repository at this point in the history
When functions inside solve block are not inlined sympy cannot find them.
The problem is already fixed for vecJcode, do the same.
  • Loading branch information
Nicolas Cornu authored and Nicolas Cornu committed Sep 27, 2022
1 parent ea1acbd commit e884563
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nmodl/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def solve_lin_system(eq_strings, vars, constants, function_calls, tmp_unique_pre
)
for var, expr in sub_exprs:
new_local_vars.append(sp.ccode(var))
code.append(f"{var} = {sp.ccode(expr.evalf())}")
code.append(f"{var} = {sp.ccode(expr.evalf(), user_functions=custom_fcts)}")
solution_vector = simplified_solution_vector[0]
for var, expr in zip(state_vars, solution_vector):
code.append(f"{sp.ccode(var)} = {sp.ccode(expr.evalf(), contract=False, user_functions=custom_fcts)}")
Expand All @@ -240,7 +240,7 @@ def solve_lin_system(eq_strings, vars, constants, function_calls, tmp_unique_pre
# construct vector F
vecFcode = []
for i, expr in enumerate(vecF):
vecFcode.append(f"F[{i}] = {sp.ccode(expr.simplify().evalf())}")
vecFcode.append(f"F[{i}] = {sp.ccode(expr.simplify().evalf(), user_functions=custom_fcts)}")
# construct matrix J
vecJcode = []
for i, expr in enumerate(matJ):
Expand Down Expand Up @@ -280,7 +280,7 @@ def solve_non_lin_system(eq_strings, vars, constants, function_calls):

vecFcode = []
for i, eq in enumerate(eqs):
vecFcode.append(f"F[{i}] = {sp.ccode(eq.simplify().subs(X_vec_map).evalf())}")
vecFcode.append(f"F[{i}] = {sp.ccode(eq.simplify().subs(X_vec_map).evalf(), user_functions=custom_fcts)}")
vecJcode = []
for i, jac in enumerate(jacobian):
# todo: fix indexing to be ascending order
Expand Down

0 comments on commit e884563

Please sign in to comment.