Skip to content

Commit

Permalink
add option to configure CVODE only to return specified time points
Browse files Browse the repository at this point in the history
even if events fire at inbetween time points
configure with mod.__settings__['cvode_return_event_timepoints']
(default True)
  • Loading branch information
jmrohwer committed Feb 18, 2021
1 parent aef1fac commit c812ccf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pysces/PyscesModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,8 @@ def InitialiseFunctions(self):

# add event types to model
def InitialiseEvents(self):
# return all event time points, even if not in self.sim_time
self.__settings__['cvode_return_event_timepoints'] = True
self.__events__ = []
# for each event
for e in self.__eDict__:
Expand Down Expand Up @@ -4282,9 +4284,9 @@ def ffull(t, s):
sim.rtol = self.__settings__["cvode_reltol"]
t, sim_res = sim.simulate(self.sim_end, ncp=0, ncp_list=self.sim_time)
# needed because CVode adds extra time points around discontinuity
self.sim_time = numpy.array(t)
t = numpy.array(t)
# divide m.sim_time into segments between event firings
idx = [0] + [numpy.max(numpy.where(self.sim_time == i)) for i in
idx = [0] + [numpy.max(numpy.where(t == i)) for i in
problem.event_times] + [len(t)]

# initialise rates array
Expand Down Expand Up @@ -4340,6 +4342,13 @@ def ffull(t, s):
if self.__HAS_RATE_RULES__:
sim_res = numpy.concatenate([sim_res, rrules], axis=1)

if self.__settings__['cvode_return_event_timepoints']:
self.sim_time = t
else:
tidx = [numpy.where(t==i)[0][0] for i in self.sim_time]
sim_res = sim_res[tidx]
rates = rates[tidx]

return sim_res, rates, True

def CVODE_VPYTHON(self, s):
Expand Down

0 comments on commit c812ccf

Please sign in to comment.