Conversation
There was a problem hiding this comment.
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
FlowFieldGridclass 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.0parameter fromnp.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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
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 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 |
This PR makes several adjustments to the
Gridclasses:FlowFieldGridentirely, since it is not used anywhere in FLORIS and I believe was deprecated in the transition from v3 to v4Gridclasses (via anattrsvalidator) to let users know that issues may arise ifzis less than or equal to zero (more on this below)grid_resolutionvalidators onto the subclasses ofGrid(see below)This originally came up because the
where=z != 0line innp.power()onFlowFieldwas raising a numpy user warning, but digging into this more, I realized that any timezis 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-positivezworks, 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_resolutionattribute onGrid, and according to this stackoverflow thread, I decided to remove the genericgrid_resolutionvalidator 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):
This script errors out with an ambiguous error
ValueError: z array must not contain non-finite values within the triangulationon 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:
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_resolutionvalidators. Probably, more could be added here.