foxes 0.8.2__py3-none-any.whl → 1.1.0.2__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 (215) 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/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 +190 -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 +247 -111
  27. foxes/algorithms/downwind/models/farm_wakes_calc.py +12 -7
  28. foxes/algorithms/downwind/models/init_farm_data.py +2 -2
  29. foxes/algorithms/downwind/models/point_wakes_calc.py +6 -7
  30. foxes/algorithms/downwind/models/reorder_farm_output.py +1 -2
  31. foxes/algorithms/downwind/models/set_amb_farm_results.py +1 -1
  32. foxes/algorithms/downwind/models/set_amb_point_results.py +5 -3
  33. foxes/algorithms/iterative/iterative.py +74 -34
  34. foxes/algorithms/iterative/models/farm_wakes_calc.py +12 -7
  35. foxes/algorithms/iterative/models/urelax.py +3 -3
  36. foxes/algorithms/sequential/models/plugin.py +5 -5
  37. foxes/algorithms/sequential/models/seq_state.py +1 -1
  38. foxes/algorithms/sequential/sequential.py +126 -255
  39. foxes/constants.py +22 -7
  40. foxes/core/__init__.py +1 -0
  41. foxes/core/algorithm.py +632 -147
  42. foxes/core/data.py +252 -20
  43. foxes/core/data_calc_model.py +15 -291
  44. foxes/core/engine.py +640 -0
  45. foxes/core/farm_controller.py +38 -10
  46. foxes/core/farm_data_model.py +16 -1
  47. foxes/core/ground_model.py +2 -2
  48. foxes/core/model.py +249 -182
  49. foxes/core/partial_wakes_model.py +1 -1
  50. foxes/core/point_data_model.py +17 -2
  51. foxes/core/rotor_model.py +27 -21
  52. foxes/core/states.py +17 -1
  53. foxes/core/turbine_type.py +28 -0
  54. foxes/core/wake_frame.py +30 -34
  55. foxes/core/wake_model.py +5 -5
  56. foxes/core/wake_superposition.py +1 -1
  57. foxes/data/windio/windio_5turbines_timeseries.yaml +31 -15
  58. foxes/engines/__init__.py +17 -0
  59. foxes/engines/dask.py +982 -0
  60. foxes/engines/default.py +75 -0
  61. foxes/engines/futures.py +72 -0
  62. foxes/engines/mpi.py +38 -0
  63. foxes/engines/multiprocess.py +71 -0
  64. foxes/engines/numpy.py +167 -0
  65. foxes/engines/pool.py +249 -0
  66. foxes/engines/ray.py +79 -0
  67. foxes/engines/single.py +141 -0
  68. foxes/input/farm_layout/__init__.py +1 -0
  69. foxes/input/farm_layout/from_csv.py +4 -0
  70. foxes/input/farm_layout/from_json.py +2 -2
  71. foxes/input/farm_layout/grid.py +2 -2
  72. foxes/input/farm_layout/ring.py +65 -0
  73. foxes/input/farm_layout/row.py +2 -2
  74. foxes/input/states/__init__.py +7 -0
  75. foxes/input/states/create/random_abl_states.py +1 -1
  76. foxes/input/states/field_data_nc.py +158 -33
  77. foxes/input/states/multi_height.py +128 -14
  78. foxes/input/states/one_point_flow.py +577 -0
  79. foxes/input/states/scan_ws.py +74 -3
  80. foxes/input/states/single.py +1 -1
  81. foxes/input/states/slice_data_nc.py +681 -0
  82. foxes/input/states/states_table.py +204 -35
  83. foxes/input/windio/__init__.py +2 -2
  84. foxes/input/windio/get_states.py +44 -23
  85. foxes/input/windio/read_attributes.py +48 -17
  86. foxes/input/windio/read_farm.py +116 -102
  87. foxes/input/windio/read_fields.py +16 -6
  88. foxes/input/windio/read_outputs.py +71 -24
  89. foxes/input/windio/runner.py +31 -17
  90. foxes/input/windio/windio.py +41 -23
  91. foxes/models/farm_models/turbine2farm.py +1 -1
  92. foxes/models/ground_models/wake_mirror.py +10 -6
  93. foxes/models/model_book.py +58 -20
  94. foxes/models/partial_wakes/axiwake.py +3 -3
  95. foxes/models/partial_wakes/rotor_points.py +3 -3
  96. foxes/models/partial_wakes/top_hat.py +2 -2
  97. foxes/models/point_models/set_uniform_data.py +1 -1
  98. foxes/models/point_models/tke2ti.py +1 -1
  99. foxes/models/point_models/wake_deltas.py +1 -1
  100. foxes/models/rotor_models/centre.py +4 -0
  101. foxes/models/rotor_models/grid.py +24 -25
  102. foxes/models/rotor_models/levels.py +4 -5
  103. foxes/models/turbine_models/calculator.py +4 -6
  104. foxes/models/turbine_models/kTI_model.py +22 -6
  105. foxes/models/turbine_models/lookup_table.py +30 -4
  106. foxes/models/turbine_models/rotor_centre_calc.py +4 -3
  107. foxes/models/turbine_models/set_farm_vars.py +103 -34
  108. foxes/models/turbine_types/PCt_file.py +27 -3
  109. foxes/models/turbine_types/PCt_from_two.py +27 -3
  110. foxes/models/turbine_types/TBL_file.py +80 -0
  111. foxes/models/turbine_types/__init__.py +2 -0
  112. foxes/models/turbine_types/lookup.py +316 -0
  113. foxes/models/turbine_types/null_type.py +51 -1
  114. foxes/models/turbine_types/wsrho2PCt_from_two.py +29 -5
  115. foxes/models/turbine_types/wsti2PCt_from_two.py +31 -7
  116. foxes/models/vertical_profiles/__init__.py +1 -1
  117. foxes/models/vertical_profiles/data_profile.py +1 -1
  118. foxes/models/wake_frames/__init__.py +1 -0
  119. foxes/models/wake_frames/dynamic_wakes.py +424 -0
  120. foxes/models/wake_frames/farm_order.py +25 -5
  121. foxes/models/wake_frames/rotor_wd.py +6 -4
  122. foxes/models/wake_frames/seq_dynamic_wakes.py +61 -74
  123. foxes/models/wake_frames/streamlines.py +21 -22
  124. foxes/models/wake_frames/timelines.py +330 -129
  125. foxes/models/wake_frames/yawed_wakes.py +7 -4
  126. foxes/models/wake_models/dist_sliced.py +2 -4
  127. foxes/models/wake_models/induction/rankine_half_body.py +5 -5
  128. foxes/models/wake_models/induction/rathmann.py +78 -24
  129. foxes/models/wake_models/induction/self_similar.py +78 -28
  130. foxes/models/wake_models/induction/vortex_sheet.py +86 -48
  131. foxes/models/wake_models/ti/crespo_hernandez.py +6 -4
  132. foxes/models/wake_models/ti/iec_ti.py +40 -21
  133. foxes/models/wake_models/top_hat.py +1 -1
  134. foxes/models/wake_models/wind/bastankhah14.py +8 -6
  135. foxes/models/wake_models/wind/bastankhah16.py +17 -16
  136. foxes/models/wake_models/wind/jensen.py +4 -3
  137. foxes/models/wake_models/wind/turbopark.py +16 -13
  138. foxes/models/wake_superpositions/ti_linear.py +1 -1
  139. foxes/models/wake_superpositions/ti_max.py +1 -1
  140. foxes/models/wake_superpositions/ti_pow.py +1 -1
  141. foxes/models/wake_superpositions/ti_quadratic.py +1 -1
  142. foxes/models/wake_superpositions/ws_linear.py +8 -7
  143. foxes/models/wake_superpositions/ws_max.py +8 -7
  144. foxes/models/wake_superpositions/ws_pow.py +8 -7
  145. foxes/models/wake_superpositions/ws_product.py +5 -5
  146. foxes/models/wake_superpositions/ws_quadratic.py +8 -7
  147. foxes/output/__init__.py +4 -1
  148. foxes/output/farm_layout.py +16 -12
  149. foxes/output/farm_results_eval.py +1 -1
  150. foxes/output/flow_plots_2d/__init__.py +0 -1
  151. foxes/output/flow_plots_2d/flow_plots.py +70 -30
  152. foxes/output/grids.py +92 -22
  153. foxes/output/results_writer.py +2 -2
  154. foxes/output/rose_plot.py +3 -3
  155. foxes/output/seq_plugins/__init__.py +2 -0
  156. foxes/output/{flow_plots_2d → seq_plugins}/seq_flow_ani_plugin.py +64 -22
  157. foxes/output/seq_plugins/seq_wake_debug_plugin.py +145 -0
  158. foxes/output/slice_data.py +131 -111
  159. foxes/output/state_turbine_map.py +19 -14
  160. foxes/output/state_turbine_table.py +19 -19
  161. foxes/utils/__init__.py +1 -1
  162. foxes/utils/abl/neutral.py +2 -2
  163. foxes/utils/abl/stable.py +2 -2
  164. foxes/utils/abl/unstable.py +2 -2
  165. foxes/utils/data_book.py +1 -1
  166. foxes/utils/dev_utils.py +42 -0
  167. foxes/utils/dict.py +24 -1
  168. foxes/utils/exec_python.py +1 -1
  169. foxes/utils/factory.py +176 -53
  170. foxes/utils/geom2d/circle.py +1 -1
  171. foxes/utils/geom2d/polygon.py +1 -1
  172. foxes/utils/geopandas_utils.py +2 -2
  173. foxes/utils/load.py +2 -2
  174. foxes/utils/pandas_helpers.py +3 -2
  175. foxes/utils/wind_dir.py +0 -2
  176. foxes/utils/xarray_utils.py +24 -14
  177. foxes/variables.py +39 -2
  178. {foxes-0.8.2.dist-info → foxes-1.1.0.2.dist-info}/METADATA +75 -33
  179. foxes-1.1.0.2.dist-info/RECORD +309 -0
  180. {foxes-0.8.2.dist-info → foxes-1.1.0.2.dist-info}/WHEEL +1 -1
  181. foxes-1.1.0.2.dist-info/top_level.txt +4 -0
  182. tests/0_consistency/iterative/test_iterative.py +92 -0
  183. tests/0_consistency/partial_wakes/test_partial_wakes.py +90 -0
  184. tests/1_verification/flappy_0_6/PCt_files/flappy/run.py +85 -0
  185. tests/1_verification/flappy_0_6/PCt_files/test_PCt_files.py +103 -0
  186. tests/1_verification/flappy_0_6/abl_states/flappy/run.py +85 -0
  187. tests/1_verification/flappy_0_6/abl_states/test_abl_states.py +87 -0
  188. tests/1_verification/flappy_0_6/partial_top_hat/flappy/run.py +82 -0
  189. tests/1_verification/flappy_0_6/partial_top_hat/test_partial_top_hat.py +82 -0
  190. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/flappy/run.py +92 -0
  191. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/test_row_Jensen_linear_centre.py +93 -0
  192. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/flappy/run.py +92 -0
  193. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/test_row_Jensen_linear_tophat.py +96 -0
  194. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/flappy/run.py +94 -0
  195. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/test_row_Jensen_linear_tophat_IECTI_2005.py +122 -0
  196. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/flappy/run.py +94 -0
  197. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/test_row_Jensen_linear_tophat_IECTI_2019.py +122 -0
  198. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/flappy/run.py +92 -0
  199. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py +93 -0
  200. tests/1_verification/flappy_0_6_2/grid_rotors/flappy/run.py +85 -0
  201. tests/1_verification/flappy_0_6_2/grid_rotors/test_grid_rotors.py +130 -0
  202. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/flappy/run.py +96 -0
  203. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/test_row_Bastankhah_Crespo.py +116 -0
  204. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/flappy/run.py +93 -0
  205. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py +99 -0
  206. tests/3_examples/test_examples.py +34 -0
  207. foxes/VERSION +0 -1
  208. foxes/output/flow_plots_2d.py +0 -0
  209. foxes/utils/geopandas_helpers.py +0 -294
  210. foxes/utils/runners/__init__.py +0 -1
  211. foxes/utils/runners/runners.py +0 -280
  212. foxes-0.8.2.dist-info/RECORD +0 -247
  213. foxes-0.8.2.dist-info/top_level.txt +0 -1
  214. foxes-0.8.2.dist-info/zip-safe +0 -1
  215. {foxes-0.8.2.dist-info → foxes-1.1.0.2.dist-info}/LICENSE +0 -0
