def get_radius_neighbors(point, kd, mean): low = 0 high = low + SR r = (low + high) / 2 # print "%g < %g < %g | to first neighbor: %g" %(low, r, high, low) neighbors = [[]] def number_neighs(r): neighbors[0] = kd.query_ball_point(point, r) return len(neighbors[0]) def od_temp(rad): return overdensity(number_neighs(rad), rad, mean) od = Memoize(od_temp) # print "dens:%g, number neighs %g" %(od(low), number_neighs(low)) while (od(r) <= K - E or od(r) >= K + E): if od(r) > K: # our density is too high, so increase r low = r else: # our density is too low, so decrease r high = r r = (low + high) / 2 # print "%g < %g < %g" %(low, r, high) #print "Current overdensity is %g" %od(r) #print od(r) return (r, neighbors[0])
def MemoizeMembers(obj, *items): import types memall = len(items) == 0 for membername in dir(obj): value = getattr(obj, membername) if ((memall and '__' not in membername) or membername in items) and not isinstance(value, Memoize) and \ isinstance(value ,(types.FunctionType,types.BuiltinFunctionType)): #print 'memoizing %s' % (membername) setattr(obj, membername, Memoize(value)) return obj
def MemoizeObject(obj, *memmethods): '''Memoize methods for object, if no method names are passed, then memoize *all* methods. This is usually overkill''' memall = len(memmethods) == 0 instancemethod = type(Memoize.__init__) for membername in dir(obj): value = getattr(obj, membername) if (memall or membername in memmethods ) and type(value) is instancemethod and not isinstance( value, Memoize): setattr(obj, membername, Memoize(value)) #print 'memoizing %s!' % (membername) return obj
from math import sqrt from memoize import Memoize from turbine_description import rotor_radius # Change in Fatigue and Extreme Loading when Moving Wind Farms Offshore // Sten Frandsen and Kenneth Thomsen. # Only nearest wake-shedding turbine matters in a wind farm. def frandsen2(ambient_turbulence, Ct, wind_speed, spacing): return sqrt(1.2 * Ct / spacing**2.0 + ambient_turbulence**2.0) frandsen2 = Memoize(frandsen2) def danish_recommendation(ambient_turbulence, ct, wind_speed, spacing): def beta_v(u): if u < 12.0: return 1.0 elif u < 20.0: return 1.747 - 0.0625 * u else: return 0.5 # Beta_l, x is turbine spacing def beta_l(d, cluster=True): if cluster: if d < 2.9838: return 1.0 elif d < 5.9856: return 1.333 - 0.1116 * d
cutout=cutout_wind_speed): table_cp = AeroLookup( "/home/sebasanper/PycharmProjects/owf_MDAO/farm_energy/wake_model_mean_new/aero_power_ct_models/nrel_cp.dat" ) if wind_speed < cutin: return 0.0 elif wind_speed <= rated: cp = table_cp.interpolation(wind_speed) return 0.5 * 1.225 * pi * r**2.0 * wind_speed**3.0 * cp elif wind_speed <= cutout: return rated_power else: return 0.0 power_coefficient = Memoize(power_coefficient) from memoize import countcalls @countcalls def power2(wind_speed, power_lookup_file, cutin=cutin_wind_speed, cutout=cutout_wind_speed, rated=rated_wind, r=rotor_radius): table_power = AeroLookup(power_lookup_file) # print "iuno" if power_lookup_file == "/home/sebasanper/PycharmProjects/owf_MDAO/farm_energy/wake_model_mean_new/aero_power_ct_models/nrel_cp.dat": if wind_speed < cutin:
""" Groups words according to a basic fuzzy matching ratio and graphs the result """ import argparse import fileinput import itertools import multiprocessing as mp from multiprocessing import Pool import matplotlib.pyplot as plot from fuzzywuzzy import fuzz import networkx from networkx.algorithms.components.connected import connected_components from memoize import Memoize MEMOIZED_FUZZ_MATCH = Memoize(fuzz.ratio) def get_fuzz_ratio(first_word, second_word): """ Returns the fuzzy matching ratio between two arguments """ return fuzz.ratio(first_word, second_word), first_word, second_word def to_edges(graph): """ treat graph as a Graph and returns it's edges to_edges(['a','b','c','d']) -> [(a,b), (b,c),(c,d)] """ return list(zip(graph[:-1], graph[1:]))
value = True return fraction, value, distance_to_centre, distance_to_turbine elif abs(radius) < abs(distance_to_centre): if abs(radius) <= abs(distance_to_centre) - r0: fraction = 0.0 value = False return fraction, value, distance_to_centre, distance_to_turbine elif abs(radius) > abs(distance_to_centre) - r0: fraction = AreaReal(r0, radius, distance_to_centre).area() value = True return fraction, value, distance_to_centre, distance_to_turbine else: return 0.0, False, distance_to_centre, distance_to_turbine determine_if_in_wake_larsen = Memoize(determine_if_in_wake_larsen) def wake_speed(U0, ct, x, y, ia): return U0 * (1.0 - ((ct * rotor_area * x**(-2.0))**(1.0 / 3.0)) / 9.0 * (y**(3.0 / 2.0) * (3.0 * c1(ct, ia)**2.0 * ct * rotor_area * x)**(-1.0 / 2.0) - (35.0 / 2.0 / pi)**(3.0 / 10.0) * (3.0 * c1(ct, ia)**2.0)**(-1.0 / 5.0))**2.0) # wake_speed = Memoize(wake_speed) def wake_deficit_larsen(U0, ct, x, y, ia): if U0 == 0.0:
from memoize import Memoize from farm_energy.wake_model_mean_new.jensen import * from farm_energy.wake_model_mean_new.larsen import * from farm_energy.wake_model_mean_new.ainslie1d import * # from farm_energy.wake_model_mean_new.ainslie2d import ainslie_full from farm_energy.wake_model_mean_new.ainslie2d_cy import ainslie_full ainslie_full = Memoize(ainslie_full) from farm_energy.wake_model_mean_new.ainslie_common import crosswind_distance, determine_front from time import time from turbine_description import rotor_radius def constantwake(coordinates_upstream, thrust_coefficient, coordinates_downstream, angle, wind_speed_upstream, ambient_turbulence_intensity): return [0.0 for _ in range(len(coordinates_downstream))] def JensenEffects(coordinates_upstream, thrust_coefficient, coordinates_downstream, angle, wind_speed_upstream, ambient_turbulence_intensity): angle3 = angle + 180.0 # coordinates downstream will be an array with coordinates and original index. partial_deficits = [] for i in range(len(coordinates_downstream)): determ = determine_if_in_wake(coordinates_upstream[1], coordinates_upstream[2], coordinates_downstream[i][1], coordinates_downstream[i][2], angle3) # print determ[1], "determ1" # print determ[0], "determ0" if determ[0] != 0.0: # print jensen.wake_deficit(thrust_coefficient, determ[1]) partial_deficits.append(determ[0] * wake_deficit(thrust_coefficient, determ[1])) else: partial_deficits.append(0.0)
Dmi = 0.0000000001 Uc1[0] = U0 * (1.0 - Dmi) # Boundary condition at x = 2.0 d1[0] = Dmi for i in range(1, n): # For all positions in the wake centreline direction. Recursive. Whole grid Uc1[i] = Uc1[i - 1] + (h * 16.0 * E(i * h, Uc1[i - 1], d1[i - 1], U0, I0, Ct) * (Uc1[i - 1] ** 3.0 - U0 * Uc1[i - 1] ** 2.0 - Uc1[i - 1] * U0 ** 2.0 + U0 ** 3.0) / (Uc1[i - 1] * Ct * U0 ** 2.0)) d1[i] = 1.0 - Uc1[i] / U0 # Code to calculate wake deficit at a specific point instead of the whole grid. Namely, the rotor's centrepoint. answer = d1[-1] * exp(- 3.56 * (Y / b(d1[-1], ct)) ** 2.0) # * (1.0 + 7.12 * (0.07 * distance_perpendicular b(d1[-1], ct))) ** (- 0.5) return answer ainslie = Memoize(ainslie) # Code to calculate average wake deficit in all area of the rotor ############### # Define function to integrate. # p. 77 Adapting and calibration of existing wake models to meet the conditions inside offshore wind farms. For integrand squared momentum deficit. # def G(r, theta): # z = sqrt(Y ** 2.0 + r ** 2.0 + 2.0 * Y * r * cos(theta)) # gauss = U0 * (1.0 - d1[n - 1] * exp(- 3.56 * (z / b(d1[n - 1])) ** 2.0)) # return r * (U0 - gauss) ** 2.0 # # A = pi * 0.5 ** 2.0 ## Unitary diameter in this program. # U = U0 - sqrt((1.0 / A) * simpson_integrate2D(G, 0.0, 0.5, 5, 0.0, 2.0 * pi, 10)) # return 1.0 - U / U0
from numpy import exp from farm_energy.wake_model_mean_new.thomas_algorithm import thomas from farm_energy.wake_model_mean_new.ainslie_common import b, E from time import time from memoize import Memoize from turbine_description import rotor_radius b = Memoize(b) E = Memoize(E) rotor_diameter = 2.0 * rotor_radius def ainslie_full(ct, u0, distance_parallel, distance_perpendicular, i0): # centreline = open('centreline.dat', 'w') # velocity = open('velocity.dat', 'w') di = 2.0 dj = distance_parallel # ni = int(di * 80) # nj = int(dj * 80) ni = 100 nj = 100 k = dj / float(nj) h = di / float(ni) nj += 1 ni += 1 Dmi = ct - 0.05 - (16.0 * ct - 0.5) * i0 / 10.0 if Dmi < 0.0: Dmi = 0.00000000001 u = [0.0 for _ in range(ni)]
selector = "chat_id" if config["export"]["is_group_chat"] else "uid" messages = _api("messages.getHistory", [(selector, config["export"]["chat_id"])], token) # prepare output if config["export"]["output_directory"] is not None: if not os.path.exists(config["export"]["output_directory"]): os.makedirs(config["export"]["output_directory"]) output_filename = 'vk_exported_dialogue_%s%s.txt' % ('ui' if not config["export"]["is_group_chat"] else 'c', config["export"]["chat_id"]) output_path = Downloader.resolve_path(config["export"]["output_directory"], output_filename) out = codecs.open(output_path, "w+", "utf-8") def resolve_uid_details(uid): return _api("users.get", [("user_ids", uid)], token)[0] resolve_uid_details = Memoize(resolve_uid_details) message_writer = MessageWriter(out, downloader, lambda uid: resolve_uid_details(uid), save_photos=config["export"]["save_photos"]) mess = 0 max_part = 200 # Due to vk.api cnt = messages[0] reporter.line("Message count: %s" % cnt) request_num = 0 while mess != cnt: # Try to retrieve info anyway if request_num % 5 == 0:
from numpy import pi, sqrt, deg2rad, tan, cos, sin from farm_energy.wake_model_mean_new.area import AreaReal from turbine_description import rotor_radius as r0, hub_height as H from memoize import Memoize D = 2.0 * r0 rotor_area = pi * r0**2.0 # print rotor_area def rnb(ia): return max(1.08 * D, 1.08 * D + 21.7 * D * (ia - 0.05)) rnb = Memoize(rnb) def r95(ia): # print 0.5 * (rnb(ia) + min(H, rnb(ia))) return 0.5 * (rnb(ia) + min(H, rnb(ia))) r95 = Memoize(r95) def wake_radius(ct, x, ia): return ((35.0 / 2.0 / pi)**(1.0 / 5.0)) * ( (3.0 * c1(ct, ia)**2.0)**(1.0 / 5.0)) * ( (ct * rotor_area * x)**(1.0 / 3.0))
return fraction, distance_to_turbine elif abs(radius) < abs(distance_to_centre) + radius: fraction = AreaReal(radius, radius, distance_to_centre).area() return fraction, distance_to_turbine elif abs(radius) < abs(distance_to_centre): if abs(radius) <= abs(distance_to_centre) - radius: fraction = 0.0 return fraction, distance_to_turbine elif abs(radius) > abs(distance_to_centre) - radius: fraction = AreaReal(radius, radius, distance_to_centre).area() return fraction, distance_to_turbine else: return 0.0, distance_to_turbine determine_if_in_wake = Memoize(determine_if_in_wake) def wake_deficit(Ct, x, k=jensen_k, r0=rotor_radius): return (1.0 - sqrt(1.0 - Ct)) / (1.0 + (k * x) / r0)**2.0 wake_deficit = Memoize(wake_deficit) def wake_radius(x, r0=rotor_radius, k=jensen_k): return r0 + k * x wake_radius = Memoize(wake_radius)
def test_fib_memoized(): fib_memoized = Memoize(fib) assert fib_memoized.memoized(10) == 55 assert fib_memoized.memoized(35) == 9227465
return fraction, distance_to_turbine elif abs(radius) < abs(distance_to_centre) + radius: fraction = AreaReal(radius, radius, distance_to_centre).area() return fraction, distance_to_turbine elif abs(radius) < abs(distance_to_centre): if abs(radius) <= abs(distance_to_centre) - radius: fraction = 0.0 return fraction, distance_to_turbine elif abs(radius) > abs(distance_to_centre) - radius: fraction = AreaReal(radius, radius, distance_to_centre).area() return fraction, distance_to_turbine else: return 0.0, distance_to_turbine determine_if_in_wake = Memoize(determine_if_in_wake) def wake_deficit(Ct, x, k=jensen_k, r0=rotor_radius): return (1.0 - sqrt(1.0 - Ct)) / (1.0 + (k * x) / r0)**2.0 # wake_deficit = Memoize(wake_deficit) def wake_radius(x, r0=rotor_radius, k=jensen_k): return r0 + k * x # wake_radius = Memoize(wake_radius)