Skip to content

Commit fe178a7

Browse files
committed
addCablesConnections bug fix, helpers bug fix, connectors pointProps adjust
-- bug fix project.addCablesConnections for calculating cable headings to adjust to updated methods -- helpers head_adjust adjust to keep headings in compass headings -- connectors adjust cost function use of pointProps (bug fix) -- add images for readmes -- add some comments in cable.py
1 parent 27085a5 commit fe178a7

File tree

6 files changed

+55
-19
lines changed

6 files changed

+55
-19
lines changed

famodel/cables/cable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ def reposition(self,headings=None,project=None,rad_fair=[]):
139139
'''
140140
# reposition cable and set end points for the first and last cable sections (or the dynamic cable for a suspended cable)
141141
if not headings:
142+
# convert headings to unit circle
142143
headingA = np.pi/2 - self.subcomponents[0].headingA
143144
headingB = np.pi/2 - self.subcomponents[-1].headingB
144145
else:
146+
# convert headings to unit circle
145147
headingA = np.pi/2 - headings[0]
148+
self.subcomponents[0].headingA = headings[0]
146149
headingB = np.pi/2 - headings[1]
150+
self.subcomponents[-1].headingB = headings[1]
147151

148152
if not isinstance(self.subcomponents[0].attached_to[0], Jtube):
149153
if not rad_fair:

famodel/helpers.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import moorpy as mp
1111
from moorpy.helpers import loadPointProps, getPointProps
1212
import shapely as sh
13+
from famodel.turbine.turbine import Turbine
1314

1415

1516
def cart2pol(x, y):
@@ -232,7 +233,7 @@ def head_adjust(att,heading,rad_buff=np.radians(30),endA_dir=1):
232233
att : list
233234
list of objects to attach to. 1 object if only concerned about the attached object associated with that side
234235
heading : float
235-
Cable heading at attachment to att in radians
236+
Cable compass heading at attachment to att in radians
236237
rad_buff : float
237238
Buffer angle in radians
238239
endA_dir : float, optional
@@ -249,7 +250,7 @@ def head_adjust(att,heading,rad_buff=np.radians(30),endA_dir=1):
249250
headnew = np.pi*2 + heading
250251
else:
251252
headnew = heading
252-
attheadings = []
253+
attheadings = [] # complete list of mooring headings to avoid, from all platforms
253254
flipheads = False # whether to flip headings ( for if you are looking at mooring headings of platform on the other end)
254255
for at in att:
255256
mhs = np.radians([m.heading for m in at.getMoorings().values()])
@@ -260,10 +261,11 @@ def head_adjust(att,heading,rad_buff=np.radians(30),endA_dir=1):
260261
if a>2*np.pi:
261262
atmh[j] = a-2*np.pi
262263
else:
263-
atmh = np.array(mhs) #at.mooring_headings + at.phi
264+
atmh = np.array(mhs) #attached platform mooring headings array
264265
#attheadings.extend(atmh)
265-
attheadings.extend(np.pi/2 - atmh) # convert to 0 rad at East going CCW
266+
attheadings.extend(atmh) # keep in compass heading
266267
flipheads = True
268+
267269
interfere_h = check_headings(attheadings,headnew,rad_buff)
268270
# if the headings interfere, adjust them by angle buffer
269271
for mhead in interfere_h:
@@ -1307,6 +1309,25 @@ def gothroughlist(dat):
13071309
# return cleaned dictionary
13081310
return(info)
13091311

1312+
'''
1313+
def createRAFTDict(project):
1314+
# Create a RAFT dictionary from a project class to create RAFT model
1315+
rd = {'keys':['ID', 'turbineID', 'platformID', 'mooringID', 'x_location', 'y_location'],
1316+
'data':[]}
1317+
for pf in project.platformList.values():
1318+
for att in pf.attachments.values():
1319+
if isinstance(att['obj'],Turbine):
1320+
turb = att['obj']
1321+
break
1322+
rd.append(pf.id, turb.dd['type'], pf.dd['type'], 0, pf.r[0], pf.r[1])
1323+
rd['site'] = {'water_depth':project.depth,'rho_water':project.rho_water,'rho_air':project.rho_air,'mu_air':project.mu_air}
1324+
rd['site']['shearExp'] = .12
1325+
1326+
for tt in project.turbineType
1327+
1328+
return rd
1329+
'''
1330+
13101331
def getFromDict(dict, key, shape=0, dtype=float, default=None, index=None):
13111332
'''
13121333
Function to streamline getting values from design dictionary from YAML file, including error checking.
24 KB
Loading
58.2 KB
Loading