@@ -0,0 +1,82 @@
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
+ print(thisdir)
14
+
15
+ c = 2000
16
+ cfile = thisdir / "flappy" / "results.csv.gz"
17
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
18
+ sfile = thisdir / "states.csv.gz"
19
+ lfile = thisdir / "test_farm.csv"
20
+
21
+ ck = {FC.STATE: c}
22
+
23
+ mbook = foxes.models.ModelBook()
24
+ ttype = foxes.models.turbine_types.PCtFile(
25
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
26
+ )
27
+ mbook.turbine_types[ttype.name] = ttype
28
+
29
+ states = foxes.input.states.StatesTable(
30
+ data_source=sfile,
31
+ output_vars=[FV.WS, FV.WD, FV.TI, FV.RHO],
32
+ var2col={FV.WS: "ws", FV.WD: "wd", FV.TI: "ti"},
33
+ fixed_vars={FV.RHO: 1.225},
34
+ )
35
+
36
+ farm = foxes.WindFarm()
37
+ foxes.input.farm_layout.add_from_file(
38
+ farm, lfile, turbine_models=[ttype.name], verbosity=0
39
+ )
40
+
41
+ algo = foxes.algorithms.Downwind(
42
+ farm,
43
+ states,
44
+ mbook=mbook,
45
+ rotor_model="centre",
46
+ wake_models=["Jensen_linear_k007"],
47
+ wake_frame="rotor_wd",
48
+ partial_wakes={"Jensen_linear_k007": "top_hat"},
49
+ chunks=ck,
50
+ verbosity=0,
51
+ )
52
+
53
+ data = algo.calc_farm()
54
+
55
+ df = data.to_dataframe()[[FV.AMB_WD, FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_P, FV.P]]
56
+
57
+ print()
58
+ print("TRESULTS\n")
59
+ print(df)
60
+
61
+ print("\nReading file", cfile)
62
+ fdata = pd.read_csv(cfile)
63
+ print(fdata)
64
+
65
+ print("\nVERIFYING\n")
66
+ df[FV.WS] = df["REWS"]
67
+ df[FV.AMB_WS] = df["AMB_REWS"]
68
+
69
+ delta = (df.reset_index() - fdata)[[FV.AMB_WS, FV.AMB_P, FV.WS, FV.P]]
70
+ print("\nDELTA\n", delta.describe())
71
+
72
+ chk = delta.abs().max()
73
+ print("\nCHK\n", chk)
74
+ print("CHK WS =", chk[FV.WS])
75
+ print("CHK P =", chk[FV.P])
76
+
77
+ assert chk[FV.WS] < 1e-5
78
+ assert chk[FV.P] < 1e-3
79
+
80
+
81
+ if __name__ == "__main__":
82
+ test()
@@ -0,0 +1,92 @@
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
+ "-c", "--chunksize", help="The maximal chunk size", type=int, default=500
13
+ )
14
+ parser.add_argument(
15
+ "-o", "--ofile", help="The output file name", default="results.csv.gz"
16
+ )
17
+ parser.add_argument(
18
+ "--n_cpus", help="The number of processors", type=int, default=1
19
+ )
20
+ args = parser.parse_args()
21
+
22
+ n_s = 800
23
+ n_t = 76
24
+ c = args.chunksize
25
+ p0 = np.array([0.0, 0.0])
26
+ stp = np.array([497.0, 0.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="centre",
43
+ wake_models=["Jensen007_rotor"],
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 = 3.0
52
+ ws1 = 30.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=270.0,
59
+ wd_delta=1.0,
60
+ wd_n_bins=1,
61
+ func_pdf_wd=None,
62
+ ti_min=0.08,
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_linear"])
78
+
79
+ time1 = time.time()
80
+ print("\nCalc time =", time1 - time0, "\n")
81
+
82
+ df = results.state_turbine_results[[FV.WD, FV.AMB_WS, FV.WS, FV.AMB_P, FV.P]]
83
+
84
+ print()
85
+ print("TRESULTS\n")
86
+ print(df)
87
+
88
+ print("\nWriting file", ofile)
89
+ df.to_csv(ofile)
90
+
91
+ # close flappy:
92
+ fl.shutdown_flappy()
@@ -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_linear_k007"],
48
+ wake_frame="rotor_wd",
49
+ partial_wakes={"Jensen_linear_k007": "rotor_points"},
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,92 @@
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
+ "-c", "--chunksize", help="The maximal chunk size", type=int, default=500
13
+ )
14
+ parser.add_argument(
15
+ "-o", "--ofile", help="The output file name", default="results.csv.gz"
16
+ )
17
+ parser.add_argument(
18
+ "--n_cpus", help="The number of processors", type=int, default=4
19
+ )
20
+ args = parser.parse_args()
21
+
22
+ n_s = 1000
23
+ n_t = 55
24
+ c = args.chunksize
25
+ p0 = np.array([0.0, 0.0])
26
+ stp = np.array([500.0, 80.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="centre",
43
+ wake_models=["Jensen007"],
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 = 3.0
52
+ ws1 = 30.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=270.0,
59
+ wd_delta=1.0,
60
+ wd_n_bins=1,
61
+ func_pdf_wd=None,
62
+ ti_min=0.08,
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_linear"])
78
+
79
+ time1 = time.time()
80
+ print("\nCalc time =", time1 - time0, "\n")
81
+
82
+ df = results.state_turbine_results[[FV.WD, FV.AMB_WS, FV.WS, FV.AMB_P, FV.P]]
83
+
84
+ print()
85
+ print("TRESULTS\n")
86
+ print(df)
87
+
88
+ print("\nWriting file", ofile)
89
+ df.to_csv(ofile)
90
+
91
+ # close flappy:
92
+ fl.shutdown_flappy()
@@ -0,0 +1,96 @@
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 = 1000
15
+ n_t = 55
16
+ c = 1000
17
+ p0 = np.array([0.0, 0.0])
18
+ stp = np.array([500.0, 80.0])
19
+ cfile = thisdir / "flappy" / "results.csv.gz"
20
+ tfile = thisdir / "NREL-5MW-D126-H90.csv"
21
+
22
+ ck = {FC.STATE: c}
23
+
24
+ mbook = foxes.models.ModelBook()
25
+ ttype = foxes.models.turbine_types.PCtFile(
26
+ data_source=tfile, var_ws_ct=FV.REWS, var_ws_P=FV.REWS
27
+ )
28
+ mbook.turbine_types[ttype.name] = ttype
29
+
30
+ states = foxes.input.states.ScanWS(
31
+ ws_list=np.linspace(3.0, 30.0, n_s), wd=270.0, ti=0.08, rho=1.225
32
+ )
33
+
34
+ farm = foxes.WindFarm()
35
+ foxes.input.farm_layout.add_row(
36
+ farm=farm,
37
+ xy_base=p0,
38
+ xy_step=stp,
39
+ n_turbines=n_t,
40
+ turbine_models=[ttype.name],
41
+ verbosity=0,
42
+ )
43
+
44
+ algo = foxes.algorithms.Downwind(
45
+ farm,
46
+ states,
47
+ mbook=mbook,
48
+ rotor_model="centre",
49
+ wake_models=["Jensen_linear_k007"],
50
+ wake_frame="rotor_wd",
51
+ partial_wakes={"Jensen_linear_k007": "top_hat"},
52
+ chunks=ck,
53
+ verbosity=0,
54
+ )
55
+
56
+ data = algo.calc_farm()
57
+
58
+ df = data.to_dataframe()[[FV.WD, FV.AMB_REWS, FV.REWS, FV.AMB_P, FV.P]]
59
+
60
+ print("\nReading file", cfile)
61
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
62
+
63
+ print()
64
+ print("TRESULTS\n")
65
+ sel = (df[FV.P] > 0) & (fdata[FV.P] > 0)
66
+ df = df.loc[sel]
67
+ fdata = fdata.loc[sel]
68
+ print(df.loc[sel])
69
+ print(fdata.loc[sel])
70
+
71
+ print("\nVERIFYING\n")
72
+ df[FV.WS] = df["REWS"]
73
+ df[FV.AMB_WS] = df["AMB_REWS"]
74
+
75
+ delta = df - fdata
76
+ print(delta)
77
+
78
+ chk = delta.abs()
79
+ print(chk.max())
80
+
81
+ var = FV.WS
82
+ print(f"\nCHECKING {var}")
83
+ sel = chk[var] >= 1e-7
84
+ print(df.loc[sel])
85
+ print(fdata.loc[sel])
86
+ print(chk.loc[sel])
87
+ assert (chk[var] < 1e-7).all()
88
+
89
+ var = FV.P
90
+ sel = chk[var] >= 1e-5
91
+ print(f"\nCHECKING {var}\n", delta.loc[sel])
92
+ assert (chk[var] < 1e-5).all()
93
+
94
+
95
+ if __name__ == "__main__":
96
+ test()
@@ -0,0 +1,94 @@
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
+ "-c", "--chunksize", help="The maximal chunk size", type=int, default=500
13
+ )
14
+ parser.add_argument(
15
+ "-o", "--ofile", help="The output file name", default="results.csv.gz"
16
+ )
17
+ parser.add_argument(
18
+ "--n_cpus", help="The number of processors", type=int, default=4
19
+ )
20
+ args = parser.parse_args()
21
+
22
+ n_s = 30
23
+ n_t = 52
24
+ c = args.chunksize
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="centre",
43
+ wake_models=["Jensen007", "IEC_TI_2005_rotor"],
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=270.0,
59
+ wd_delta=1.0,
60
+ wd_n_bins=1,
61
+ func_pdf_wd=None,
62
+ ti_min=0.08,
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_linear", "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_P, FV.P, FV.AMB_TI, FV.TI, FV.AMB_CT, FV.CT]
84
+ ]
85
+
86
+ print()
87
+ print("TRESULTS\n")
88
+ print(df)
89
+
90
+ print("\nWriting file", ofile)
91
+ df.to_csv(ofile)
92
+
93
+ # close flappy:
94
+ fl.shutdown_flappy()
@@ -0,0 +1,122 @@
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
+ states = foxes.input.states.ScanWS(
34
+ ws_list=np.linspace(6.0, 16.0, n_s), wd=wd, ti=ti, rho=1.225
35
+ )
36
+
37
+ farm = foxes.WindFarm()
38
+ foxes.input.farm_layout.add_row(
39
+ farm=farm,
40
+ xy_base=p0,
41
+ xy_step=stp,
42
+ n_turbines=n_t,
43
+ turbine_models=[ttype.name],
44
+ verbosity=1,
45
+ )
46
+
47
+ algo = foxes.algorithms.Downwind(
48
+ farm,
49
+ states,
50
+ rotor_model="centre",
51
+ mbook=mbook,
52
+ wake_models=["Jensen_linear_k007", "IECTI2005_max"],
53
+ wake_frame="rotor_wd",
54
+ partial_wakes=["top_hat", "top_hat"],
55
+ chunks=ck,
56
+ verbosity=1,
57
+ )
58
+
59
+ data = algo.calc_farm()
60
+
61
+ df = data.to_dataframe()[
62
+ [
63
+ FV.X,
64
+ FV.Y,
65
+ FV.WD,
66
+ FV.AMB_REWS,
67
+ FV.REWS,
68
+ FV.AMB_TI,
69
+ FV.TI,
70
+ FV.AMB_CT,
71
+ FV.CT,
72
+ ]
73
+ ]
74
+
75
+ print("\nReading file", cfile)
76
+ fdata = pd.read_csv(cfile).set_index(["state", "turbine"])
77
+
78
+ print()
79
+ print("TRESULTS\n")
80
+ """sel = (df[FV.P] > 0) & (fdata[FV.P] > 0)
81
+ df = df.loc[sel]
82
+ fdata = fdata.loc[sel]"""
83
+ print(df)
84
+ print(fdata)
85
+
86
+ print("\nVERIFYING\n")
87
+ df[FV.WS] = df["REWS"]
88
+ df[FV.AMB_WS] = df["AMB_REWS"]
89
+
90
+ delta = df - fdata
91
+ print(delta)
92
+
93
+ chk = delta.abs()
94
+ print(chk.max())
95
+
96
+ var = FV.WS
97
+ print(f"\nCHECKING {var}")
98
+ sel = chk[var] >= 3e-3
99
+ print(df.loc[sel])
100
+ print(fdata.loc[sel])
101
+ print(chk.loc[sel])
102
+ assert (chk[var] < 3e-3).all()
103
+
104
+ var = FV.TI
105
+ print(f"\nCHECKING {var}")
106
+ sel = chk[var] >= 3e-4
107
+ print(df.loc[sel])
108
+ print(fdata.loc[sel])
109
+ print(chk.loc[sel])
110
+ assert (chk[var] < 3e-4).all()
111
+
112
+ var = FV.CT
113
+ print(f"\nCHECKING {var}")
114
+ sel = chk[var] >= 3e-5
115
+ print(df.loc[sel])
116
+ print(fdata.loc[sel])
117
+ print(chk.loc[sel])
118
+ assert (chk[var] < 3e-5).all()
119
+
120
+
121
+ if __name__ == "__main__":
122
+ test()