From 70e0f4ed4dcdd564af47cfc767acc9d23759a561 Mon Sep 17 00:00:00 2001 From: Henry <henry.korb@geo.uu.se> Date: Tue, 14 Nov 2023 17:44:39 +0100 Subject: [PATCH] add example script with wifi --- Python/actuator_line_with_wifi/NREL5MW.cd | 75 ++++++++ Python/actuator_line_with_wifi/NREL5MW.cl | 75 ++++++++ Python/actuator_line_with_wifi/NREL5MW.geo | 18 ++ Python/actuator_line_with_wifi/NREL5MW.json | 33 ++++ .../SingleTurbine.json | 14 ++ .../configActuatorLine.txt | 40 +++++ .../actuator_line_with_wifi/controller.json | 76 ++++++++ Python/actuator_line_with_wifi/read_output.py | 39 ++++ Python/actuator_line_with_wifi/runscript.py | 169 ++++++++++++++++++ 9 files changed, 539 insertions(+) create mode 100644 Python/actuator_line_with_wifi/NREL5MW.cd create mode 100644 Python/actuator_line_with_wifi/NREL5MW.cl create mode 100644 Python/actuator_line_with_wifi/NREL5MW.geo create mode 100644 Python/actuator_line_with_wifi/NREL5MW.json create mode 100644 Python/actuator_line_with_wifi/SingleTurbine.json create mode 100644 Python/actuator_line_with_wifi/configActuatorLine.txt create mode 100644 Python/actuator_line_with_wifi/controller.json create mode 100644 Python/actuator_line_with_wifi/read_output.py create mode 100644 Python/actuator_line_with_wifi/runscript.py diff --git a/Python/actuator_line_with_wifi/NREL5MW.cd b/Python/actuator_line_with_wifi/NREL5MW.cd new file mode 100644 index 000000000..36cdd133e --- /dev/null +++ b/Python/actuator_line_with_wifi/NREL5MW.cd @@ -0,0 +1,75 @@ +0 1 0.4 0.35 0.3 0.25 0.21 0.18 +-180 0.5 0.0602 0.0407 0.0267 0.0202 0.0185 0.0198 +-170 0.5 0.1107 0.1055 0.0968 0.0943 0.0945 0.0955 +-160 0.5 0.3045 0.2982 0.2876 0.2848 0.2809 0.2807 +-150 0.5 0.5355 0.5308 0.5232 0.5215 0.5112 0.5086 +-140 0.5 0.7685 0.7672 0.7656 0.766 0.7485 0.7427 +-130 0.5 0.9788 0.9819 0.9882 0.9911 0.9665 0.9574 +-120 0.5 1.1499 1.158 1.173 1.1787 1.1476 1.1355 +-110 0.5 1.2716 1.2847 1.3084 1.3168 1.2805 1.2656 +-100 0.5 1.3378 1.3557 1.3875 1.3984 1.3582 1.341 +-90 0.5 1.346 1.368 1.407 1.4201 1.3774 1.3587 +-80 0.5 1.2964 1.3218 1.3664 1.3811 1.3376 1.3181 +-70 0.5 1.1918 1.2193 1.2676 1.2833 1.2409 1.2212 +-60 0.5 1.0376 1.066 1.1156 1.1315 1.0919 1.0731 +-50 0.5 0.8429 0.8705 0.9187 0.9341 0.899 0.882 +-40 0.5 0.6215 0.6466 0.6904 0.7042 0.6754 0.661 +-35 0.5 0.5067 0.5299 0.5703 0.5829 0.5579 0.5451 +-30 0.5 0.3932 0.4141 0.4503 0.4616 0.4405 0.4295 +-25 0.5 0.2849 0.303 0.3357 0.3441 0.3256 0.3071 +-22 0.5 0.2242 0.2404 0.2752 0.273 0.2506 0.2297 +-20 0.5 0.1861 0.2011 0.2388 0.2237 0.1983 0.1785 +-18 0.5 0.1533 0.164 0.2056 0.1743 0.1457 0.1288 +-16 0.5 0.1281 0.13 0.1754 0.1256 0.094 0.0786 +-14 0.5 0.1101 0.1 0.1413 0.0789 0.0508 0.0283 +-12 0.5 0.0986 0.0744 0.1015 0.0271 0.0271 0.0134 +-10 0.5 0.0931 0.0534 0.0718 0.0287 0.0287 0.0111 +-9 0.5 0.0931 0.0469 0.0545 0.0271 0.0201 0.0099 +-8 0.5 0.093 0.0404 0.0254 0.0195 0.012 0.0091 +-7 0.5 0.0809 0.034 0.0175 0.0105 0.009 0.0086 +-6 0.5 0.0689 0.0275 0.0117 0.0091 0.0082 0.0082 +-5 0.5 0.0547 0.0223 0.0097 0.0073 0.0069 0.0079 +-4 0.5 0.0411 0.0173 0.0091 0.007 0.0063 0.0072 +-3 0.5 0.0299 0.024 0.0089 0.0068 0.0058 0.0064 +-2 0.5 0.0198 0.016 0.0088 0.0068 0.0057 0.0054 +-1 0.5 0.0147 0.0118 0.0088 0.0067 0.0057 0.0052 +0 0.5 0.0113 0.0094 0.0087 0.0065 0.0057 0.0052 +1 0.5 0.0118 0.0098 0.0088 0.0066 0.0058 0.0052 +2 0.5 0.0124 0.01 0.009 0.0068 0.0059 0.0053 +3 0.5 0.0123 0.0103 0.0092 0.007 0.0063 0.0053 +4 0.5 0.0119 0.0105 0.0095 0.0073 0.0071 0.0054 +5 0.5 0.0125 0.0108 0.0097 0.0079 0.009 0.0058 +6 0.5 0.0135 0.011 0.0101 0.0099 0.0113 0.0091 +7 0.5 0.0158 0.0115 0.0107 0.0132 0.0131 0.0113 +8 0.5 0.0198 0.012 0.0125 0.0153 0.0147 0.0124 +9 0.5 0.0275 0.0133 0.0155 0.0181 0.0181 0.0136 +10 0.5 0.0393 0.0156 0.0192 0.0262 0.0255 0.015 +11 0.5 0.058 0.0194 0.0255 0.042 0.0347 0.0383 +12 0.5 0.0816 0.0269 0.037 0.0601 0.0468 0.0613 +13 0.5 0.1129 0.0398 0.063 0.0785 0.0633 0.0841 +14 0.5 0.1469 0.0614 0.0931 0.1 0.0806 0.1065 +15 0.5 0.1845 0.0979 0.1239 0.1219 0.0987 0.1287 +16 0.5 0.225 0.1377 0.1592 0.1433 0.117 0.1509 +17 0.5 0.2684 0.1814 0.1903 0.1649 0.1368 0.1728 +18 0.5 0.3121 0.2316 0.2186 0.1845 0.1562 0.1947 +19 0.5 0.3554 0.2719 0.2455 0.2061 0.177 0.2165 +20 0.5 0.3997 0.3085 0.2689 0.228 0.1987 0.2379 +22 0.5 0.483 0.382 0.3246 0.2814 0.2499 0.2799 +25 0.5 0.6141 0.4988 0.4198 0.3678 0.3371 0.3377 +30 0.5 0.8441 0.6978 0.5843 0.5149 0.4813 0.4294 +35 0.5 1.0722 0.8869 0.7438 0.6548 0.6127 0.5324 +40 0.5 1.2873 1.0671 0.897 0.7901 0.7396 0.6452 +50 0.5 1.6401 1.3747 1.1686 1.0378 0.9781 0.8664 +60 0.5 1.836 1.5728 1.3647 1.2333 1.1796 1.0693 +70 0.5 1.8347 1.6302 1.4621 1.3587 1.3297 1.2438 +80 0.5 1.6334 1.5423 1.4544 1.4063 1.4202 1.3809 +90 0.5 1.3879 1.4041 1.3938 1.3985 1.4512 1.4565 +100 0.5 1.3795 1.3914 1.3798 1.381 1.4294 1.4345 +110 0.5 1.3114 1.3188 1.3063 1.3041 1.3464 1.3512 +120 0.5 1.1864 1.1891 1.1763 1.1709 1.2057 1.2099 +130 0.5 1.0102 1.0086 0.9962 0.9883 1.0144 1.0179 +140 0.5 0.7935 0.7883 0.7771 0.7676 0.7845 0.7871 +150 0.5 0.5532 0.5457 0.5364 0.5264 0.5346 0.5363 +160 0.5 0.3147 0.3066 0.3 0.2912 0.2922 0.2931 +170 0.5 0.1144 0.1085 0.1051 0.0995 0.0969 0.0971 +180 0.5 0.0602 0.0407 0.0267 0.0202 0.0185 0.0198 diff --git a/Python/actuator_line_with_wifi/NREL5MW.cl b/Python/actuator_line_with_wifi/NREL5MW.cl new file mode 100644 index 000000000..f4634706d --- /dev/null +++ b/Python/actuator_line_with_wifi/NREL5MW.cl @@ -0,0 +1,75 @@ +0 1 0.4 0.35 0.3 0.25 0.21 0.18 +-180 0 0 0 0 0 0 0 +-170 0 0.397 0.405 0.547 0.735 0.788 0.749 +-160 0 0.642 0.658 0.685 0.695 0.67 0.659 +-150 0 0.757 0.778 0.816 0.828 0.797 0.783 +-140 0 0.762 0.787 0.832 0.846 0.813 0.798 +-130 0 0.68 0.708 0.756 0.771 0.739 0.724 +-120 0 0.532 0.56 0.609 0.624 0.596 0.581 +-110 0 0.337 0.365 0.411 0.426 0.403 0.39 +-100 0 0.114 0.139 0.182 0.195 0.179 0.169 +-90 0 -0.12 -0.098 -0.061 -0.05 -0.06 -0.067 +-80 0 -0.349 -0.331 -0.302 -0.294 -0.295 -0.299 +-70 0 -0.557 -0.544 -0.523 -0.518 -0.512 -0.512 +-60 0 -0.727 -0.72 -0.708 -0.706 -0.693 -0.689 +-50 0 -0.842 -0.84 -0.838 -0.839 -0.82 -0.814 +-40 0 -0.886 -0.889 -0.895 -0.898 -0.875 -0.866 +-35 0 -0.875 -0.88 -0.889 -0.893 -0.869 -0.86 +-30 0 -0.839 -0.846 -0.858 -0.862 -0.838 -0.829 +-25 0 -0.777 -0.784 -0.832 -0.803 -0.791 -0.853 +-22 0 -0.725 -0.733 -0.919 -0.792 -0.821 -0.911 +-20 0 -0.685 -0.693 -1.013 -0.815 -0.869 -0.958 +-18 0 -0.635 -0.648 -1.125 -0.854 -0.931 -1.005 +-16 0 -0.571 -0.601 -1.245 -0.905 -0.999 -1.113 +-14 0 -0.494 -0.559 -1.21 -0.959 -1.031 -1.078 +-12 0 -0.407 -0.519 -1.033 -0.952 -0.952 -0.904 +-10 0 -0.311 -0.48 -0.85 -0.828 -0.828 -0.711 +-9 0 -0.259 -0.459 -0.767 -0.754 -0.674 -0.595 +-8 0 -0.208 -0.437 -0.744 -0.628 -0.519 -0.478 +-7 0 -0.16 -0.416 -0.664 -0.493 -0.378 -0.375 +-6 0 -0.111 -0.395 -0.525 -0.355 -0.245 -0.264 +-5 0 -0.072 -0.359 -0.382 -0.22 -0.113 -0.151 +-4 0 -0.054 -0.351 -0.251 -0.084 0.016 -0.017 +-3 0 0.003 -0.24 -0.12 0.049 0.145 0.088 +-2 0 0.009 -0.091 0.017 0.181 0.27 0.213 +-1 0 0.036 0.052 0.152 0.312 0.396 0.328 +0 0 0.137 0.196 0.288 0.444 0.521 0.442 +1 0 0.292 0.335 0.421 0.573 0.645 0.556 +2 0 0.444 0.472 0.554 0.701 0.768 0.67 +3 0 0.58 0.608 0.685 0.827 0.888 0.784 +4 0 0.71 0.742 0.815 0.952 0.996 0.898 +5 0 0.841 0.875 0.944 1.062 1.095 1.011 +6 0 0.967 1.007 1.072 1.161 1.192 1.103 +7 0 1.084 1.134 1.197 1.254 1.283 1.181 +8 0 1.193 1.26 1.305 1.336 1.358 1.257 +9 0 1.287 1.368 1.39 1.4 1.403 1.326 +10 0 1.368 1.475 1.458 1.442 1.358 1.382 +11 0 1.425 1.57 1.512 1.374 1.287 1.415 +12 0 1.473 1.642 1.549 1.277 1.272 1.434 +13 0 1.513 1.7 1.47 1.246 1.273 1.451 +14 0 1.563 1.712 1.354 1.256 1.272 1.448 +15 0 1.614 1.687 1.333 1.271 1.275 1.445 +16 0 1.649 1.649 1.329 1.289 1.284 1.448 +17 0 1.681 1.598 1.321 1.304 1.306 1.438 +18 0 1.719 1.549 1.333 1.315 1.308 1.448 +19 0 1.751 1.544 1.362 1.33 1.308 1.448 +20 0 1.783 1.565 1.398 1.354 1.311 1.428 +22 0 1.83 1.563 1.418 1.325 1.277 1.359 +25 0 1.872 1.546 1.354 1.215 1.136 1.168 +30 0 1.904 1.522 1.265 1.076 0.962 0.926 +35 0 1.929 1.544 1.264 1.066 0.947 0.8 +40 0 1.903 1.529 1.258 1.064 0.95 0.804 +50 0 1.69 1.376 1.146 0.98 0.884 0.763 +60 0 1.323 1.097 0.932 0.81 0.74 0.656 +70 0 0.88 0.75 0.657 0.582 0.54 0.495 +80 0 0.449 0.396 0.362 0.326 0.304 0.291 +90 0 0.124 0.101 0.092 0.072 0.053 0.053 +100 0 -0.118 -0.143 -0.15 -0.17 -0.198 -0.199 +110 0 -0.348 -0.374 -0.379 -0.399 -0.434 -0.436 +120 0 -0.549 -0.575 -0.578 -0.596 -0.637 -0.64 +130 0 -0.702 -0.727 -0.727 -0.743 -0.787 -0.79 +140 0 -0.787 -0.809 -0.807 -0.821 -0.864 -0.868 +150 0 -0.782 -0.8 -0.797 -0.806 -0.847 -0.85 +160 0 -0.664 -0.677 -0.673 -0.679 -0.711 -0.714 +170 0 -0.41 -0.417 -0.547 -0.735 -0.788 -0.749 +180 0 0 0 0 0 0 0 diff --git a/Python/actuator_line_with_wifi/NREL5MW.geo b/Python/actuator_line_with_wifi/NREL5MW.geo new file mode 100644 index 000000000..e01eae6e0 --- /dev/null +++ b/Python/actuator_line_with_wifi/NREL5MW.geo @@ -0,0 +1,18 @@ +2.8667 13.308 3.542 1 +5.6 13.308 3.854 1 +8.3333 13.308 4.167 1 +11.75 13.308 4.557 0.4 +15.85 11.48 4.652 0.35 +19.95 10.162 4.458 0.35 +24.05 9.011 4.249 0.3 +28.15 7.795 4.007 0.25 +32.25 6.544 3.748 0.25 +36.35 5.361 3.502 0.21 +40.45 4.188 3.256 0.21 +44.55 3.125 3.01 0.18 +48.65 2.319 2.764 0.18 +52.75 1.526 2.518 0.18 +56.1667 0.863 2.313 0.18 +58.9 0.37 2.086 0.18 +61.6333 0.106 1.419 0.18 +63.00 0.000 0.878 0.18 diff --git a/Python/actuator_line_with_wifi/NREL5MW.json b/Python/actuator_line_with_wifi/NREL5MW.json new file mode 100644 index 000000000..24cc92690 --- /dev/null +++ b/Python/actuator_line_with_wifi/NREL5MW.json @@ -0,0 +1,33 @@ +{ + "generator": + { + "rated_speed": 122.9, + "rated_torque": 43093.55, + "max_torque": 44748, + "max_torque_rate": 15000, + "efficiency": 0.944, + "slip": 0.1 + }, + "gearbox": + { + "ratio": 97 + }, + "blade": + { + "tip_radius": 63, + "inertia": 11776047, + "mass": 17740, + "file_format": "standard", + "standard_dict": { + "geometry_file": "NREL5MW.geo", + "cl_file": "NREL5MW.cl", + "cd_file": "NREL5MW.cd" + }, + "openfast_dict": { + "input_file": "OpenFASTCoupled/NREL5MW.fst" + }, + "max_pitch_rate": 8, + "root_radius": 1.5 + }, + "number_of_blades_per_turbine": 3 +} \ No newline at end of file diff --git a/Python/actuator_line_with_wifi/SingleTurbine.json b/Python/actuator_line_with_wifi/SingleTurbine.json new file mode 100644 index 000000000..5fb3b4fc5 --- /dev/null +++ b/Python/actuator_line_with_wifi/SingleTurbine.json @@ -0,0 +1,14 @@ +{ + "turbine_model": { + "name": "NREL5MW", + "file": "NREL5MW.json", + "file_type": "json" + }, + "controller": { + "name": "NREL5MWController", + "type": "Greedy", + "file": "GreedyController.json", + "file_type": "json" + }, + "hub_positions": [[0,0,0]] +} \ No newline at end of file diff --git a/Python/actuator_line_with_wifi/configActuatorLine.txt b/Python/actuator_line_with_wifi/configActuatorLine.txt new file mode 100644 index 000000000..8f1fbd929 --- /dev/null +++ b/Python/actuator_line_with_wifi/configActuatorLine.txt @@ -0,0 +1,40 @@ +################################################## +#information for Writing +################################################## +Path = ./output/ +################################################## +#informationsfor reading +################################################## +GridPath = . +################################################## +Devices = 0 +################################################## +tStartOut = 0 +tOut = 300 +tEnd = 600 +################################################## +tStartAveraging = 0 +tStartTmpAveraging = 300 +tAveraging = 200 +tStartOutProbe = 0 +tOutProbe = 100 +################################################## +Ma = 0.1 +nodesPerDiameter = 32 +velocity = 9 + +bodyForce = true +SGSconstant = 0.333333 +TurbulenceModel = QR + +QuadricLimiterP = 10000.0 +QuadricLimiterD = 10000.0 +QuadricLimiterM = 10000.0 + +################################################## +readPrecursor = false +nTimestepsReadPrecursor = 1 +precursorFile = precursor/Precursor + +################################################## +NumberOfNodesPerAL = 32 diff --git a/Python/actuator_line_with_wifi/controller.json b/Python/actuator_line_with_wifi/controller.json new file mode 100644 index 000000000..1283360cc --- /dev/null +++ b/Python/actuator_line_with_wifi/controller.json @@ -0,0 +1,76 @@ +{ + "filter_frequency": 0.25, + "regions": + [ + { + "name": 1, + "min_speed": "-Inf", + "max_speed": 70, + + "torque": + { + "mode": "zero" + } + + }, + { + "name": 1.5, + "min_speed": 70, + "max_speed": 91.3, + + "torque": + { + "mode": "linear", + "kappa": 912.7, + "x_0": 70 + } + }, + { + "name": 2, + "min_speed": 91.3, + "max_speed": 120, + + "torque": + { + "mode": "quadratic", + "kappa": 2.332287 + } + }, + { + "name": 2.5, + "min_speed": 120, + "max_speed": 122.9, + "min_pitch": "-Inf", + "max_pitch": 1, + + "torque": + { + "mode": "linear", + "kappa": 4333, + "x_0": 111.3 + } + + }, + { + "name": 3, + "min_speed": 0, + "max_speed": "Inf", + "min_pitch": 0, + "max_pitch": 90, + + "pitch": + { + "mode": "PI", + "kappa_p": 0.01882681, + "kappa_i": 0.008068634, + "theta_k": 6.302336 + }, + "torque": + { + "mode": "inverse", + "kappa": 5296610 + } + + } + ] +} \ No newline at end of file diff --git a/Python/actuator_line_with_wifi/read_output.py b/Python/actuator_line_with_wifi/read_output.py new file mode 100644 index 000000000..4b90e477d --- /dev/null +++ b/Python/actuator_line_with_wifi/read_output.py @@ -0,0 +1,39 @@ +#%% +from pandas import HDFStore +from matplotlib import pyplot as plt +import numpy as np +from pathlib import Path + +from wiFI.turbine import create_turbine_from_farm_json + +def get_blade_array(hdf5: HDFStore, key: str): + blade_df = hdf5.get(key) + _, n_turbines, n_blades, n_nodes = blade_df.columns[-1] + return blade_df.to_numpy().reshape(-1, 3, n_turbines+1, n_blades+1, n_nodes+1) + +#%% +turbine_file = Path(__file__).parent/"SingleTurbine.json" +output_dir = Path(__file__).parents[2]/"output" +wifi_output = HDFStore(output_dir/"wifi.h5", mode="r") +turbine_model = create_turbine_from_farm_json(turbine_file, number_of_blade_nodes=32) +# %% +print(wifi_output.keys()) +#%% + +plt.plot(wifi_output["/Rotor_speed"]) +# %% +blade_forces = get_blade_array(wifi_output, "Blade_forces") + +plt.plot(blade_forces[-1, 0, 0, :, :].T) + +# %% +blade_coordinates = get_blade_array(wifi_output, "Blade_coordinates") +plt.scatter(blade_coordinates[-1,1,0,:,:], blade_coordinates[-1,2,0,:,:]) + +# %% +blade_velocities = get_blade_array(wifi_output, "Blade_velocities") +plt.plot(blade_velocities[-1, 0, 0, :, :].T) +# %% +plt.plot(blade_velocities[-1, 1, 0,:,:].T) + +# %% diff --git a/Python/actuator_line_with_wifi/runscript.py b/Python/actuator_line_with_wifi/runscript.py new file mode 100644 index 000000000..88e32edcb --- /dev/null +++ b/Python/actuator_line_with_wifi/runscript.py @@ -0,0 +1,169 @@ +from pathlib import Path +from wiFI.turbine import create_turbine_from_farm_json +from wiFI.logging import LoggerConfig, LogEntry +from wiFI.interfaces.implementations.velocity_provider.VirtualFluids.VirtualFluids import create_standard_actuator_farm +from wiFI.controller.controller import ControllerTypes +from pyfluids import basics, gpu, logger, parallel +import numpy as np + + +#%% +sim_name = "ABL" +config_file = Path(__file__).parent/"configActuatorLine.txt" +turbine_file = Path(__file__).parent/"SingleTurbine.json" +controller_file = Path(__file__).parent/"controller.json" + +def load_config_file(config_file: Path): + config = basics.ConfigurationFile() + config.load(str(config_file)) + return config + +def add_plane_probes(plane_locs: np.ndarray, para: gpu.Parameter, t_start_averaging: float, t_start_out_probe: float, t_out_probe: float, dt: float, dx: float, length: np.ndarray): + for n_probe, probe_pos in enumerate(plane_locs): + plane_probe = gpu.probes.PlaneProbe(f"planeProbe_{n_probe+1}", para.get_output_path(), int(t_start_averaging/dt), 10, int(t_start_out_probe/dt), int(t_out_probe/dt)) + plane_probe.set_probe_plane(probe_pos, -length[1]/2, -length[2]/2, dx, length[1], length[2]) + plane_probe.add_all_available_statistics() + para.add_probe(plane_probe) + + +def main(sim_name: str, config_file: Path, turbine_file: Path, controller_file: Path): + logger.Logger.initialize_logger() + + config = load_config_file(config_file) + grid_builder = gpu.grid_generator.MultipleGridBuilder() + communicator = parallel.MPICommunicator.get_instance() + + para = gpu.Parameter(communicator.get_number_of_processes(), communicator.get_process_id(), config) + bc_factory = gpu.BoundaryConditionFactory() + + + viscosity = config.get_float_value("viscosity", 1.56e-5) + velocity = config.get_float_value("velocity", 9.0) + + mach = config.get_float_value("Ma", 0.1) + nodes_per_diameter = config.get_uint_value("nodesPerDiameter", 32) + + + density = config.get_float_value("Density", 1.225) + level = 0 + n_blade_nodes = config.get_int_value("NumberOfNodesPerAL", 32) + + read_precursor = config.get_bool_value("readPrecursor", False) + + if read_precursor: + nTReadPrecursor = config.get_int_value("nTimestepsReadPrecursor") + use_distributions = config.get_bool_value("useDistributions", False) + precursor_directory = config.get_string_value("precursorDirectory") + + # all in s + t_start_out = config.get_float_value("tStartOut") + t_out = config.get_float_value("tOut") + t_end = config.get_float_value("tEnd") # total time of simulation + + t_start_averaging = config.get_float_value("tStartAveraging") + t_start_tmp_averaging = config.get_float_value("tStartTmpAveraging") + t_averaging = config.get_float_value("tAveraging") + t_start_out_probe = config.get_float_value("tStartOutProbe") + t_out_probe = config.get_float_value("tOutProbe") + + + turbine_model = create_turbine_from_farm_json(turbine_file, + n_blade_nodes, + load_data = True, + use_gpu = True) + + diameter = turbine_model.blade_tip_radius*2 + + length = np.array([24,8,8])*diameter + dx = diameter/nodes_per_diameter + dt = dx * mach / (np.sqrt(3) * velocity) + velocity_ratio = dx/dt + velocity_LB = velocity / velocity_ratio # LB units + viscosity_LB = viscosity / (velocity_ratio * dx) # LB units + + logger.vf_log_info(f"velocity [dx/dt] = {velocity_LB}") + logger.vf_log_info(f"dt = {dt}") + logger.vf_log_info(f"dx = {dx}") + logger.vf_log_info(f"viscosity [10^8 dx^2/dt] = {viscosity_LB*1e8}") + + para.set_output_prefix(sim_name) + para.set_print_files(True) + output_path = Path(para.get_output_path()) + output_path.mkdir(exist_ok=True) + + para.set_forcing(0, 0, 0) + para.set_velocity_LB(velocity_LB) + para.set_viscosity_LB(viscosity_LB) + para.set_velocity_ratio(dx/dt) + para.set_viscosity_ratio(dx*dx/dt) + para.set_density_ratio(1.0) + + para.configure_main_kernel(gpu.kernel.compressible.K17CompressibleNavierStokes) + + para.set_timestep_start_out(int(t_start_out/dt)) + para.set_timestep_out(int(t_out/dt)) + para.set_timestep_end(int(t_end/dt)) + para.set_is_body_force(True) + + tm_factory = gpu.TurbulenceModelFactory(para) + tm_factory.read_config_file(config) + #%% + grid_scaling_factory = gpu.GridScalingFactory() + grid_scaling_factory.set_scaling_factory(gpu.GridScaling.ScaleCompressible) + + grid_builder.add_coarse_grid(-3*diameter, -length[1]/2, -length[2]/2, length[0]-3*diameter, length[1]/2, length[2]/2, dx) + grid_builder.set_periodic_boundary_condition(False, True, True) + grid_builder.build_grids(False) + + if read_precursor: + precursor = gpu.create_file_collection(precursor_directory + "/precursor", gpu.FileType.VTK) + grid_builder.set_precursor_boundary_condition(gpu.SideType.MX, precursor, nTReadPrecursor, 0, 0, 0) + else: + grid_builder.set_velocity_boundary_condition(gpu.SideType.MX, velocity_LB, 0, 0) + + grid_builder.set_pressure_boundary_condition(gpu.SideType.PX, 0) + + bc_factory.set_stress_boundary_condition(gpu.StressBC.StressPressureBounceBack) + bc_factory.set_slip_boundary_condition(gpu.SlipBC.SlipBounceBack) + bc_factory.set_pressure_boundary_condition(gpu.PressureBC.OutflowNonReflective) + if read_precursor: + bc_factory.set_precursor_boundary_condition(gpu.PrecursorBC.DistributionsPrecursor if use_distributions else gpu.PrecursorBC.VelocityPrecursor) + else: + bc_factory.set_velocity_boundary_condition(gpu.VelocityBC.VelocityAndPressureCompressible) + + para.set_outflow_pressure_correction_factor(0.0) + + para.set_initial_condition_uniform(velocity_LB, 0, 0) + + + logging_config = LoggerConfig("wifi", output_path, start_time=1000, log_period=100) + logging_dict = {"wind_farm": [LogEntry("rotor_speed", True, True), + LogEntry("azimuth", True, True)]} + + + tip_speed_ratio = 7.55*np.ones(turbine_model.n_turbines) + rotor_speeds = tip_speed_ratio * velocity / turbine_model.blade_tip_radius + smearing_width = 2*dx + farm = create_standard_actuator_farm(logging_config, logging_dict, turbine_model, density, smearing_width, + level, dt, dx, communicator.get_process_id(), + ControllerTypes.Greedy, controller_file, rotor_speeds) + + # farm = gpu.ActuatorFarmStandalone(turbine_model.blade_tip_radius*2, turbine_model.n_nodes_per_blade, turbine_model.hub_positions.x, turbine_model.hub_positions.y, turbine_model.hub_positions.z, rotor_speeds, density, smearing_width, level, dt, dx) + farm.enable_output("ALM", 0, int(t_out_probe/dt)) + para.add_actuator(farm) + + plane_locs = np.array([-1,1,2,3,4])*diameter + add_plane_probes(plane_locs, para, t_start_averaging, t_start_out_probe, t_out_probe, dt, dx, length) + plane_probe = gpu.probes.PlaneProbe(f"streamwiseProbe", para.get_output_path(), int(t_start_averaging/dt), 10, int(t_start_out_probe/dt), int(t_out_probe/dt)) + plane_probe.set_probe_plane(-diameter*3, 0, -length[2]/2, length[0], dx, length[2]) + plane_probe.add_all_available_statistics() + para.add_probe(plane_probe) + + cuda_memory_manager = gpu.CudaMemoryManager(para) + grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager, communicator) + sim = gpu.Simulation(para, cuda_memory_manager, communicator, grid_generator, bc_factory, tm_factory, grid_scaling_factory) + sim.run() + + +if __name__ == '__main__': + main(sim_name, config_file, turbine_file, controller_file) -- GitLab