Skip to content

Clean up grid classes#1183

Open
misi9170 wants to merge 9 commits intoNatLabRockies:developfrom
misi9170:bugfix/z-equals-zero
Open

Clean up grid classes#1183
misi9170 wants to merge 9 commits intoNatLabRockies:developfrom
misi9170:bugfix/z-equals-zero

Conversation

@misi9170
Copy link
Copy Markdown
Collaborator

@misi9170 misi9170 commented Feb 11, 2026

This PR makes several adjustments to the Grid classes:

  • Removes FlowFieldGrid entirely, since it is not used anywhere in FLORIS and I believe was deprecated in the transition from v3 to v4
  • Adds a warning to Grid classes (via an attrs validator) to let users know that issues may arise if z is less than or equal to zero (more on this below)
  • Moves grid_resolution validators onto the subclasses of Grid (see below)

This originally came up because the where=z != 0 line in np.power() on FlowField was raising a numpy user warning, but digging into this more, I realized that any time z is less than or equal to zero can cause FLORIS to fail. Rather than generate an error, which might be a breaking change in case there are some workflows where non-positive z works, I opted to raise a warning to help users track down any issue that might arise.

In doing so, I believe I am also sufficiently addressing #760.

Finally, I noticed a TODO in the validators for the grid_resolution attribute on Grid, and according to this stackoverflow thread, I decided to remove the generic grid_resolution validator and instead add checks for correctness to the __attrs_post_init__ of each subclass.

To check the new behavior, the following script can be run (based on examples/examples_visualization/003_visualize_cross_plane):

import matplotlib.pyplot as plt

from floris import FlorisModel
from floris.flow_visualization import visualize_cut_plane

fmodel = FlorisModel("../inputs/gch.yaml")

# Set a 1 turbine layout
fmodel.set(
    layout_x=[0],
    layout_y=[0],
    wind_directions=[270],
    wind_speeds=[8],
    turbulence_intensities=[0.06],
)

# Collect the cross plane downstream of the turbine
cross_plane = fmodel.calculate_cross_plane(
    y_resolution=100,
    z_resolution=100,
    downstream_dist=500.0,
    z_bounds=[0, 500], # Raises warning, and also errors out. Changing lower bound to a value greater than zero works
)

# Plot the flow field
fig, ax = plt.subplots(figsize=(4, 6))
visualize_cut_plane(
    cross_plane, ax=ax, min_speed=3, max_speed=9, label_contours=True, title="Cross Plane"
)

# plt.show()

This script errors out with an ambiguous error ValueError: z array must not contain non-finite values within the triangulation on the develop branch, which the new warning should help users identify.

With the proposed change, this error is still raised, but is preceded by the added warning:

floris.logging_manager.LoggingManager WARNING Non-positive z coordinates detected. This may cause issues with the flow model calculations. To fix this, consider adjusting the z coordinates to be positive.

I have added tests under a new test script grid_unit_test.py to ensure that the warning is correctly raised and to check the grid_resolution validators. Probably, more could be added here.

@misi9170 misi9170 added the enhancement An improvement of an existing feature label Feb 11, 2026
@misi9170 misi9170 changed the title Raise warning when solving for z at or below ground level Clean up grid classes Feb 11, 2026
@misi9170 misi9170 requested a review from Copilot February 11, 2026 23:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR cleans up the Grid class hierarchy by removing the deprecated FlowFieldGrid class, adding validation warnings for non-positive z coordinates, and refactoring grid_resolution validation.

Changes:

  • Removes the deprecated FlowFieldGrid class entirely from the codebase
  • Adds a z_sorted validator that warns when z coordinates are ≤ 0, helping users identify potential numerical issues
  • Refactors grid_resolution validation from a generic base class validator to type-specific checks in each Grid subclass's __attrs_post_init__ method
  • Removes the where=z != 0.0 parameter from np.power() in flow_field.py, relying on the new warning instead
  • Updates type hints in solver functions to remove FlowFieldGrid references

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
floris/core/grid.py Removes FlowFieldGrid class (70 lines), adds z_sorted validator warning for non-positive values, moves grid_resolution validation to subclass attrs_post_init methods
floris/core/flow_field.py Removes where=z != 0.0 parameter from np.power() call that was masking potential division issues
floris/core/core.py Replaces FlowFieldGrid instantiation with ValueError indicating deprecation in favor of FlowFieldPlanarGrid
floris/core/solver.py Updates type hints for full_flow solver functions to remove FlowFieldGrid and use FlowFieldPlanarGrid | PointsGrid instead
floris/core/init.py Removes FlowFieldGrid from module exports
tests/conftest.py Removes flow_field_grid_fixture as it's no longer needed
tests/grid_unit_test.py Adds new test file with tests for z-coordinate warnings and grid_resolution validators for TurbineGrid and FlowFieldPlanarGrid
docs/dev_guide.md Updates documentation to remove FlowFieldGrid references and use FlowFieldPlanarGrid in examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread floris/core/grid.py Outdated
Comment thread floris/core/grid.py Outdated
Comment thread floris/core/core.py Outdated
Comment thread tests/grid_unit_test.py Outdated
misi9170 and others added 3 commits February 11, 2026 16:50
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lejeunemax
Copy link
Copy Markdown

Maybe this PR is the opportunity to integrate the keep_inertial_frame argument of #1175. I believe this would allow to isolate better responsibilities.

@misi9170
Copy link
Copy Markdown
Collaborator Author

misi9170 commented Feb 23, 2026

Maybe this PR is the opportunity to integrate the keep_inertial_frame argument of #1175. I believe this would allow to isolate better responsibilities.

@lejeunemax good idea! And sorry that I've been slow to get to #1175. Would you like to add the keep_inertial_frame option to this branch? If that doesn't work (i.e. you can't commit to this branch), I can just grab those changes myself.

EDIT: actually, sorry, let me take a day to just look over #1175 in more detail and make sure I understand the purpose and usage of keep_inertial_frame. I'll try to get back to you by the end of the day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants