Oct-02-2019, 07:33 PM
Okay, after reviewing this for a bit, I believe the data types are changing during the loop, which is the major problem with dynamic data types. The range slices (e.g. list[0:j]) return lists of items or even an empty list. So, I suspect the following:
I ran a short test to confirm on my end using the same logic basic logic as your loop:
The loop you have above is infinite because "j=j+1" is on a different indentation level. Also, avoid while loops any time you can; I refactored the while loop into a for loop for you.
- Iteration 1: self.H_ev_hf_vec contains 2 floats, j = 0. Line 9 above changes self.H_ev_hf_vec to a list of [[], float, [float]].
- Iteration 2: self.H_ev_hf_vec contains an empty list, a float, and a list with one float, j = 1. Line 9 above changes self.H_ev_hf_vec to a list of [[[]], float], float, [[float]]].
- Etc.
I ran a short test to confirm on my end using the same logic basic logic as your loop:
x = [1,2,3] for j in range(2): print(x) x = [x[0:j], x[j] + 5.0 / 2.5, x[j+1:]] # Output [1, 2, 3] [[], 3.0, [2, 3]]To verify, add a print() call to print the contents of self.H_ev_hf_vec and self.H_ev_wf_vec.
The loop you have above is infinite because "j=j+1" is on a different indentation level. Also, avoid while loops any time you can; I refactored the while loop into a for loop for you.
self.H_ev_hf_vec = [self.H_ev_ex_l_hf, self.H_ev_su_v_hf] self.H_ev_wf_vec = [self.H_ev_su_l_wf, self.H_ev_ex_l_wf, self.H_ev_su_v_wf, self.H_ev_ex_v_wf] for j in range(max(len(self.H_ev_hf_vec), len(self.H_ev_wf_vec)) - 2): self.Q_ev_hf = self.m_hf * (self.H_ev_hf_vec[j+1] - self.H_ev_hf_vec[j]) self.Q_ev_wf = self.m_wf * (self.H_ev_wf_vec[j+1] - self.H_ev_wf_vec[j]) if self.Q_ev_hf > self.Q_ev_wf: self.H_ev_hf_vec = [self.H_ev_hf_vec[0:j], self.H_ev_hf_vec[j] + self.Q_ev_wf / self.m_hf, self.H_ev_hf_vec[j+1:len(self.H_ev_wf_vec)]] else: self.H_ev_wf_vec = [self.H_ev_wf_vec[0:j], self.H_ev_wf_vec[j] + self.Q_ev_hf / self.m_wf, self.H_ev_wf_vec[j+1:len(self.H_ev_hf_vec)]]