I'm currently working on a wind farm design software and basically I have to analyze the incidence of certain wind turbines on other downwind, in order to calculate the velocity drop in the wind once the downstream turbine "sees" the flow.
I have sorted out most of the code and it works, yet this particular piece of it is extremely slow to compute.
for wd in wind_direction_index: self.list_for_speed.append() for ws in wind_speed_index: self.list_for_speed[wd].append() wind_speed = self._wind_speeds[ws] #For every wind turbine, remember this list is still ordered from up to dow dummylist=copy.deepcopy(self.list_for_direction[wd]) for WT in dummylist: #Replace No deficit with 0 if WT=='NO_deficit': WT=[0.0] else: pass #For every WT that causes a wake effect on current one for upWT in WT: #Define current turbine and rotating upwind turbine for ready in dummylist: if upWT==ready: upWT=ready else: pass current_turbine=WT upwind_turbine=upWT #Calculate wind speeds deficits in every current WT due to every upwind WT to it only if here are upwind WTS if len(current_turbine)!=0: self.calculate_deficits(current_turbine,upwind_turbine,wind_speed) else: pass #Now we have appended all deficits in current_turbine(6) Time to add them up, find the speed and replace #First, I square the list of deficits WT=[i**2 for i in WT] #Now, i add the squares of the deficits deficit_squared=sum(WT) #Take the square root deficit_current=sqrt(deficit_squared) #Finally calculate wind speed at the rotor U=wind_speed*(1-deficit_current) #And I replace the list of wind speed deficits with the wind speed at the rotor WT=U _Ct=self.team.rna_analysts.get_Ct(U) #Save results to local wind speeds array self.local_wind_speeds[WT][wd][ws]=[U,_Ct] self.list_for_speed[wd][ws].append(dummylist)
I know it's a bit messy, but you can see more or less how my data structures are arranged. I have to calculate a wind speed "deficit" for every turbine, based on the wind direction and the wind speed (evidenced by
local_wind_speeds). Can anyone spot how to make this piece of code much much faster?