Skip to content
Merged
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
0504e15
include utility functions for polygon boundary constraints
jaredthomas68 May 2, 2025
be9e587
Merge branch 'organize_utils' into boundary
jaredthomas68 May 2, 2025
e540d6f
rename get_closest_point to get_closest_point_on_line_seg
jaredthomas68 May 5, 2025
ef42e88
include tests for point_on_line
jaredthomas68 May 5, 2025
a12e437
include unit tests for single_polygon_normals_calculator
jaredthomas68 May 5, 2025
a70d1a1
vectorize single_polygon_normals_calculator
jaredthomas68 May 5, 2025
baf6ded
jit normals calculator
jaredthomas68 May 5, 2025
8e1b0c1
include multi-polygon normals tests with heterogenous polygon shapes …
jaredthomas68 May 5, 2025
89bb9ed
stash polygon work for a bit
jaredthomas68 May 5, 2025
b621380
Merge branch 'offshore-development' into boundary
jaredthomas68 May 6, 2025
4f4be7b
minor comment update
jaredthomas68 May 6, 2025
dbac56a
Merge branch 'temp' into boundary
jaredthomas68 May 7, 2025
0f878c1
loosen rtol for point_to_polygon numeric deriv check
jaredthomas68 May 7, 2025
cc150e0
switch from jit decorator to jit function
jaredthomas68 May 7, 2025
b563d5c
get multi-point multi-polygon working unvectorized
jaredthomas68 May 7, 2025
fefb691
vectorize and make multi point to multi polygon function differentiable
jaredthomas68 May 7, 2025
92bebde
get derivatives working for multi point to multi polygon distance
jaredthomas68 May 8, 2025
ecd7855
add tests for get_nearest_polygons
jaredthomas68 May 8, 2025
bb734ad
do sparse patrial computation for polygon boundary and include deriva…
jaredthomas68 May 8, 2025
3e45580
include boundary and related unit tests
jaredthomas68 May 8, 2025
b60c325
update shift default back to 1E-10
jaredthomas68 May 9, 2025
3382227
run black
jaredthomas68 May 9, 2025
ec601c4
Merge branch 'offshore-development' into boundary
cfrontin May 9, 2025
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
105 changes: 105 additions & 0 deletions ard/layout/boundary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import numpy as np
import jax.numpy as jnp
import jax

jax.config.update("jax_enable_x64", True)
import ard.utils.mathematics
import ard.utils.geometry
import openmdao.api as om


class FarmBoundaryDistancePolygon(om.ExplicitComponent):
"""
A class to return distances between turbines and a polygonal boundary, or
sets of polygonal boundary regions.

Options
-------
modeling_options : dict
a modeling options dictionary (inherited from `FarmAeroTemplate`)

Inputs
------
x_turbines : np.ndarray
a 1D numpy array indicating the x-dimension locations of the turbines,
with length `N_turbines` (mirrored w.r.t. `FarmAeroTemplate`)
y_turbines : np.ndarray
a 1D numpy array indicating the y-dimension locations of the turbines,
with length `N_turbines` (mirrored w.r.t. `FarmAeroTemplate`)
"""

def initialize(self):
"""Initialization of the OpenMDAO component."""
self.options.declare("modeling_options")

def setup(self):
"""Setup of the OpenMDAO component."""

# load modeling options
self.modeling_options = self.options["modeling_options"]
self.N_turbines = int(self.modeling_options["farm"]["N_turbines"])
self.boundary_vertices = self.modeling_options["farm"]["boundary"]["vertices"]
self.boundary_regions = self.modeling_options["farm"]["boundary"][
"turbine_region_assignments"
]

self.distance_multi_point_to_multi_polygon_ray_casting_jac = jax.jacfwd(
ard.utils.geometry.distance_multi_point_to_multi_polygon_ray_casting, [0, 1]
)
# MANAGE ADDITIONAL LATENT VARIABLES HERE!!!!!

# set up inputs and outputs for mooring system
self.add_input(
"x_turbines", jnp.zeros((self.N_turbines,)), units="km"
) # x location of the mooring platform in km w.r.t. reference coordinates
self.add_input(
"y_turbines", jnp.zeros((self.N_turbines,)), units="km"
) # y location of the mooring platform in km w.r.t. reference coordinates

self.add_output(
"boundary_distances",
jnp.zeros(self.N_turbines),
units="km",
)

def setup_partials(self):
"""Derivative setup for the OpenMDAO component."""
# the default (but not preferred!) derivatives are FDM
self.declare_partials(
"*",
"*",
method="exact",
rows=np.arange(self.N_turbines),
cols=np.arange(self.N_turbines),
)

def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
"""Computation for the OpenMDAO component."""

# unpack the working variables
x_turbines = inputs["x_turbines"]
y_turbines = inputs["y_turbines"]

boundary_distances = (
ard.utils.geometry.distance_multi_point_to_multi_polygon_ray_casting(
x_turbines,
y_turbines,
boundary_vertices=self.boundary_vertices,
regions=self.boundary_regions,
)
)

outputs["boundary_distances"] = boundary_distances

def compute_partials(self, inputs, partials, discrete_inputs=None):

# unpack the working variables
x_turbines = inputs["x_turbines"]
y_turbines = inputs["y_turbines"]

jacobian = self.distance_multi_point_to_multi_polygon_ray_casting_jac(
x_turbines, y_turbines, self.boundary_vertices, self.boundary_regions
)

partials["boundary_distances", "x_turbines"] = jacobian[0].diagonal()
partials["boundary_distances", "y_turbines"] = jacobian[1].diagonal()
Loading