Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TopFarm2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TOPFARM
TopFarm2
Commits
993c0c91
Commit
993c0c91
authored
6 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
implemented openmdao methods for PolygonBoundaryComp and added caching of results
parent
78bbd85f
No related branches found
No related tags found
1 merge request
!94
Handle disabled mpi
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
topfarm/constraint_components/boundary_component.py
+39
-3
39 additions, 3 deletions
topfarm/constraint_components/boundary_component.py
topfarm/cost_models/fuga/Colonel
+1
-1
1 addition, 1 deletion
topfarm/cost_models/fuga/Colonel
topfarm/plotting.py
+17
-8
17 additions, 8 deletions
topfarm/plotting.py
with
57 additions
and
12 deletions
topfarm/constraint_components/boundary_component.py
+
39
−
3
View file @
993c0c91
...
...
@@ -190,8 +190,26 @@ class PolygonBoundaryComp(BoundaryComp):
self
.
dEdgeDist_dx
=
-
self
.
dy
/
self
.
length
self
.
dEdgeDist_dy
=
self
.
dx
/
self
.
length
self
.
_cache_input
=
None
self
.
_cache_output
=
None
def
calc_distance
(
self
,
x
,
y
):
def
setup
(
self
):
# Explicitly size input arrays
self
.
add_input
(
'
turbineX
'
,
np
.
zeros
(
self
.
nTurbines
),
units
=
'
m
'
,
desc
=
'
x coordinates of turbines in global ref. frame
'
)
self
.
add_input
(
'
turbineY
'
,
np
.
zeros
(
self
.
nTurbines
),
units
=
'
m
'
,
desc
=
'
y coordinates of turbines in global ref. frame
'
)
# Explicitly size output array
# (vector with positive elements if turbines outside of hull)
self
.
add_output
(
'
boundaryDistances
'
,
np
.
zeros
(
self
.
nTurbines
),
desc
=
"
signed perpendicular distance from each turbine to each face CCW; + is inside
"
)
self
.
declare_partials
(
'
boundaryDistances
'
,
[
'
turbineX
'
,
'
turbineY
'
])
#self.declare_partials('boundaryDistances', ['boundaryVertices', 'boundaryNormals'], method='fd')
def
calc_distance_and_gradients
(
self
,
x
,
y
):
"""
distance point(x,y) to edge((x1,y1)->(x2,y2))
+/-: inside/outside
...
...
@@ -205,7 +223,9 @@ class PolygonBoundaryComp(BoundaryComp):
ddist_dx = sign * 2*x-2*x1 / (2 * distance^.5)
ddist_dy = sign * 2*y-2*y1 / (2 * distance^.5)
"""
if
np
.
all
(
np
.
array
([
x
,
y
])
==
self
.
_cache_input
):
return
self
.
_cache_output
X
,
Y
=
[
np
.
tile
(
xy
,
(
len
(
self
.
x1
),
1
)).
T
for
xy
in
[
x
,
y
]]
# dim = (ntb, nEdges)
X1
,
Y1
,
X2
,
Y2
,
ddist_dX
,
ddist_dY
=
[
np
.
tile
(
xy
,
(
len
(
x
),
1
))
for
xy
in
[
self
.
x1
,
self
.
y1
,
self
.
x2
,
self
.
y2
,
self
.
dEdgeDist_dx
,
self
.
dEdgeDist_dy
]]
...
...
@@ -258,4 +278,20 @@ class PolygonBoundaryComp(BoundaryComp):
closest_edge_index
=
np
.
argmin
(
np
.
abs
(
distance
),
1
)
return
[
np
.
choose
(
closest_edge_index
,
v
.
T
)
for
v
in
[
distance
,
ddist_dX
,
ddist_dY
]]
self
.
_cache_input
=
np
.
array
([
x
,
y
])
self
.
_cache_output
=
[
np
.
choose
(
closest_edge_index
,
v
.
T
)
for
v
in
[
distance
,
ddist_dX
,
ddist_dY
]]
return
self
.
_cache_output
def
compute
(
self
,
inputs
,
outputs
):
turbineX
=
inputs
[
'
turbineX
'
]
turbineY
=
inputs
[
'
turbineY
'
]
outputs
[
'
boundaryDistances
'
]
=
self
.
calc_distance_and_gradients
(
turbineX
,
turbineY
)[
0
]
def
compute_partials
(
self
,
inputs
,
partials
):
turbineX
=
inputs
[
'
turbineX
'
]
turbineY
=
inputs
[
'
turbineY
'
]
_
,
dx
,
dy
=
self
.
calc_distance_and_gradients
(
turbineX
,
turbineY
)
partials
[
'
boundaryDistances
'
,
'
turbineX
'
]
=
np
.
diagflat
(
dx
)
partials
[
'
boundaryDistances
'
,
'
turbineY
'
]
=
np
.
diagflat
(
dy
)
This diff is collapsed.
Click to expand it.
Colonel
@
63d550ac
Compare
b3d528b5
...
63d550ac
Subproject commit
b
3d5
28b5bddb5d62f4a6d9f476d7989f5d0f2ad7
Subproject commit
6
3d5
50ac397e2058fc278ecf1488323440a786fc
This diff is collapsed.
Click to expand it.
topfarm/plotting.py
+
17
−
8
View file @
993c0c91
...
...
@@ -21,9 +21,6 @@ def mypause(interval):
class
PlotComp
(
ExplicitComponent
):
"""
Evaluates the equation f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3.
"""
colors
=
[
'
b
'
,
'
r
'
,
'
m
'
,
'
c
'
,
'
g
'
,
'
y
'
,
'
orange
'
,
'
indigo
'
,
'
grey
'
]
*
100
def
__init__
(
self
,
memory
=
10
,
delay
=
0.001
):
...
...
@@ -56,11 +53,6 @@ class PlotComp(ExplicitComponent):
plt
.
ylim
(
ylim
)
def
compute
(
self
,
inputs
,
outputs
):
"""
f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3
Optimal solution (minimum): x = 6.6667; y = -7.3333
"""
x
=
inputs
[
'
turbineX
'
]
y
=
inputs
[
'
turbineY
'
]
cost
=
inputs
[
'
cost
'
]
...
...
@@ -81,3 +73,20 @@ class PlotComp(ExplicitComponent):
mypause
(
self
.
delay
)
self
.
counter
+=
1
class
NoPlot
(
PlotComp
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
ExplicitComponent
.
__init__
(
self
)
def
show
(
self
):
pass
def
setup
(
self
):
self
.
add_input
(
'
turbineX
'
,
np
.
zeros
(
self
.
n_wt
),
units
=
'
m
'
)
self
.
add_input
(
'
turbineY
'
,
np
.
zeros
(
self
.
n_wt
),
units
=
'
m
'
)
self
.
add_input
(
'
cost
'
,
0.
)
self
.
add_input
(
'
boundary
'
,
np
.
zeros
((
self
.
n_vertices
,
2
)),
units
=
'
m
'
)
def
compute
(
self
,
inputs
,
outputs
):
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment