Example #1
0
def jensen_angle(layout_x, layout_y, wind_speed, angle):
    U0 = wind_speed  # Free stream wind speed

    nt = len(layout_x)  # Number of turbines ## Length of layout list

    k = 0.04  # Decay constant
    r0 = 40.0  # Turbine rotor radius
    # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90.
    angle3 = angle + 180.0
    deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
    proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
    distance = [[0.0 for _ in range(2)] for _ in range(nt)]
    U = [U0 for _ in range(nt)]
    total_deficit = [0.0 for _ in range(nt)]

    for tur in range(nt):
        distance[tur] = [
            distance_to_front(layout_x[tur], layout_y[tur], angle), tur
        ]
    distance.sort()

    for turbine in range(nt):
        for num in range(turbine):
            total_deficit[distance[turbine][1]] += deficit_matrix[
                distance[turbine][1]][distance[num][1]]**2.0

        total_deficit[distance[turbine][1]] = sqrt(
            total_deficit[distance[turbine][1]])
        U[distance[turbine][1]] = U0 * (1.0 -
                                        total_deficit[distance[turbine][1]])

        for i in range(turbine + 1, nt):

            determ = wake.determine_if_in_wake(layout_x[distance[turbine][1]],
                                               layout_y[distance[turbine][1]],
                                               layout_x[distance[i][1]],
                                               layout_y[distance[i][1]], k, r0,
                                               angle3)
            proportion[distance[turbine][1]][distance[i][1]] = determ[0]

            if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                deficit_matrix[distance[i][1]][
                    distance[turbine][1]] = proportion[distance[turbine][1]][
                        distance[i][1]] * wake.wake_deficit(
                            Ct(U[distance[turbine][1]]), k, determ[1], r0)
            else:
                deficit_matrix[distance[i][1]][distance[turbine][1]] = 0.0

    # Farm efficiency
    profit = 0.0

    for l in range(nt):
        profit += power(U[l])

    for g in layout_x:
        print '%f\t' % g
    print
    # print profit
    return -profit
Example #2
0
    def solve_nonlinear(self, params, unknowns, resids):

        U0 = params['mean_ambient_wind_speed']  # Free stream wind speed
        layout_x = params['layout_x']
        layout_y = params['layout_y']
        k = params['k'] = 0.04  # Decay constant
        r0 = params['rotor_radius']  # Turbine rotor radius
        angle = params['wind_direction']
        nt = num_turb
        # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90.
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
        proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
        distance = [[0.0 for _ in range(2)] for _ in range(nt)]
        U = [U0 for _ in range(nt)]
        total_deficit = [0.0 for _ in range(nt)]

        for tur in range(nt):
            distance[tur] = [
                distance_to_front(layout_x[tur], layout_y[tur], angle), tur
            ]
        distance.sort()

        for turbine in range(nt):

            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[
                    distance[turbine][1]][distance[num][1]]**2.0
            total_deficit[distance[turbine][1]] = sqrt(
                total_deficit[distance[turbine][1]])
            U[distance[turbine]
              [1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

            for i in range(turbine + 1, nt):

                determ = wake.determine_if_in_wake(
                    layout_x[distance[turbine][1]],
                    layout_y[distance[turbine][1]], layout_x[distance[i][1]],
                    layout_y[distance[i][1]], k, r0, angle3)
                proportion[distance[turbine][1]][distance[i][1]] = determ[0]

                if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                    deficit_matrix[distance[i][1]][distance[turbine][
                        1]] = proportion[distance[turbine][1]][
                            distance[i][1]] * wake.wake_deficit(
                                Ct(U[distance[turbine][1]]), k, determ[1], r0)
                else:
                    deficit_matrix[distance[i][1]][distance[turbine][1]] = 0.0

        # return [list(_) for _ in zip(
        #     zip([x for (y, x) in sorted(zip([item[0] for item in distance], layout_x))], [x for (y, x) in sorted(
        #         zip([item[0] for item in distance], layout_y))]), U)]

        unknowns['U'] = array(U)
    def jensen_angle(self, U0, angle):

        nt = len(self.layout_y)  # Number of turbines ## Length of layout list

        k = 0.04  # Decay constant
        r0 = 62.0  # Turbine rotor radius
        angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90.
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
        proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
        distance = [[0.0 for _ in range(2)] for _ in range(nt)]
        self.U = [U0 for _ in range(nt)]
        total_deficit = [0.0 for _ in range(nt)]

        for tur in range(nt):
            distance[tur] = [distance_to_front(self.layout_x[tur], self.layout_y[tur], angle), tur]
        distance.sort()

        for turbine in range(nt):
            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0

            total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
            self.U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

            for i in range(turbine + 1, nt):

                determ = wake.determine_if_in_wake(self.layout_x[distance[turbine][1]],
                                                           self.layout_y[distance[turbine][1]],
                                                           self.layout_x[distance[i][1]], self.layout_y[distance[i][1]], k,
                                                           r0, angle3)
                proportion[distance[turbine][1]][distance[i][1]] = determ[0]

                if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                    deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][
                                                                               distance[i][1]] * wake.wake_deficit(
                        Ct(self.U[distance[turbine][1]]), k, determ[1], r0)

        # Farm efficiency
        self.profit = 0.0

        for l in range(nt):
            self.profit += power(self.U[l])
        self.efficiency = self.profit * 100.0 / (float(nt) * power(self.U[distance[0][1]]))  # same as using U0
        self.powers = [power(self.U[i]) for i in range(nt)]

        with open('speed_jensen.dat', 'w') as out:
            for i in range(len(self.U)):
                out.write('{0:f}\n'.format(self.U[i]))
    def solve_nonlinear(self, params, unknowns, resids):

        U0 = params['mean_ambient_wind_speed']  # Free stream wind speed
        layout_x = params['layout_x']
        layout_y = params['layout_y']
        k = params['k'] = 0.04  # Decay constant
        r0 = params['rotor_radius']  # Turbine rotor radius
        angle = params['wind_direction']
        nt = num_turb
        # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90.
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
        proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
        distance = [[0.0 for _ in range(2)] for _ in range(nt)]
        U = [U0 for _ in range(nt)]
        total_deficit = [0.0 for _ in range(nt)]

        for tur in range(nt):
            distance[tur] = [distance_to_front(layout_x[tur], layout_y[tur], angle), tur]
        distance.sort()

        for turbine in range(nt):

            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0
            total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
            U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

            for i in range(turbine + 1, nt):

                determ = wake.determine_if_in_wake(layout_x[distance[turbine][1]],
                                                   layout_y[distance[turbine][1]],
                                                   layout_x[distance[i][1]], layout_y[distance[i][1]], k,
                                                   r0, angle3)
                proportion[distance[turbine][1]][distance[i][1]] = determ[0]

                if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                    deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][
                                                                               distance[i][1]] * wake.wake_deficit(
                        Ct(U[distance[turbine][1]]), k, determ[1], r0)
                else:
                    deficit_matrix[distance[i][1]][distance[turbine][1]] = 0.0

        # return [list(_) for _ in zip(
        #     zip([x for (y, x) in sorted(zip([item[0] for item in distance], layout_x))], [x for (y, x) in sorted(
        #         zip([item[0] for item in distance], layout_y))]), U)]

        unknowns['U'] = array(U)
    def loop2(i):
        determ = wake.determine_if_in_wake(layout_x[distance[turbine][1]],
                                           layout_y[distance[turbine][1]],
                                           layout_x[distance[i][1]],
                                           layout_y[distance[i][1]], k, r0,
                                           angle3)
        proportion[distance[turbine][1]][distance[i][1]] = determ[0]

        if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
            deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[
                distance[turbine][1]][distance[i][1]] * wake.wake_deficit(
                    Ct(U[distance[turbine][1]]), k, determ[1], r0)
        else:
            deficit_matrix[distance[i][1]][distance[turbine][1]] = 0.0

        return deficit_matrix[distance[i][1]][distance[turbine][1]]
def jensen_1angle(layout_x, layout_y, wind_speed, angle, rotor_radius, k):
    U0 = wind_speed  # Free stream wind speed

    nt = len(layout_y)  # Number of turbines ## Length of layout list

    r0 = rotor_radius  # Turbine rotor radius
    # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90.
    angle3 = angle + 180.0
    deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
    proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
    distance = [[0.0 for _ in range(2)] for _ in range(nt)]
    U = [U0 for _ in range(nt)]
    total_deficit = [0.0 for _ in range(nt)]

    for tur in range(nt):
        distance[tur] = [distance_to_front(layout_x[tur], layout_y[tur], angle), tur]
    distance.sort()

    for turbine in range(nt):

        for num in range(turbine):
            total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0
        total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
        U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

        for i in range(turbine + 1, nt):

            determ = wake.determine_if_in_wake(layout_x[distance[turbine][1]],
                                               layout_y[distance[turbine][1]],
                                               layout_x[distance[i][1]], layout_y[distance[i][1]], k,
                                               r0, angle3)
            proportion[distance[turbine][1]][distance[i][1]] = determ[0]

            if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][
                                                                           distance[i][1]] * wake.wake_deficit(
                    Ct(U[distance[turbine][1]]), k, determ[1], r0)
            else:
                deficit_matrix[distance[i][1]][distance[turbine][1]] = 0.0

    return U
Example #7
0
def Jensen(a, Nt, rad):
    from math import sqrt, log
    import wake
    from power_curve5MW import power5MW_kW as power  # Power curve 5 MW NREL

    windrose = open('horns_rev_windrose.dat', 'r')
    nt = Nt
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    windrose_angle = []
    windrose_speed = []
    windrose_frequency = []
    for line in windrose:
        columns = line.split()
        windrose_angle.append(float(columns[0]))
        windrose_speed.append(float(columns[1]))
        windrose_frequency.append(float(columns[2]))

    windrose.close()
    summation = 0.0

    ## Power curve 2 MW Siemens.
    # def power(U0):
    #     if U0 < 4.0:
    #         return 0.0
    #     elif U0 >= 4.0:
    #         return 19.7907842158 * U0 ** 2.0 - 74.9080669331 * U0 + 37.257967033  # From 4 to 11 m/s

    # for wind in range(0, len(windrose_speed)):
    for wind in range(0, 1):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (90.0 /
                   10.0)**0.11  # Power or log law for wind shear profile
        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
        k = 0.04  # Decay constant
        r0 = rad  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        wake_deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        for turbine in range(nt):
            flag = [False for x in range(nt)]
            proportion = [0.0 for x in range(nt)]
            for i in range(nt):
                try:
                    proportion[i], flag[i] = wake.determine_if_in_wake(
                        layout_x[turbine], layout_y[turbine], layout_x[i],
                        layout_y[i], k, r0, angle3)
                except TypeError:
                    print layout_x[turbine], layout_y[turbine], layout_x[
                        i], layout_y[i], k, r0, angle3

            # Matrix with effect of each turbine <i = turbine> on every other turbine <j> of the farm
            for j in range(nt):
                if turbine != j and flag[j] is True:
                    wake_deficit_matrix[turbine][
                        j] = proportion[j] * wake.wake_deficit(
                            0.46, k,
                            wake.distance(layout_x[turbine], layout_y[turbine],
                                          layout_x[j], layout_y[j]), r0)
                elif turbine == j:
                    wake_deficit_matrix[turbine][j] = 0.0

        total_deficit = [0.0 for x in range(nt)]
        total_speed = [0.0 for x in range(nt)]
        for j in range(nt):
            for i in range(nt):
                total_deficit[j] += wake_deficit_matrix[i][j]**2.0
            total_deficit[j] = sqrt(total_deficit[j])
            total_speed[j] = U0 * (1.0 - total_deficit[j])

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [
            0.0 for x in range(0, len(windrose_frequency))
        ]
        efficiency = 0.0
        for l in range(nt):
            profit += power(total_speed[l])
        efficiency = profit * 100.0 / (float(nt) * power(U0))
        efficiency_proportion[
            wind] = efficiency * windrose_frequency[wind] / 100.0
        summation += efficiency_proportion[wind]
    return summation  # Farm efficiency


# if __name__ == '__main__':
#     start_time = time.time()
#     Jensen()
# print("--- %s seconds ---" % (time.time() - start_time))
def Jensen(a, Nt, rad):
    from math import sqrt, log
    import wake
    # from power_curve5MW import power5MW_kW as power  # Power curve 5 MW NREL

    windrose = open('horns_rev_windrose2.dat', 'r')
    nt = Nt
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    windrose_angle = []
    windrose_speed = []
    windrose_frequency = []
    for line in windrose:
        columns = line.split()
        windrose_angle.append(float(columns[0]))
        windrose_speed.append(float(columns[1]))
        windrose_frequency.append(float(columns[2]))

    windrose.close()
    summation = 0.0

    # Power curve 2 MW Siemens.
    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 0.0003234808 * U0 ** 7.0 - 0.0331940121 * U0 ** 6.0 + 1.3883148012 * U0 **5.0 - 30.3162345004 * U0 **4.0 + 367.6835557011 * U0 ** 3.0 - 2441.6860655008 * U0 ** 2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

    # for wind in range(0, len(windrose_speed)):
    for wind in range(0, 1):
        # U1 = windrose_speed[wind]  # Free stream wind speed
        # U0 = U1 * (90.0 / 10.0) ** 0.11  # Power or log law for wind shear profile
        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
        U0 = 8.5
        k = 0.04  # Decay constant
        r0 = rad  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        wake_deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        for turbine in range(nt):
            flag = [False for x in range(nt)]
            proportion = [0.0 for x in range(nt)]
            for i in range(nt):
                try:
                    proportion[i], flag[i] = wake.determine_if_in_wake(layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3)
                except TypeError:
                    print layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3

            # Matrix with effect of each turbine <i = turbine> on every other turbine <j> of the farm
            for j in range(nt):
                if turbine != j and flag[j] is True:
                    wake_deficit_matrix[turbine][j] = proportion[j] * wake.wake_deficit(0.81, k, wake.distance(layout_x[turbine], layout_y[turbine], layout_x[j], layout_y[j]), r0)
                elif turbine == j:
                    wake_deficit_matrix[turbine][j] = 0.0

        total_deficit = [0.0 for x in range(nt)]
        total_speed = [0.0 for x in range(nt)]
        for j in range(nt):
            for i in range(nt):
                total_deficit[j] += wake_deficit_matrix[i][j] ** 2.0
            total_deficit[j] = sqrt(total_deficit[j])
            total_speed[j] = U0 * (1.0 - total_deficit[j])

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
        efficiency = 0.0
        for l in range(nt):
            profit += power(total_speed[l])
        efficiency = profit * 100.0 / (float(nt) * power(U0))
        efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
        summation += efficiency_proportion[wind]
    return efficiency  # Farm efficiency

# if __name__ == '__main__':
#     start_time = time.time()
#     Jensen()
# print("--- %s seconds ---" % (time.time() - start_time))
    def jensen_windrose(self, windrose_file):

        windrose = open(windrose_file, 'r')
        windrose_angle = []
        windrose_speed = []
        windrose_frequency = []

        for line in windrose:
            columns = line.split()
            windrose_angle.append(float(columns[0]))
            windrose_speed.append(float(columns[1]))
            windrose_frequency.append(float(columns[2]))

        nt = len(self.layout_y)  # Number of turbines ## Length of layout list

        turb_data = open('turb1_power_jensen.dat', 'w', 1)
        direction = open('direction_power_jensen.dat', 'w', 1)

        for wind in range(len(windrose_angle)):
            U0 = windrose_speed[wind]  # Free stream wind speed
            k = 0.04  # Decay constant
            r0 = 62.0  # Turbine rotor radius
            angle = windrose_angle[wind]
            # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90
            angle3 = angle + 180.0
            deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
            proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
            distance = [[0.0 for _ in range(2)] for _ in range(nt)]
            U = [U0 for _ in range(nt)]
            total_deficit = [0.0 for _ in range(nt)]

            for tur in range(nt):
                distance[tur] = [distance_to_front(self.layout_x[tur], self.layout_y[tur], angle), tur]

            distance.sort()

            for turbine in range(nt):
                for num in range(turbine):
                    total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0

                total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
                U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

                for i in range(turbine + 1, nt):

                    determ = wake.determine_if_in_wake(self.layout_x[distance[turbine][1]],
                                                               self.layout_y[distance[turbine][1]],
                                                               self.layout_x[distance[i][1]], self.layout_y[distance[i][1]], k,
                                                               r0, angle3)
                    proportion[distance[turbine][1]][distance[i][1]] = determ[0]

                    if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                        deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][
                                                                                   distance[i][1]] * wake.wake_deficit(
                            Ct(U[distance[turbine][1]]), k, determ[1], r0)

            # Farm efficiency
            efficiency_proportion = [0.0 for _ in range(len(windrose_frequency))]
            profit_sum = 0.0
            for l in range(nt):
                profit_sum += power(U[l])
            profit = profit_sum
            efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]]))  # same as using U0
            efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
            self.summation += efficiency_proportion[wind]

            # turb_data.write('{0:f} {1:f}\n'.format(angle, power(U[2])))  # Number of turbine you want output of. Now 14.
            direction.write('{0:f} {1:f}\n'.format(angle, profit))
        turb_data.close()
        direction.close()
Example #10
0
                def analysis():

                    # Random layout to test, since optimiser will always be dealing with random layouts.
                    layout_x = []
                    layout_y = []
                    nt = 80
                    for xx in range(nt):
                        l = random()
                        k = random()
                        layout_x.append(5457.0 * l)
                        if layout_x[-1] <= 412.0:
                            layout_y.append(
                                k * 3907.0 + (1.0 - k) *
                                (-3907.0 / 412.0 * layout_x[-1] + 3907.0))
                        elif layout_x[-1] <= 5040.0:
                            layout_y.append(k * 3907.0)
                        else:
                            layout_y.append(k * (3907.0 / 417.0 *
                                                 (-layout_x[-1] + 5457.0)))

                        nt = len(
                            layout_y
                        )  # Number of turbines ## Length of layout list
                        summation = 0.0

                    def distance_to_front(
                        x, y, theta, r
                    ):  ## TODO: Calculate distance to any front and use negative distances to order.
                        theta = deg2rad(theta)
                        return abs(x + tan(theta) * y - r /
                                   cos(theta)) / sqrt(1.0 + tan(theta)**2.0)

                    for wind in range(0, len(windrose_angle)):
                        # for wind in range(90, 91):
                        # if wind in [100, 133, 271, 280, 313]:
                        #     continue
                        U1 = windrose_speed[wind]  # Free stream wind speed
                        U0 = U1 * (
                            70.0 / 10.0
                        )**0.11  # Power or log law for wind shear profile
                        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
                        # U0 = 8.5
                        k = 0.04  # Decay constant
                        r0 = 40.0  # Turbine rotor radius
                        angle = windrose_angle[wind]
                        angle3 = angle + 180.0
                        deficit_matrix = [[0.0 for x in range(nt)]
                                          for x in range(nt)]
                        proportion = [[0.0 for x in range(nt)]
                                      for x in range(nt)]
                        distance = [[0.0 for x in range(2)] for x in range(nt)]

                        U = [U0 for x in range(nt)]
                        total_deficit = [0.0 for x in range(nt)]

                        for tur in range(nt):
                            distance[tur] = [
                                distance_to_front(layout_x[tur], layout_y[tur],
                                                  angle, 100000000.0), tur
                            ]
                        distance.sort()

                        for turbine in range(nt):
                            for num in range(turbine):
                                total_deficit[
                                    distance[turbine][1]] += deficit_matrix[
                                        distance[turbine][1]][distance[num]
                                                              [1]]**2.0
                            total_deficit[distance[turbine][1]] = sqrt(
                                total_deficit[distance[turbine][1]])
                            U[distance[turbine][1]] = U0 * (
                                1.0 - total_deficit[distance[turbine][1]])
                            for i in range(turbine + 1, nt):
                                proportion[distance[turbine][1]][distance[i][
                                    1]] = wake.determine_if_in_wake(
                                        layout_x[distance[turbine][1]],
                                        layout_y[distance[turbine][1]],
                                        layout_x[distance[i][1]],
                                        layout_y[distance[i][1]], k, r0,
                                        angle3)
                                # If statement for proportion = 0
                                deficit_matrix[distance[i][1]][
                                    distance[turbine]
                                    [1]] = proportion[distance[turbine][1]][
                                        distance[i][1]] * wake.wake_deficit(
                                            Ct(U[distance[turbine][1]]), k,
                                            wake.distance(
                                                layout_x[distance[turbine][1]],
                                                layout_y[distance[turbine][1]],
                                                layout_x[distance[i][1]],
                                                layout_y[distance[i][1]]), r0)

                        # for turb in range(nt):
                        #     for i in range(nt):
                        #         output.write('{0:f}\t'.format(deficit_matrix[turb][i]))
                        #     output.write('\n')
                        #     output2.write('{0:d}\t{1:.1f}\t{2:.1f}\t{3:f}\t{4:f}\t{5:d}\t{6:f}\n'.format(turb, layout_x[turb], layout_y[turb], total_deficit[turb], U[turb], int(angle), power(U[turb])))
                        # output2.write('\n')

                        # for n in range(nt):
                        #     aver[n] += power(U[n]) / 360.0
                        # ---------------------------------------TODO UNCOMMENT -----------------------------------------
                        if withdata:
                            turb_data.write('{0:f} {1:f}\n'.format(
                                angle, power(U[14])))

                        # Farm efficiency
                        profit = 0.0
                        efficiency_proportion = [
                            0.0 for x in range(0, len(windrose_frequency))
                        ]
                        for l in range(nt):
                            profit += power(U[l])
                        efficiency = profit * 100.0 / (float(nt) * power(
                            U[distance[0][1]]))  # same as using U0
                        efficiency_proportion[
                            wind] = efficiency * windrose_frequency[
                                wind] / 100.0
                        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
                        # ---------------------------------------TODO UNCOMMENT ------------------------------------------
                        if withdata:
                            direction.write('{0:f} {1:f}\n'.format(
                                angle, profit))
                        summation += efficiency_proportion[wind]
                    return summation
                def analysis():
                    nt = len(layout_y
                             )  # Number of turbines ## Length of layout list
                    summation = 0.0

                    def distance_to_front(
                        x, y, theta, r
                    ):  ## TODO: Calculate distance to any front and use negative distances to order.
                        theta = deg2rad(theta)
                        return abs(x + tan(theta) * y - r /
                                   cos(theta)) / sqrt(1.0 + tan(theta)**2.0)

                    for wind in range(len(windrose_angle)):
                        # for wind in range(90, 91):
                        #     U1 = windrose_speed[wind]  # Free stream wind speed
                        #     U0 = U1 * (70.0 / 10.0) ** 0.11 # Power or log law for wind shear profile
                        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
                        U0 = 7.5
                        k = 0.04  # Decay constant
                        r0 = 40.0  # Turbine rotor radius
                        angle = windrose_angle[wind]
                        angle3 = angle + 180.0
                        deficit_matrix = [[0.0 for x in range(nt)]
                                          for x in range(nt)]
                        proportion = [[0.0 for x in range(nt)]
                                      for x in range(nt)]
                        distance = [[0.0 for x in range(2)] for x in range(nt)]

                        U = [U0 for x in range(nt)]
                        total_deficit = [0.0 for x in range(nt)]

                        for tur in range(nt):
                            distance[tur] = [
                                distance_to_front(layout_x[tur], layout_y[tur],
                                                  angle, 100000000.0), tur
                            ]
                        distance.sort()

                        for turbine in range(nt):
                            for num in range(turbine):
                                total_deficit[
                                    distance[turbine][1]] += deficit_matrix[
                                        distance[turbine][1]][distance[num]
                                                              [1]]**2.0
                            total_deficit[distance[turbine][1]] = sqrt(
                                total_deficit[distance[turbine][1]])
                            U[distance[turbine][1]] = U0 * (
                                1.0 - total_deficit[distance[turbine][1]])
                            for i in range(turbine + 1, nt):
                                determ = wake.determine_if_in_wake(
                                    layout_x[distance[turbine][1]],
                                    layout_y[distance[turbine][1]],
                                    layout_x[distance[i][1]],
                                    layout_y[distance[i][1]], k, r0, angle3)
                                proportion[distance[turbine][1]][
                                    distance[i][1]] = determ[0]
                                # If statement for proportion = 0
                                deficit_matrix[distance[i][1]][
                                    distance[turbine]
                                    [1]] = proportion[distance[turbine][1]][
                                        distance[i][1]] * wake.wake_deficit(
                                            Ct(U[distance[turbine][1]]), k,
                                            determ[1], r0)

                        # for turb in range(nt):
                        #     for i in range(nt):
                        #         output.write('{0:f}\t'.format(deficit_matrix[turb][i]))
                        #     output.write('\n')
                        #     output2.write('{0:d}\t{1:.1f}\t{2:.1f}\t{3:f}\t{4:f}\t{5:d}\t{6:f}\n'.format(turb, layout_x[turb], layout_y[turb], total_deficit[turb], U[turb], int(angle), power(U[turb])))
                        # output2.write('\n')

                        # for n in range(nt):
                        #     aver[n] += power(U[n]) / 360.0
                        # ---------------------------------------TODO UNCOMMENT -----------------------------------------
                        if withdata:
                            turb_data.write('{0:f} {1:f}\n'.format(
                                angle, power(U[3])
                            ))  # Number of turbine you want output of. Now 14.

                        # Farm efficiency
                        profit = 0.0
                        efficiency_proportion = [
                            0.0 for x in range(0, len(windrose_frequency))
                        ]
                        for l in range(nt):
                            profit += power(U[l])
                        efficiency = profit * 100.0 / (float(nt) * power(
                            U[distance[0][1]]))  # same as using U0
                        efficiency_proportion[
                            wind] = efficiency * windrose_frequency[
                                wind] / 100.0
                        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
                        # ---------------------------------------TODO UNCOMMENT ------------------------------------------
                        if withdata:
                            direction.write('{0:f} {1:f}\n'.format(
                                angle, profit))
                        summation += efficiency_proportion[wind]
                    return summation
