@@ -682,10 +682,11 @@ def positionSubcomponents(self):
682682
683683 # Tabulate the section lengths
684684 L = []
685-
686685 n_serial_nodes = 0 # number of serial nodes, including first and last
687686
688- # First pass, going through each section in series to figure out lengths
687+ # ----- First pass, going through each section in series -----
688+
689+ # Figure out lengths
689690 for item in self .subcomponents :
690691
691692 if isinstance (item , list ): # indicates there are parallel sections here
@@ -712,32 +713,78 @@ def positionSubcomponents(self):
712713
713714 # Position nodes along main serial string between rA and rB
714715 Lsum = np .cumsum (np .array (L ))
715- i = 0 # index of node along serial string (at A is 0)
716+ j = 0 # index of node along serial string (at A is 0)
716717
717- for item in self .subcomponents :
718+ for i , item in enumerate ( self .subcomponents ) :
718719 if isinstance (item , list ) or isinstance (item , Edge ):
719- i = i + 1 # note that we're moving a certain length along the string
720- print (i )
720+ j = j + 1 # note that we're moving a certain length along the string
721721
722- # if it's a node, but no the first or last one
723- elif isinstance (item , Node ) and i > 0 and i < n_serial_nodes - 1 :
724- r = self .rA + (self .rB - self .rA )* Lsum [i ]/ Lsum [- 1 ]
722+ # if it's a node, but not the first or last one
723+ elif isinstance (item , Node ) and i > 0 and i < len ( self . subcomponents ) - 1 :
724+ r = self .rA + (self .rB - self .rA )* Lsum [j ]/ Lsum [- 1 ]
725725 item .setPosition (r )
726- print (f'Set position of Node { i } to { r [0 ]:5.0f} , { r [1 ]:5.0f} , { r [2 ]:5.0f} ' )
726+ print (f'Set position of subcom { i } to { r [0 ]:5.0f} , { r [1 ]:5.0f} , { r [2 ]:5.0f} ' )
727727
728728
729729
730- # Second pass, to position any nodes that are along parallel sections
731- '''
732- for i in range(n):
733- TODO
734- if isinstance(items[i], list): # indicates there are parallel sections here
735- subL = []
736- for subitem in items[i]: # go through each parallel subitem
737- '''
738-
739-
730+ # ----- Second pass, to position any nodes that are along parallel sections -----
731+ for i , item in enumerate (self .subcomponents ):
732+
733+ if isinstance (item , list ): # indicates there are parallel sections here
734+ for j , parallel in enumerate (item ): # go through each parallel string
735+
736+ # --- go through each item along the parallel path ---
737+ # Note: this part repeats some logic, could be replaced with recursive fn
738+ L = []
739+ n_serial_nodes = 0
740+
741+ for subitem in parallel :
742+ if isinstance (item , Node ):
743+ n_serial_nodes += 1
744+
745+ elif isinstance (subitem , Edge ):
746+ L .append (subitem ['L' ]) # save length of section
740747
748+ # --- Figure out the end points of this paralle string ---
749+
750+ # if this parallel is on the first section, then it's a bridle at A
751+ if i == 0 :
752+ if isinstance (parallel [0 ], Edge ): # if first object is an Edge
753+ rA = parallel [0 ].rA
754+ else :
755+ rA = parallel [0 ].r
756+ else :
757+ rA = self .subcomponents [i - 1 ].r
758+
759+ # if this parallel is on the last section, then it's a bridle at B
760+ if i == len (self .subcomponents )- 1 :
761+ if isinstance (parallel [- 1 ], Edge ): # if last object is an Edge
762+ rB = parallel [- 1 ].rB
763+ else :
764+ rB = parallel [- 1 ].r
765+ else :
766+ rB = self .subcomponents [i + 1 ].r
767+
768+ # --- Do the positioning ---
769+ Lsum = np .cumsum (np .array (L ))
770+ print (f'parallel string ends A and B are at' )
771+ print (f'{ rA [0 ]:5.0f} , { rA [1 ]:5.0f} , { rA [2 ]:5.0f} ' )
772+ print (f'{ rB [0 ]:5.0f} , { rB [1 ]:5.0f} , { rB [2 ]:5.0f} ' )
773+
774+ for subitem in parallel :
775+ if isinstance (subitem , Edge ):
776+ j = j + 1 # note that we're moving a certain length along the string
777+
778+ # if it's a node, but not the first or last one
779+ elif isinstance (item , Node ):
780+ if j > 0 and j < n_serial_nodes - 1 :
781+ r = rA + (rB - rA )* Lsum [j ]/ Lsum [- 1 ]
782+ item .setPosition (r )
783+ print (f'Set position of Node { j } to { r [0 ]:5.0f} , { r [1 ]:5.0f} , { r [2 ]:5.0f} ' )
784+ else :
785+ print ('end of parallel' )
786+ breakpoint ()
787+ print ('yep' )
741788
742789 def mirror (self ,create_subsystem = True ):
743790 ''' Mirrors a half design dictionary. Useful for symmetrical shared mooring lines where
0 commit comments