foxes 0.8.2__py3-none-any.whl → 1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of foxes might be problematic. Click here for more details.

Files changed (174) hide show
  1. docs/source/conf.py +353 -0
  2. examples/abl_states/run.py +160 -0
  3. examples/compare_rotors_pwakes/run.py +217 -0
  4. examples/compare_wakes/run.py +241 -0
  5. examples/dyn_wakes/run.py +311 -0
  6. examples/field_data_nc/run.py +121 -0
  7. examples/induction_RHB/run.py +201 -0
  8. examples/multi_height/run.py +113 -0
  9. examples/power_mask/run.py +249 -0
  10. examples/random_timeseries/run.py +210 -0
  11. examples/scan_row/run.py +193 -0
  12. examples/sector_management/run.py +162 -0
  13. examples/sequential/run.py +209 -0
  14. examples/single_state/run.py +201 -0
  15. examples/states_lookup_table/run.py +137 -0
  16. examples/streamline_wakes/run.py +138 -0
  17. examples/tab_file/run.py +142 -0
  18. examples/timelines/run.py +267 -0
  19. examples/timeseries/run.py +183 -0
  20. examples/timeseries_slurm/run.py +185 -0
  21. examples/wind_rose/run.py +141 -0
  22. examples/windio/run.py +29 -0
  23. examples/yawed_wake/run.py +196 -0
  24. foxes/__init__.py +4 -8
  25. foxes/algorithms/__init__.py +1 -1
  26. foxes/algorithms/downwind/downwind.py +232 -101
  27. foxes/algorithms/downwind/models/farm_wakes_calc.py +11 -6
  28. foxes/algorithms/downwind/models/init_farm_data.py +1 -1
  29. foxes/algorithms/downwind/models/point_wakes_calc.py +5 -6
  30. foxes/algorithms/downwind/models/reorder_farm_output.py +0 -1
  31. foxes/algorithms/downwind/models/set_amb_point_results.py +4 -2
  32. foxes/algorithms/iterative/iterative.py +73 -33
  33. foxes/algorithms/iterative/models/farm_wakes_calc.py +11 -6
  34. foxes/algorithms/sequential/models/plugin.py +1 -1
  35. foxes/algorithms/sequential/sequential.py +126 -255
  36. foxes/constants.py +17 -2
  37. foxes/core/__init__.py +1 -0
  38. foxes/core/algorithm.py +631 -146
  39. foxes/core/data.py +252 -20
  40. foxes/core/data_calc_model.py +13 -289
  41. foxes/core/engine.py +630 -0
  42. foxes/core/farm_controller.py +37 -9
  43. foxes/core/farm_data_model.py +15 -0
  44. foxes/core/model.py +133 -80
  45. foxes/core/point_data_model.py +15 -0
  46. foxes/core/rotor_model.py +27 -21
  47. foxes/core/states.py +16 -0
  48. foxes/core/turbine_type.py +28 -0
  49. foxes/core/wake_frame.py +22 -4
  50. foxes/core/wake_model.py +2 -3
  51. foxes/data/windio/windio_5turbines_timeseries.yaml +23 -1
  52. foxes/engines/__init__.py +16 -0
  53. foxes/engines/dask.py +975 -0
  54. foxes/engines/default.py +75 -0
  55. foxes/engines/futures.py +72 -0
  56. foxes/engines/mpi.py +38 -0
  57. foxes/engines/multiprocess.py +74 -0
  58. foxes/engines/numpy.py +185 -0
  59. foxes/engines/pool.py +263 -0
  60. foxes/engines/single.py +139 -0
  61. foxes/input/farm_layout/__init__.py +1 -0
  62. foxes/input/farm_layout/from_csv.py +4 -0
  63. foxes/input/farm_layout/from_json.py +1 -1
  64. foxes/input/farm_layout/grid.py +2 -2
  65. foxes/input/farm_layout/ring.py +65 -0
  66. foxes/input/farm_layout/row.py +2 -2
  67. foxes/input/states/__init__.py +6 -0
  68. foxes/input/states/create/random_abl_states.py +1 -1
  69. foxes/input/states/field_data_nc.py +157 -32
  70. foxes/input/states/multi_height.py +127 -13
  71. foxes/input/states/one_point_flow.py +577 -0
  72. foxes/input/states/scan_ws.py +73 -2
  73. foxes/input/states/states_table.py +204 -35
  74. foxes/input/windio/__init__.py +1 -1
  75. foxes/input/windio/get_states.py +44 -23
  76. foxes/input/windio/read_attributes.py +41 -16
  77. foxes/input/windio/read_farm.py +116 -102
  78. foxes/input/windio/read_fields.py +13 -6
  79. foxes/input/windio/read_outputs.py +63 -22
  80. foxes/input/windio/runner.py +31 -17
  81. foxes/input/windio/windio.py +36 -22
  82. foxes/models/ground_models/wake_mirror.py +8 -4
  83. foxes/models/model_book.py +29 -18
  84. foxes/models/partial_wakes/rotor_points.py +3 -3
  85. foxes/models/rotor_models/centre.py +4 -0
  86. foxes/models/rotor_models/grid.py +22 -23
  87. foxes/models/rotor_models/levels.py +4 -5
  88. foxes/models/turbine_models/calculator.py +0 -2
  89. foxes/models/turbine_models/lookup_table.py +27 -2
  90. foxes/models/turbine_models/rotor_centre_calc.py +4 -3
  91. foxes/models/turbine_models/set_farm_vars.py +103 -34
  92. foxes/models/turbine_types/PCt_file.py +24 -0
  93. foxes/models/turbine_types/PCt_from_two.py +24 -0
  94. foxes/models/turbine_types/__init__.py +1 -0
  95. foxes/models/turbine_types/lookup.py +316 -0
  96. foxes/models/turbine_types/null_type.py +50 -0
  97. foxes/models/turbine_types/wsrho2PCt_from_two.py +24 -0
  98. foxes/models/turbine_types/wsti2PCt_from_two.py +24 -0
  99. foxes/models/vertical_profiles/data_profile.py +1 -1
  100. foxes/models/wake_frames/__init__.py +1 -0
  101. foxes/models/wake_frames/dynamic_wakes.py +424 -0
  102. foxes/models/wake_frames/farm_order.py +23 -3
  103. foxes/models/wake_frames/rotor_wd.py +4 -2
  104. foxes/models/wake_frames/seq_dynamic_wakes.py +56 -63
  105. foxes/models/wake_frames/streamlines.py +19 -20
  106. foxes/models/wake_frames/timelines.py +328 -127
  107. foxes/models/wake_frames/yawed_wakes.py +4 -1
  108. foxes/models/wake_models/dist_sliced.py +1 -3
  109. foxes/models/wake_models/induction/rankine_half_body.py +4 -4
  110. foxes/models/wake_models/induction/rathmann.py +2 -2
  111. foxes/models/wake_models/induction/self_similar.py +2 -2
  112. foxes/models/wake_models/induction/vortex_sheet.py +2 -2
  113. foxes/models/wake_models/ti/iec_ti.py +34 -17
  114. foxes/models/wake_models/top_hat.py +1 -1
  115. foxes/models/wake_models/wind/bastankhah14.py +2 -2
  116. foxes/models/wake_models/wind/bastankhah16.py +8 -7
  117. foxes/models/wake_models/wind/jensen.py +1 -1
  118. foxes/models/wake_models/wind/turbopark.py +2 -2
  119. foxes/output/__init__.py +4 -1
  120. foxes/output/farm_layout.py +2 -2
  121. foxes/output/flow_plots_2d/__init__.py +0 -1
  122. foxes/output/flow_plots_2d/flow_plots.py +70 -30
  123. foxes/output/grids.py +91 -21
  124. foxes/output/seq_plugins/__init__.py +2 -0
  125. foxes/output/{flow_plots_2d → seq_plugins}/seq_flow_ani_plugin.py +62 -20
  126. foxes/output/seq_plugins/seq_wake_debug_plugin.py +145 -0
  127. foxes/output/slice_data.py +131 -111
  128. foxes/output/state_turbine_map.py +18 -13
  129. foxes/output/state_turbine_table.py +19 -19
  130. foxes/utils/__init__.py +1 -1
  131. foxes/utils/dev_utils.py +42 -0
  132. foxes/utils/dict.py +1 -1
  133. foxes/utils/factory.py +147 -52
  134. foxes/utils/pandas_helpers.py +4 -3
  135. foxes/utils/wind_dir.py +0 -2
  136. foxes/utils/xarray_utils.py +23 -13
  137. foxes/variables.py +37 -0
  138. {foxes-0.8.2.dist-info → foxes-1.0.dist-info}/METADATA +71 -33
  139. foxes-1.0.dist-info/RECORD +307 -0
  140. {foxes-0.8.2.dist-info → foxes-1.0.dist-info}/WHEEL +1 -1
  141. foxes-1.0.dist-info/top_level.txt +4 -0
  142. tests/0_consistency/iterative/test_iterative.py +92 -0
  143. tests/0_consistency/partial_wakes/test_partial_wakes.py +90 -0
  144. tests/1_verification/flappy_0_6/PCt_files/flappy/run.py +85 -0
  145. tests/1_verification/flappy_0_6/PCt_files/test_PCt_files.py +103 -0
  146. tests/1_verification/flappy_0_6/abl_states/flappy/run.py +85 -0
  147. tests/1_verification/flappy_0_6/abl_states/test_abl_states.py +87 -0
  148. tests/1_verification/flappy_0_6/partial_top_hat/flappy/run.py +82 -0
  149. tests/1_verification/flappy_0_6/partial_top_hat/test_partial_top_hat.py +82 -0
  150. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/flappy/run.py +92 -0
  151. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/test_row_Jensen_linear_centre.py +93 -0
  152. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/flappy/run.py +92 -0
  153. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/test_row_Jensen_linear_tophat.py +96 -0
  154. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/flappy/run.py +94 -0
  155. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/test_row_Jensen_linear_tophat_IECTI_2005.py +122 -0
  156. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/flappy/run.py +94 -0
  157. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/test_row_Jensen_linear_tophat_IECTI_2019.py +122 -0
  158. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/flappy/run.py +92 -0
  159. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py +93 -0
  160. tests/1_verification/flappy_0_6_2/grid_rotors/flappy/run.py +85 -0
  161. tests/1_verification/flappy_0_6_2/grid_rotors/test_grid_rotors.py +130 -0
  162. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/flappy/run.py +96 -0
  163. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/test_row_Bastankhah_Crespo.py +116 -0
  164. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/flappy/run.py +93 -0
  165. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py +99 -0
  166. tests/3_examples/test_examples.py +34 -0
  167. foxes/VERSION +0 -1
  168. foxes/output/flow_plots_2d.py +0 -0
  169. foxes/utils/runners/__init__.py +0 -1
  170. foxes/utils/runners/runners.py +0 -280
  171. foxes-0.8.2.dist-info/RECORD +0 -247
  172. foxes-0.8.2.dist-info/top_level.txt +0 -1
  173. foxes-0.8.2.dist-info/zip-safe +0 -1
  174. {foxes-0.8.2.dist-info → foxes-1.0.dist-info}/LICENSE +0 -0
