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

Refactor the solver module to a more general and class-based system #503

Draft
wants to merge 23 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
33c848b
generalize the x, y, z mean calc and start sequential solver class
RHammond2 Sep 19, 2022
082722d
work towards base solver class, complete sequential solver, and start…
RHammond2 Sep 19, 2022
1f61279
refactor cc solver
RHammond2 Sep 20, 2022
3525909
generalize long computations that naturally break onto multiple lines
RHammond2 Sep 20, 2022
bb28fdc
add turbopark refactor
RHammond2 Sep 20, 2022
e03f3be
improve spacing and run linter
RHammond2 Sep 20, 2022
5eb59db
add comment
RHammond2 Sep 20, 2022
cc05377
fix merge conflict
RHammond2 Feb 7, 2023
a68d2cd
enable future typing patterns
RHammond2 Feb 7, 2023
9ed1b17
fix bad grid reference
RHammond2 Feb 7, 2023
7028db4
fix merge conflicts
RHammond2 Jul 10, 2023
e3d462d
bring the refactored solvers up to date with all past changes
RHammond2 Jul 13, 2023
e78158f
add the trailing commas back
RHammond2 Jul 13, 2023
b3aeab3
Merge branch 'develop' into enhancement/solver_refactor
RHammond2 Jul 13, 2023
80c07ec
udpate the solver method typing
RHammond2 Jul 13, 2023
ea9d239
integrate the sequential solver and fix a logic error
RHammond2 Jul 13, 2023
0c4067d
reduce small piece to one line and fix logic bug in if/else
RHammond2 Jul 13, 2023
61c15a8
fix remaining inconsistencies in the sequential solver and bring up …
RHammond2 Jul 13, 2023
00990fd
fix small logic bugs in cc solver
RHammond2 Jul 14, 2023
9ed672b
convert empirical gauss solver to EmpiricalGauss.solve()
RHammond2 Jul 14, 2023
211f4bd
initialize solver with a value and better check types
RHammond2 Jul 14, 2023
6ec0b5f
copy.deepcopy is not a valid converter, Chris
RHammond2 Jul 14, 2023
2797f50
add FlowFieldPlanarGrid as valid solver
RHammond2 Jul 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions floris/simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@
from .wake import WakeModelManager
from .solver import (
cc_solver,
CCSolver,
empirical_gauss_solver,
EmpiricalGaussSolver,
full_flow_cc_solver,
full_flow_empirical_gauss_solver,
full_flow_sequential_solver,
full_flow_turbopark_solver,
sequential_solver,
turbopark_solver,
SequentialSolver,
TurbOParkSolver,
)
from .floris import Floris

Expand Down
85 changes: 54 additions & 31 deletions floris/simulation/floris.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

from pathlib import Path

import attrs
import yaml
from attrs import define, field

from floris import logging_manager
from floris.simulation import (
BaseClass,
cc_solver,
CCSolver,
empirical_gauss_solver,
EmpiricalGaussSolver,
Farm,
FlowField,
FlowFieldGrid,
Expand All @@ -35,10 +38,12 @@
Grid,
PointsGrid,
sequential_solver,
SequentialSolver,
State,
TurbineCubatureGrid,
TurbineGrid,
turbopark_solver,
TurbOParkSolver,
WakeModelManager,
)
from floris.utilities import load_yaml
Expand All @@ -65,6 +70,13 @@ class Floris(BaseClass):
floris_version: str = field(converter=str)

grid: Grid = field(init=False)
solve: SequentialSolver | CCSolver | TurbOParkSolver | EmpiricalGaussSolver = field(
default=None,
init=False,
validator=attrs.validators.instance_of(
(SequentialSolver, CCSolver, TurbOParkSolver, EmpiricalGaussSolver, type(None))
)
)

def __attrs_post_init__(self) -> None:

Expand Down Expand Up @@ -223,33 +235,16 @@ def steady_state_atmospheric_condition(self):
)

