Skip to content

Commit

Permalink
Fix last values of last section
Browse files Browse the repository at this point in the history
  • Loading branch information
daklauss committed Oct 29, 2024
1 parent 8b48d27 commit c3179e8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CADETPythonSimulator/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ def solve(self) -> NoReturn:
# self.initialize_system()
self.initialize_solution_recorder()

for section in self.sections:
for section in self.sections[:-1]:
self.solve_section(section)
self.solve_section(section[-1])

def initialize_system(self):
"""Initialize System."""
Expand All @@ -168,6 +169,7 @@ def initialize_system(self):
def solve_section(
self,
section: Dict,
last_section=False,
) -> NoReturn:
"""
Solve a time section of the differential-algebraic equation system.
Expand All @@ -179,6 +181,8 @@ def solve_section(
----------
section : Dict
The time points at which the solution is sought.
last_section : Bool
Parameter to check if calculating the last section for consistent issues
#TODO: Consider creating a section class instead of using Addict
"""
Expand All @@ -205,7 +209,10 @@ def solve_section(
self._system.y = y_history[-1]
self._system.y_dot = y_dot_history[-1]

self.write_solution(times[:-1], y_history[:-1], y_dot_history[:-1])
if not last_section:
self.write_solution(times[:-1], y_history[:-1], y_dot_history[:-1])
else:
self.write_solution(times, y_history, y_dot_history)

def get_section_solution_times(self, section: Dict) -> np.ndarray:
"""
Expand Down

0 comments on commit c3179e8

Please sign in to comment.