@@ -0,0 +1,93 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pathlib import Path
4
+ import inspect
5
+
6
+ import foxes
7
+ import foxes.variables as FV
8
+ import foxes.constants as FC
9
+
10
+ thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
+
12
+
13
+ def test():
14
+ n_s = 800
15
+ n_t = 76
16
+ c = 1000
17
+ p0 = np.array([0.0, 0.0])
18
+ stp = np.array([497.0, 0.0])
19
+ cfile = thisdir / "flappy" / "results.csv.gz"
20
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
21
+
22
+ mbook = foxes.models.ModelBook()
23
+ ttype = foxes.models.turbine_types.PCtFile(
24
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
25
+ )
26
+ mbook.turbine_types[ttype.name] = ttype
27
+
28
+ states = foxes.input.states.ScanWS(
29
+ ws_list=np.linspace(3.0, 30.0, n_s), wd=270.0, ti=0.08, rho=1.225
30
+ )
31
+
32
+ farm = foxes.WindFarm()
33
+ foxes.input.farm_layout.add_row(
34
+ farm=farm,
35
+ xy_base=p0,
36
+ xy_step=stp,
37
+ n_turbines=n_t,
38
+ turbine_models=[ttype.name],
39
+ verbosity=0,
40
+ )
41
+
42
+ algo = foxes.algorithms.Downwind(
43
+ farm,
44
+ states,
45
+ mbook=mbook,
46
+ rotor_model="centre",
47
+ wake_models=["Jensen_quadratic_k007"],
48
+ wake_frame="rotor_wd",
49
+ partial_wakes={"Jensen_linear_k007": "centre"},
50
+ verbosity=0,
51
+ )
52
+
53
+ data = algo.calc_farm()
54
+
55
+ df = data.to_dataframe()[[FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_P, FV.P]]
56
+
57
+ print("\nReading file", cfile)
58
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
59
+
60
+ print()
61
+ print("TRESULTS\n")
62
+ sel = (df[FV.P] > 0) & (fdata[FV.P] > 0)
63
+ df = df.loc[sel]
64
+ fdata = fdata.loc[sel]
65
+ print(df.loc[sel])
66
+ print(fdata.loc[sel])
67
+
68
+ print("\nVERIFYING\n")
69
+ df[FV.WS] = df["REWS"]
70
+ df[FV.AMB_WS] = df["AMB_REWS"]
71
+
72
+ delta = df - fdata
73
+ print(delta)
74
+
75
+ chk = delta.abs()
76
+ print(chk.max())
77
+
78
+ var = FV.WS
79
+ print(f"\nCHECKING {var}")
80
+ sel = chk[var] >= 1e-7
81
+ print(df.loc[sel])
82
+ print(fdata.loc[sel])
83
+ print(chk.loc[sel])
84
+ assert (chk[var] < 1e-7).all()
85
+
86
+ var = FV.P
87
+ sel = chk[var] >= 1e-5
88
+ print(f"\nCHECKING {var}\n", delta.loc[sel])
89
+ assert (chk[var] < 1e-5).all()
90
+
91
+
92
+ if __name__ == "__main__":
93
+ test()
@@ -0,0 +1,85 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ import time
4
+ import argparse
5
+ from pathlib import Path
6
+
7
+ import flappy as fl
8
+ from flappy.config.variables import variables as FV
9
+
10
+ if __name__ == "__main__":
11
+ parser = argparse.ArgumentParser()
12
+ parser.add_argument(
13
+ "-c", "--chunksize", help="The maximal chunk size", type=int, default=500
14
+ )
15
+ parser.add_argument("-o", "--opath", help="The output file path", default=".")
16
+ parser.add_argument(
17
+ "--n_cpus", help="The number of processors", type=int, default=4
18
+ )
19
+ args = parser.parse_args()
20
+
21
+ c = args.chunksize
22
+ p0 = np.array([0.0, 0.0])
23
+ stp = np.array([500.0, 0.0])
24
+ opath = Path(args.opath)
25
+ tfile = "../NREL-5MW-D126-H90.csv"
26
+ sfile = "../states.csv.gz"
27
+ lfile = "../test_farm.csv"
28
+ cases = [
29
+ (["Bastankhah_rotor"], ["wind_linear"], "centre"),
30
+ (["Bastankhah_rotor"], ["wind_linear"], "grid4"),
31
+ (["Bastankhah_rotor"], ["wind_linear"], "grid16"),
32
+ (["Bastankhah_rotor"], ["wind_linear"], "grid64"),
33
+ ]
34
+
35
+ # init flappy:
36
+ fl.init_flappy(n_cpus=args.n_cpus)
37
+
38
+ for i, (wakes, superp, rotor) in enumerate(cases):
39
+ print(f"\nCase {(wakes, superp, rotor)}")
40
+
41
+ # load model book:
42
+ mbook = fl.ModelBook(ct_power_curve_file=tfile)
43
+
44
+ # create wind farm:
45
+ farm = fl.WindFarm()
46
+ fl.input.add_turbines_from_csv(
47
+ farm,
48
+ lfile,
49
+ col_index="index",
50
+ col_x="x",
51
+ col_y="y",
52
+ rotor_diameter=126.0,
53
+ hub_height=90.0,
54
+ rotor_model=rotor,
55
+ wake_models=wakes,
56
+ turbine_models=["ct_P_curves"],
57
+ output_level=0,
58
+ )
59
+
60
+ # create states:
61
+ states = fl.input.AFSStatesTable(
62
+ data_file=sfile,
63
+ col_wd="wd",
64
+ col_ws_ref="ws",
65
+ col_ti="ti",
66
+ col_weight="weight",
67
+ air_density=1.225,
68
+ z0=0.1,
69
+ h_ref=100.0,
70
+ max_chunk_size=args.chunksize,
71
+ output_level=0,
72
+ )
73
+ states.initialize()
74
+
75
+ # run calculation:
76
+ results = farm.calculate(mbook, states, wake_superp=superp, output_level=0)
77
+
78
+ df = results.state_turbine_results[[FV.WD, FV.AMB_WS, FV.WS, FV.AMB_P, FV.P]]
79
+
80
+ ofile = opath / f"results_{i}.csv.gz"
81
+ print(f"Writing file {ofile}")
82
+ df.to_csv(ofile)
83
+
84
+ # close flappy:
85
+ fl.shutdown_flappy()
@@ -0,0 +1,130 @@
1
+ import pandas as pd
2
+ from pathlib import Path
3
+ import inspect
4
+
5
+ import foxes
6
+ import foxes.variables as FV
7
+ import foxes.constants as FC
8
+
9
+ thisdir = Path(inspect.getfile(inspect.currentframe())).parent
10
+
11
+
12
+ def test():
13
+ c = 500
14
+ cpath = thisdir / "flappy"
15
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
16
+ sfile = thisdir / "states.csv.gz"
17
+ lfile = thisdir / "test_farm.csv"
18
+ cases = [
19
+ (["Basta"], "centre", "rotor_points"),
20
+ (["Basta"], "grid4", "grid4"),
21
+ (["Basta"], "grid16", "grid16"),
22
+ (["Basta"], "grid64", "grid64"),
23
+ ]
24
+
25
+ ck = {FC.STATE: c}
26
+
27
+ for i, (wakes, rotor, pwake) in enumerate(cases):
28
+ print(f"\nENTERING CASE {(wakes, rotor, pwake)}\n")
29
+
30
+ mbook = foxes.models.ModelBook()
31
+ ttype = foxes.models.turbine_types.PCtFile(
32
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
33
+ )
34
+ mbook.turbine_types[ttype.name] = ttype
35
+
36
+ mbook.wake_models["Basta"] = foxes.models.wake_models.wind.Bastankhah2014(
37
+ sbeta_factor=0.25, superposition="ws_linear", induction="Betz"
38
+ )
39
+
40
+ states = foxes.input.states.StatesTable(
41
+ data_source=sfile,
42
+ output_vars=[FV.WS, FV.WD, FV.TI, FV.RHO],
43
+ var2col={FV.WS: "ws", FV.WD: "wd", FV.TI: "ti"},
44
+ fixed_vars={FV.RHO: 1.225, FV.Z0: 0.1, FV.H: 100.0},
45
+ profiles={FV.WS: "ABLLogNeutralWsProfile"},
46
+ )
47
+
48
+ farm = foxes.WindFarm()
49
+ foxes.input.farm_layout.add_from_file(
50
+ farm,
51
+ lfile,
52
+ turbine_models=["kTI_amb_02", ttype.name],
53
+ verbosity=1,
54
+ )
55
+
56
+ algo = foxes.algorithms.Downwind(
57
+ farm,
58
+ states,
59
+ mbook=mbook,
60
+ rotor_model=rotor,
61
+ wake_models=wakes,
62
+ wake_frame="rotor_wd",
63
+ partial_wakes=pwake,
64
+ chunks=ck,
65
+ verbosity=1,
66
+ )
67
+
68
+ data = algo.calc_farm()
69
+
70
+ df = data.to_dataframe()[
71
+ [FV.AMB_WD, FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_P, FV.P]
72
+ ]
73
+
74
+ cfile = cpath / f"results_{i}.csv.gz"
75
+ print("\nReading file", cfile)
76
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
77
+
78
+ print()
79
+ print("TRESULTS\n")
80
+ print(df)
81
+ print(fdata)
82
+
83
+ print("\nVERIFYING\n")
84
+ df[FV.WS] = df["REWS"]
85
+ df[FV.AMB_WS] = df["AMB_REWS"]
86
+
87
+ delta = df - fdata
88
+ print(delta)
89
+ chk = delta[[FV.AMB_WS, FV.AMB_P, FV.WS, FV.P]]
90
+ print(chk)
91
+ chk = chk.abs()
92
+ print(chk.max())
93
+
94
+ var = FV.AMB_WS
95
+ sel = chk[var] >= 1e-7
96
+ print(f"\nCHECKING {var}, {(wakes, rotor, pwake)}\n")
97
+ print(df.loc[sel])
98
+ print(fdata.loc[sel])
99
+ print(delta.loc[sel])
100
+ assert (chk[var] < 1e-7).all()
101
+
102
+ var = FV.AMB_P
103
+ sel = chk[var] >= 1e-5
104
+ print(f"\nCHECKING {var}, {(wakes, rotor, pwake)}\n")
105
+ print(df.loc[sel])
106
+ print(fdata.loc[sel])
107
+ print(delta.loc[sel])
108
+ assert (chk[var] < 1e-5).all()
109
+
110
+ var = FV.WS
111
+ sel = chk[var] >= 1.7e-3
112
+ print(f"\nCHECKING {var}, {(wakes, rotor, pwake)}\n")
113
+ print(df.loc[sel])
114
+ print(fdata.loc[sel])
115
+ print(delta.loc[sel])
116
+ assert (chk[var] < 1.7e-3).all()
117
+
118
+ var = FV.P
119
+ sel = chk[var] >= 1.51
120
+ print(f"\nCHECKING {var}, {(wakes, rotor, pwake)}\n")
121
+ print(df.loc[sel])
122
+ print(fdata.loc[sel])
123
+ print(delta.loc[sel])
124
+ assert (chk[var] < 1.51).all()
125
+
126
+ print()
127
+
128
+
129
+ if __name__ == "__main__":
130
+ test()
@@ -0,0 +1,96 @@
1
+ import numpy as np
2
+ import time
3
+ import argparse
4
+ from pathlib import Path
5
+
6
+ import flappy as fl
7
+ from flappy.config.variables import variables as FV
8
+
9
+ if __name__ == "__main__":
10
+ parser = argparse.ArgumentParser()
11
+ parser.add_argument(
12
+ "-o", "--ofile", help="The output file name", default="results.csv.gz"
13
+ )
14
+ parser.add_argument(
15
+ "--n_cpus", help="The number of processors", type=int, default=1
16
+ )
17
+ args = parser.parse_args()
18
+
19
+ n_s = 30
20
+ n_t = 52
21
+ wd = 270.0
22
+ ti = 0.08
23
+ rotor = "centre"
24
+ c = 100
25
+ p0 = np.array([0.0, 0.0])
26
+ stp = np.array([601.0, 15.0])
27
+ tfile = "../NREL-5MW-D126-H90.csv"
28
+ ofile = Path(args.ofile)
29
+
30
+ # init flappy:
31
+ fl.init_flappy(n_cpus=args.n_cpus)
32
+
33
+ # load model book:
34
+ mbook = fl.ModelBook(ct_power_curve_file=tfile)
35
+
36
+ # create wind farm:
37
+ farm = fl.WindFarm()
38
+ fl.input.add_turbine_row(
39
+ farm,
40
+ rotor_diameter=126.0,
41
+ hub_height=90.0,
42
+ rotor_model=rotor,
43
+ wake_models=["Bastankhah", "CrespoHernandez"],
44
+ turbine_models=["ct_P_curves"],
45
+ base_point=p0,
46
+ step_vector=stp,
47
+ steps=n_t - 1,
48
+ )
49
+
50
+ # create states:
51
+ ws0 = 6.0
52
+ ws1 = 16.0
53
+ states = fl.input.AFSScan(
54
+ ws_min=ws0,
55
+ ws_delta=(ws1 - ws0) / (n_s - 1),
56
+ ws_n_bins=n_s,
57
+ func_pdf_ws=None,
58
+ wd_min=wd,
59
+ wd_delta=1.0,
60
+ wd_n_bins=1,
61
+ func_pdf_wd=None,
62
+ ti_min=ti,
63
+ ti_delta=0.01,
64
+ ti_n_bins=1,
65
+ func_pdf_ti=None,
66
+ rho_min=1.225,
67
+ rho_delta=0.001,
68
+ rho_n_bins=1,
69
+ func_pdf_rho=None,
70
+ max_chunk_size=c,
71
+ )
72
+ states.initialize()
73
+
74
+ time0 = time.time()
75
+
76
+ # run calculation:
77
+ results = farm.calculate(mbook, states, wake_superp=["wind_quadratic", "ti_max"])
78
+
79
+ time1 = time.time()
80
+ print("\nCalc time =", time1 - time0, "\n")
81
+
82
+ df = results.state_turbine_results[
83
+ [FV.WD, FV.AMB_WS, FV.WS, FV.AMB_TI, FV.TI, FV.AMB_CT, FV.CT]
84
+ ]
85
+
86
+ print(results.turbine_results[[FV.X, FV.Y]])
87
+
88
+ print()
89
+ print("TRESULTS\n")
90
+ print(df)
91
+
92
+ print("\nWriting file", ofile)
93
+ df.to_csv(ofile)
94
+
95
+ # close flappy:
96
+ fl.shutdown_flappy()
@@ -0,0 +1,116 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pathlib import Path
4
+ import inspect
5
+
6
+ import foxes
7
+ import foxes.variables as FV
8
+ import foxes.constants as FC
9
+
10
+ thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
+
12
+
13
+ def test():
14
+ n_s = 30
15
+ n_t = 52
16
+ wd = 270.0
17
+ ti = 0.08
18
+ rotor = "centre"
19
+ c = 100
20
+ p0 = np.array([0.0, 0.0])
21
+ stp = np.array([601.0, 15.0])
22
+ cfile = thisdir / "flappy" / "results.csv.gz"
23
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
24
+
25
+ ck = {FC.STATE: c}
26
+
27
+ mbook = foxes.models.ModelBook()
28
+ ttype = foxes.models.turbine_types.PCtFile(
29
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
30
+ )
31
+ mbook.turbine_types[ttype.name] = ttype
32
+
33
+ mbook.wake_models["Basta"] = foxes.models.wake_models.wind.Bastankhah2014(
34
+ sbeta_factor=0.25, superposition="ws_quadratic", induction="Betz"
35
+ )
36
+ mbook.wake_models["Crespo"] = foxes.models.wake_models.ti.CrespoHernandezTIWake(
37
+ superposition="ti_max", induction="Betz"
38
+ )
39
+
40
+ states = foxes.input.states.ScanWS(
41
+ ws_list=np.linspace(6.0, 16.0, n_s), wd=wd, ti=ti, rho=1.225
42
+ )
43
+
44
+ farm = foxes.WindFarm()
45
+ foxes.input.farm_layout.add_row(
46
+ farm=farm,
47
+ xy_base=p0,
48
+ xy_step=stp,
49
+ n_turbines=n_t,
50
+ turbine_models=["kTI_amb_02", ttype.name],
51
+ verbosity=1,
52
+ )
53
+
54
+ algo = foxes.algorithms.Downwind(
55
+ farm,
56
+ states,
57
+ mbook=mbook,
58
+ rotor_model=rotor,
59
+ wake_models=["Basta", "Crespo"],
60
+ wake_frame="rotor_wd",
61
+ partial_wakes=["axiwake6", "top_hat"],
62
+ chunks=ck,
63
+ verbosity=1,
64
+ )
65
+
66
+ data = algo.calc_farm()
67
+
68
+ df = data.to_dataframe()[
69
+ [FV.X, FV.Y, FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_TI, FV.TI]
70
+ ]
71
+
72
+ print()
73
+ print("TRESULTS\n")
74
+ print(df)
75
+
76
+ print("\nReading file", cfile)
77
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
78
+
79
+ print()
80
+ print("TRESULTS\n")
81
+ # sel = (df[FV.P]>0) & (fdata[FV.P]>0)
82
+ # df = df.loc[sel]
83
+ # fdata = fdata.loc[sel]
84
+ print(df)
85
+ print(fdata)
86
+
87
+ print("\nVERIFYING\n")
88
+ df[FV.WS] = df["REWS"]
89
+ df[FV.AMB_WS] = df["AMB_REWS"]
90
+
91
+ delta = df - fdata
92
+ print(df)
93
+ print(delta[[FV.WS, FV.TI]])
94
+
95
+ chk = delta.abs()
96
+ print(chk.max())
97
+
98
+ var = FV.WS
99
+ print(f"\nCHECKING {var}")
100
+ sel = chk[var] >= 3e-3
101
+ print(df.loc[sel])
102
+ print(fdata.loc[sel])
103
+ print(chk.loc[sel])
104
+ assert (chk[var] < 3e-3).all()
105
+
106
+ var = FV.TI
107
+ print(f"\nCHECKING {var}")
108
+ sel = chk[var] >= 3e-4
109
+ print(df.loc[sel])
110
+ print(fdata.loc[sel])
111
+ print(chk.loc[sel])
112
+ assert (chk[var] < 3e-4).all()
113
+
114
+
115
+ if __name__ == "__main__":
116
+ test()
@@ -0,0 +1,93 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ import time
4
+ import argparse
5
+ from pathlib import Path
6
+
7
+ import flappy as fl
8
+ from flappy.config.variables import variables as FV
9
+
10
+ if __name__ == "__main__":
11
+ parser = argparse.ArgumentParser()
12
+ parser.add_argument(
13
+ "-o", "--ofile", help="The output file name", default="results.csv.gz"
14
+ )
15
+ parser.add_argument(
16
+ "--n_cpus", help="The number of processors", type=int, default=1
17
+ )
18
+ args = parser.parse_args()
19
+
20
+ n_s = 99
21
+ n_t = 84
22
+ wd = 88.1
23
+ ti = 0.04
24
+ rotor = "centre"
25
+ c = 100
26
+ p0 = np.array([0.0, 0.0])
27
+ stp = np.array([533.0, 12.0])
28
+ tfile = "../NREL-5MW-D126-H90.csv"
29
+ ofile = Path(args.ofile)
30
+
31
+ # init flappy:
32
+ fl.init_flappy(n_cpus=args.n_cpus)
33
+
34
+ # load model book:
35
+ mbook = fl.ModelBook(ct_power_curve_file=tfile)
36
+
37
+ # create wind farm:
38
+ farm = fl.WindFarm()
39
+ fl.input.add_turbine_row(
40
+ farm,
41
+ rotor_diameter=126.0,
42
+ hub_height=90.0,
43
+ rotor_model=rotor,
44
+ wake_models=["Bastankhah_rotor"],
45
+ turbine_models=["ct_P_curves"],
46
+ base_point=p0,
47
+ step_vector=stp,
48
+ steps=n_t - 1,
49
+ )
50
+
51
+ # create states:
52
+ ws0 = 6.0
53
+ ws1 = 16.0
54
+ states = fl.input.AFSScan(
55
+ ws_min=ws0,
56
+ ws_delta=(ws1 - ws0) / (n_s - 1),
57
+ ws_n_bins=n_s,
58
+ func_pdf_ws=None,
59
+ wd_min=wd,
60
+ wd_delta=1.0,
61
+ wd_n_bins=1,
62
+ func_pdf_wd=None,
63
+ ti_min=ti,
64
+ ti_delta=0.01,
65
+ ti_n_bins=1,
66
+ func_pdf_ti=None,
67
+ rho_min=1.225,
68
+ rho_delta=0.001,
69
+ rho_n_bins=1,
70
+ func_pdf_rho=None,
71
+ max_chunk_size=c,
72
+ )
73
+ states.initialize()
74
+
75
+ time0 = time.time()
76
+
77
+ # run calculation:
78
+ results = farm.calculate(mbook, states, wake_superp=["wind_linear"])
79
+
80
+ time1 = time.time()
81
+ print("\nCalc time =", time1 - time0, "\n")
82
+
83
+ df = results.state_turbine_results[[FV.WD, FV.AMB_WS, FV.WS, FV.AMB_P, FV.P]]
84
+
85
+ print()
86
+ print("TRESULTS\n")
87
+ print(df)
88
+
89
+ print("\nWriting file", ofile)
90
+ df.to_csv(ofile)
91
+
92
+ # close flappy:
93
+ fl.shutdown_flappy()
@@ -0,0 +1,99 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from pathlib import Path
4
+ import inspect
5
+
6
+ import foxes
7
+ import foxes.variables as FV
8
+ import foxes.constants as FC
9
+
10
+ thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
+
12
+
13
+ def test():
14
+ n_s = 99
15
+ n_t = 84
16
+ wd = 88.1
17
+ ti = 0.04
18
+ rotor = "centre"
19
+ c = 100
20
+ p0 = np.array([0.0, 0.0])
21
+ stp = np.array([533.0, 12.0])
22
+ cfile = thisdir / "flappy" / "results.csv.gz"
23
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
24
+
25
+ ck = {FC.STATE: c}
26
+
27
+ mbook = foxes.models.ModelBook()
28
+ ttype = foxes.models.turbine_types.PCtFile(
29
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
30
+ )
31
+ mbook.turbine_types[ttype.name] = ttype
32
+
33
+ mbook.wake_models["Basta"] = foxes.models.wake_models.wind.Bastankhah2014(
34
+ sbeta_factor=0.25, superposition="ws_linear", induction="Betz"
35
+ )
36
+
37
+ states = foxes.input.states.ScanWS(
38
+ ws_list=np.linspace(6.0, 16.0, n_s), wd=wd, ti=ti, rho=1.225
39
+ )
40
+
41
+ farm = foxes.WindFarm()
42
+ foxes.input.farm_layout.add_row(
43
+ farm=farm,
44
+ xy_base=p0,
45
+ xy_step=stp,
46
+ n_turbines=n_t,
47
+ turbine_models=["kTI_amb_02", ttype.name],
48
+ verbosity=1,
49
+ )
50
+
51
+ algo = foxes.algorithms.Downwind(
52
+ farm,
53
+ states,
54
+ mbook=mbook,
55
+ rotor_model=rotor,
56
+ wake_models=["Basta"],
57
+ wake_frame="rotor_wd",
58
+ partial_wakes="rotor_points",
59
+ chunks=ck,
60
+ verbosity=1,
61
+ )
62
+
63
+ data = algo.calc_farm()
64
+
65
+ df = data.to_dataframe()[[FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_P, FV.P]]
66
+
67
+ print("\nReading file", cfile)
68
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
69
+
70
+ print()
71
+ print("TRESULTS\n")
72
+ sel = (df[FV.P] > 0) & (fdata[FV.P] > 0)
73
+ df = df.loc[sel]
74
+ fdata = fdata.loc[sel]
75
+ print(df.loc[sel])
76
+ print(fdata.loc[sel])
77
+
78
+ print("\nVERIFYING\n")
79
+ df[FV.WS] = df["REWS"]
80
+ df[FV.AMB_WS] = df["AMB_REWS"]
81
+
82
+ delta = df - fdata
83
+ print(delta)
84
+
85
+ chk = delta.abs()
86
+ print(chk.max())
87
+
88
+ var = FV.WS
89
+ print(f"\nCHECKING {var}")
90
+ sel = chk[var] >= 1e-7
91
+ print(df.loc[sel])
92
+ print(fdata.loc[sel])
93
+ print(chk.loc[sel])
94
+ assert (chk[var] < 1e-7).all()
95
+
96
+ var = FV.P
97
+ sel = chk[var] >= 1e-5
98
+ print(f"\nCHECKING {var}\n", delta.loc[sel])
99
+ assert (chk[var] < 1e-5).all()