famodel/mooring/connector.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ def getProps(self):
100100
if self['CdA']>0:
101101
details['CdA'] = self['CdA']
102102
if self.mpConn:
103+
# add point type to system and assign to point entity if mp connector point exists
103104
pt = self.mpConn.sys.setPointType(design,**details)
105+
self.mpConn.entity = pt
104106
else:
107+
# otherwise, jsut get the point properties dict and return
105108
props = loadPointProps(None)
106109
pt = getPointProps(design, Props=props, **details)
107110
self.required_safety_factor = pt['FOS']
@@ -115,13 +118,21 @@ def getCost(self,update=True, fx=0.0, fz=0.0, peak_tension=None, MBL=None):
115118
'''Get cost of the connector from MoorPy pointProps.
116119
Wrapper for moorpy's getCost_and_MBL helper function'''
117120
if update:
118-
if self.mpConn:
119-
# use pointProps to update cost
120-
try:
121-
self.getProps()
122-
self.cost['materials'], MBL, info = self.mpConn.getCost_and_MBL(fx=fx, fz=fz, peak_tension=peak_tension)
123-
except:
124-
print('Warning: unable to find cost from MoorPy pointProps, cost dictionary not updated')
121+
# use pointProps to update cost
122+
try:
123+
# get point properties from wrapper function
124+
ptype = self.getProps()
125+
if self.mpConn:
126+
point = self.mpConn
127+
else:
128+
from moorpy import System
129+
ms = System() # create a blank moorpy system
130+
point = ms.addPoint(0, r=[0,0]) # add a dummy point
131+
point.entity = ptype # get the point properties and assign to point entity
132+
# calculate cost with any given forces/tensions
133+
self.cost['materials'], MBL, info = point.getCost_and_MBL(fx=fx, fz=fz, peak_tension=peak_tension)
134+
except:
135+
print('Warning: unable to find cost from MoorPy pointProps, cost dictionary not updated')
125136
# if update == False, just return existing costs
126137

127138
return sum(self.cost.values())

famodel/project.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,12 +2026,11 @@ def addCablesConnections(self,connDict,cableType_def='dynamic_cable_66',oss=Fals
20262026
attB = pf
20272027
# update platform location
20282028
pf.r[:2] = connDict[i]['coordinates'][-1]
2029-
2030-
# get heading of cable from attached object coordinates
2031-
headingA = np.radians(90) - np.arctan2((connDict[i]['coordinates'][-1][0]-connDict[i]['coordinates'][0][0]),
2032-
(connDict[i]['coordinates'][-1][1]-connDict[i]['coordinates'][0][1]))
2033-
headingB = np.radians(90) - np.arctan2((connDict[i]['coordinates'][0][0]-connDict[i]['coordinates'][-1][0]),
2034-
(connDict[i]['coordinates'][0][1]-connDict[i]['coordinates'][-1][1]))
2029+
2030+
# get heading of cable from attached object coordinates (compass heading)
2031+
headingA = calc_heading(connDict[i]['coordinates'][-1],
2032+
connDict[i]['coordinates'][0])
2033+
headingB = headingA + np.pi
20352034

20362035
# figure out approx. depth at location
20372036
initial_depths = []
@@ -2127,8 +2126,8 @@ def addCablesConnections(self,connDict,cableType_def='dynamic_cable_66',oss=Fals
21272126
stat_cable = cab.subcomponents[ind+ind_of_stat]
21282127
# get new coordinate routing point
21292128
stat_cable_end = stat_cable.rA if ind==0 else stat_cable.rB
2130-
coord = [stat_cable_end[0] + np.cos(heads[ii])*spandiff,
2131-
stat_cable_end[1] + np.sin(heads[ii])*spandiff]
2129+
coord = [stat_cable_end[0] + np.cos(np.pi/2-heads[ii])*spandiff,
2130+
stat_cable_end[1] + np.sin(np.pi/2-heads[ii])*spandiff]
21322131
# append it to static cable object coordinates
21332132
coords.append(coord)
21342133

@@ -3202,6 +3201,7 @@ def getRAFT(self,RAFTDict,pristine=1):
32023201
See RAFT documentation for requirements for each sub-dictionary
32033202
'''
32043203
print('Creating RAFT object')
3204+
32053205
# create RAFT model if necessary components exist
32063206
if 'platforms' in RAFTDict or 'platform' in RAFTDict:
32073207
# set up a dictionary with keys as the table names for each row (ease of use later)

0 commit comments

Comments
 (0)