Skip to content

Commit

Permalink
fix inhomogeneous equation in a system of equations
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Jul 15, 2024
1 parent 67e9ded commit a8ffecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion odetoolbox/system_of_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def generate_propagator_solver(self):
# this is an inhomogeneous ODE
if _is_zero(self.A_[row, row]):
# of the form x' = const
update_expr_terms.append(Config().output_timestep_symbol + " * " + str(self.b_[col]))
update_expr_terms.append(Config().output_timestep_symbol + " * " + str(self.b_[row]))
else:
particular_solution = -self.b_[row] / self.A_[row, row]
sym_str = "__P__{}__{}".format(str(self.x_[row]), str(self.x_[row]))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_inhomogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,17 @@ def test_inhomogeneous_solver_second_order_combined_system_api(self):
result = odetoolbox.analysis(indict)
assert len(result) == 1 \
and result[0]["solver"] == "analytical"

def test_inhomogeneous_solver_combined_system(self):
r"""test propagators generation for combined homogeneous/inhomogeneous ODEs when called via analysis()"""
indict = {"dynamics": [{"expression": "x' = a * 0.001",
"initial_value": "0.3"},
{"expression": "y' = -y / b",
"initial_value": "0"}]}

result = odetoolbox.analysis(indict, log_level="DEBUG")

assert len(result) == 1
assert result[0]["solver"] == "analytical"
assert "__h" in result[0]["update_expressions"]["x"]
assert "__h" not in result[0]["update_expressions"]["y"]

0 comments on commit a8ffecc

Please sign in to comment.