Example #12
0
def Jensen(a, Nt, rad):
    from math import sqrt, log
    import wake
    # from power_curve5MW import power5MW_kW as power  # Power curve 5 MW NREL

    windrose = open('horns_rev_windrose2.dat', 'r')
    nt = Nt
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    windrose_angle = []
    windrose_speed = []
    windrose_frequency = []
    for line in windrose:
        columns = line.split()
        windrose_angle.append(float(columns[0]))
        windrose_speed.append(float(columns[1]))
        windrose_frequency.append(float(columns[2]))

    windrose.close()
    summation = 0.0

    # Power curve 2 MW Siemens.
    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 0.0003234808 * U0**7.0 - 0.0331940121 * U0**6.0 + 1.3883148012 * U0**5.0 - 30.3162345004 * U0**4.0 + 367.6835557011 * U0**3.0 - 2441.6860655008 * U0**2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

    # for wind in range(0, len(windrose_speed)):
    for wind in range(0, 1):
        # U1 = windrose_speed[wind]  # Free stream wind speed
        # U0 = U1 * (90.0 / 10.0) ** 0.11  # Power or log law for wind shear profile
        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
        U0 = 8.5
        k = 0.04  # Decay constant
        r0 = rad  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        wake_deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        for turbine in range(nt):
            flag = [False for x in range(nt)]
            proportion = [0.0 for x in range(nt)]
            for i in range(nt):
                try:
                    proportion[i], flag[i] = wake.determine_if_in_wake(
                        layout_x[turbine], layout_y[turbine], layout_x[i],
                        layout_y[i], k, r0, angle3)
                except TypeError:
                    print layout_x[turbine], layout_y[turbine], layout_x[
                        i], layout_y[i], k, r0, angle3

            # Matrix with effect of each turbine <i = turbine> on every other turbine <j> of the farm
            for j in range(nt):
                if turbine != j and flag[j] is True:
                    wake_deficit_matrix[turbine][
                        j] = proportion[j] * wake.wake_deficit(
                            0.81, k,
                            wake.distance(layout_x[turbine], layout_y[turbine],
                                          layout_x[j], layout_y[j]), r0)
                elif turbine == j:
                    wake_deficit_matrix[turbine][j] = 0.0

        total_deficit = [0.0 for x in range(nt)]
        total_speed = [0.0 for x in range(nt)]
        for j in range(nt):
            for i in range(nt):
                total_deficit[j] += wake_deficit_matrix[i][j]**2.0
            total_deficit[j] = sqrt(total_deficit[j])
            total_speed[j] = U0 * (1.0 - total_deficit[j])

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [
            0.0 for x in range(0, len(windrose_frequency))
        ]
        efficiency = 0.0
        for l in range(nt):
            profit += power(total_speed[l])
        efficiency = profit * 100.0 / (float(nt) * power(U0))
        efficiency_proportion[
            wind] = efficiency * windrose_frequency[wind] / 100.0
        summation += efficiency_proportion[wind]
    return efficiency  # Farm efficiency


# if __name__ == '__main__':
#     start_time = time.time()
#     Jensen()
# print("--- %s seconds ---" % (time.time() - start_time))
                def analysis():
                    nt = len(layout_y)  # Number of turbines ## Length of layout list
                    summation = 0.0

                    def distance_to_front(x, y, theta, r): ## TODO: Calculate distance to any front and use negative distances to order.
                        theta = deg2rad(theta)
                        return abs(x + tan(theta) * y - r / cos(theta)) / sqrt(1.0 + tan(theta) ** 2.0)

                    for wind in range(len(windrose_angle)):
                    # for wind in range(90, 91):
                        # if wind in [100, 133, 271, 280, 313]:
                        #     continue
                        # U1 = windrose_speed[wind]  # Free stream wind speed
                        # U0 = U1 * (70.0 / 10.0) ** 0.11 # Power or log law for wind shear profile
                        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
                        U0 = 8.5
                        k = 0.04  # Decay constant
                        r0 = 40.0  # Turbine rotor radius
                        angle = windrose_angle[wind]
                        angle3 = angle + 180.0
                        deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
                        proportion = [[0.0 for x in range(nt)] for x in range(nt)]
                        distance = [[0.0 for x in range(2)] for x in range(nt)]

                        U = [U0 for x in range(nt)]
                        total_deficit = [0.0 for x in range(nt)]

                        for tur in range(nt):
                            distance[tur] = [distance_to_front(layout_x[tur], layout_y[tur], angle, 100000000.0), tur]
                        distance.sort()

                        for turbine in range(nt):
                            for num in range(turbine):
                                total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0
                            total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
                            U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])
                            for i in range(turbine + 1, nt):
                                determ = wake.determine_if_in_wake(layout_x[distance[turbine][1]], layout_y[distance[turbine][1]], layout_x[distance[i][1]], layout_y[distance[i][1]], k, r0, angle3)
                                proportion[distance[turbine][1]][distance[i][1]] = determ[0]
                                # If statement for proportion != 0
                                deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][distance[i][1]] * wake.wake_deficit(Ct(U[distance[turbine][1]]), k, determ[1], r0)

                        # for turb in range(nt):
                        #     for i in range(nt):
                        #         output.write('{0:f}\t'.format(deficit_matrix[turb][i]))
                        #     output.write('\n')
                        #     output2.write('{0:d}\t{1:.1f}\t{2:.1f}\t{3:f}\t{4:f}\t{5:d}\t{6:f}\n'.format(turb, layout_x[turb], layout_y[turb], total_deficit[turb], U[turb], int(angle), power(U[turb])))
                        # output2.write('\n')

                        # for n in range(nt):
                        #     aver[n] += power(U[n]) / 360.0
                        # ---------------------------------------TODO UNCOMMENT -----------------------------------------
                        if withdata:
                            turb_data.write('{0:f} {1:f}\n'.format(angle, power(U[14])))

                        # Farm efficiency
                        profit = 0.0
                        efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
                        for l in range(nt):
                            profit += power(U[l])
                        efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]])) # same as using U0
                        efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
                        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
                    # ---------------------------------------TODO UNCOMMENT ------------------------------------------
                        if withdata:
                            direction.write('{0:f} {1:f}\n'.format(angle, profit))
                        summation += efficiency_proportion[wind]
                    return summation
    def jensen_windrose(self):
        self.efficiency = 0.0
        self.profit = []
        self.U = []
        self.powers = []
        self.summation = 0.0
        windrose_angle = self.wind_direction
        windrose_speed = self.wind_speed
        windrose_frequency = self.wind_frequency

        nt = self.nt  # Number of turbines ## Length of layout list

        direction = open('direction_power_jensen.dat', 'w', 1)

        for wind in range(len(windrose_angle)):
            U0 = windrose_speed[wind]  # Free stream wind speed
            k = 0.04  # Decay constant
            r0 = self.radius  # Turbine rotor radius
            angle = windrose_angle[wind]
            # angle2 = - 270.0 - angle  # To read windroses where N is 0 and E is 90
            angle3 = angle + 180.0
            deficit_matrix = [[0.0 for _ in range(nt)] for _ in range(nt)]
            proportion = [[0.0 for _ in range(nt)] for _ in range(nt)]
            distance = [[0.0 for _ in range(2)] for _ in range(nt)]
            U = [U0 for _ in range(nt)]
            total_deficit = [0.0 for _ in range(nt)]

            for tur in range(nt):
                distance[tur] = [
                    distance_to_front(self.layout_x[tur], self.layout_y[tur],
                                      angle), tur
                ]

            distance.sort()

            for turbine in range(nt):
                for num in range(turbine):
                    total_deficit[distance[turbine][1]] += deficit_matrix[
                        distance[turbine][1]][distance[num][1]]**2.0

                total_deficit[distance[turbine][1]] = sqrt(
                    total_deficit[distance[turbine][1]])
                U[distance[turbine]
                  [1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])

                for i in range(turbine + 1, nt):

                    determ = wake.determine_if_in_wake(
                        self.layout_x[distance[turbine][1]],
                        self.layout_y[distance[turbine][1]],
                        self.layout_x[distance[i][1]],
                        self.layout_y[distance[i][1]], k, r0, angle3)
                    proportion[distance[turbine][1]][distance[i]
                                                     [1]] = determ[0]

                    if proportion[distance[turbine][1]][distance[i][1]] != 0.0:
                        deficit_matrix[distance[i][1]][distance[turbine][
                            1]] = proportion[distance[turbine][1]][
                                distance[i][1]] * wake.wake_deficit(
                                    Ct(U[distance[turbine][1]]), k, determ[1],
                                    r0)
                    else:
                        deficit_matrix[distance[i][1]][distance[turbine]
                                                       [1]] = 0.0

            # Farm efficiency
            efficiency_proportion = [
                0.0 for _ in range(len(windrose_frequency))
            ]
            profit_sum = 0.0
            for l in range(nt):
                profit_sum += power(U[l])
            profit = profit_sum
            efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]])
                                           )  # same as using U0
            efficiency_proportion[
                wind] = efficiency * windrose_frequency[wind] / 100.0
            self.summation += efficiency_proportion[wind]

            direction.write('{0:f} {1:f}\n'.format(angle, profit))
        direction.close()
Example #15
0
def jensen(a, windrose_angle, windrose_speed, windrose_frequency):
    import wake
    from math import sqrt, log, tan, cos
    from numpy import deg2rad

    nt = len(a)
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

        # Ct curves.
        # Polynomials 6th, 4th 3rd
        # - 3.10224672352816e-5 * U0 ** 4.0 + 0.0021367624 * U0 ** 3.0 - 0.0495873986 * U0 ** 2.0 + 0.3976324804 * U0 - 0.1608576035
        # 3.374593e-4 * U0 ** 3.0 - 0.0136412226 * U0 ** 2.0 + 0.1118003309 * U0 + 0.5782039288

        # Ct look-up table for linear interpolation
        # def thrust_table(v):
        #     if v == 4: return 0.82
        #     if v == 5: return 0.81
        #     if v == 6: return 0.8
        #     if v == 7: return 0.81
        #     if v == 8: return 0.81
        #     if v == 9: return 0.78
        #     if v == 10: return 0.74
        #     if v == 11: return 0.65
        #     if v == 12: return 0.57
        #     if v == 13: return 0.41
        #     if v == 14: return 0.31
        #     if v == 15: return 0.25
        #     if v == 16: return 0.2
        #     if v == 17: return 0.17
        #     if v == 18: return 0.14
        #     if v == 19: return 0.12
        #     if v == 20: return 0.1
        #     if v == 21: return 0.09
        #     if v == 22: return 0.08
        #     if v == 23: return 0.07
        #     if v == 24: return 0.06
        #     if v == 25: return 0.05

        # 2 step thrust curve:
        # 0.80 if U0 in 4 - 9 m/s
        # 0.250625 if U0 in 10 - 25 m/s

    def Ct(U0):
        if U0 < 4.0:
            return 0.1
        elif U0 <= 25.0:
            return 7.3139922126945e-7 * U0**6.0 - 6.68905596915255e-5 * U0**5.0 + 2.3937885e-3 * U0**4.0 + -0.0420283143 * U0**3.0 + 0.3716111285 * U0**2.0 - 1.5686969749 * U0 + 3.2991094727
        else:
            return 0.0

    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 3.234808e-4 * U0**7.0 - 0.0331940121 * U0**6.0 + 1.3883148012 * U0**5.0 - 30.3162345004 * U0**4.0 + 367.6835557011 * U0**3.0 - 2441.6860655008 * U0**2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

            # Power curve polynomials.
        # elif U0 <= 25.0
        # - 0.0110778061 * U0 ** 5.0 + 0.8986075613 * U0 ** 4.0 - 27.2165513154 * U0 ** 3.0 + 368.8877606215 * U0 ** 2.0 - 1994.1905079276 * U0 + 3712.3986113386 #  5th degree
        # - 0.5308414162 * U0 ** 3.0 - 15.4948143381 * U0 ** 2.0 + 13.1508234816 * U0  # 3rd degree

        #  Interpolation
        #table:

    # def power_table(v):
    #     if v == 4: return 66.3
    #     if v == 5: return 152
    #     if v == 6: return 280
    #     if v == 7: return 457
    #     if v == 8: return 690
    #     if v == 9: return 978
    #     if v == 10: return 1296
    #     if v == 11: return 1598
    #     if v == 12: return 1818
    #     if v == 13: return 1935
    #     if v == 14: return 1980
    #     if v == 15: return 1995
    #     if v == 16: return 1999
    #     if v == 17: return 2000
    #     if v == 18: return 2000
    #     if v == 19: return 2000
    #     if v == 20: return 2000
    #     if v == 21: return 2000
    #     if v == 22: return 2000
    #     if v == 23: return 2000
    #     if v == 24: return 2000
    #     if v == 25: return 2000
