diff --git a/src/TNL/Meshes/DistributedMeshes/BufferEntitiesHelper.h b/src/TNL/Meshes/DistributedMeshes/BufferEntitiesHelper.h index 0b3c7b3638266702374b669459498d2bbb98a540..599ed9e8e9d6f1c6d559be2815d0572e248ffb31 100644 --- a/src/TNL/Meshes/DistributedMeshes/BufferEntitiesHelper.h +++ b/src/TNL/Meshes/DistributedMeshes/BufferEntitiesHelper.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace TNL { namespace Meshes { @@ -43,10 +44,14 @@ class BufferEntitiesHelper< MeshFunctionType, MaskPointer, 1, RealType, Device, const MaskPointer& maskPointer, RealType* buffer, bool isBoundary, - const Index& beginx, - const Index& sizex, + const Containers::StaticVector<1,Index>& begin, + const Containers::StaticVector<1,Index>& size, bool tobuffer ) { + + Index beginx=begin.x(); + Index sizex=size.x(); + auto mesh = meshFunction.getMesh(); RealType* meshFunctionData = meshFunction.getData().getData(); const typename MaskPointer::ObjectType* mask( nullptr ); @@ -83,12 +88,16 @@ class BufferEntitiesHelper< MeshFunctionType, MaskPointer, 2, RealType, Device, const MaskPointer& maskPointer, RealType* buffer, bool isBoundary, - const Index& beginx, - const Index& beginy, - const Index& sizex, - const Index& sizey, + const Containers::StaticVector<2,Index>& begin, + const Containers::StaticVector<2,Index>& size, bool tobuffer) { + + Index beginx=begin.x(); + Index beginy=begin.y(); + Index sizex=size.x(); + Index sizey=size.y(); + auto mesh=meshFunction.getMesh(); RealType* meshFunctionData = meshFunction.getData().getData(); const typename MaskPointer::ObjectType* mask( nullptr ); @@ -127,15 +136,18 @@ class BufferEntitiesHelper< MeshFunctionType, MaskPointer, 3, RealType, Device, const MaskPointer& maskPointer, RealType* buffer, bool isBoundary, - const Index& beginx, - const Index& beginy, - const Index& beginz, - const Index& sizex, - const Index& sizey, - const Index& sizez, + const Containers::StaticVector<3,Index>& begin, + const Containers::StaticVector<3,Index>& size, bool tobuffer) { + Index beginx=begin.x(); + Index beginy=begin.y(); + Index beginz=begin.z(); + Index sizex=size.x(); + Index sizey=size.y(); + Index sizez=size.z(); + auto mesh=meshFunction.getMesh(); RealType * meshFunctionData=meshFunction.getData().getData(); const typename MaskPointer::ObjectType* mask( nullptr ); diff --git a/src/TNL/Meshes/DistributedMeshes/CMakeLists.txt b/src/TNL/Meshes/DistributedMeshes/CMakeLists.txt index 7785de6c4b977353b9ef736b15bc0c8b46e126a3..89a64d74c16a41e0ad7343de4a01fd2c9df17001 100644 --- a/src/TNL/Meshes/DistributedMeshes/CMakeLists.txt +++ b/src/TNL/Meshes/DistributedMeshes/CMakeLists.txt @@ -5,9 +5,6 @@ SET( headers BufferEntitiesHelper.h DistributedGrid.h DistributedGrid.hpp DistributedGridSynchronizer.h - DistributedGridSynchronizer_1D.h - DistributedGridSynchronizer_2D.h - DistributedGridSynchronizer_3D.h DistributedGridIO.h DistributedGridIO_MeshFunction.h DistributedGridIO_VectorField.h diff --git a/src/TNL/Meshes/DistributedMeshes/Directions.h b/src/TNL/Meshes/DistributedMeshes/Directions.h index 8813f3c9fc5f290aac3ea0916e3c0addbb683064..84a5afa91aad85d6724c329fa18b068df7dfc8d2 100644 --- a/src/TNL/Meshes/DistributedMeshes/Directions.h +++ b/src/TNL/Meshes/DistributedMeshes/Directions.h @@ -14,7 +14,7 @@ namespace DistributedMeshes { // -> 0 - not used, 1 negative direction, 2 positive direction //finaly we subtrackt 1 because we dont need (0,0,0) aka 0 aka no direction -enum Directions2D { Left = 0 , Right = 1 , Up = 2, UpLeft =3, UpRight=4, Down=5, DownLeft=6, DownRight=7 }; +//enum Directions2D { Left = 0 , Right = 1 , Up = 2, UpLeft =3, UpRight=4, Down=5, DownLeft=6, DownRight=7 }; /*MEH - osa zed je zdola nahoru, asi--- enum Directions3D { West = 0 , East = 1 , @@ -28,16 +28,33 @@ enum Directions3D { West = 0 , East = 1 , BottomSouth = 23, BottomSouthWest = 24, BottomSouthEast = 25, };*/ -enum Directions3D { West = 0 , East = 1 , - North = 2, NorthWest = 3, NorthEast = 4, - South = 5, SouthWest = 6, SouthEast = 7, - Bottom = 8 ,BottomWest = 9 , BottomEast = 10 , - BottomNorth = 11, BottomNorthWest = 12, BottomNorthEast = 13, - BottomSouth = 14, BottomSouthWest = 15, BottomSouthEast = 16, - Top = 17, TopWest = 18, TopEast =19, - TopNorth = 20, TopNorthWest = 21, TopNorthEast = 22, - TopSouth = 23, TopSouthWest = 24,TopSouthEast = 25, +/* +with self +enum Directions3D { + ZzYzXz = 0, ZzYzXm = 1, ZzYzXp = 2, + ZzYmXz = 3, ZzYmXm = 4, ZzYmXp = 5, + ZzYpXz = 6, ZzYpXm = 7, ZzYpXp = 8, + ZmYzXz = 9, ZmYzXm = 10, ZmYzXp = 11, + ZmYmXz = 12, ZmYmXm = 13, ZmYmXp = 14, + ZmYpXz = 15, ZmYpXm = 16, ZmYpXp = 17, + ZpYzXz = 18, ZpYzXm = 19, ZpYzXp = 20, + ZpYmXz = 21, ZpYmXm = 22, ZpYmXp = 23, + ZpYpXz = 24, ZpYpXm = 25, ZpYpXp = 26 }; +*/ + +enum Directions3D { + ZzYzXm = 0, ZzYzXp = 1, + ZzYmXz = 2, ZzYmXm = 3, ZzYmXp = 4, + ZzYpXz = 5, ZzYpXm = 6, ZzYpXp = 7, + ZmYzXz = 8, ZmYzXm = 9, ZmYzXp = 10, + ZmYmXz = 11, ZmYmXm = 12, ZmYmXp = 13, + ZmYpXz = 14, ZmYpXm = 15, ZmYpXp = 16, + ZpYzXz = 17, ZpYzXm = 18, ZpYzXp = 19, + ZpYmXz = 20, ZpYmXm = 21, ZpYmXp = 22, + ZpYpXz = 23, ZpYpXm = 24, ZpYpXp = 25 + }; + class Directions { diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h index 35297485b66301e5abba45d94b25bf57f62aa5b5..6a4fdf7df492415ca339810bc795c9d0475a6cd2 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h @@ -62,7 +62,7 @@ class DistributedMesh< Grid< Dimension, Real, Device, Index > > const GridType& getGlobalGrid() const; void setOverlaps( const SubdomainOverlapsType& lower, - const SubdomainOverlapsType& upper ); + const SubdomainOverlapsType& upper); void setupGrid( GridType& grid); @@ -74,6 +74,7 @@ class DistributedMesh< Grid< Dimension, Real, Device, Index > > // It is still being used in cuts set-up const CoordinatesType& getOverlap() const { return this->overlap;}; + //currently used overlaps at this subdomain const SubdomainOverlapsType& getLowerOverlap() const; const SubdomainOverlapsType& getUpperOverlap() const; @@ -147,7 +148,7 @@ class DistributedMesh< Grid< Dimension, Real, Device, Index > > CoordinatesType globalBegin; PointType spaceSteps; - SubdomainOverlapsType lowerOverlap, upperOverlap; + SubdomainOverlapsType lowerOverlap, upperOverlap, globalLowerOverlap, globalUpperOverlap; CoordinatesType domainDecomposition; CoordinatesType subdomainCoordinates; diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp index 1fbbe12aa5b6815de77aad583b6126e9e0cce7d2..1f68fe289e2d838024b1988182f6bf4aa41a7222 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp @@ -170,7 +170,7 @@ template< int Dimension, typename Real, typename Device, typename Index > void DistributedMesh< Grid< Dimension, Real, Device, Index > >:: setOverlaps( const SubdomainOverlapsType& lower, - const SubdomainOverlapsType& upper ) + const SubdomainOverlapsType& upper) { this->lowerOverlap = lower; this->upperOverlap = upper; diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h index 989f7419adca3796206da5dbdea5360fc70703c8..b68136e07926ebb6f8bdf34855a8a3db630b6f1c 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h @@ -10,6 +10,222 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include + +namespace TNL { +namespace Functions{ +template< typename Mesh, + int MeshEntityDimension, + typename Real > +class MeshFunction; +}//Functions +}//TNL + +namespace TNL { +namespace Meshes { +namespace DistributedMeshes { + +template +class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension, GridReal, Device, Index >,EntityDimension, RealType>> +{ + + public: + static constexpr int getMeshDimension() { return MeshDimension; }; + static constexpr int getNeighborCount() {return DirectionCount::get();}; + + typedef typename Grid< MeshDimension, GridReal, Device, Index >::Cell Cell; + // FIXME: clang does not like this (incomplete type error) +// typedef typename Functions::MeshFunction< Grid< 3, GridReal, Device, Index >,EntityDimension, RealType> MeshFunctionType; + typedef typename Grid< MeshDimension, GridReal, Device, Index >::DistributedMeshType DistributedGridType; + typedef typename DistributedGridType::CoordinatesType CoordinatesType; + using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; + + DistributedMeshSynchronizer() + { + isSet = false; + }; + + DistributedMeshSynchronizer( DistributedGridType *distributedGrid ) + { + isSet = false; + setDistributedGrid( distributedGrid ); + }; + + void setDistributedGrid( DistributedGridType *distributedGrid ) + { + isSet = true; + + this->distributedGrid = distributedGrid; + + const SubdomainOverlapsType& lowerOverlap = this->distributedGrid->getLowerOverlap(); + const SubdomainOverlapsType& upperOverlap = this->distributedGrid->getUpperOverlap(); + + const CoordinatesType& localBegin = this->distributedGrid->getLocalBegin(); + const CoordinatesType& localSize = this->distributedGrid->getLocalSize(); + const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); + + const int *neighbors = distributedGrid->getNeighbors(); + + for( int i=0; igetNeighborCount(); i++ ) + { + Index sendSize=1;//sended and recieve areas has same size + + // bool isBoundary=( neighbor[ i ] == -1 ); + auto directions=Directions::template getXYZ(i); + + sendDimensions[i]=localSize;//send and recieve areas has same dimensions + sendBegin[i]=localBegin; + recieveBegin[i]=localBegin; + + for(int j=0;jgetMeshDimension();j++) + { + if(directions[j]==-1) + { + sendDimensions[i][j]=lowerOverlap[j]; + recieveBegin[i][j]=0; + } + + if(directions[j]==1) + { + sendDimensions[i][j]=upperOverlap[j]; + sendBegin[i][j]=localBegin[j]+localSize[j]-upperOverlap[j]; + recieveBegin[i][j]=localBegin[j]+localSize[j]; + } + + sendSize*=sendDimensions[i][j]; + } + + sendSizes[ i ] = sendSize; + sendBuffers[ i ].setSize( sendSize ); + recieveBuffers[ i ].setSize( sendSize); + + //Periodic-BC copy from overlap into domain + //if Im on boundary, and i is direction of the boundary i will swap source and destination + //i do this only for basic 6 directions, + //because this swap at conners and edges produces writing multiple values at sam place in localsubdomain + { + if( ( i==ZzYzXm || i==ZzYzXp + ||i==ZzYmXz || i==ZzYpXz + ||i==ZmYzXz || i==ZpYzXz ) + && neighbors[ i ] == -1) + { + //swap begins + CoordinatesType tmp = sendBegin[i]; + sendBegin[i]=recieveBegin[i]; + recieveBegin[i]=tmp; + } + } + + } + } + + template< typename CommunicatorType, + typename MeshFunctionType, + typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > + void synchronize( MeshFunctionType &meshFunction, + bool periodicBoundaries = false, + const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) + { + + TNL_ASSERT_TRUE( isSet, "Synchronizer is not set, but used to synchronize" ); + + if( !distributedGrid->isDistributed() ) return; + + const int *neighbors = distributedGrid->getNeighbors(); + const int *periodicNeighbors = distributedGrid->getPeriodicNeighbors(); + + //fill send buffers + copyBuffers( meshFunction, + sendBuffers, sendBegin,sendDimensions, + true, + neighbors, + periodicBoundaries, + PeriodicBoundariesMaskPointer( nullptr ) ); // the mask is used only when receiving data ); + + //async send and receive + typename CommunicatorType::Request requests[2*this->getNeighborCount()]; + typename CommunicatorType::CommunicationGroup group; + group=*((typename CommunicatorType::CommunicationGroup *)(distributedGrid->getCommunicationGroup())); + int requestsCount( 0 ); + + //send everything, recieve everything + for( int i=0; igetNeighborCount(); i++ ) + if( neighbors[ i ] != -1 ) + { + requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sendSizes[ i ], neighbors[ i ], 0, group ); + requests[ requestsCount++ ] = CommunicatorType::IRecv( recieveBuffers[ i ].getData(), sendSizes[ i ], neighbors[ i ], 0, group ); + } + else if( periodicBoundaries && sendSizes[ i ] !=0 ) + { + requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sendSizes[ i ], periodicNeighbors[ i ], 1, group ); + requests[ requestsCount++ ] = CommunicatorType::IRecv( recieveBuffers[ i ].getData(), sendSizes[ i ], periodicNeighbors[ i ], 1, group ); + } + + //wait until send is done + CommunicatorType::WaitAll( requests, requestsCount ); + + //copy data from receive buffers + copyBuffers(meshFunction, + recieveBuffers,recieveBegin,sendDimensions , + false, + neighbors, + periodicBoundaries, + mask ); + } + + private: + template< typename Real_, + typename MeshFunctionType, + typename PeriodicBoundariesMaskPointer > + void copyBuffers( + MeshFunctionType& meshFunction, + Containers::Array* buffers, + CoordinatesType* begins, + CoordinatesType* sizes, + bool toBuffer, + const int* neighbor, + bool periodicBoundaries, + const PeriodicBoundariesMaskPointer& mask ) + { + using Helper = BufferEntitiesHelper< MeshFunctionType, PeriodicBoundariesMaskPointer, getMeshDimension(), Real_, Device >; + + for(int i=0;igetNeighborCount();i++) + { + bool isBoundary=( neighbor[ i ] == -1 ); + if( ! isBoundary || periodicBoundaries ) + { + Helper::BufferEntities( meshFunction, mask, buffers[ i ].getData(), isBoundary, begins[i], sizes[i], toBuffer ); + } + } + } + + private: + + Containers::Array sendBuffers[getNeighborCount()]; + Containers::Array recieveBuffers[getNeighborCount()]; + Containers::StaticArray< getNeighborCount(), int > sendSizes; + + CoordinatesType sendDimensions[getNeighborCount()]; + CoordinatesType recieveDimensions[getNeighborCount()]; + CoordinatesType sendBegin[getNeighborCount()]; + CoordinatesType recieveBegin[getNeighborCount()]; + + DistributedGridType *distributedGrid; + + bool isSet; + +}; + + +} // namespace DistributedMeshes +} // namespace Meshes +} // namespace TNL + diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_1D.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_1D.h deleted file mode 100644 index 2aaa47bab1509a61e42e87578a7c6af4752039af..0000000000000000000000000000000000000000 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_1D.h +++ /dev/null @@ -1,206 +0,0 @@ -/*************************************************************************** - DistributedGridSynchronizer_1D.h - description - ------------------- - begin : Aug 15, 2018 - copyright : (C) 2018 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include -#include -#include - - -namespace TNL { -namespace Functions{ -template< typename Mesh, - int MeshEntityDimension, - typename Real > -class MeshFunction; -}//Functions -}//TNL - -namespace TNL { -namespace Meshes { -namespace DistributedMeshes { - -template -class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< 1, GridReal, Device, Index >, EntityDimension, Real > > -{ - - public: - using RealType = Real; - typedef typename Grid< 1, GridReal, Device, Index >::Cell Cell; - // FIXME: clang does not like this (incomplete type error) -// typedef typename Functions::MeshFunction< Grid< 1, GridReal, Device, Index >,EntityDimension, RealType> MeshFunctionType; - typedef typename Grid< 1, GridReal, Device, Index >::DistributedMeshType DistributedGridType; - typedef typename DistributedGridType::CoordinatesType CoordinatesType; - using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; - - DistributedMeshSynchronizer() - { - isSet = false; - }; - - DistributedMeshSynchronizer( DistributedGridType *distributedGrid ) - { - isSet = false; - setDistributedGrid( distributedGrid ); - }; - - void setDistributedGrid( DistributedGridType *distributedGrid) - { - isSet=true; - - this->distributedGrid=distributedGrid; - - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localSize = distributedGrid->getLocalSize(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - - sendBuffers[ Left ].setSize( lowerOverlap.x() ); - sendBuffers[ Right ].setSize( upperOverlap.x() ); - receiveBuffers[ Left ].setSize( lowerOverlap.x() ); - receiveBuffers[ Right ].setSize( upperOverlap.x() ); - - }; - - template< typename CommunicatorType, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > - void synchronize( MeshFunctionType &meshFunction, - bool periodicBoundaries = false, - const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) - { - TNL_ASSERT_TRUE( isSet, "Synchronizer is not set, but used to synchronize" ); - - if( !distributedGrid->isDistributed() ) - return; - - int totalSize = meshFunction.getMesh().getDimensions().x(); - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - leftSource = lowerOverlap.x(); - rightSource = localGridSize.x() - 2 * upperOverlap.x(); - leftDestination = 0; - rightDestination = localGridSize.x() - upperOverlap.x(); - - const int *neighbors = distributedGrid->getNeighbors(); - const int *periodicNeighbors = distributedGrid->getPeriodicNeighbors(); - - if( periodicBoundaries ) - { - if( neighbors[ Left ] == -1 ) - swap( leftSource, leftDestination ); - if( neighbors[ Right ] == -1 ) - swap( rightSource, rightDestination ); - } - - copyBuffers( meshFunction, sendBuffers, true, - leftSource, rightSource, - lowerOverlap, upperOverlap, - neighbors, - periodicBoundaries, - PeriodicBoundariesMaskPointer( nullptr ) ); // the mask is used only when receiving data - - //async send - typename CommunicatorType::Request requests[ 4 ]; - typename CommunicatorType::CommunicationGroup group; - group=*((typename CommunicatorType::CommunicationGroup *)(distributedGrid->getCommunicationGroup())); - int requestsCount( 0 ); - - //send everything, recieve everything - if( neighbors[ Left ] != -1 ) - { - TNL_ASSERT_GE( sendBuffers[ Left ].getSize(), lowerOverlap.x(), "" ); - TNL_ASSERT_GE( receiveBuffers[ Left ].getSize(), lowerOverlap.x(), "" ); - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ Left ].getData(), lowerOverlap.x(), neighbors[ Left ], 0, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ Left ].getData(), lowerOverlap.x(), neighbors[ Left ], 0, group ); - } - else if( periodicBoundaries ) - { - TNL_ASSERT_GE( sendBuffers[ Left ].getSize(), lowerOverlap.x(), "" ); - TNL_ASSERT_GE( receiveBuffers[ Left ].getSize(), lowerOverlap.x(), "" ); - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ Left ].getData(), lowerOverlap.x(), periodicNeighbors[ Left ], 1, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ Left ].getData(), lowerOverlap.x(), periodicNeighbors[ Left ], 1, group ); - } - - if( neighbors[ Right ] != -1 ) - { - TNL_ASSERT_GE( sendBuffers[ Right ].getSize(), upperOverlap.x(), "" ); - TNL_ASSERT_GE( receiveBuffers[ Right ].getSize(), upperOverlap.x(), "" ); - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ Right ].getData(), upperOverlap.x(), neighbors[ Right ], 0, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ Right ].getData(), upperOverlap.x(), neighbors[ Right ], 0, group ); - } - else if( periodicBoundaries ) - { - TNL_ASSERT_GE( sendBuffers[ Right ].getSize(), upperOverlap.x(), "" ); - TNL_ASSERT_GE( receiveBuffers[ Right ].getSize(), upperOverlap.x(), "" ); - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ Right ].getData(), upperOverlap.x(), periodicNeighbors[ Right ], 1, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ Right ].getData(), upperOverlap.x(), periodicNeighbors[ Right ], 1, group ); - } - - //wait until send and receive is done - CommunicatorType::WaitAll( requests, requestsCount ); - - copyBuffers( meshFunction, receiveBuffers, false, - leftDestination, rightDestination, - lowerOverlap, - upperOverlap, - neighbors, - periodicBoundaries, - mask ); - } - - private: - template< typename Real_, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer > - void copyBuffers( - MeshFunctionType& meshFunction, - TNL::Containers::Array* buffers, - bool toBuffer, - int left, int right, - const SubdomainOverlapsType& lowerOverlap, - const SubdomainOverlapsType& upperOverlap, - const int* neighbors, - bool periodicBoundaries, - const PeriodicBoundariesMaskPointer& mask ) - - { - typedef BufferEntitiesHelper< MeshFunctionType, PeriodicBoundariesMaskPointer, 1, Real_, Device > Helper; - bool leftIsBoundary = ( neighbors[ Left ] == -1 ); - bool rightIsBoundary = ( neighbors[ Right ] == -1 ); - if( ! leftIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Left ].getData(), leftIsBoundary, left, lowerOverlap.x(), toBuffer ); - if( ! rightIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Right ].getData(), rightIsBoundary, right, upperOverlap.x(), toBuffer ); - } - - Containers::Array sendBuffers[ 2 ], receiveBuffers[ 2 ]; - - DistributedGridType *distributedGrid; - - int leftSource; - int rightSource; - int leftDestination; - int rightDestination; - - bool isSet; -}; - -} // namespace DistributedMeshes -} // namespace Meshes -} // namespace TNL diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_2D.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_2D.h deleted file mode 100644 index 51c2aef56fa824aa9f7ccac86f5f279d0e5b56c4..0000000000000000000000000000000000000000 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_2D.h +++ /dev/null @@ -1,248 +0,0 @@ -/*************************************************************************** - DistributedGridSynchronizer_2D.h - description - ------------------- - begin : Aug 15, 2018 - copyright : (C) 2018 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include -#include -#include - - -namespace TNL { -namespace Functions{ -template< typename Mesh, - int MeshEntityDimension, - typename Real > -class MeshFunction; -}//Functions -}//TNL - -namespace TNL { -namespace Meshes { -namespace DistributedMeshes { - -template -class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< 2, GridReal, Device, Index >,EntityDimension, RealType>> -{ - - public: - - typedef typename Grid< 2, GridReal, Device, Index >::Cell Cell; - // FIXME: clang does not like this (incomplete type error) -// typedef typename Functions::MeshFunction< Grid< 2, GridReal, Device, Index >,EntityDimension, RealType> MeshFunctionType; - typedef typename Grid< 2, GridReal, Device, Index >::DistributedMeshType DistributedGridType; - typedef typename DistributedGridType::CoordinatesType CoordinatesType; - using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; - - - DistributedMeshSynchronizer() - { - isSet=false; - }; - - DistributedMeshSynchronizer(DistributedGridType *distributedGrid) - { - isSet=false; - setDistributedGrid( distributedGrid ); - }; - - void setDistributedGrid( DistributedGridType *distributedGrid ) - { - isSet=true; - - this->distributedGrid = distributedGrid; - - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localSize = distributedGrid->getLocalSize(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - // TODO: SWAP up and down - sizes[ Left ] = localSize.y() * lowerOverlap.x(); - sizes[ Right ] = localSize.y() * upperOverlap.x(); - sizes[ Up ] = localSize.x() * lowerOverlap.y(); - sizes[ Down ] = localSize.x() * upperOverlap.y(); - sizes[ UpLeft ] = lowerOverlap.x() * lowerOverlap.y(); - sizes[ DownLeft ] = lowerOverlap.x() * upperOverlap.y(); - sizes[ UpRight ] = upperOverlap.x() * lowerOverlap.y(); - sizes[ DownRight ] = upperOverlap.x() * upperOverlap.y(); - - for(int i=0;i<8;i++) - { - sendBuffers[ i ].setSize( sizes[ i ] ); - receiveBuffers[ i ].setSize( sizes[ i ] ); - } - - } - - template< typename CommunicatorType, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > - void synchronize( MeshFunctionType &meshFunction, - bool periodicBoundaries = false, - const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) - { - - TNL_ASSERT_TRUE( isSet, "Synchronizer is not set, but used to synchronize" ); - - if( !distributedGrid->isDistributed() ) - return; - - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localSize = distributedGrid->getLocalSize(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - leftSource = lowerOverlap.x(); - rightSource = localGridSize.x() - 2 * upperOverlap.x(); - upSource = lowerOverlap.y(); // TODO: SWAP up and down - downSource = localGridSize.y() - 2 * upperOverlap.y(); // TODO: SWAP up and down - - xCenter = lowerOverlap.x(); - yCenter = lowerOverlap.y(); - - leftDestination = 0; - rightDestination = localGridSize.x() - upperOverlap.x(); - upDestination = 0; - downDestination = localGridSize.y() - upperOverlap.y(); - - const int *neighbors = distributedGrid->getNeighbors(); - const int *periodicNeighbors = distributedGrid->getPeriodicNeighbors(); - - if( periodicBoundaries ) - { - if( neighbors[ Left ] == -1 ) - swap( leftSource, leftDestination ); - if( neighbors[ Right ] == -1 ) - swap( rightSource, rightDestination ); - if( neighbors[ Up ] == -1 ) - swap( upSource, upDestination ); - if( neighbors[ Down ] == -1 ) - swap( downSource, downDestination ); - } - - copyBuffers(meshFunction, sendBuffers, true, - leftSource, rightSource, upSource, downSource, - xCenter, yCenter, - lowerOverlap, upperOverlap, localSize, - neighbors, - periodicBoundaries, - PeriodicBoundariesMaskPointer( nullptr ) ); // the mask is used only when receiving data - - //async send and receive - typename CommunicatorType::Request requests[ 16 ]; - typename CommunicatorType::CommunicationGroup group; - group=*((typename CommunicatorType::CommunicationGroup *)(distributedGrid->getCommunicationGroup())); - int requestsCount( 0 ); - - //send everything, receive everything - for( int i = 0; i < 8; i++ ) - { - if( neighbors[ i ] != -1 ) - { - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sizes[ i ], neighbors[ i ], 0, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ i ].getData(), sizes[ i ], neighbors[ i ], 0, group ); - } - else if( periodicBoundaries ) - { - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sizes[ i ], periodicNeighbors[ i ], 1, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ i ].getData(), sizes[ i ], periodicNeighbors[ i ], 1, group ); - } - } - - //wait until send is done - CommunicatorType::WaitAll( requests, requestsCount ); - - //copy data from receive buffers - copyBuffers(meshFunction, receiveBuffers, false, - leftDestination, rightDestination, upDestination, downDestination, - xCenter, yCenter, - lowerOverlap, upperOverlap, localSize, - neighbors, - periodicBoundaries, - mask ); - } - - private: - - template< typename Real_, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer > - void copyBuffers( - MeshFunctionType& meshFunction, - Containers::Array* buffers, - bool toBuffer, - int left, int right, int up, int down, - int xcenter, int ycenter, - const CoordinatesType& lowerOverlap, - const CoordinatesType& upperOverlap, - const CoordinatesType& localSize, - const int *neighbors, - bool periodicBoundaries, - const PeriodicBoundariesMaskPointer& mask ) - { - // TODO: SWAP up and down - bool leftIsBoundary = ( neighbors[ Left ] == -1 ); - bool rightIsBoundary = ( neighbors[ Right ] == -1 ); - bool upIsBoundary = ( neighbors[ Up ] == -1 ); - bool downIsBoundary = ( neighbors[ Down ] == -1 ); - bool upLeftIsBoundary = ( neighbors[ UpLeft ] == -1 ); - bool upRightIsBoundary = ( neighbors[ UpRight ] == -1 ); - bool downLeftIsBoundary = ( neighbors[ DownLeft ] == -1 ); - bool downRightIsBoundary = ( neighbors[ DownRight ] == -1 ); - - using Helper = BufferEntitiesHelper< MeshFunctionType, PeriodicBoundariesMaskPointer, 2, Real_, Device >; - if( ! leftIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Left ].getData(), leftIsBoundary, left, ycenter, lowerOverlap.x(), localSize.y(), toBuffer ); - if( ! rightIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Right ].getData(), rightIsBoundary, right, ycenter, upperOverlap.x(), localSize.y(), toBuffer ); - if( ! upIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Up ].getData(), upIsBoundary, xcenter, up, localSize.x(), lowerOverlap.y(), toBuffer ); - if( ! downIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Down ].getData(), downIsBoundary, xcenter, down, localSize.x(), upperOverlap.y(), toBuffer ); - if( ! upLeftIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ UpLeft ].getData(), upLeftIsBoundary, left, up, lowerOverlap.x(), lowerOverlap.y(), toBuffer ); - if( ! upRightIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ UpRight ].getData(), upRightIsBoundary, right, up, upperOverlap.x(), lowerOverlap.y(), toBuffer ); - if( ! downLeftIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ DownLeft ].getData(), downLeftIsBoundary, left, down, lowerOverlap.x(), upperOverlap.y(), toBuffer ); - if( ! downRightIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ DownRight ].getData(), downRightIsBoundary, right, down, upperOverlap.x(), upperOverlap.y(), toBuffer ); - } - - DistributedGridType *distributedGrid; - - Containers::Array sendBuffers[8]; - Containers::Array receiveBuffers[8]; - Containers::StaticArray< 8, int > sizes; - - int leftSource; - int rightSource; - int upSource; - int downSource; - int xCenter; - int yCenter; - int leftDestination; - int rightDestination; - int upDestination; - int downDestination; - - bool isSet; -}; - -} // namespace DistributedMeshes -} // namespace Meshes -} // namespace TNL - - diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_3D.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_3D.h deleted file mode 100644 index 047cf982298f8098425a91106913212fe2a0f425..0000000000000000000000000000000000000000 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer_3D.h +++ /dev/null @@ -1,350 +0,0 @@ -/*************************************************************************** - DistributedGridSynchronizer_3D.h - description - ------------------- - begin : Aug 15, 2018 - copyright : (C) 2018 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include -#include -#include - - -namespace TNL { -namespace Functions{ -template< typename Mesh, - int MeshEntityDimension, - typename Real > -class MeshFunction; -}//Functions -}//TNL - -namespace TNL { -namespace Meshes { -namespace DistributedMeshes { - -template -class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< 3, GridReal, Device, Index >,EntityDimension, RealType>> -{ - - public: - typedef typename Grid< 3, GridReal, Device, Index >::Cell Cell; - // FIXME: clang does not like this (incomplete type error) -// typedef typename Functions::MeshFunction< Grid< 3, GridReal, Device, Index >,EntityDimension, RealType> MeshFunctionType; - typedef typename Grid< 3, GridReal, Device, Index >::DistributedMeshType DistributedGridType; - typedef typename DistributedGridType::CoordinatesType CoordinatesType; - using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; - - DistributedMeshSynchronizer() - { - isSet = false; - }; - - DistributedMeshSynchronizer( DistributedGridType *distributedGrid ) - { - isSet = false; - setDistributedGrid( distributedGrid ); - }; - - void setDistributedGrid( DistributedGridType *distributedGrid ) - { - isSet = true; - - this->distributedGrid = distributedGrid; - - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localSize = distributedGrid->getLocalSize(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - sizes[ West ] = localSize.y() * localSize.z() * lowerOverlap.x(); - sizes[ East ] = localSize.y() * localSize.z() * upperOverlap.x(); - sizes[ North ] = localSize.x() * localSize.z() * lowerOverlap.y(); - sizes[ South ] = localSize.x() * localSize.z() * upperOverlap.y(); - sizes[ Bottom ] = localSize.x() * localSize.y() * lowerOverlap.z(); - sizes[ Top ] = localSize.x() * localSize.y() * upperOverlap.z(); - - sizes[ NorthWest ] = localSize.z() * lowerOverlap.x() * lowerOverlap.y(); - sizes[ NorthEast ] = localSize.z() * upperOverlap.x() * lowerOverlap.y(); - sizes[ SouthWest ] = localSize.z() * lowerOverlap.x() * upperOverlap.y(); - sizes[ SouthEast ] = localSize.z() * upperOverlap.x() * upperOverlap.y(); - sizes[ BottomWest ] = localSize.y() * lowerOverlap.x() * lowerOverlap.z(); - sizes[ BottomEast ] = localSize.y() * upperOverlap.x() * lowerOverlap.z(); - sizes[ TopWest ] = localSize.y() * lowerOverlap.x() * upperOverlap.z(); - sizes[ TopEast ] = localSize.y() * upperOverlap.x() * upperOverlap.z(); - sizes[ BottomNorth ] = localSize.x() * lowerOverlap.y() * lowerOverlap.z(); - sizes[ BottomSouth ] = localSize.x() * upperOverlap.y() * lowerOverlap.z(); - sizes[ TopNorth ] = localSize.x() * lowerOverlap.y() * upperOverlap.z(); - sizes[ TopSouth ] = localSize.x() * upperOverlap.y() * upperOverlap.z(); - - sizes[ BottomNorthWest ] = lowerOverlap.x() * lowerOverlap.y() * lowerOverlap.z(); - sizes[ BottomNorthEast ] = upperOverlap.x() * lowerOverlap.y() * lowerOverlap.z(); - sizes[ BottomSouthWest ] = lowerOverlap.x() * upperOverlap.y() * lowerOverlap.z(); - sizes[ BottomSouthEast ] = upperOverlap.x() * upperOverlap.y() * lowerOverlap.z(); - sizes[ TopNorthWest ] = lowerOverlap.x() * lowerOverlap.y() * upperOverlap.z(); - sizes[ TopNorthEast ] = upperOverlap.x() * lowerOverlap.y() * upperOverlap.z(); - sizes[ TopSouthWest ] = lowerOverlap.x() * upperOverlap.y() * upperOverlap.z(); - sizes[ TopSouthEast ] = upperOverlap.x() * upperOverlap.y() * upperOverlap.z(); - - for( int i=0; i<26; i++ ) - { - sendBuffers[ i ].setSize( sizes[ i ] ); - receiveBuffers[ i ].setSize( sizes[ i ] ); - } - - } - - template< typename CommunicatorType, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > - void synchronize( MeshFunctionType &meshFunction, - bool periodicBoundaries = false, - const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) - { - - TNL_ASSERT_TRUE( isSet, "Synchronizer is not set, but used to synchronize" ); - - if( !distributedGrid->isDistributed() ) return; - - const SubdomainOverlapsType& lowerOverlap = distributedGrid->getLowerOverlap(); - const SubdomainOverlapsType& upperOverlap = distributedGrid->getUpperOverlap(); - const CoordinatesType& localSize = distributedGrid->getLocalSize(); - const CoordinatesType& localGridSize = this->distributedGrid->getLocalGridSize(); - - westSource = lowerOverlap.x(); - eastSource = localGridSize.x() - 2 * upperOverlap.x(); - northSource = lowerOverlap.y(); - southSource = localGridSize.y() - 2 * upperOverlap.y(); - bottomSource = lowerOverlap.z(); - topSource = localGridSize.z() - 2 * upperOverlap.z(); - - xCenter = lowerOverlap.x(); - yCenter = lowerOverlap.y(); - zCenter = lowerOverlap.z(); - - westDestination = 0; - eastDestination = localGridSize.x() - upperOverlap.x(); - northDestination = 0; - southDestination = localGridSize.y() - upperOverlap.y(); - bottomDestination = 0; - topDestination = localGridSize.z() - upperOverlap.z(); - - const int *neighbors = distributedGrid->getNeighbors(); - const int *periodicNeighbors = distributedGrid->getPeriodicNeighbors(); - - if( periodicBoundaries ) - { - if( neighbors[ West ] == -1 ) - swap( westSource, westDestination ); - if( neighbors[ East ] == -1 ) - swap( eastSource, eastDestination ); - if( neighbors[ South ] == -1 ) - swap( southSource, southDestination ); - if( neighbors[ North ] == -1 ) - swap( northSource, northDestination ); - if( neighbors[ Bottom ] == -1 ) - swap( bottomSource, bottomDestination ); - if( neighbors[ Top ] == -1 ) - swap( topSource, topDestination ); - } - - //fill send buffers - copyBuffers( meshFunction, sendBuffers, true, - westSource, eastSource, northSource, southSource, bottomSource, topSource, - xCenter, yCenter, zCenter, - lowerOverlap, upperOverlap, localSize, - neighbors, - periodicBoundaries, - PeriodicBoundariesMaskPointer( nullptr ) ); // the mask is used only when receiving data ); - - //async send and receive - typename CommunicatorType::Request requests[52]; - typename CommunicatorType::CommunicationGroup group; - group=*((typename CommunicatorType::CommunicationGroup *)(distributedGrid->getCommunicationGroup())); - int requestsCount( 0 ); - - //send everything, receive everything - for( int i = 0; i < 26; i++ ) - if( neighbors[ i ] != -1 ) - { - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sizes[ i ], neighbors[ i ], 0, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ i ].getData(), sizes[ i ], neighbors[ i ], 0, group ); - } - else if( periodicBoundaries ) - { - requests[ requestsCount++ ] = CommunicatorType::ISend( sendBuffers[ i ].getData(), sizes[ i ], periodicNeighbors[ i ], 1, group ); - requests[ requestsCount++ ] = CommunicatorType::IRecv( receiveBuffers[ i ].getData(), sizes[ i ], periodicNeighbors[ i ], 1, group ); - } - - //wait until send is done - CommunicatorType::WaitAll( requests, requestsCount ); - - //copy data from receive buffers - copyBuffers(meshFunction, receiveBuffers, false, - westDestination, eastDestination, northDestination, southDestination, bottomDestination, topDestination, - xCenter, yCenter, zCenter, - lowerOverlap, upperOverlap, localSize, - neighbors, - periodicBoundaries, - mask ); - } - - private: - - template< typename Real_, - typename MeshFunctionType, - typename PeriodicBoundariesMaskPointer > - void copyBuffers( - MeshFunctionType& meshFunction, - Containers::Array* buffers, - bool toBuffer, - int west, int east, int north, int south, int bottom, int top, - int xcenter, int ycenter, int zcenter, - const CoordinatesType& lowerOverlap, - const CoordinatesType& upperOverlap, - const CoordinatesType& localSize, - const int* neighbor, - bool periodicBoundaries, - const PeriodicBoundariesMaskPointer& mask ) - { - bool westIsBoundary = ( neighbor[ West ] == -1 ); - bool eastIsBoundary = ( neighbor[ East ] == -1 ); - bool northIsBoundary = ( neighbor[ North ] == -1 ); - bool southIsBoundary = ( neighbor[ South ] == -1 ); - bool bottomIsBoundary = ( neighbor[ Bottom ] == -1 ); - bool topIsBoundary = ( neighbor[ Top ] == -1 ); - - bool northWestIsBoundary = ( neighbor[ NorthWest ] == -1 ); - bool northEastIsBoundary = ( neighbor[ NorthEast ] == -1 ); - bool southWestIsBoundary = ( neighbor[ SouthWest ] == -1 ); - bool southEastIsBoundary = ( neighbor[ SouthEast ] == -1 ); - - bool bottomWestIsBoundary = ( neighbor[ BottomWest ] == -1 ); - bool bottomEastIsBoundary = ( neighbor[ BottomEast ] == -1 ); - bool bottomNorthIsBoundary = ( neighbor[ BottomNorth ] == -1 ); - bool bottomSouthIsBoundary = ( neighbor[ BottomSouth ] == -1 ); - - bool topWestIsBoundary = ( neighbor[ TopWest ] == -1 ); - bool topEastIsBoundary = ( neighbor[ TopEast ] == -1 ); - bool topNorthIsBoundary = ( neighbor[ TopNorth ] == -1 ); - bool topSouthIsBoundary = ( neighbor[ TopSouth ] == -1 ); - - bool bottomNorthWestIsBoundary = ( neighbor[ BottomNorthWest ] == -1 ); - bool bottomNorthEastIsBoundary = ( neighbor[ BottomNorthEast ] == -1 ); - bool bottomSouthWestIsBoundary = ( neighbor[ BottomSouthWest ] == -1 ); - bool bottomSouthEastIsBoundary = ( neighbor[ BottomSouthEast ] == -1 ); - - bool topNorthWestIsBoundary = ( neighbor[ TopNorthWest ] == -1 ); - bool topNorthEastIsBoundary = ( neighbor[ TopNorthEast ] == -1 ); - bool topSouthWestIsBoundary = ( neighbor[ TopSouthWest ] == -1 ); - bool topSouthEastIsBoundary = ( neighbor[ TopSouthEast ] == -1 ); - - using Helper = BufferEntitiesHelper< MeshFunctionType, PeriodicBoundariesMaskPointer, 3, Real_, Device >; - //X-Y-Z - if( ! westIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ West ].getData(), westIsBoundary, west, ycenter, zcenter, lowerOverlap.x(), localSize.y(), localSize.z(), toBuffer ); - if( ! eastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ East ].getData(), eastIsBoundary, east, ycenter, zcenter, upperOverlap.x(), localSize.y(), localSize.z(), toBuffer ); - if( ! northIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ North ].getData(), northIsBoundary, xcenter, north, zcenter, localSize.x(), lowerOverlap.y(), localSize.z(), toBuffer ); - if( ! southIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ South ].getData(), southIsBoundary, xcenter, south, zcenter, localSize.x(), upperOverlap.y(), localSize.z(), toBuffer ); - if( ! bottomIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Bottom ].getData(), bottomIsBoundary, xcenter, ycenter, bottom, localSize.x(), localSize.y(), lowerOverlap.z(), toBuffer ); - if( ! topIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ Top ].getData(), topIsBoundary, xcenter, ycenter, top, localSize.x(), localSize.y(), upperOverlap.z(), toBuffer ); - - //XY - if( ! northWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ NorthWest ].getData(), northWestIsBoundary, west, north, zcenter, lowerOverlap.x(), lowerOverlap.y(), localSize.z(), toBuffer ); - if( ! northEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ NorthEast ].getData(), northEastIsBoundary, east, north, zcenter, upperOverlap.x(), lowerOverlap.y(), localSize.z(), toBuffer ); - if( ! southWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ SouthWest ].getData(), southWestIsBoundary, west, south, zcenter, lowerOverlap.x(), upperOverlap.y(), localSize.z(), toBuffer ); - if( ! southEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ SouthEast ].getData(), southEastIsBoundary, east, south, zcenter, upperOverlap.x(), upperOverlap.y(), localSize.z(), toBuffer ); - - //XZ - if( ! bottomWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomWest ].getData(), bottomWestIsBoundary, west, ycenter, bottom, lowerOverlap.x(), localSize.y(), lowerOverlap.z(), toBuffer ); - if( ! bottomEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomEast ].getData(), bottomEastIsBoundary, east, ycenter, bottom, upperOverlap.x(), localSize.y(), lowerOverlap.z(), toBuffer ); - if( ! topWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopWest ].getData(), topWestIsBoundary, west, ycenter, top, lowerOverlap.x(), localSize.y(), upperOverlap.z(), toBuffer ); - if( ! topEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopEast ].getData(), topEastIsBoundary, east, ycenter, top, upperOverlap.x(), localSize.y(), upperOverlap.z(), toBuffer ); - - //YZ - if( ! bottomNorthIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomNorth ].getData(), bottomNorthIsBoundary, xcenter, north, bottom, localSize.x(), lowerOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! bottomSouthIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomSouth ].getData(), bottomSouthIsBoundary, xcenter, south, bottom, localSize.x(), upperOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! topNorthIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopNorth ].getData(), topNorthIsBoundary, xcenter, north, top, localSize.x(), lowerOverlap.y(), upperOverlap.z(), toBuffer ); - if( ! topSouthIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopSouth ].getData(), topSouthIsBoundary, xcenter, south, top, localSize.x(), upperOverlap.y(), upperOverlap.z(), toBuffer ); - - //XYZ - if( ! bottomNorthWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomNorthWest ].getData(), bottomNorthWestIsBoundary, west, north, bottom, lowerOverlap.x(), lowerOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! bottomNorthEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomNorthEast ].getData(), bottomNorthEastIsBoundary, east, north, bottom, upperOverlap.x(), lowerOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! bottomSouthWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomSouthWest ].getData(), bottomSouthWestIsBoundary, west, south, bottom, lowerOverlap.x(), upperOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! bottomSouthEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ BottomSouthEast ].getData(), bottomSouthEastIsBoundary, east, south, bottom, upperOverlap.x(), upperOverlap.y(), lowerOverlap.z(), toBuffer ); - if( ! topNorthWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopNorthWest ].getData(), topNorthWestIsBoundary, west, north, top, lowerOverlap.x(), lowerOverlap.y(), upperOverlap.z(), toBuffer ); - if( ! topNorthEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopNorthEast ].getData(), topNorthEastIsBoundary, east, north, top, upperOverlap.x(), lowerOverlap.y(), upperOverlap.z(), toBuffer ); - if( ! topSouthWestIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopSouthWest ].getData(), topSouthEastIsBoundary, west, south, top, lowerOverlap.x(), upperOverlap.y(), upperOverlap.z(), toBuffer ); - if( ! topSouthEastIsBoundary || periodicBoundaries ) - Helper::BufferEntities( meshFunction, mask, buffers[ TopSouthEast ].getData(), topSouthEastIsBoundary, east, south, top, upperOverlap.x(), upperOverlap.y(), upperOverlap.z(), toBuffer ); - } - - private: - - Containers::Array sendBuffers[26]; - Containers::Array receiveBuffers[26]; - Containers::StaticArray< 26, int > sizes; - - DistributedGridType *distributedGrid; - - int westSource; - int eastSource; - int northSource; - int southSource; - int bottomSource; - int topSource; - int xCenter; - int yCenter; - int zCenter; - int westDestination; - int eastDestination; - int northDestination; - int southDestination; - int bottomDestination; - int topDestination; - - CoordinatesType overlap; - CoordinatesType localSize; - - bool isSet; - -}; - - -} // namespace DistributedMeshes -} // namespace Meshes -} // namespace TNL - diff --git a/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp b/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp index abf6243aba37d309362158bd013000997222faed..7d84382b90dc980aba912096f20db0d9b1fa2532 100644 --- a/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp +++ b/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp @@ -38,6 +38,7 @@ getOverlaps( const DistributedMeshType* distributedMesh, for( int i = 0; i < Dimension; i++ ) { + if( subdomainCoordinates[ i ] > 0 ) lower[ i ] = subdomainOverlapSize; else diff --git a/src/TNL/Meshes/GridDetails/Traverser_Grid1D_impl.h b/src/TNL/Meshes/GridDetails/Traverser_Grid1D_impl.h index d3d2a129cc3c888981e9a684cc435ba57979f9aa..c0ddcf2dae86cf1b4a8da74d7d8d18307f240b73 100644 --- a/src/TNL/Meshes/GridDetails/Traverser_Grid1D_impl.h +++ b/src/TNL/Meshes/GridDetails/Traverser_Grid1D_impl.h @@ -48,7 +48,7 @@ processBoundaryEntities( const GridPointer& gridPointer, else //Distributed { const int* neighbors=distributedGrid->getNeighbors(); - if( neighbors[ Meshes::DistributedMeshes::Left ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -57,7 +57,7 @@ processBoundaryEntities( const GridPointer& gridPointer, userData ); } - if( neighbors[ Meshes::DistributedMeshes::Right ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXp ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -100,10 +100,10 @@ processInteriorEntities( const GridPointer& gridPointer, CoordinatesType end( gridPointer->getDimensions() - distributedGrid->getUpperOverlap() - CoordinatesType( 1 ) ); const int* neighbors = distributedGrid->getNeighbors(); - if( neighbors[ Meshes::DistributedMeshes::Left ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) begin += CoordinatesType( 1 ); - if( neighbors[ Meshes::DistributedMeshes::Right ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXp ] == -1 ) end -= CoordinatesType( 1 ); /* diff --git a/src/TNL/Meshes/GridDetails/Traverser_Grid2D_impl.h b/src/TNL/Meshes/GridDetails/Traverser_Grid2D_impl.h index 23d93d7e0b968bfeb53be9fe922855d999d91837..41e1612565dd66a61eb5a505ff9ffdbdb67adf41 100644 --- a/src/TNL/Meshes/GridDetails/Traverser_Grid2D_impl.h +++ b/src/TNL/Meshes/GridDetails/Traverser_Grid2D_impl.h @@ -50,7 +50,7 @@ processBoundaryEntities( const GridPointer& gridPointer, const CoordinatesType end = gridPointer->getDimensions() - distributedGrid->getUpperOverlap() - CoordinatesType( 1, 1 ); const int* neighbors=distributedGrid->getNeighbors(); - if( neighbors[ Meshes::DistributedMeshes::Left ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -60,7 +60,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if(neighbors[Meshes::DistributedMeshes::Right]==-1) + if(neighbors[Meshes::DistributedMeshes::ZzYzXp]==-1) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -70,8 +70,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - // TODO: Up and Down should by swapped, I think - if( neighbors[ Meshes::DistributedMeshes::Up ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYmXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -81,7 +80,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::Down ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYpXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -124,16 +123,16 @@ processInteriorEntities( const GridPointer& gridPointer, const int* neighbors = distributedGrid->getNeighbors(); CoordinatesType begin( distributedGrid->getLowerOverlap()); CoordinatesType end( gridPointer->getDimensions() - distributedGrid->getUpperOverlap()- CoordinatesType(1,1) ); - if( neighbors[ Meshes::DistributedMeshes::Left ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) begin.x() += 1 ; - if( neighbors[ Meshes::DistributedMeshes::Right ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXp ] == -1 ) end.x() -= 1; - if( neighbors[ Meshes::DistributedMeshes::Up ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYmXz ] == -1 ) begin.y() += 1 ; - if( neighbors[ Meshes::DistributedMeshes::Down ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYpXz ] == -1 ) end.y() -= 1; diff --git a/src/TNL/Meshes/GridDetails/Traverser_Grid3D_impl.h b/src/TNL/Meshes/GridDetails/Traverser_Grid3D_impl.h index 3c9fffd813d5675310505a09b286c827610dc691..e32c5a12ef0080ce8b7e0d57e3dacaf8a75425f7 100644 --- a/src/TNL/Meshes/GridDetails/Traverser_Grid3D_impl.h +++ b/src/TNL/Meshes/GridDetails/Traverser_Grid3D_impl.h @@ -52,7 +52,7 @@ processBoundaryEntities( const GridPointer& gridPointer, const CoordinatesType end = gridPointer->getDimensions() - distributedGrid->getUpperOverlap() - CoordinatesType( 1, 1, 1 ); const int* neighbors = distributedGrid->getNeighbors(); - if( neighbors[ Meshes::DistributedMeshes::West ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -62,7 +62,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::East ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXp ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -72,7 +72,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::North ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYmXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -82,7 +82,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::South ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYpXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -92,7 +92,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::Bottom ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZmYzXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -102,7 +102,7 @@ processBoundaryEntities( const GridPointer& gridPointer, 0 ); } - if( neighbors[ Meshes::DistributedMeshes::Top ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZpYzXz ] == -1 ) { GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( gridPointer, @@ -146,22 +146,22 @@ processInteriorEntities( const GridPointer& gridPointer, CoordinatesType begin( distributedGrid->getLowerOverlap()); CoordinatesType end( gridPointer->getDimensions() - distributedGrid->getUpperOverlap()- CoordinatesType(1,1,1) ); - if( neighbors[ Meshes::DistributedMeshes::West ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXm ] == -1 ) begin.x() += 1 ; - if( neighbors[ Meshes::DistributedMeshes::East ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYzXp ] == -1 ) end.x() -= 1; - if( neighbors[ Meshes::DistributedMeshes::North ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYmXz ] == -1 ) begin.y() += 1; - if( neighbors[ Meshes::DistributedMeshes::South ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZzYpXz ] == -1 ) end.y() -= 1; - if( neighbors[ Meshes::DistributedMeshes::Bottom ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZmYzXz ] == -1 ) begin.z() += 1 ; - if( neighbors[ Meshes::DistributedMeshes::Top ] == -1 ) + if( neighbors[ Meshes::DistributedMeshes::ZpYzXz ] == -1 ) end.z() -= 1; GridTraverser< GridType >::template processEntities< GridEntity, EntitiesProcessor, UserData, false >( diff --git a/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp b/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp index 0d2bc77ede3577153944398c8a61c6370d1bf876..b772ecda067d8563a838ce92fadc1fc03b6984fe 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DirectionsTest.cpp @@ -10,111 +10,111 @@ using namespace TNL; TEST(Direction1D, Conners) { - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),Left) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),Right) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),ZzYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),ZzYzXp) << "Failed"; } TEST(Direction2D, Edge) { - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),Left) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),Right) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-2)),Up) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(2)),Down) << "Failed"; - - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-1,0)),Left) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(1,0)),Right) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(0,-2)),Up) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(0,2)),Down) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),ZzYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),ZzYzXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-2)),ZzYmXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(2)),ZzYpXz) << "Failed"; + + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-1,0)),ZzYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(1,0)),ZzYzXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(0,-2)),ZzYmXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(0,2)),ZzYpXz) << "Failed"; } TEST(Direction2D, Conners) { - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2,-1)),UpLeft) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2, 1)),UpRight) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(2,-1)),DownLeft) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(2,1)),DownRight) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2,-1)),ZzYmXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2, 1)),ZzYmXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(2,-1)),ZzYpXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(2,1)),ZzYpXp) << "Failed"; } TEST(Direction3D, Faces) { - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),West) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),East) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-2)),North) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(2)),South) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-3)),Bottom) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(3)),Top) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-1)),ZzYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(1)),ZzYzXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-2)),ZzYmXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(2)),ZzYpXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(-3)),ZmYzXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<1,int>(3)),ZpYzXz) << "Failed"; } TEST(Direction3D, Edges) { - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2,-1)),NorthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2, 1)),NorthEast) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 2,-1)),SouthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 2, 1)),SouthEast) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2,-1)),ZzYmXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-2, 1)),ZzYmXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 2,-1)),ZzYpXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 2, 1)),ZzYpXp) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3,-1)),BottomWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3, 1)),BottomEast) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3,-2)),BottomNorth) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3, 2)),BottomSouth) << "Failed"; - - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3,-1)),TopWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3, 1)),TopEast) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3,-2)),TopNorth) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3, 2)),TopSouth) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3,-1)),ZmYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3, 1)),ZmYzXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3,-2)),ZmYmXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>(-3, 2)),ZmYpXz) << "Failed"; + + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3,-1)),ZpYzXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3, 1)),ZpYzXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3,-2)),ZpYmXz) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<2,int>( 3, 2)),ZpYpXz) << "Failed"; } TEST(Direction3D, Conners) { - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3,-2,-1)),BottomNorthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3,-2, 1)),BottomNorthEast) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3, 2,-1)),BottomSouthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3, 2, 1)),BottomSouthEast) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3,-2,-1)),ZmYmXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3,-2, 1)),ZmYmXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3, 2,-1)),ZmYpXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(-3, 2, 1)),ZmYpXp) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3,-2,-1)),TopNorthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3,-2, 1)),TopNorthEast) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3, 2,-1)),TopSouthWest) << "Failed"; - EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3, 2, 1)),TopSouthEast) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3,-2,-1)),ZpYmXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3,-2, 1)),ZpYmXp) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3, 2,-1)),ZpYpXm) << "Failed"; + EXPECT_EQ(Directions::getDirection(StaticVector<3,int>(3, 2, 1)),ZpYpXp) << "Failed"; } TEST(XYZ, 2D ) { - EXPECT_EQ( Directions::template getXYZ<2>(Left), (StaticVector<2,int>(-1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(Right), (StaticVector<2,int>(1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(Up), (StaticVector<2,int>(0,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(Down), (StaticVector<2,int>(0,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYzXm), (StaticVector<2,int>(-1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYzXp), (StaticVector<2,int>(1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYmXz), (StaticVector<2,int>(0,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYpXz), (StaticVector<2,int>(0,1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(UpLeft), (StaticVector<2,int>(-1,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(UpRight), (StaticVector<2,int>(1,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(DownLeft), (StaticVector<2,int>(-1,1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<2>(DownRight), (StaticVector<2,int>(1,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYmXm), (StaticVector<2,int>(-1,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYmXp), (StaticVector<2,int>(1,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYpXm), (StaticVector<2,int>(-1,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<2>(ZzYpXp), (StaticVector<2,int>(1,1)) ) << "Failed"; } TEST(XYZ, 3D ) { - EXPECT_EQ( Directions::template getXYZ<3>(West), (StaticVector<3,int>(-1,0,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(East), (StaticVector<3,int>(1,0,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(North), (StaticVector<3,int>(0,-1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(South), (StaticVector<3,int>(0,1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(Bottom), (StaticVector<3,int>(0,0,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(Top), (StaticVector<3,int>(0,0,1)) ) << "Failed"; - - EXPECT_EQ( Directions::template getXYZ<3>(NorthWest), (StaticVector<3,int>(-1,-1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(NorthEast), (StaticVector<3,int>(1,-1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(SouthWest), (StaticVector<3,int>(-1,1,0)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(SouthEast), (StaticVector<3,int>(1,1,0)) ) << "Failed"; - - EXPECT_EQ( Directions::template getXYZ<3>(BottomWest), (StaticVector<3,int>(-1,0,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(BottomEast), (StaticVector<3,int>(1,0,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(TopWest), (StaticVector<3,int>(-1,0,1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(TopEast), (StaticVector<3,int>(1,0,1)) ) << "Failed"; - - EXPECT_EQ( Directions::template getXYZ<3>(BottomNorth), (StaticVector<3,int>(0,-1,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(BottomSouth), (StaticVector<3,int>(0,1,-1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(TopNorth), (StaticVector<3,int>(0,-1,1)) ) << "Failed"; - EXPECT_EQ( Directions::template getXYZ<3>(TopSouth), (StaticVector<3,int>(0,1,1)) ) << "Failed"; - - EXPECT_EQ( Directions::template getXYZ<3>(TopSouthWest), (StaticVector<3,int>(-1,1,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYzXm), (StaticVector<3,int>(-1,0,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYzXp), (StaticVector<3,int>(1,0,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYmXz), (StaticVector<3,int>(0,-1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYpXz), (StaticVector<3,int>(0,1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZmYzXz), (StaticVector<3,int>(0,0,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZpYzXz), (StaticVector<3,int>(0,0,1)) ) << "Failed"; + + EXPECT_EQ( Directions::template getXYZ<3>(ZzYmXm), (StaticVector<3,int>(-1,-1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYmXp), (StaticVector<3,int>(1,-1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYpXm), (StaticVector<3,int>(-1,1,0)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZzYpXp), (StaticVector<3,int>(1,1,0)) ) << "Failed"; + + EXPECT_EQ( Directions::template getXYZ<3>(ZmYzXm), (StaticVector<3,int>(-1,0,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZmYzXp), (StaticVector<3,int>(1,0,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZpYzXm), (StaticVector<3,int>(-1,0,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZpYzXp), (StaticVector<3,int>(1,0,1)) ) << "Failed"; + + EXPECT_EQ( Directions::template getXYZ<3>(ZmYmXz), (StaticVector<3,int>(0,-1,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZmYpXz), (StaticVector<3,int>(0,1,-1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZpYmXz), (StaticVector<3,int>(0,-1,1)) ) << "Failed"; + EXPECT_EQ( Directions::template getXYZ<3>(ZpYpXz), (StaticVector<3,int>(0,1,1)) ) << "Failed"; + + EXPECT_EQ( Directions::template getXYZ<3>(ZpYpXm), (StaticVector<3,int>(-1,1,1)) ) << "Failed"; } diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp index 251b9f553a4fc82b7d1bb5ef768991a519aec047..fca8bb8cff9f3968cb97f9674da3e4f8da2f17f0 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_1D.cpp @@ -222,7 +222,6 @@ TEST_F(DistributedGridTest_1D, SynchronizerNeighborsTest ) EXPECT_EQ((dof)[dof.getSize()-1],rank+1)<< "Right Overlap was filled by wrong process."; } - TEST_F(DistributedGridTest_1D, EvaluateLinearFunction ) { //fill mesh function with linear function (physical center of cell corresponds with its coordinates in grid) @@ -258,12 +257,14 @@ TEST_F(DistributedGridTest_1D, SynchronizePeriodicNeighborsWithoutMask ) maskDofs.setValue( true ); constFunctionEvaluator.evaluateAllEntities( meshFunctionPtr, constFunctionPtr ); meshFunctionPtr->template synchronize( true ); + if( rank == 0 ) EXPECT_EQ( dof[ 1 ], -nproc ) << "Left Overlap was filled by wrong process."; if( rank == nproc-1 ) EXPECT_EQ( dof[ dof.getSize() - 2 ], -1 )<< "Right Overlap was filled by wrong process."; } + TEST_F(DistributedGridTest_1D, SynchronizePeriodicNeighborsWithActiveMask ) { // Setup periodic boundaries diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp index b19b0f13db2cd70d4fe52451d726bb68c75d0adf..26bfbb4572e43cecd9b3e4de8f49083b8ebf3626 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_2D.cpp @@ -370,7 +370,8 @@ class DistributedGridTest_2D : public ::testing::Test distributedGrid->setDomainDecomposition( typename DistributedGridType::CoordinatesType( 3, 3 ) ); distributedGrid->template setGlobalGrid( globalGrid ); typename DistributedGridType::SubdomainOverlapsType lowerOverlap, upperOverlap; - SubdomainOverlapsGetter< GridType, CommunicatorType >::getOverlaps( distributedGrid, lowerOverlap, upperOverlap, 1 ); + SubdomainOverlapsGetter< GridType, CommunicatorType >:: + getOverlaps( distributedGrid, lowerOverlap, upperOverlap, 1 ); distributedGrid->setOverlaps( lowerOverlap, upperOverlap ); distributedGrid->setupGrid(*gridPtr); @@ -400,6 +401,7 @@ TEST_F(DistributedGridTest_2D, evaluateAllEntities) check_Inner_2D(rank, *gridPtr, *dof, rank); } + TEST_F(DistributedGridTest_2D, evaluateBoundaryEntities) { //Boundary entities, without overlap @@ -686,7 +688,7 @@ TEST_F(DistributedGridTest_2D, SynchronizerNeighborPeriodicBoundariesWithInactiv //Expecting 9 processes setDof_2D(*dof, -rank-1 ); maskDofs.setValue( true ); - if( distributedGrid->getNeighbors()[ Left ] == -1 ) + if( distributedGrid->getNeighbors()[ ZzYzXm ] == -1 ) { for( IndexType i = 0; i < gridPtr->getDimensions().y(); i++ ) { @@ -770,7 +772,7 @@ TEST_F(DistributedGridTest_2D, SynchronizerNeighborPeriodicBoundariesWithInActiv //Expecting 9 processes setDof_2D(*dof, -rank-1 ); maskDofs.setValue( true ); - if( distributedGrid->getNeighbors()[ Right ] == -1 ) + if( distributedGrid->getNeighbors()[ ZzYzXp ] == -1 ) { for( IndexType i = 0; i < gridPtr->getDimensions().y(); i++ ) { @@ -854,7 +856,7 @@ TEST_F(DistributedGridTest_2D, SynchronizerNeighborPeriodicBoundariesWithInActiv //Expecting 9 processes setDof_2D(*dof, -rank-1 ); maskDofs.setValue( true ); - if( distributedGrid->getNeighbors()[ Up ] == -1 ) + if( distributedGrid->getNeighbors()[ ZzYmXz ] == -1 ) { for( IndexType i = 0; i < gridPtr->getDimensions().x(); i++ ) { @@ -938,7 +940,7 @@ TEST_F(DistributedGridTest_2D, SynchronizerNeighborPeriodicBoundariesWithInActiv //Expecting 9 processes setDof_2D(*dof, -rank-1 ); maskDofs.setValue( true ); - if( distributedGrid->getNeighbors()[ Down ] == -1 ) + if( distributedGrid->getNeighbors()[ ZzYpXz ] == -1 ) { for( IndexType i = 0; i < gridPtr->getDimensions().x(); i++ ) { diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp index 6bbd7ad257a176f8f10f2dcefcd5315b385307ce..f92ef08d7a58fb053541ae5f6b5e2b4dc75560a0 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridTest_3D.cpp @@ -642,12 +642,13 @@ class DistributedGirdTest_3D : public ::testing::Test globalGrid.setDimensions(size,size,size); globalGrid.setDomain(globalOrigin,globalProportions); - typename DistributedGridType::SubdomainOverlapsType lowerOverlap, upperOverlap; distributedGrid=new DistributedGridType(); distributedGrid->setDomainDecomposition( typename DistributedGridType::CoordinatesType( 3, 3, 3 ) ); distributedGrid->template setGlobalGrid( globalGrid ); distributedGrid->setupGrid(*gridptr); - SubdomainOverlapsGetter< GridType, CommunicatorType >::getOverlaps( distributedGrid, lowerOverlap, upperOverlap, 1 ); + typename DistributedGridType::SubdomainOverlapsType lowerOverlap, upperOverlap; + SubdomainOverlapsGetter< GridType, CommunicatorType >:: + getOverlaps( distributedGrid, lowerOverlap, upperOverlap, 1 ); distributedGrid->setOverlaps( lowerOverlap, upperOverlap ); distributedGrid->setupGrid(*gridptr);