Skip to content

Commit

Permalink
Merge pull request #16 from Yuricst/15-solve-function-stops-1-step-to…
Browse files Browse the repository at this point in the history
…o-soon

moving convergence criteria after storing current step information
  • Loading branch information
Yuricst authored Feb 4, 2025
2 parents 0dc8511 + 3a0fe22 commit 9c55daa
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pyqlaw/_qlaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,28 @@ def solve(self, eta_a=0.0, eta_r=0.0):
t_step_local = max(self.step_min, min(self.step_max,h_next))
else:
raise ValueError("integrator name invalid!")


# update battery
if duty:
battery_iter = np.clip(battery_iter-self.battery_charge_discharge_rate[1]*t_step_local,
self.battery_capacity[0], self.battery_capacity[1])
else:
battery_iter = np.clip(battery_iter+self.battery_charge_discharge_rate[0]*t_step_local,
self.battery_capacity[0], self.battery_capacity[1])
if battery_iter == self.battery_capacity[1]:
charging = False # turn OFF charging mode

# store current state etc.
self.times.append(t_iter)
self.states.append(oe_iter)
self.masses.append(mass_iter)
self.controls.append([alpha, beta, throttle])
self.etas.append([val_eta_a, val_eta_r])
self.etas_bounds.append([eta_a_current, eta_r_current])
self.Qs.append(q)
self.dQdts.append(qdot_current)
self.battery.append(battery_iter)

# check convergence
if self.check_convergence(oe_next, self.oeT, self.woe, self.tol_oe) == True:
self.exitcode = 1
Expand Down Expand Up @@ -571,27 +592,6 @@ def solve(self, eta_a=0.0, eta_r=0.0):
self.exitcode = -1
break

# store
self.times.append(t_iter)
self.states.append(oe_iter)
self.masses.append(mass_iter)
self.controls.append([alpha, beta, throttle])
self.etas.append([val_eta_a, val_eta_r])
self.etas_bounds.append([eta_a_current, eta_r_current])
self.Qs.append(q)
self.dQdts.append(qdot_current)

# update battery
if duty:
battery_iter = np.clip(battery_iter-self.battery_charge_discharge_rate[1]*t_step_local,
self.battery_capacity[0], self.battery_capacity[1])
else:
battery_iter = np.clip(battery_iter+self.battery_charge_discharge_rate[0]*t_step_local,
self.battery_capacity[0], self.battery_capacity[1])
if battery_iter == self.battery_capacity[1]:
charging = False # turn OFF charging mode
self.battery.append(battery_iter)

# index update
idx += 1

Expand Down

0 comments on commit 9c55daa

Please sign in to comment.