Skip to content

Commit

Permalink
MNT: Move ode solver validation to separate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmbressan committed Dec 7, 2024
1 parent d12ba41 commit 83aa20e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,18 +1213,7 @@ def __init_solver_monitors(self):
self.t = self.solution[-1][0]
self.y_sol = self.solution[-1][1:]

if isinstance(self.ode_solver, OdeSolver):
self._solver = self.ode_solver
else:
try:
self._solver = ODE_SOLVER_MAP[self.ode_solver]
except KeyError as e:
raise ValueError(
f"Invalid ``ode_solver`` input: {self.ode_solver}. "
f"Available options are: {', '.join(ODE_SOLVER_MAP.keys())}"
) from e

self.__is_lsoda = hasattr(self._solver, "_lsoda_solver")
self.__set_ode_solver(self.ode_solver)

def __init_equations_of_motion(self):
"""Initialize equations of motion."""
Expand Down Expand Up @@ -1263,6 +1252,28 @@ def __cache_sensor_data(self):
sensor_data[sensor] = sensor.measured_data[:]
self.sensor_data = sensor_data

def __set_ode_solver(self, solver):
"""Sets the ODE solver to be used in the simulation.
Parameters
----------
solver : str, ``scipy.integrate.OdeSolver``
Integration method to use to solve the equations of motion ODE,
or a custom ``scipy.integrate.OdeSolver``.
"""
if isinstance(solver, OdeSolver):
self._solver = solver
else:
try:
self._solver = ODE_SOLVER_MAP[solver]
except KeyError as e:
raise ValueError(
f"Invalid ``ode_solver`` input: {solver}. "
f"Available options are: {', '.join(ODE_SOLVER_MAP.keys())}"
) from e

self.__is_lsoda = hasattr(self._solver, "_lsoda_solver")

@cached_property
def effective_1rl(self):
"""Original rail length minus the distance measured from nozzle exit
Expand Down

0 comments on commit 83aa20e

Please sign in to comment.