floris_design #7
@ -3,6 +3,7 @@ import os.path
|
||||
import sys
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from typing import Set
|
||||
|
||||
from floris import FlorisModel
|
||||
from floris.flow_visualization import visualize_cut_plane
|
||||
@ -11,7 +12,6 @@ import floris.layout_visualization as layoutviz
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
_wind_direction_to_val: dict[str, float] = {
|
||||
"N": 0.0,
|
||||
"E": 90.0,
|
||||
@ -54,33 +54,90 @@ class FlorisULSTU(FlorisModel):
|
||||
|
||||
super().set(**kwargs)
|
||||
|
||||
def visualisation(self):
|
||||
def visualization(
|
||||
self,
|
||||
interest_plots: Set[str]
|
||||
):
|
||||
dct_functions = {
|
||||
"horizontal_plane": self._horizontal_plane_visualization,
|
||||
"vertical_plane": self._vertical_plane_visualization,
|
||||
}
|
||||
|
||||
res = {}
|
||||
|
||||
for param in interest_plots:
|
||||
if param not in dct_functions:
|
||||
res[param] = "Not found"
|
||||
continue
|
||||
res[param] = dct_functions[param]()
|
||||
|
||||
return res
|
||||
|
||||
def _horizontal_plane_visualization(self):
|
||||
return self._plane_visualization(self.calculate_horizontal_plane, {"height": 90.0})
|
||||
|
||||
def _vertical_plane_visualization(self):
|
||||
return self._plane_visualization(self.calculate_y_plane,
|
||||
{"crossstream_dist": 0.0,
|
||||
"x_resolution": 200,
|
||||
"z_resolution": 100})
|
||||
|
||||
def _plane_visualization(self, plane_func, func_params: dict[str, float] = {}):
|
||||
wind_dirs = self.core.flow_field.wind_directions
|
||||
wind_speeds = self.core.flow_field.wind_speeds
|
||||
|
||||
experiment_counts = len(wind_dirs)
|
||||
near_square = math.ceil(math.sqrt(experiment_counts))
|
||||
fig, axarr = plt.subplots(near_square, near_square, figsize=(15,8))
|
||||
axarr = axarr.flatten()
|
||||
fig, ax_arr = plt.subplots(near_square, near_square, figsize=(15, 8))
|
||||
ax_arr = ax_arr.flatten()
|
||||
|
||||
for experiment_count in range(experiment_counts):
|
||||
self.reset_operation()
|
||||
self.set(wind_speeds=[wind_speeds[experiment_count]], wind_directions=[wind_dirs[experiment_count]],
|
||||
turbulence_intensities=[0.05])
|
||||
ax = axarr[experiment_count]
|
||||
horizontal_plane = self.calculate_horizontal_plane(height=90.0)
|
||||
ax = ax_arr[experiment_count]
|
||||
plane = plane_func(**func_params)
|
||||
visualize_cut_plane(
|
||||
horizontal_plane,
|
||||
plane,
|
||||
ax=ax,
|
||||
title=f"Wind flow day {experiment_count + 1}",
|
||||
)
|
||||
|
||||
# plot_turbine_labels(self, axarr[0, 0])
|
||||
filename = str(uuid.uuid4()) + ".png"
|
||||
plt.savefig(Path(__file__).parent.parent.parent / f"public/floris/{filename}")
|
||||
plt.close()
|
||||
|
||||
self.set(wind_speeds=wind_speeds, wind_directions=wind_dirs, turbulence_intensities=[0.05] * len(wind_dirs))
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def _cross_visualization(self, plane_func, func_params: dict[str, float] = {}):
|
||||
wind_dirs = self.core.flow_field.wind_directions
|
||||
wind_speeds = self.core.flow_field.wind_speeds
|
||||
|
||||
|
||||
experiment_counts = len(wind_dirs)
|
||||
near_square = math.ceil(math.sqrt(experiment_counts))
|
||||
fig, ax_arr = plt.subplots(near_square, near_square, figsize=(15, 8))
|
||||
ax_arr = ax_arr.flatten()
|
||||
|
||||
for experiment_count in range(experiment_counts):
|
||||
self.reset_operation()
|
||||
self.set(wind_speeds=[wind_speeds[experiment_count]], wind_directions=[wind_dirs[experiment_count]],
|
||||
turbulence_intensities=[0.05])
|
||||
ax = ax_arr[experiment_count]
|
||||
plane = plane_func(**func_params)
|
||||
visualize_cut_plane(
|
||||
plane,
|
||||
ax=ax,
|
||||
title=f"Wind flow day {experiment_count + 1}",
|
||||
)
|
||||
|
||||
filename = str(uuid.uuid4()) + ".png"
|
||||
plt.savefig(Path(__file__).parent.parent.parent / f"public/floris/{filename}")
|
||||
plt.close()
|
||||
|
||||
self.set(wind_speeds=wind_speeds, wind_directions=wind_dirs, turbulence_intensities=[0.05] * len(wind_dirs))
|
||||
|
||||
return filename
|
@ -13,10 +13,11 @@ class SFlorisInputParams(BaseModel):
|
||||
layout_x: list[float] = Field(Query([]))
|
||||
layout_y: list[float] = Field(Query([]))
|
||||
yaw_angle: list[float] = Field(Query([]))
|
||||
plots: set[str] = Field(Query(["horizontal_plane"]))
|
||||
date_start: date
|
||||
date_end: date
|
||||
|
||||
|
||||
class SFlorisOutputData(BaseModel):
|
||||
file_name: str
|
||||
file_name: object
|
||||
data: object
|
@ -62,10 +62,10 @@ async def get_windmill_data(
|
||||
fmodel.run()
|
||||
|
||||
res = fmodel.get_turbine_powers().tolist()
|
||||
file_name = fmodel.visualisation()
|
||||
file_names = fmodel.visualization(data.plots)
|
||||
|
||||
return SFlorisOutputData(
|
||||
file_name=file_name,
|
||||
file_name=file_names,
|
||||
data=res
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user