# interpolation function
# def interpolate(minx, miny, maxx, maxy, valx):
# return miny + (maxy - miny) * ((valx - minx) / (maxx - minx))

# 2 step Power curve
# 815.0333333 kw from 4 to 13 m/s, 2000 from 13-25 m/s

# for U0 in range(4, 20):
    summation = 0.0

    def distance_to_front(x, y, theta, r):
        theta = deg2rad(theta)
        return abs(x + tan(theta) * y - r / cos(theta)) / sqrt(1.0 +
                                                               tan(theta)**2.0)

    # for wind in range(0, 1):
    for wind in range(0, len(windrose_angle)):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (70.0 /
                   10.0)**0.11  # Power or log law for wind shear profile
        # U0 = 8.5
        k = 0.04  # Decay constant
        r0 = 40.0  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        proportion = [[0.0 for x in range(nt)] for x in range(nt)]
        distance = [[0.0 for x in range(2)] for x in range(nt)]

        U = [U0 for x in range(nt)]
        total_deficit = [0.0 for x in range(nt)]

        for tur in range(nt):
            distance[tur] = [
                distance_to_front(layout_x[tur], layout_y[tur], angle,
                                  100000000.0), tur
            ]
        distance.sort()

        for turbine in range(nt):
            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[
                    distance[turbine][1]][distance[num][1]]**2.0
            total_deficit[distance[turbine][1]] = sqrt(
                total_deficit[distance[turbine][1]])
            U[distance[turbine]
              [1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])
            for i in range(turbine + 1, nt):
                proportion[distance[turbine][1]][
                    distance[i][1]] = wake.determine_if_in_wake(
                        layout_x[distance[turbine][1]],
                        layout_y[distance[turbine][1]],
                        layout_x[distance[i][1]], layout_y[distance[i][1]], k,
                        r0, angle3)
                deficit_matrix[distance[i][1]][
                    distance[turbine][1]] = proportion[distance[turbine][1]][
                        distance[i][1]] * wake.wake_deficit(
                            Ct(U[distance[turbine][1]]), k,
                            wake.distance(layout_x[distance[turbine][1]],
                                          layout_y[distance[turbine][1]],
                                          layout_x[distance[i][1]],
                                          layout_y[distance[i][1]]), r0)

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [
            0.0 for x in range(0, len(windrose_frequency))
        ]
        for l in range(nt):
            profit += power(U[l])
        efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]]))
        efficiency_proportion[
            wind] = efficiency * windrose_frequency[wind] / 100.0

        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
        summation += efficiency_proportion[wind]

    return 100.0 - summation
    def solve_nonlinear(self, params, unknowns, resids):

        a = params['a']

        from math import sqrt, log
        import wake
        windrose = open('horns_rev_windrose2.dat', 'r')
        nt = 80
        layout_x = [0.0 for x in range(nt)]
        layout_y = [0.0 for x in range(nt)]
        for x in range(nt):
            layout_x[x] = float(a[x][0])
            layout_y[x] = float(a[x][1])

        windrose_angle = []
        windrose_speed = []
        windrose_frequency = []
        for line in windrose:
            columns = line.split()
            windrose_angle.append(float(columns[0]))
            windrose_speed.append(float(columns[1]))
            windrose_frequency.append(float(columns[2]))

        windrose.close()
        summation = 0.0

        def Ct(U0):
            return 0.0001923077 * U0 ** 4.0 + -0.0075407925 * U0 ** 3.0 + 0.096462704 * U0 ** 2.0 - 0.5012354312 * U0 + 1.7184749184

        def power(U0):
            if U0 < 4.0:
                return 0.0
            elif U0 >= 4.0:
                return 19.7907842158 * U0 ** 2.0 - 74.9080669331 * U0 + 37.257967033  # From 4 to 11 m/s

        for wind in range(0, len(windrose_speed)):
        # for wind in range(0, 1):
            U1 = windrose_speed[wind]  # Free stream wind speed
            U0 = U1 * (70.0 / 10.0) ** 0.11  # Power or log law for wind shear profile
            # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
            k = 0.04  # Decay constant
            r0 = 40.0  # Turbine rotor radius
            angle = windrose_angle[wind]
            angle3 = angle + 180.0
            wake_deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
            for turbine in range(nt):
                flag = [False for x in range(nt)]
                proportion = [0.0 for x in range(nt)]
                for i in range(nt):
                    try:
                        proportion[i], flag[i] = wake.determine_if_in_wake(layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3)
                    except TypeError:
                        print(layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3)

                # Matrix with effect of each turbine <i = turbine> on every other turbine <j> of the farm
                for j in range(nt):
                    if turbine != j and flag[j] is True:
                        wake_deficit_matrix[turbine][j] = proportion[j] * wake.wake_deficit(0.81, k, wake.distance(layout_x[turbine], layout_y[turbine], layout_x[j], layout_y[j]), r0)
                    elif turbine == j:
                        wake_deficit_matrix[turbine][j] = 0.0

            total_deficit = [0.0 for x in range(nt)]
            total_speed = [0.0 for x in range(nt)]
            for j in range(nt):
                for i in range(nt):
                    total_deficit[j] += wake_deficit_matrix[i][j] ** 2.0
                total_deficit[j] = sqrt(total_deficit[j])
                total_speed[j] = U0 * (1.0 - total_deficit[j])

            # Farm efficiency
            profit = 0.0
            efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
            for l in range(nt):
                profit += power(total_speed[l])
            efficiency = profit * 100.0 / (float(nt) * power(U0))
            efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
            summation += efficiency_proportion[wind]
        unknowns['eff'] = summation  # Farm efficiency
Example #17
0
def jensen(a, windrose_angle, windrose_speed, windrose_frequency):
    import wake
    from math import sqrt, log, tan, cos
    from numpy import deg2rad

    nt = len(a)
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    def Ct(U0):
        if U0 < 4.0:
            return 0.1
        elif U0 <= 25.0:
            return 0.00000073139922126945 * U0**6.0 - 0.0000668905596915255 * U0**5.0 + 0.0023937885 * U0**4.0 + -0.0420283143 * U0**3.0 + 0.3716111285 * U0**2.0 - 1.5686969749 * U0 + 3.2991094727
        else:
            return 0.0

    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 0.0003234808 * U0**7.0 - 0.0331940121 * U0**6.0 + 1.3883148012 * U0**5.0 - 30.3162345004 * U0**4.0 + 367.6835557011 * U0**3.0 - 2441.6860655008 * U0**2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

    # for U0 in range(4, 20):
    nt = 80  # Number of turbines
    summation = 0.0

    def distance_to_front(x, y, theta, r):
        theta = deg2rad(theta)
        return abs(x + tan(theta) * y - r / cos(theta)) / sqrt(1.0 +
                                                               tan(theta)**2.0)

    for wind in range(0, len(windrose_angle)):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (70.0 /
                   10.0)**0.11  # Power or log law for wind shear profile
        k = 0.04  # Decay constant
        r0 = 40.0  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        proportion = [[0.0 for x in range(nt)] for x in range(nt)]
        distance = [[0.0 for x in range(2)] for x in range(nt)]

        U = [U0 for x in range(nt)]
        total_deficit = [0.0 for x in range(nt)]

        for tur in range(nt):
            distance[tur] = [
                distance_to_front(layout_x[tur], layout_y[tur], angle,
                                  100000000.0), tur
            ]
        distance.sort()

        for turbine in range(nt):
            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[
                    distance[turbine][1]][distance[num][1]]**2.0
            total_deficit[distance[turbine][1]] = sqrt(
                total_deficit[distance[turbine][1]])
            U[distance[turbine]
              [1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])
            for i in range(turbine + 1, nt):
                proportion[distance[turbine][1]][
                    distance[i][1]] = wake.determine_if_in_wake(
                        layout_x[distance[turbine][1]],
                        layout_y[distance[turbine][1]],
                        layout_x[distance[i][1]], layout_y[distance[i][1]], k,
                        r0, angle3)
                deficit_matrix[distance[i][1]][
                    distance[turbine][1]] = proportion[distance[turbine][1]][
                        distance[i][1]] * wake.wake_deficit(
                            Ct(U[distance[turbine][1]]), k,
                            wake.distance(layout_x[distance[turbine][1]],
                                          layout_y[distance[turbine][1]],
                                          layout_x[distance[i][1]],
                                          layout_y[distance[i][1]]), r0)

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [
            0.0 for x in range(0, len(windrose_frequency))
        ]
        for l in range(nt):
            profit += power(U[l])
        efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]]))
        efficiency_proportion[
            wind] = efficiency * windrose_frequency[wind] / 100.0
        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
        summation += efficiency_proportion[wind]

    return summation
def jensen(a, windrose_angle, windrose_speed, windrose_frequency):
    import wake
    from math import sqrt, log, tan, cos
    from numpy import deg2rad

    nt = len(a)
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])


        # Ct curves.
        # Polynomials 6th, 4th 3rd
        # - 3.10224672352816e-5 * U0 ** 4.0 + 0.0021367624 * U0 ** 3.0 - 0.0495873986 * U0 ** 2.0 + 0.3976324804 * U0 - 0.1608576035
        # 3.374593e-4 * U0 ** 3.0 - 0.0136412226 * U0 ** 2.0 + 0.1118003309 * U0 + 0.5782039288

        # Ct look-up table for linear interpolation
        # def thrust_table(v):
            #     if v == 4: return 0.82
            #     if v == 5: return 0.81
            #     if v == 6: return 0.8
            #     if v == 7: return 0.81
            #     if v == 8: return 0.81
            #     if v == 9: return 0.78
            #     if v == 10: return 0.74
            #     if v == 11: return 0.65
            #     if v == 12: return 0.57
            #     if v == 13: return 0.41
            #     if v == 14: return 0.31
            #     if v == 15: return 0.25
            #     if v == 16: return 0.2
            #     if v == 17: return 0.17
            #     if v == 18: return 0.14
            #     if v == 19: return 0.12
            #     if v == 20: return 0.1
            #     if v == 21: return 0.09
            #     if v == 22: return 0.08
            #     if v == 23: return 0.07
            #     if v == 24: return 0.06
            #     if v == 25: return 0.05

        # 2 step thrust curve:
        # 0.80 if U0 in 4 - 9 m/s
        # 0.250625 if U0 in 10 - 25 m/s


    def Ct(U0):
        if U0 < 4.0:
            return 0.1
        elif U0 <= 25.0:
            return 7.3139922126945e-7 * U0 ** 6.0 - 6.68905596915255e-5 * U0 ** 5.0 + 2.3937885e-3 * U0 ** 4.0 + - 0.0420283143 * U0 ** 3.0 + 0.3716111285 * U0 ** 2.0 - 1.5686969749 * U0 + 3.2991094727
        else:
            return 0.0

    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 3.234808e-4 * U0 ** 7.0 - 0.0331940121 * U0 ** 6.0 + 1.3883148012 * U0 ** 5.0 - 30.3162345004 * U0 ** 4.0 + 367.6835557011 * U0 ** 3.0 - 2441.6860655008 * U0 ** 2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

            # Power curve polynomials.
        # elif U0 <= 25.0
            # - 0.0110778061 * U0 ** 5.0 + 0.8986075613 * U0 ** 4.0 - 27.2165513154 * U0 ** 3.0 + 368.8877606215 * U0 ** 2.0 - 1994.1905079276 * U0 + 3712.3986113386 #  5th degree
            # - 0.5308414162 * U0 ** 3.0 - 15.4948143381 * U0 ** 2.0 + 13.1508234816 * U0  # 3rd degree

        #  Interpolation
            #table:
    # def power_table(v):
    #     if v == 4: return 66.3
    #     if v == 5: return 152
    #     if v == 6: return 280
    #     if v == 7: return 457
    #     if v == 8: return 690
    #     if v == 9: return 978
    #     if v == 10: return 1296
    #     if v == 11: return 1598
    #     if v == 12: return 1818
    #     if v == 13: return 1935
    #     if v == 14: return 1980
    #     if v == 15: return 1995
    #     if v == 16: return 1999
    #     if v == 17: return 2000
    #     if v == 18: return 2000
    #     if v == 19: return 2000
    #     if v == 20: return 2000
    #     if v == 21: return 2000
    #     if v == 22: return 2000
    #     if v == 23: return 2000
    #     if v == 24: return 2000
    #     if v == 25: return 2000
# interpolation function
    # def interpolate(minx, miny, maxx, maxy, valx):
        # return miny + (maxy - miny) * ((valx - minx) / (maxx - minx))

        # 2 step Power curve
        # 815.0333333 kw from 4 to 13 m/s, 2000 from 13-25 m/s


    # for U0 in range(4, 20):
    summation = 0.0

    def distance_to_front(x, y, theta, r):
        theta = deg2rad(theta)
        return abs(x + tan(theta) * y - r / cos(theta)) / sqrt(1.0 + tan(theta) ** 2.0)

    # for wind in range(0, 1):
    for wind in range(0, len(windrose_angle)):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (70.0 / 10.0) ** 0.11 # Power or log law for wind shear profile
        # U0 = 8.5
        k = 0.04  # Decay constant
        r0 = 40.0  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        proportion = [[0.0 for x in range(nt)] for x in range(nt)]
        distance = [[0.0 for x in range(2)] for x in range(nt)]

        U = [U0 for x in range(nt)]
        total_deficit = [0.0 for x in range(nt)]

        for tur in range(nt):
            distance[tur] = [distance_to_front(layout_x[tur], layout_y[tur], angle, 100000000.0), tur]
        distance.sort()

        for turbine in range(nt):
            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0
            total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
            U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])
            for i in range(turbine + 1, nt):
                proportion[distance[turbine][1]][distance[i][1]] = wake.determine_if_in_wake(layout_x[distance[turbine][1]], layout_y[distance[turbine][1]], layout_x[distance[i][1]], layout_y[distance[i][1]], k, r0, angle3)
                deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][distance[i][1]] * wake.wake_deficit(Ct(U[distance[turbine][1]]), k, wake.distance(layout_x[distance[turbine][1]], layout_y[distance[turbine][1]], layout_x[distance[i][1]], layout_y[distance[i][1]]), r0)

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
        for l in range(nt):
            profit += power(U[l])
        efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]]))
        efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0

        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
        summation += efficiency_proportion[wind]

    return 100.0 - summation
def Jensen(a, Nt, rad):
    from math import sqrt, log
    import wake
    from power_curve5MW import power5MW_kW as power  # Power curve 5 MW NREL

    windrose = open('horns_rev_windrose.dat', 'r')
    nt = Nt
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    windrose_angle = []
    windrose_speed = []
    windrose_frequency = []
    for line in windrose:
        columns = line.split()
        windrose_angle.append(float(columns[0]))
        windrose_speed.append(float(columns[1]))
        windrose_frequency.append(float(columns[2]))

    windrose.close()
    summation = 0.0

    ## Power curve 2 MW Siemens.
    # def power(U0):
    #     if U0 < 4.0:
    #         return 0.0
    #     elif U0 >= 4.0:
    #         return 19.7907842158 * U0 ** 2.0 - 74.9080669331 * U0 + 37.257967033  # From 4 to 11 m/s

    # for wind in range(0, len(windrose_speed)):
    for wind in range(0, 1):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (90.0 / 10.0) ** 0.11  # Power or log law for wind shear profile
        # U0 = U1 * log(70.0 / 0.005) / log(10.0 / 0.005)
        k = 0.04  # Decay constant
        r0 = rad  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        wake_deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        for turbine in range(nt):
            flag = [False for x in range(nt)]
            proportion = [0.0 for x in range(nt)]
            for i in range(nt):
                try:
                    proportion[i], flag[i] = wake.determine_if_in_wake(layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3)
                except TypeError:
                    print layout_x[turbine], layout_y[turbine], layout_x[i], layout_y[i], k, r0, angle3

            # Matrix with effect of each turbine <i = turbine> on every other turbine <j> of the farm
            for j in range(nt):
                if turbine != j and flag[j] is True:
                    wake_deficit_matrix[turbine][j] = proportion[j] * wake.wake_deficit(0.46, k, wake.distance(layout_x[turbine], layout_y[turbine], layout_x[j], layout_y[j]), r0)
                elif turbine == j:
                    wake_deficit_matrix[turbine][j] = 0.0

        total_deficit = [0.0 for x in range(nt)]
        total_speed = [0.0 for x in range(nt)]
        for j in range(nt):
            for i in range(nt):
                total_deficit[j] += wake_deficit_matrix[i][j] ** 2.0
            total_deficit[j] = sqrt(total_deficit[j])
            total_speed[j] = U0 * (1.0 - total_deficit[j])

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
        efficiency = 0.0
        for l in range(nt):
            profit += power(total_speed[l])
        efficiency = profit * 100.0 / (float(nt) * power(U0))
        efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
        summation += efficiency_proportion[wind]
    return summation  # Farm efficiency

# if __name__ == '__main__':
#     start_time = time.time()
#     Jensen()
# print("--- %s seconds ---" % (time.time() - start_time))
def jensen(a, windrose_angle, windrose_speed, windrose_frequency):
    import wake
    from math import sqrt, log, tan, cos
    from numpy import deg2rad

    nt = len(a)
    layout_x = [0.0 for x in range(nt)]
    layout_y = [0.0 for x in range(nt)]
    for x in range(nt):
        layout_x[x] = float(a[x][0])
        layout_y[x] = float(a[x][1])

    def Ct(U0):
        if U0 < 4.0:
            return 0.1
        elif U0 <= 25.0:
            return 0.00000073139922126945 * U0 ** 6.0 - 0.0000668905596915255 * U0 ** 5.0 + 0.0023937885 * U0 ** 4.0 + - 0.0420283143 * U0 ** 3.0 + 0.3716111285 * U0 ** 2.0 - 1.5686969749 * U0 + 3.2991094727
        else:
            return 0.0

    def power(U0):
        if U0 < 4.0:
            return 0.0
        elif U0 <= 25.0:
            return 0.0003234808 * U0 ** 7.0 - 0.0331940121 * U0 ** 6.0 + 1.3883148012 * U0 ** 5.0 - 30.3162345004 * U0 ** 4.0 + 367.6835557011 * U0 ** 3.0 - 2441.6860655008 * U0 ** 2.0 + 8345.6777042343 * U0 - 11352.9366182805
        else:
            return 0.0

    # for U0 in range(4, 20):
    nt = 80  # Number of turbines
    summation = 0.0

    def distance_to_front(x, y, theta, r):
        theta = deg2rad(theta)
        return abs(x + tan(theta) * y - r / cos(theta)) / sqrt(1.0 + tan(theta) ** 2.0)

    for wind in range(0, len(windrose_angle)):
        U1 = windrose_speed[wind]  # Free stream wind speed
        U0 = U1 * (70.0 / 10.0) ** 0.11 # Power or log law for wind shear profile
        k = 0.04  # Decay constant
        r0 = 40.0  # Turbine rotor radius
        angle = windrose_angle[wind]
        angle3 = angle + 180.0
        deficit_matrix = [[0.0 for x in range(nt)] for x in range(nt)]
        proportion = [[0.0 for x in range(nt)] for x in range(nt)]
        distance = [[0.0 for x in range(2)] for x in range(nt)]

        U = [U0 for x in range(nt)]
        total_deficit = [0.0 for x in range(nt)]

        for tur in range(nt):
            distance[tur] = [distance_to_front(layout_x[tur], layout_y[tur], angle, 100000000.0), tur]
        distance.sort()

        for turbine in range(nt):
            for num in range(turbine):
                total_deficit[distance[turbine][1]] += deficit_matrix[distance[turbine][1]][distance[num][1]] ** 2.0
            total_deficit[distance[turbine][1]] = sqrt(total_deficit[distance[turbine][1]])
            U[distance[turbine][1]] = U0 * (1.0 - total_deficit[distance[turbine][1]])
            for i in range(turbine + 1, nt):
                proportion[distance[turbine][1]][distance[i][1]] = wake.determine_if_in_wake(layout_x[distance[turbine][1]], layout_y[distance[turbine][1]], layout_x[distance[i][1]], layout_y[distance[i][1]], k, r0, angle3)
                deficit_matrix[distance[i][1]][distance[turbine][1]] = proportion[distance[turbine][1]][distance[i][1]] * wake.wake_deficit(Ct(U[distance[turbine][1]]), k, wake.distance(layout_x[distance[turbine][1]], layout_y[distance[turbine][1]], layout_x[distance[i][1]], layout_y[distance[i][1]]), r0)

        # Farm efficiency
        profit = 0.0
        efficiency_proportion = [0.0 for x in range(0, len(windrose_frequency))]
        for l in range(nt):
            profit += power(U[l])
        efficiency = profit * 100.0 / (float(nt) * power(U[distance[0][1]]))
        efficiency_proportion[wind] = efficiency * windrose_frequency[wind] / 100.0
        # print 'Farm efficiency with wind direction = {0:d} deg: {1:2.2f}%'.format(int(angle), efficiency)
        summation += efficiency_proportion[wind]

    return summation