Skip to content

Commit

Permalink
Merge pull request #42 from jrenaud90/edits-to-t-eval
Browse files Browse the repository at this point in the history
minor changes to t_eval handling in cysolver
  • Loading branch information
jrenaud90 authored Oct 27, 2023
2 parents 184e287 + a99424d commit 8363584
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CyRK/cy/cysolver.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ cdef class CySolver:

cdef void change_t_eval_pointer(
self,
double * t_eval_ptr,
size_t len_t_eval,
double* new_t_eval_ptr,
size_t new_len_t_eval,
bool_cpp_t auto_reset_state = *
)

Expand Down
35 changes: 22 additions & 13 deletions CyRK/cy/cysolver.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ cdef class CySolver:
# Store y0 values and determine y-size information
self.y_size = y0.size
self.y_size_dbl = <double> self.y_size

self.y_size_sqrt = sqrt(self.y_size_dbl)

self.y0_ptr = <double *> allocate_mem(self.y_size * sizeof(double), 'y0_ptr (init)')
for i in range(self.y_size):
self.y0_ptr[i] = y0[i]
Expand Down Expand Up @@ -1197,6 +1197,10 @@ cdef class CySolver:
# Setup loop variables
cdef size_t i, j

# Check to make sure that t-eval is set
if not self.t_eval_ptr:
raise ValueError('Interpolation function called but t_eval_ptr is null.')

# TODO: The current version of CySolver has not implemented sicpy's dense output. Instead we use an interpolation.
# Build final interpolated time and solution arrays
if self._interpolate_solution_t_ptr is NULL:
Expand Down Expand Up @@ -1619,17 +1623,17 @@ cdef class CySolver:
self.len_t_eval * sizeof(double),
't_eval_ptr (change_t_eval)')

for i in range(self.len_t_eval):
if self.run_interpolation:
if self.run_interpolation:
for i in range(self.len_t_eval):
self.t_eval_ptr[i] = t_eval[i]

if auto_reset_state:
self.reset_state()

cdef void change_t_eval_pointer(
self,
double* t_eval_ptr,
size_t len_t_eval,
double* new_t_eval_ptr,
size_t new_len_t_eval,
bool_cpp_t auto_reset_state = False
):
"""
Expand All @@ -1645,16 +1649,21 @@ cdef class CySolver:

# Determine interpolation information
self.run_interpolation = True
self.len_t_eval = len_t_eval
self.len_t_eval = new_len_t_eval

self.t_eval_ptr = <double *> reallocate_mem(
self.t_eval_ptr,
self.len_t_eval * sizeof(double),
't_eval_ptr (change_t_eval_pointer)')
if self.t_eval_ptr is NULL:
self.t_eval_ptr = <double *> allocate_mem(
self.len_t_eval * sizeof(double),
't_eval_ptr (change_t_eval_pointer)')
else:
self.t_eval_ptr = <double *> reallocate_mem(
self.t_eval_ptr,
self.len_t_eval * sizeof(double),
't_eval_ptr (change_t_eval_pointer)')

for i in range(self.len_t_eval):
if self.run_interpolation:
self.t_eval_ptr[i] = t_eval_ptr[i]
if self.run_interpolation:
for i in range(self.len_t_eval):
self.t_eval_ptr[i] = new_t_eval_ptr[i]

if auto_reset_state:
self.reset_state()
Expand Down

0 comments on commit 8363584

Please sign in to comment.