Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to reload input file when updating/plotting in a loop? #315

Closed
paulf81 opened this issue Feb 14, 2022 · 4 comments · Fixed by #327
Closed

Need to reload input file when updating/plotting in a loop? #315

paulf81 opened this issue Feb 14, 2022 · 4 comments · Fixed by #327
Assignees
Labels
bug Something isn't working v3 Label to denote focus on v3
Milestone

Comments

@paulf81
Copy link
Collaborator

paulf81 commented Feb 14, 2022

Bug description
Had a code set up to change FLORIS settings and plot in a loop and discovered it only worked if I reopened the input file (or if don't plot). Is this expected operation

To Reproduce
Made this code example, it doesn't work for me unless I:
1). Uncomment the code which reopens the model from input yaml
2) Dont plot

import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools.visualization import visualize_cut_plane


# Inputs
X = [0, 500]
Y = [0, 0]
yaw_angles = np.zeros((1, 1, 2)) # 1 wd/ 1ws/ N*N turbines
fi_gch = FlorisInterface("inputs/gch.yaml")


for wd_idx, wind_direction in enumerate([270.,  280.]):

    # Code works if this lined is uncommented
    # fi_gch = FlorisInterface("inputs/gch.yaml") 


    fi_gch.reinitialize(  layout=( X, Y ), wind_speeds=[8.0], wind_directions=[wind_direction], turbulence_intensity=0.06 )
    fi_gch.calculate_wake(yaw_angles=yaw_angles)
    turbine_powers_gch = fi_gch.get_turbine_powers()
    turbine_powers_gch = np.sort(turbine_powers_gch.flatten())[::-1]/1000.

    # Code also works if comment out this block
    fig, ax = plt.subplots()
    horizontal_plane_gch = fi_gch.get_hor_plane(x_resolution=100, y_resolution=100)
    visualize_cut_plane(horizontal_plane_gch, ax=ax, title="Wind Direction = %.1f" % wind_direction)


plt.show()

Expected behavior
Was expecting the code to work without the call back to the yaml, is something in plotting "sticking"?

Screenshots, if applicable
If the code works plots:
image

Floris Version
V3

@paulf81 paulf81 added bug Something isn't working v3 Label to denote focus on v3 labels Feb 14, 2022
@paulf81 paulf81 added this to the v3.0rc3 milestone Feb 14, 2022
@bayc
Copy link
Collaborator

bayc commented Feb 15, 2022

Yea, I noticed this too. My thought was that something was sticking from the grid used for the flow field visualizations, but haven't been able to dig into it yet.

@rafmudaf
Copy link
Collaborator

@paulf81 can you confirm that this is fixed by #327?

@paulf81
Copy link
Collaborator Author

paulf81 commented Feb 21, 2022

Confirmed! I had to update the function call from get_ to calculate_ but then I modified the test also a little bit to confirm that after going back and forth a few times I produce the same answer, and have the same total number of grid points. I think all confirmed via:

import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools.visualization import visualize_cut_plane


# Inputs
X = [0, 500]
Y = [0, 0]
yaw_angles = np.zeros((1, 1, 2)) # 1 wd/ 1ws/ N*N turbines
fi_gch = FlorisInterface("inputs/gch.yaml")
fi_gch.reinitialize(  layout=( X, Y ))
print('starting shape:', fi_gch.floris.grid.x.shape)
for wd_idx, wind_direction in enumerate([270.,  270., 280., 270.]):

    # Code works if this lined is uncommented
    # fi_gch = FlorisInterface("inputs/gch.yaml") 


    fi_gch.reinitialize(  layout=( X, Y ), wind_speeds=[8.0], wind_directions=[wind_direction], turbulence_intensity=0.06 )
    fi_gch.calculate_wake(yaw_angles=yaw_angles)
    turbine_powers_gch = fi_gch.get_turbine_powers()
    turbine_powers_gch = np.sort(turbine_powers_gch.flatten())[::-1]/1000.

    # Code also works if comment out this block
    fig, ax = plt.subplots()
    horizontal_plane_gch = fi_gch.calculate_horizontal_plane(x_resolution=100, y_resolution=100)
    visualize_cut_plane(horizontal_plane_gch, ax=ax, title="Wind Direction = %.1f" % wind_direction)

    print(turbine_powers_gch, fi_gch.floris.grid.x.shape)


plt.show()

yielding:

starting shape: (1, 1, 2, 3, 3)
[1691.32648289  361.23204874] (1, 1, 2, 3, 3)
[1691.32648289  361.23204874] (1, 1, 2, 3, 3)
[1691.32648289 1290.71622033] (1, 1, 2, 3, 3)
[1691.32648289  361.23204874] (1, 1, 2, 3, 3)

and working plots, all good!

@rafmudaf
Copy link
Collaborator

Currently, the FlorisInterface.calculate_XX_plane() routines reinitialize Floris with a single atmospheric condition (required for plotting). While we reset the solver settings, we do not reset the state of Floris prior to making the change for plotting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3 Label to denote focus on v3
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants