Skip to content

Commit 4bbf5e2

Browse files
committed
Suggestive comments + mirror and addFairlead methods in project.py:
- should the node in famodel_base be three-dimensional? - the way the load function seems to create the fairlead dictionary seems erroneous. I suggested an alternative as a comment. This is how it is done in conceptDesign2. - the addFairlead updates the fairlead position and reflects the absolute location of fairlead positions 'fl.r' which can be helpful later. Especially when connecting to moorings. - Update to the function to make it work with the new base work with the shared lines.
1 parent 5d94109 commit 4bbf5e2

File tree

4 files changed

+64
-68
lines changed

4 files changed

+64
-68
lines changed

famodel/famodel_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, id):
9898
self.part_of = None # whether this object is part of an Edge group
9999

100100
# position/orientation variables
101-
self.r = np.zeros(2) # position [m]
101+
self.r = np.zeros(2) # position [m] <<< Rudy: Can we consider 3D here??
102102
self.theta = 0 # heading [rad] CCW+
103103
self.R = np.eye(2) # rotation matrix
104104

famodel/mooring/mooring.py

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -706,88 +706,78 @@ def positionSubcomponents(self):
706706
else:
707707
print('end of parallel')
708708
breakpoint()
709-
710-
def mirror(self,create_subsystem=True):
711-
''' Mirrors a half design dictionary. Useful for symmetrical shared mooring lines where
712-
only half of the line is provided
713709

714-
Parameters
715-
----------
716-
create_subsystem : bool, optional
717-
Controls whether to create a new subsystem after mirroring dd.
718-
Default is True
710+
def mirror(self, create_subsystem=True):
719711
'''
720-
# disconnect all sections and connectors
721-
# TODO: update to work with dd['subcomponents']
712+
Mirrors a half design to create a full line (symmetry assumption).
713+
Works with self.sections() and self.connectors() instead of self.dd.
714+
'''
715+
716+
# detach existing subcomponents
722717
for i in self.i_sec:
723718
sec = self.getSubcomponent(i)
724719
sec.detachFrom(end='a')
725720
sec.detachFrom(end='b')
726-
# find out if the connector at end A (center of line) is empty
727-
if not self.dd['connectors'][0] or self.dd['connectors'][0]['m']==0:
728-
# do not double the middle section length
729-
doubleL = True
721+
722+
# copy base sections and connectors
723+
sections = deepcopy(self.sections())
724+
connectors = deepcopy(self.connectors())
725+
726+
# check middle connector (connector[0] assumed at line center)
727+
if not connectors[0] or connectors[0].get('m', 0) == 0:
728+
doubleL = True # double the middle section length instead
730729
else:
731-
# double the middle section length
732-
doubleL = False
733-
from copy import deepcopy
734-
# sections list is currently reversed (second half of full list)
735-
addSections = deepcopy(self.dd['sections'])
736-
addConns = deepcopy(self.dd['connectors'])
737-
# reverse to get first half of full list
738-
self.dd['sections'].reverse()
739-
self.dd['connectors'].reverse()
740-
# combine middle mirrored sections into one by removing from add list and doubling length
730+
doubleL = False # double connector mass/volume instead
731+
732+
# prepare mirrored versions
733+
addSections = deepcopy(sections)
734+
addConns = deepcopy(connectors)
735+
736+
# handle the middle connector
741737
if doubleL:
742-
# remove mirror section and connector in middle, double length of middle section
738+
# drop first section + connector, double middle section length
743739
addSections.pop(0)
744740
addConns.pop(0)
745-
self.dd['connectors'].pop(-1)
746-
self.dd['sections'][-1]['L'] = self.dd['sections'][-1]['L']*2
741+
connectors.pop(0) # drop first original connector
742+
sections[0]['L'] *= 2
747743
else:
744+
# drop first mirrored connector, double last connector’s props
748745
addConns.pop(0)
749-
self.dd['connectors'][-1]['m'] *= 2
750-
self.dd['connectors'][-1]['v'] *= 2
746+
connectors[0]['m'] *= 2
747+
connectors[0]['v'] *= 2
751748

752-
753-
# combine addSections and current reversed sectiosn list
754-
self.dd['sections'].extend(addSections)
755-
self.dd['connectors'].extend(addConns)
749+
# reverse and extend lists
750+
sections.reverse()
751+
connectors.reverse()
752+
sections.extend(addSections)
753+
connectors.extend(addConns)
754+
755+
# update Mooring design dictionary with these sections and connectors
756756

757-
# create Section objects for ALL sections and connectors
758-
for i, sec in enumerate(self.dd['sections']):
759-
self.dd['sections'][i] = Section('Section'+str(i),**self.dd['sections'][i])
760-
761-
for i,con in enumerate(self.dd['connectors']):
762-
if con and 'type' in con:
763-
Cid=con['type']+str(i)
764-
else:
765-
Cid = 'Conn'+str(i)
766-
767-
self.dd['connectors'][i] = Connector(Cid,**self.dd['connectors'][i])
768-
769-
# Connect them and store them in self(Edge).subcomponents!
770-
subcons = [] # temporary list of node-edge-node... to pass to the function
771-
for i in range(len(self.dd['sections'])):
772-
subcons.append(self.dd['connectors'][i])
773-
subcons.append(self.dd['sections'][i])
774-
subcons.append(self.dd['connectors'][-1])
775-
self.addSubcomponents(subcons) # Edge method to connect and store em
776-
777-
self.n_sec = len(self.dd['sections'])
778-
# Indices of connectors and sections in self.subcomponents list
779-
self.i_con = list(range(0, 2*self.n_sec+1, 2))
780-
self.i_sec = list(range(1, 2*self.n_sec+1, 2))
781-
782757

783-
# creat subsystem if asked
758+
759+
# -----------------------------
760+
# build alternating subcomponent list
761+
# [C0, S0, C1, S1, ..., Sn, Cn+1], where n is the number of sections.
762+
# -----------------------------
763+
subs_list = []
764+
for i in range(len(sections)):
765+
subs_list.append(connectors[i])
766+
subs_list.append(sections[i])
767+
subs_list.append(connectors[-1])
768+
769+
# convert dicts into Section/Connector objects
770+
self.dd['subcomponents'] = subs_list
771+
self.subcomponents = []
772+
self.i_con = [] # reset indices
773+
self.i_sec = []
774+
self.convertSubcomponents(subs_list)
775+
self.addSubcomponents(self.dd['subcomponents'])
776+
# create subsystem if asked
784777
if create_subsystem:
785778
self.createSubsystem(case=1)
786779

787780

788-
789-
790-
791781
"""
792782
# rough method ideas...maybe not necessary or can use existing dict methods
793783
def ddApply():

famodel/project.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ def addFairlead(self, id=None, platform=None, r_rel=[0,0,0],
16671667
# attach subordinately to platform and provide relative location
16681668
if platform:
16691669
platform.attach(fl, r_rel=r_rel)
1670-
1670+
fl.r = platform.r + r_rel # absolute location
16711671
# attach equally to mooring end connector
16721672
if mooring:
16731673
if end in ['a','A',0]:
@@ -4282,8 +4282,14 @@ def unload(self,file='project.yaml'):
42824282
ts_loc = 0
42834283
msys = []
42844284
newms = True
4285-
fairleads = [att['r_rel'] for att in pf.attachments.values() if isinstance(att['obj'], Fairlead)]
4286-
jtubes = [att['r_rel'] for att in pf.attachments.values() if isinstance(att['obj'], Jtube)]
4285+
fairleads = [att['r_rel'] for att in pf.attachments.values() if isinstance(att['obj'], Fairlead)] # Rudy: this line is getting att['r_rel'] only. But in LoadDesign, it's looking for the 'heading' or 'r_rel' attribute of the fairlead. Therefore, I omitted '[r_rel']' here and passed the att object as a whole.
4286+
# Rudy: maybe consider this instead:
4287+
# pf_dd_['fairleads'] = [
4288+
# {'r_rel': att['r_rel']}
4289+
# for att in platform.attachments.values()
4290+
# if isinstance(att['obj'], Fairlead)
4291+
# ]
4292+
jtubes = [att['r_rel'] for att in pf.attachments.values() if isinstance(att['obj'], Jtube)] # Rudy: perhaps same here too???
42874293
if not 'type' in pf.dd:
42884294
pf_type_info = [pf.rFair, pf.zFair, pf.entity, fairleads, jtubes]
42894295
if not pf_type_info in pf_types:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
long_description = fh.read()
55

66
setuptools.setup(
7-
name="FAModel",
7+
name="famodel",
88
version="0.1.0",
99
author="National Renewable Energy Laboratory",
1010
author_email="matthew.hall@nrel.gov",

0 commit comments

Comments
 (0)