@@ -725,7 +725,6 @@ int CSlidingMesh::Build_3D_surface_element(const su2vector<unsigned long>& map,
725725
726726 constexpr unsigned short nDim = 3 ;
727727
728- int **OuterNodesNeighbour;
729728 const unsigned long *OuterNodes;
730729
731730 /* --- Store central node as element first point --- */
@@ -737,51 +736,42 @@ int CSlidingMesh::Build_3D_surface_element(const su2vector<unsigned long>& map,
737736
738737 OuterNodes = &map[ startIndex[centralNode] ];
739738
740- /* --- Allocate auxiliary structure, vectors are longer than needed but this avoid further re-allocations due to length variation --- */
741-
742- OuterNodesNeighbour = new int *[nOuterNodes];
743- for ( unsigned long iNode = 0 ; iNode < nOuterNodes; iNode++ )
744- OuterNodesNeighbour[ iNode ] = new int [2 ];
745-
746- /* --- Finds which and how many nodes belong to the specified marker, initialize some variables --- */
747-
748- for ( unsigned long iNode = 0 ; iNode < nOuterNodes; iNode++ ){
749- OuterNodesNeighbour[ iNode ][0 ] = -1 ;
750- OuterNodesNeighbour[ iNode ][1 ] = -1 ;
751- }
752-
753- /* --- For each outer node, the program finds the two neighbouring outer nodes --- */
754-
739+ // For each neighbor n of centralNode, store <=2 neighbors of centralNode that are neighbors of n.
740+ su2matrix<int > OuterNodesNeighbour (nOuterNodes,2 );
741+ OuterNodesNeighbour = -1 ;
742+ // Typically there are exactly 2 such neighbors, and all the neighbors of centralNode can be
743+ // arranged into a closed chain. However at 1D boundaries of 2D markers, the neighbors might
744+ // be an open chain, with the two ends having only 1 such neighbor.
745+ // StartNode is a node where we can start to iterate through the chain. I.e. it's any node in
746+ // case of a closed chain, or one of the two ends in case of an open chain.
755747 int StartNode = 0 ;
756748 for ( unsigned long iNode = 0 ; iNode < nOuterNodes; iNode++ ){
757749
758- int count = 0 ; // number of neighboring outer nodes already found
759- const unsigned long iPoint = OuterNodes[ iNode ];
760- const unsigned long *ptr = &map[ startIndex[iPoint] ];
761-
762- for ( unsigned long jNode = 0 ; jNode < nNeighbor[iPoint]; jNode++ ){
763- const unsigned long jPoint = ptr[jNode];
764- for ( unsigned long kNode = 0 ; kNode < nOuterNodes; kNode ++ ){
765- if ( jPoint == OuterNodes[ kNode ] && jPoint != centralNode){
766- OuterNodesNeighbour[iNode][count] = (int )kNode ;
767- count++;
768- break ;
750+ int count = 0 ; // number of neighboring outer nodes already found
751+ const unsigned long iPoint = OuterNodes[ iNode ];
752+ const unsigned long *ptr = &map[ startIndex[iPoint] ];
753+
754+ for ( unsigned long jNode = 0 ; jNode < nNeighbor[iPoint]; jNode++ ){
755+ const unsigned long jPoint = ptr[jNode];
756+ for ( unsigned long kNode = 0 ; kNode < nOuterNodes; kNode ++ ){
757+ if ( jPoint == OuterNodes[ kNode ] && jPoint != centralNode){
758+ OuterNodesNeighbour (iNode,count) = static_cast <int >(kNode );
759+ count++;
760+ break ;
761+ }
769762 }
770763 }
771- }
772-
773- // If the central node belongs to two different markers, ie at corners, makes this outer node the starting point for reconstructing the element
774- if ( count == 1 )
775- StartNode = (int )iNode;
764+ if ( count == 1 )
765+ StartNode = static_cast <int >(iNode);
776766 }
777767
778768 /* --- Build element, starts from one outer node and loops along the external edges until the element is reconstructed --- */
779769
780770 int CurrentNode = StartNode;
781- int NextNode = OuterNodesNeighbour[ CurrentNode ][ 0 ] ;
771+ int NextNode = OuterNodesNeighbour ( CurrentNode, 0 ) ;
782772 unsigned long iElementNode = 1 ;
783773
784- while ( NextNode != -1 ){
774+ while ( NextNode != -1 ){ // We finished iterating through the chain if it is an open chain and we reached the other end.
785775
786776 for (unsigned short iDim = 0 ; iDim < nDim; iDim++)
787777 element[ iElementNode ][iDim] = ( element[0 ][iDim] + coord (OuterNodes[ CurrentNode ], iDim) )/2 .;
@@ -793,36 +783,31 @@ int CSlidingMesh::Build_3D_surface_element(const su2vector<unsigned long>& map,
793783 coord (OuterNodes[ NextNode ], iDim) )/3 .;
794784 iElementNode++;
795785
796- if ( OuterNodesNeighbour[ NextNode ][0 ] == CurrentNode){
786+ // "Place the next domino piece in the correct orientation."
787+ if ( OuterNodesNeighbour (NextNode, 0 ) == CurrentNode){
797788 CurrentNode = NextNode;
798- NextNode = OuterNodesNeighbour[ NextNode ][1 ];
799- }
800- else {
789+ NextNode = OuterNodesNeighbour (NextNode, 1 );
790+ } else {
801791 CurrentNode = NextNode;
802- NextNode = OuterNodesNeighbour[ NextNode ][ 0 ] ;
792+ NextNode = OuterNodesNeighbour ( NextNode, 0 ) ;
803793 }
804794
795+ // We finished iterating through the chain if it is closed and we reached the beginning again.
805796 if (CurrentNode == StartNode)
806797 break ;
807- }
808-
809- if ( CurrentNode == StartNode ){ // This is a closed element, so add again element 1 to the end of the structure, useful later
798+ }
810799
800+ if ( CurrentNode == StartNode ){ // This is a closed element, so add again element 1 to the end of the structure, useful later
811801 for (unsigned short iDim = 0 ; iDim < nDim; iDim++)
812802 element[ iElementNode ][iDim] = element[1 ][iDim];
813803 iElementNode++;
814- }
815- else {
804+ } else {
816805 for (unsigned short iDim = 0 ; iDim < nDim; iDim++)
817- element[ iElementNode ][iDim] = ( element[0 ][iDim] + coord (OuterNodes[ CurrentNode ], iDim) )/2 .;
806+ element[ iElementNode ][iDim] = ( element[0 ][iDim] + coord (OuterNodes[ CurrentNode ], iDim) )/2 .;
818807 iElementNode++;
819808 }
820809
821- for ( unsigned long iNode = 0 ; iNode < nOuterNodes; iNode++ )
822- delete [] OuterNodesNeighbour[ iNode ];
823- delete [] OuterNodesNeighbour;
824-
825- return (int )iElementNode;
810+ return static_cast <int >(iElementNode);
826811
827812}
828813
0 commit comments