if vel_model=="cc":
cc_solver(
self.farm,
self.flow_field,
self.grid,
self.wake
)
self.solve = CCSolver(self.farm, self.flow_field, self.grid, self.wake)
elif vel_model=="turbopark":
turbopark_solver(
self.farm,
self.flow_field,
self.grid,
self.wake
)
self.solve = TurbOParkSolver(self.farm, self.flow_field, self.grid, self.wake)
elif vel_model=="empirical_gauss":
empirical_gauss_solver(
self.farm,
self.flow_field,
self.grid,
self.wake
)
self.solve = EmpiricalGaussSolver(self.farm, self.flow_field, self.grid, self.wake)
else:
sequential_solver(
self.farm,
self.flow_field,
self.grid,
self.wake
)
self.solve = SequentialSolver(self.farm, self.flow_field, self.grid, self.wake)

self.solve.solve()
self.post_solve_update_flow_field()
# end = time.time()
# elapsed_time = end - start

Expand All @@ -268,13 +263,16 @@ def solve_for_viz(self):
vel_model = self.wake.model_strings["velocity_model"]

if vel_model=="cc":
full_flow_cc_solver(self.farm, self.flow_field, self.grid, self.wake)
self.solve = CCSolver(self.farm, self.flow_field, self.grid, self.wake)
elif vel_model=="turbopark":
full_flow_turbopark_solver(self.farm, self.flow_field, self.grid, self.wake)
self.solve = TurbOParkSolver(self.farm, self.flow_field, self.grid, self.wake)
elif vel_model=="empirical_gauss":
full_flow_empirical_gauss_solver(self.farm, self.flow_field, self.grid, self.wake)
self.solve = EmpiricalGaussSolver(self.farm, self.flow_field, self.grid, self.wake)
else:
full_flow_sequential_solver(self.farm, self.flow_field, self.grid, self.wake)
self.solve = SequentialSolver(self.farm, self.flow_field, self.grid, self.wake)

self.solve.solve(full_flow=True)
self.post_solve_update_flow_field()

def solve_for_points(self, x, y, z):
# Do the calculation with the TurbineGrid for a single wind speed
Expand Down Expand Up @@ -307,13 +305,38 @@ def solve_for_points(self, x, y, z):
"solve_for_points is currently only available with the "+\
"gauss, jensen, and empirical_guass models."
)
elif vel_model == "empirical_gauss":
full_flow_empirical_gauss_solver(self.farm, self.flow_field, field_grid, self.wake)

if vel_model == "empirical_gauss":
self.solve = EmpiricalGaussSolver(self.farm, self.flow_field, field_grid, self.wake)
else:
full_flow_sequential_solver(self.farm, self.flow_field, field_grid, self.wake)
# full_flow_sequential_solver(self.farm, self.flow_field, field_grid, self.wake)
self.solve = SequentialSolver(self.farm, self.flow_field, self.grid, self.wake)

self.solve.solve(full_flow=True)
self.post_solve_update_flow_field()

return self.flow_field.u_sorted[:,:,:,0,0] # Remove turbine grid dimensions

def post_solve_update_flow_field(self):
"""Updates the `flow_field` values with those that were solved during the steady state
calculation.
"""
self.flow_field.u = self.solve.flow_field.u
self.flow_field.v = self.solve.flow_field.v
self.flow_field.w = self.solve.flow_field.w
self.flow_field.u_sorted = self.solve.flow_field.u_sorted
self.flow_field.v_sorted = self.solve.flow_field.v_sorted
self.flow_field.w_sorted = self.solve.flow_field.w_sorted
self.flow_field.turbulence_intensity_field = (
self.solve.flow_field.turbulence_intensity_field
)
self.flow_field.turbulence_intensity_field_sorted = (
self.solve.flow_field.turbulence_intensity_field_sorted
)
self.flow_field.turbulence_intensity_field_sorted_avg = (
self.solve.flow_field.turbulence_intensity_field_sorted_avg
)

def finalize(self):
# Once the wake calculation is finished, unsort the values to match
# the user-supplied order of things.
Expand Down
Loading