Loading Grid3DAdaptive.h +4 −15 Original line number Diff line number Diff line Loading @@ -82,7 +82,6 @@ class GridA< 3, Real, Device, Index > { public: typedef Real RealType; // For VTK writer typedef Device DeviceType; typedef Index GlobalIndexTyppe; typedef Containers::StaticVector< 3, Real > PointType; typedef Containers::StaticVector< 3, Index > CoordinatesType; Loading @@ -97,7 +96,7 @@ public: */ typedef std::vector< std::vector< short int > > DirectionsArray; using GlobalIndexType = Index; using GlobalIndexType = Index; // For VTK writer /* Adjacency matrix that holds the information about the adjacency of cells */ Loading Loading @@ -170,6 +169,7 @@ public: /* Adaptive grid methods */ /* TODO: is it useful? */ void appendElement( const AdaptiveCell< Index, Index, Index >& cellToAppend ); Loading Loading @@ -204,17 +204,15 @@ public: /* TODO: move this out of public space after the debug getCoordinatesOnBasicGridphase */ std::vector<Index> getAdjacentCellsUlt( Index cell ); void getAdjacentCellsAtConstLevel( Index cell ); /* Methods for generating the temporary adjacency matrix (std::vector) */ /* Works for non-refined grids! */ void calculateAdjacencyMatrix( int mode ); void calculateComponentAdjacencyMatrix(); std::unordered_map< Index, std::vector< Index > > getFinerVirtualIndices() const; std::unordered_map< Index, std::vector< Index > > getCoarserVirtualIndices() const; Loading Loading @@ -275,15 +273,6 @@ private: std::vector< AdaptiveCell< Index, Index, Index > > getParentCells( const AdaptiveCell< Index, Index, Index >& baseCell ) const; /* This method works only for getting next level cels adjacent on the left * side of a cell. It needs to be modified to accomodate all needs. */ std::vector< AdaptiveCell< Index, Index, Index > > getFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, Index levelsToGen, int direction ) const; /* A method that finds finer cells */ std::vector< AdaptiveCell< Index, Index, Index > > getFourFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, int direction ) const; /* NOTE: rewrite the following functions using typedefs, I often use * std::vector<Index> instead of IndexArray etc. this is good for now, as it * improves readabiliy. */ Loading Grid3DAdaptive_impl.h +0 −262 Original line number Diff line number Diff line Loading @@ -691,177 +691,6 @@ GridA< 3, Real, Device, Index >::getParentCells( const AdaptiveCell< Index, Inde return returnVector; } /* Generates cells that represent finer levels of refinement of adjacent cells. */ /* All of the finer cells recovered are non-virtual */ template< typename Real, typename Device, typename Index > std::vector< AdaptiveCell< Index, Index, Index > > GridA< 3, Real, Device, Index >::getFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, Index levelsToGen, int direction ) const { /* The structure that is to be returned is set up, with sufficient memory */ std::vector< AdaptiveCell< Index, Index, Index > > returnVector; returnVector.reserve( pow( pow( 2, levelsToGen ), 2 ) + 1 ); /* The theoretical adjacent cell is appended first */ /* All cells are non-virtual by default */ returnVector.push_back( baseCell ); if( baseCell.meshPos != -1 ) { Index offset = 0; for( Index i = 1; i <= levelsToGen; i++ ) { Index sizeNow = (Index) returnVector.size(); for( Index j = offset; j < sizeNow; j++ ) { std::vector< AdaptiveCell< Index, Index, Index > > fourCells; fourCells.reserve( 4 ); fourCells = getFourFinerCells( returnVector[ j ], direction ); /* Inserts the two cells at the end of of the returnVector */ returnVector.insert( returnVector.end(), fourCells.begin(), fourCells.end() ); } offset += pow( pow( 2, ( i - 1 ) ), 2 ); } /* "parent cells" also need to be added to the array */ std::vector< AdaptiveCell< Index, Index, Index > > parentCells = getParentCells( baseCell ); returnVector.insert( returnVector.end(), parentCells.begin(), parentCells.end() ); } else { returnVector[ 0 ].refinementPos = -1; returnVector[ 0 ].levelOfRef = -1; } /* make sure all the cells in the return vector are NON-VIRTUAL! */ for( Index i = 0; i < (Index) returnVector.size(); i++ ) { returnVector[ i ].setCellVirtual( 0 ); } return returnVector; } /* */ template< typename Real, typename Device, typename Index > std::vector< AdaptiveCell< Index, Index, Index > > GridA< 3, Real, Device, Index >::getFourFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, int direction ) const { /* Set up the vector that will hold the cells to be returned by the method. */ std::vector< AdaptiveCell< Index, Index, Index > > returnVector; returnVector.reserve( 4 ); Index const bitChain = baseCell.refinementPos; /* We create and define the adaptive cell to be returned */ AdaptiveCell< Index, Index, Index > adaptiveCell( baseCell.meshPos, baseCell.levelOfRef + 1 ); /* We toggle bits dependent of the refinement level and the direction. */ /* Two finer cells are created */ /* NOTE: this method will also have to be refactored to not feature so much * repetetive code */ /* HERE THE DIRECTION IS THE INWARDS POINTING ARROW */ if( direction == X_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 3 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 5 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == X_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 6 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Y_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 3 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 6 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Y_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 5 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Z_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 5 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 6 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Z_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 3 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } return returnVector; } /* Method that sorts the grid using the custom sort criterion: * sortCritForCells(-) */ template< typename Real, typename Device, typename Index > Loading @@ -884,10 +713,6 @@ GridA< 3, Real, Device, Index >::calculateAdjacencyMatrix( int mode ) /* Build the rows of the matrix, then push them into the vector */ for( Index k = 0; k < this->getNumberOfCells(); k++ ) { if( 1 ) { std::cout << " generating adjacency matrix @ cell: " << k << " / " << this->getNumberOfCells() << std::endl; } getAdjacentCellsUlt( k ); /* adds the centre cell to the adjacency list & remap the direction = add Loading Loading @@ -2625,25 +2450,6 @@ GridA< 3, Real, Device, Index >::layerSortVirtualGrid() std::cout << "--------- LAYER SORT ENDED ------------- " << std::endl; } /* Adjacency matrix generation for virtual cells */ /* TODO: merge this methods with the regular adjacency matrix generation */ template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::calculateComponentAdjacencyMatrix() { buildAdjacencyExportRemap(); /* Build the rows of the matrix, then push them into the vector */ for( Index k = 0; k < this->getNumberOfCellsWithVirtual(); k++ ) { getAdjacentCellsAtConstLevel( k ); /* adds the centre cell to the adjacency list & remap the direction = add * extra data */ addCentreCellToAdjacencyList( k ); remapDirections(); } } template< typename Real, typename Device, typename Index > std::unordered_map< Index, std::vector< Index > > GridA< 3, Real, Device, Index >::getFinerVirtualIndices() const Loading @@ -2658,53 +2464,6 @@ GridA< 3, Real, Device, Index >::getCoarserVirtualIndices() const return linkToCoarseVirtuals; } /* method used to get cells on virtualized grid - using the structures that * separate refinement levels */ template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::getAdjacentCellsAtConstLevel( Index cell ) { adjacentCellIndicesAllDirections.clear(); directionsOfAdjacentCellsFlat.clear(); AdaptiveCell< Index, Index, Index > centreCell = gridCellsWithVirtual[ cell ]; /* decide which memory map to use - each corresponds to a partiuclar * refinement level */ MemoryMap* memoryMapInUse = NULL; if( centreCell.levelOfRef == 0 ) { memoryMapInUse = &level0MemoryMap; } else if( centreCell.levelOfRef == 1 ) { memoryMapInUse = &level1MemoryMap; } /* !!! NEXT: delete unwanted sections & check all the cells that I have * listed! */ /* Loop all directions */ for( int d = 0; d < 26; d++ ) { /* construct same level adjacent cell */ AdaptiveCell< Index, Index, Index > virtualAdjacentCell = getVirtualAdjacentCell( centreCell, d ); /* find the coarse cell index, where the cell lies */ Index coarseCellIndexAdjacentCell = virtualAdjacentCell.meshPos; /* do not do anything if the cells is on the border */ if( coarseCellIndexAdjacentCell > -1 ) { /* case 1: check if we can find the virtual cell directly */ for( size_t a = 0; a < ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ].size(); a++ ) { if( cellIsTheSame( gridCellsWithVirtual[ ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ], virtualAdjacentCell ) ) { adjacentCellIndicesAllDirections.push_back( ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ); directionsOfAdjacentCellsFlat.push_back( d ); } } } } } template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::recalculateMemoryMapsByLayer() Loading @@ -2729,27 +2488,6 @@ GridA< 3, Real, Device, Index >::recalculateMemoryMapsByLayer() level1MemoryMap[ coarseIndex ].push_back( w ); } } /* DEBUG - check purity */ for( size_t w = 0; w < level0MemoryMap.size(); w++ ) { for( size_t d = 0; d < level0MemoryMap[ w ].size(); d++ ) { if( gridCellsWithVirtual[ level0MemoryMap[ w ][ d ] ].levelOfRef != 0 ) { std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! level0MemoryMap " "corrupted! " << std::endl; } } } for( size_t w = 0; w < level1MemoryMap.size(); w++ ) { for( size_t d = 0; d < level1MemoryMap[ w ].size(); d++ ) { if( gridCellsWithVirtual[ level1MemoryMap[ w ][ d ] ].levelOfRef != 1 ) { std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! level1MemoryMap " "corrupted! " << std::endl; } } } } /* remaps directions for adjacency matrix export - adds directions for export */ Loading LBM.h +3 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ private: std::vector< Index > flaggedForOutflow; std::vector< Index > nonAdjacentCellsDirections; /* TODO: remove after debug */ void getAdjacentCellsAtConstLevel( Index cell ); std::vector< Index > getCoordinatesOnBasicGrid( Index meshPosition ) const; Loading LBM_impl.h +47 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,53 @@ namespace TNL { namespace Meshes { /* method used to get cells on virtualized grid - using the structures that * separate refinement levels */ template< typename Real, typename Device, typename Index > void LBM<Real, Device, Index >::getAdjacentCellsAtConstLevel( Index cell ) { adjacentCellIndicesAllDirections.clear(); directionsOfAdjacentCellsFlat.clear(); AdaptiveCell< Index, Index, Index > centreCell = gridCellsWithVirtual[ cell ]; /* decide which memory map to use - each corresponds to a partiuclar * refinement level */ MemoryMap* memoryMapInUse = NULL; if( centreCell.levelOfRef == 0 ) { memoryMapInUse = &level0MemoryMap; } else if( centreCell.levelOfRef == 1 ) { memoryMapInUse = &level1MemoryMap; } /* !!! NEXT: delete unwanted sections & check all the cells that I have * listed! */ /* Loop all directions */ for( int d = 0; d < 26; d++ ) { /* construct same level adjacent cell */ AdaptiveCell< Index, Index, Index > virtualAdjacentCell = getVirtualAdjacentCell( centreCell, d ); /* find the coarse cell index, where the cell lies */ Index coarseCellIndexAdjacentCell = virtualAdjacentCell.meshPos; /* do not do anything if the cells is on the border */ if( coarseCellIndexAdjacentCell > -1 ) { /* case 1: check if we can find the virtual cell directly */ for( size_t a = 0; a < ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ].size(); a++ ) { if( cellIsTheSame( gridCellsWithVirtual[ ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ], virtualAdjacentCell ) ) { adjacentCellIndicesAllDirections.push_back( ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ); directionsOfAdjacentCellsFlat.push_back( d ); } } } } } template< typename Real, typename Device, typename Index > std::vector< Index > LBM<Real, Device, Index >::getCoordinatesOnBasicGrid( Index meshPosition ) const Loading Loading
Grid3DAdaptive.h +4 −15 Original line number Diff line number Diff line Loading @@ -82,7 +82,6 @@ class GridA< 3, Real, Device, Index > { public: typedef Real RealType; // For VTK writer typedef Device DeviceType; typedef Index GlobalIndexTyppe; typedef Containers::StaticVector< 3, Real > PointType; typedef Containers::StaticVector< 3, Index > CoordinatesType; Loading @@ -97,7 +96,7 @@ public: */ typedef std::vector< std::vector< short int > > DirectionsArray; using GlobalIndexType = Index; using GlobalIndexType = Index; // For VTK writer /* Adjacency matrix that holds the information about the adjacency of cells */ Loading Loading @@ -170,6 +169,7 @@ public: /* Adaptive grid methods */ /* TODO: is it useful? */ void appendElement( const AdaptiveCell< Index, Index, Index >& cellToAppend ); Loading Loading @@ -204,17 +204,15 @@ public: /* TODO: move this out of public space after the debug getCoordinatesOnBasicGridphase */ std::vector<Index> getAdjacentCellsUlt( Index cell ); void getAdjacentCellsAtConstLevel( Index cell ); /* Methods for generating the temporary adjacency matrix (std::vector) */ /* Works for non-refined grids! */ void calculateAdjacencyMatrix( int mode ); void calculateComponentAdjacencyMatrix(); std::unordered_map< Index, std::vector< Index > > getFinerVirtualIndices() const; std::unordered_map< Index, std::vector< Index > > getCoarserVirtualIndices() const; Loading Loading @@ -275,15 +273,6 @@ private: std::vector< AdaptiveCell< Index, Index, Index > > getParentCells( const AdaptiveCell< Index, Index, Index >& baseCell ) const; /* This method works only for getting next level cels adjacent on the left * side of a cell. It needs to be modified to accomodate all needs. */ std::vector< AdaptiveCell< Index, Index, Index > > getFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, Index levelsToGen, int direction ) const; /* A method that finds finer cells */ std::vector< AdaptiveCell< Index, Index, Index > > getFourFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, int direction ) const; /* NOTE: rewrite the following functions using typedefs, I often use * std::vector<Index> instead of IndexArray etc. this is good for now, as it * improves readabiliy. */ Loading
Grid3DAdaptive_impl.h +0 −262 Original line number Diff line number Diff line Loading @@ -691,177 +691,6 @@ GridA< 3, Real, Device, Index >::getParentCells( const AdaptiveCell< Index, Inde return returnVector; } /* Generates cells that represent finer levels of refinement of adjacent cells. */ /* All of the finer cells recovered are non-virtual */ template< typename Real, typename Device, typename Index > std::vector< AdaptiveCell< Index, Index, Index > > GridA< 3, Real, Device, Index >::getFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, Index levelsToGen, int direction ) const { /* The structure that is to be returned is set up, with sufficient memory */ std::vector< AdaptiveCell< Index, Index, Index > > returnVector; returnVector.reserve( pow( pow( 2, levelsToGen ), 2 ) + 1 ); /* The theoretical adjacent cell is appended first */ /* All cells are non-virtual by default */ returnVector.push_back( baseCell ); if( baseCell.meshPos != -1 ) { Index offset = 0; for( Index i = 1; i <= levelsToGen; i++ ) { Index sizeNow = (Index) returnVector.size(); for( Index j = offset; j < sizeNow; j++ ) { std::vector< AdaptiveCell< Index, Index, Index > > fourCells; fourCells.reserve( 4 ); fourCells = getFourFinerCells( returnVector[ j ], direction ); /* Inserts the two cells at the end of of the returnVector */ returnVector.insert( returnVector.end(), fourCells.begin(), fourCells.end() ); } offset += pow( pow( 2, ( i - 1 ) ), 2 ); } /* "parent cells" also need to be added to the array */ std::vector< AdaptiveCell< Index, Index, Index > > parentCells = getParentCells( baseCell ); returnVector.insert( returnVector.end(), parentCells.begin(), parentCells.end() ); } else { returnVector[ 0 ].refinementPos = -1; returnVector[ 0 ].levelOfRef = -1; } /* make sure all the cells in the return vector are NON-VIRTUAL! */ for( Index i = 0; i < (Index) returnVector.size(); i++ ) { returnVector[ i ].setCellVirtual( 0 ); } return returnVector; } /* */ template< typename Real, typename Device, typename Index > std::vector< AdaptiveCell< Index, Index, Index > > GridA< 3, Real, Device, Index >::getFourFinerCells( const AdaptiveCell< Index, Index, Index >& baseCell, int direction ) const { /* Set up the vector that will hold the cells to be returned by the method. */ std::vector< AdaptiveCell< Index, Index, Index > > returnVector; returnVector.reserve( 4 ); Index const bitChain = baseCell.refinementPos; /* We create and define the adaptive cell to be returned */ AdaptiveCell< Index, Index, Index > adaptiveCell( baseCell.meshPos, baseCell.levelOfRef + 1 ); /* We toggle bits dependent of the refinement level and the direction. */ /* Two finer cells are created */ /* NOTE: this method will also have to be refactored to not feature so much * repetetive code */ /* HERE THE DIRECTION IS THE INWARDS POINTING ARROW */ if( direction == X_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 3 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 5 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == X_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 6 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Y_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 3 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 6 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Y_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 5 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Z_NEGATIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 4 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 5 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 6 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 7 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } else if( direction == Z_POSITIVE ) { std::vector< Index > chainsToAppend; chainsToAppend.reserve( 4 ); chainsToAppend[ 0 ] = ( 0 << 3 * baseCell.levelOfRef ); chainsToAppend[ 1 ] = ( 1 << 3 * baseCell.levelOfRef ); chainsToAppend[ 2 ] = ( 2 << 3 * baseCell.levelOfRef ); chainsToAppend[ 3 ] = ( 3 << 3 * baseCell.levelOfRef ); for( int k = 0; k < 4; k++ ) { Index bitChainToAppend; bitChainToAppend = ( bitChain | chainsToAppend[ k ] ); adaptiveCell.refinementPos = bitChainToAppend; returnVector.push_back( adaptiveCell ); } } return returnVector; } /* Method that sorts the grid using the custom sort criterion: * sortCritForCells(-) */ template< typename Real, typename Device, typename Index > Loading @@ -884,10 +713,6 @@ GridA< 3, Real, Device, Index >::calculateAdjacencyMatrix( int mode ) /* Build the rows of the matrix, then push them into the vector */ for( Index k = 0; k < this->getNumberOfCells(); k++ ) { if( 1 ) { std::cout << " generating adjacency matrix @ cell: " << k << " / " << this->getNumberOfCells() << std::endl; } getAdjacentCellsUlt( k ); /* adds the centre cell to the adjacency list & remap the direction = add Loading Loading @@ -2625,25 +2450,6 @@ GridA< 3, Real, Device, Index >::layerSortVirtualGrid() std::cout << "--------- LAYER SORT ENDED ------------- " << std::endl; } /* Adjacency matrix generation for virtual cells */ /* TODO: merge this methods with the regular adjacency matrix generation */ template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::calculateComponentAdjacencyMatrix() { buildAdjacencyExportRemap(); /* Build the rows of the matrix, then push them into the vector */ for( Index k = 0; k < this->getNumberOfCellsWithVirtual(); k++ ) { getAdjacentCellsAtConstLevel( k ); /* adds the centre cell to the adjacency list & remap the direction = add * extra data */ addCentreCellToAdjacencyList( k ); remapDirections(); } } template< typename Real, typename Device, typename Index > std::unordered_map< Index, std::vector< Index > > GridA< 3, Real, Device, Index >::getFinerVirtualIndices() const Loading @@ -2658,53 +2464,6 @@ GridA< 3, Real, Device, Index >::getCoarserVirtualIndices() const return linkToCoarseVirtuals; } /* method used to get cells on virtualized grid - using the structures that * separate refinement levels */ template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::getAdjacentCellsAtConstLevel( Index cell ) { adjacentCellIndicesAllDirections.clear(); directionsOfAdjacentCellsFlat.clear(); AdaptiveCell< Index, Index, Index > centreCell = gridCellsWithVirtual[ cell ]; /* decide which memory map to use - each corresponds to a partiuclar * refinement level */ MemoryMap* memoryMapInUse = NULL; if( centreCell.levelOfRef == 0 ) { memoryMapInUse = &level0MemoryMap; } else if( centreCell.levelOfRef == 1 ) { memoryMapInUse = &level1MemoryMap; } /* !!! NEXT: delete unwanted sections & check all the cells that I have * listed! */ /* Loop all directions */ for( int d = 0; d < 26; d++ ) { /* construct same level adjacent cell */ AdaptiveCell< Index, Index, Index > virtualAdjacentCell = getVirtualAdjacentCell( centreCell, d ); /* find the coarse cell index, where the cell lies */ Index coarseCellIndexAdjacentCell = virtualAdjacentCell.meshPos; /* do not do anything if the cells is on the border */ if( coarseCellIndexAdjacentCell > -1 ) { /* case 1: check if we can find the virtual cell directly */ for( size_t a = 0; a < ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ].size(); a++ ) { if( cellIsTheSame( gridCellsWithVirtual[ ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ], virtualAdjacentCell ) ) { adjacentCellIndicesAllDirections.push_back( ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ); directionsOfAdjacentCellsFlat.push_back( d ); } } } } } template< typename Real, typename Device, typename Index > void GridA< 3, Real, Device, Index >::recalculateMemoryMapsByLayer() Loading @@ -2729,27 +2488,6 @@ GridA< 3, Real, Device, Index >::recalculateMemoryMapsByLayer() level1MemoryMap[ coarseIndex ].push_back( w ); } } /* DEBUG - check purity */ for( size_t w = 0; w < level0MemoryMap.size(); w++ ) { for( size_t d = 0; d < level0MemoryMap[ w ].size(); d++ ) { if( gridCellsWithVirtual[ level0MemoryMap[ w ][ d ] ].levelOfRef != 0 ) { std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! level0MemoryMap " "corrupted! " << std::endl; } } } for( size_t w = 0; w < level1MemoryMap.size(); w++ ) { for( size_t d = 0; d < level1MemoryMap[ w ].size(); d++ ) { if( gridCellsWithVirtual[ level1MemoryMap[ w ][ d ] ].levelOfRef != 1 ) { std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! level1MemoryMap " "corrupted! " << std::endl; } } } } /* remaps directions for adjacency matrix export - adds directions for export */ Loading
LBM.h +3 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ private: std::vector< Index > flaggedForOutflow; std::vector< Index > nonAdjacentCellsDirections; /* TODO: remove after debug */ void getAdjacentCellsAtConstLevel( Index cell ); std::vector< Index > getCoordinatesOnBasicGrid( Index meshPosition ) const; Loading
LBM_impl.h +47 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,53 @@ namespace TNL { namespace Meshes { /* method used to get cells on virtualized grid - using the structures that * separate refinement levels */ template< typename Real, typename Device, typename Index > void LBM<Real, Device, Index >::getAdjacentCellsAtConstLevel( Index cell ) { adjacentCellIndicesAllDirections.clear(); directionsOfAdjacentCellsFlat.clear(); AdaptiveCell< Index, Index, Index > centreCell = gridCellsWithVirtual[ cell ]; /* decide which memory map to use - each corresponds to a partiuclar * refinement level */ MemoryMap* memoryMapInUse = NULL; if( centreCell.levelOfRef == 0 ) { memoryMapInUse = &level0MemoryMap; } else if( centreCell.levelOfRef == 1 ) { memoryMapInUse = &level1MemoryMap; } /* !!! NEXT: delete unwanted sections & check all the cells that I have * listed! */ /* Loop all directions */ for( int d = 0; d < 26; d++ ) { /* construct same level adjacent cell */ AdaptiveCell< Index, Index, Index > virtualAdjacentCell = getVirtualAdjacentCell( centreCell, d ); /* find the coarse cell index, where the cell lies */ Index coarseCellIndexAdjacentCell = virtualAdjacentCell.meshPos; /* do not do anything if the cells is on the border */ if( coarseCellIndexAdjacentCell > -1 ) { /* case 1: check if we can find the virtual cell directly */ for( size_t a = 0; a < ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ].size(); a++ ) { if( cellIsTheSame( gridCellsWithVirtual[ ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ], virtualAdjacentCell ) ) { adjacentCellIndicesAllDirections.push_back( ( *memoryMapInUse )[ coarseCellIndexAdjacentCell ][ a ] ); directionsOfAdjacentCellsFlat.push_back( d ); } } } } } template< typename Real, typename Device, typename Index > std::vector< Index > LBM<Real, Device, Index >::getCoordinatesOnBasicGrid( Index meshPosition ) const Loading