@@ -180,7 +180,7 @@ def set_custom_past(self, past: chspy.CubicHermiteSpline, t_truncate=None):
180180 past .truncate (t_truncate )
181181 self .custom_past = past
182182
183- def finalize (self , times ):
183+ def finalize (self , start_time ):
184184 """
185185 Instantiate and store JiTCDDE integrator.
186186
@@ -208,7 +208,7 @@ def finalize(self, times):
208208 # set initial conditions
209209 if not self .custom_past :
210210 self .y0 = [n .y0 for n in self .nodes .values ()]
211- DDE .constant_past (self .y0 , time = times [ 0 ] )
211+ DDE .constant_past (self .y0 , time = start_time )
212212 else :
213213 # shift past time to end at t = 0
214214 t_last = self .custom_past [- 1 ].time
@@ -262,7 +262,7 @@ def get_node_by_index(self, idx):
262262 raise ValueError (f'Node with index { idx } not found' )
263263
264264 def _prepare_integrator (self ,
265- times ,
265+ start_time = 0.0 ,
266266 abs_tol = 1e-10 ,
267267 rel_tol = 1e-05 ,
268268 min_step = 1e-10 ,
@@ -279,7 +279,7 @@ def _prepare_integrator(self,
279279
280280 # set integrator
281281 print ("finalizing integrator..." )
282- self .finalize (times )
282+ self .finalize (start_time )
283283 self .integrator .set_integration_parameters (atol = abs_tol , rtol = rel_tol , min_step = min_step , max_step = max_step )
284284
285285 def solve (self ,
@@ -311,7 +311,7 @@ def solve(self,
311311 np.ndarray: Solution matrix.
312312 """
313313 self .max_delay = max_delay
314- self ._prepare_integrator (T , abs_tol , rel_tol , min_step , max_step )
314+ self ._prepare_integrator (T [ 0 ] , abs_tol , rel_tol , min_step , max_step )
315315
316316 print ("integrating..." )
317317 # solve
@@ -412,13 +412,14 @@ def equilibrium_search(self,
412412 rel_tol_eq = 1e-4 ,
413413 max_iter = MAX_INT ,
414414 norm = None ,
415- show_conv_metrics = False
415+ show_conv_metrics = False ,
416+ start_time = 0.0
416417 ):
417418 """
418419 Solves until equilibrium condition reached
419420 """
420421 self .max_delay = max_delay
421- self ._prepare_integrator (abs_tol , rel_tol , min_step , max_step )
422+ self ._prepare_integrator (start_time , abs_tol , rel_tol , min_step , max_step )
422423
423424 if self .trip_conditions :
424425 raise ValueError ('equilibrium_search not compatible with trip conditions' )
@@ -683,7 +684,14 @@ def set_dndt(self, r: y, beta_eff: float, Lambda: float, lam: list, C: list):
683684 else :
684685 raise ValueError ("Nodes need to be added to a System() object before setting dynamics." )
685686
686- def set_dcdt (self , n : y , beta : float , Lambda : float , lam : float , flow : bool = False , t_c : float = 0.0 , t_l : float = 0.0 ):
687+ def set_dcdt (self ,
688+ n : y , beta : float ,
689+ Lambda : float ,
690+ lam : float ,
691+ flow : bool = False ,
692+ t_c : float = 0.0 ,
693+ t_l : float = 0.0 ,
694+ force_steady_state : bool = False ):
687695 """
688696 Set the rate of change of precursor concentration.
689697
@@ -716,10 +724,14 @@ def set_dcdt(self, n: y, beta: float, Lambda: float, lam: float, flow: bool = Fa
716724 self .dcdt = 0.0
717725 source = n * beta / Lambda
718726 decay = lam * self .y ()
719- if flow :
727+ if flow and force_steady_state :
720728 outflow = self .y () / t_c
721729 inflow = self .y (t - t_l ) * sp .exp (- lam * t_l ) / t_c
722730 self .dcdt = source - decay - outflow + inflow
731+ elif flow and (not force_steady_state ):
732+ outflow = self .y () / t_c
733+ inflow = (self .y () / t_c ) * (1 - sp .exp (- lam * t_l ) / t_c )
734+ self .dcdt = source - decay - outflow + inflow
723735 else :
724736 self .dcdt = source - decay
725737 else :
0 commit comments