diff --git a/src/TNL/Meshes/BuildConfigTags.h b/src/TNL/Meshes/BuildConfigTags.h index 35aa2b2f89041575587e3f9ac291db02475dd0fa..456a0d63649edcd7d3b6c2788f6791ea22a25610 100644 --- a/src/TNL/Meshes/BuildConfigTags.h +++ b/src/TNL/Meshes/BuildConfigTags.h @@ -20,6 +20,10 @@ #include <TNL/Meshes/Topologies/Hexahedron.h> #include <TNL/Meshes/Topologies/Simplex.h> +#ifdef HAVE_ADAPTIVE_GRID +#include <TNL/Meshes/GridAdaptive.h> +#endif + namespace TNL { namespace Meshes { namespace BuildConfigTags { @@ -60,6 +64,17 @@ struct GridTag< ConfigTag, Grid< Dimension, Real, Device, Index > > }; }; +#ifdef HAVE_ADAPTIVE_GRID +template< typename ConfigTag, int Dimension, typename Real, typename Device, typename Index > +struct GridTag< ConfigTag, GridA< Dimension, Real, Device, Index > > +{ + enum { enabled = GridDimensionTag< ConfigTag, Dimension >::enabled && + GridRealTag< ConfigTag, Real >::enabled && + GridDeviceTag< ConfigTag, Device >::enabled && + GridIndexTag< ConfigTag, Index >::enabled + }; +}; +#endif /**** * Configuration for unstructured meshes diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.h b/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.h new file mode 100644 index 0000000000000000000000000000000000000000..73c75a7599f3b18da0f22e8bf89677d331b18e00 --- /dev/null +++ b/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.h @@ -0,0 +1,186 @@ +/*************************************************************************** + DistributedAdaptiveGrid.h - part common for all Dimensionensions + ------------------- + begin : Apr 04, 2019 + copyright : (C) 2019 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <iostream> + +#include <TNL/Meshes/Grid.h> +#include <TNL/Logger.h> +#include <TNL/Meshes/DistributedMeshes/Directions.h> +#include <TNL/Meshes/DistributedMeshes/DistributedMesh.h> + +#ifdef HAVE_ADAPTIVE_GRID +#include <TNL/Meshes/GridAdaptive.h> +#endif + + +namespace TNL { +namespace Meshes { +namespace DistributedMeshes { + + +#ifdef HAVE_ADAPTIVE_GRID +template< int Dimension, + typename Real, + typename Device, + typename Index > +class DistributedMesh< GridA< Dimension, Real, Device, Index > > +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef Grid< Dimension, Real, Device, IndexType > GridType; + typedef typename GridType::PointType PointType; + typedef Containers::StaticVector< Dimension, IndexType > CoordinatesType; + typedef Containers::StaticVector< Dimension, IndexType > SubdomainOverlapsType; + + static constexpr int getMeshDimension() { return Dimension; }; + + static constexpr int getNeighborsCount() { return DirectionCount<Dimension>::get(); } //c++14 may use Directions::pow3(Dimension)-1 + + DistributedMesh(); + + ~DistributedMesh(); + + static void configSetup( Config::ConfigDescription& config ); + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix ); + + void setDomainDecomposition( const CoordinatesType& domainDecomposition ); + + const CoordinatesType& getDomainDecomposition() const; + + template< typename CommunicatorType > + void setGlobalGrid( const GridType& globalGrid ); + + const GridType& getGlobalGrid() const; + + void setOverlaps( const SubdomainOverlapsType& lower, + const SubdomainOverlapsType& upper); + + void setupGrid( GridType& grid); + + bool isDistributed() const; + + bool isBoundarySubdomain() const; + + // TODO: replace it with getLowerOverlap() and getUpperOverlap() + // 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; + + //number of elements of local sub domain WITHOUT overlap + // TODO: getSubdomainDimensions + const CoordinatesType& getLocalSize() const; + + // TODO: delete + //Dimensions of global grid + const CoordinatesType& getGlobalSize() const; + + //coordinates of begin of local subdomain without overlaps in global grid + const CoordinatesType& getGlobalBegin() const; + + //number of elements of local sub domain WITH overlap + // TODO: replace with localGrid + const CoordinatesType& getLocalGridSize() const; + + //coordinates of begin of local subdomain without overlaps in local grid + const CoordinatesType& getLocalBegin() const; + + const CoordinatesType& getSubdomainCoordinates() const; + + const PointType& getLocalOrigin() const; + const PointType& getSpaceSteps() const; + + //aka MPI-communcicator + void setCommunicationGroup(void * group); + void * getCommunicationGroup() const; + + template< int EntityDimension > + IndexType getEntitiesCount() const; + + template< typename Entity > + IndexType getEntitiesCount() const; + + const int* getNeighbors() const; + + const int* getPeriodicNeighbors() const; + + template<typename CommunicatorType, typename DistributedGridType> + bool SetupByCut(DistributedGridType &inputDistributedGrid, + Containers::StaticVector<Dimension, int> savedDimensions, + Containers::StaticVector<DistributedGridType::getMeshDimension()-Dimension,int> reducedDimensions, + Containers::StaticVector<DistributedGridType::getMeshDimension()-Dimension,IndexType> fixedIndexs); + + int getRankOfProcCoord(const CoordinatesType &nodeCoordinates) const; + + String printProcessCoords() const; + + String printProcessDistr() const; + + void writeProlog( Logger& logger ); + + public: + + bool isThereNeighbor(const CoordinatesType &direction) const; + + void setupNeighbors(); + + void print( std::ostream& str ) const; + + GridType globalGrid; + PointType localOrigin; + CoordinatesType localBegin; + CoordinatesType localSize; + CoordinatesType localGridSize; + CoordinatesType overlap; + //CoordinatesType globalDimensions; + CoordinatesType globalBegin; + PointType spaceSteps; + + SubdomainOverlapsType lowerOverlap, upperOverlap, globalLowerOverlap, globalUpperOverlap; + + CoordinatesType domainDecomposition; + CoordinatesType subdomainCoordinates; + + // TODO: static arrays + int neighbors[ getNeighborsCount() ]; + int periodicNeighbors[ getNeighborsCount() ]; + + IndexType Dimensions; + bool distributed; + + int rank; + int nproc; + + bool isSet; + + //aka MPI-communicator + void * communicationGroup; + +}; + +#endif + +} // namespace DistributedMeshes +} // namespace Meshes +} // namespace TNL + +#include <TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.hpp> + diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.hpp b/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..07730505f69a63cfaecde7092744152229c7a6f9 --- /dev/null +++ b/src/TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.hpp @@ -0,0 +1,293 @@ +/*************************************************************************** + DistributedAdaptiveGrid.hpp - description + ------------------- + begin : July 07, 2018 + copyright : (C) 2018 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <cstdlib> +#include <TNL/Communicators/MpiCommunicator.h> +#include <TNL/Meshes/DistributedMeshes/DistributedGrid.h> + +#ifdef HAVE_ADAPTIVE_GRID +#include <TNL/Meshes/GridAdaptive.h> +#endif + +namespace TNL { + namespace Meshes { + namespace DistributedMeshes { + +template<int Dimension, typename Real, typename Device, typename Index > +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +DistributedMesh() + : domainDecomposition( 0 ), isSet( false ) {} + +template<int Dimension, typename Real, typename Device, typename Index > +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +~DistributedMesh() +{ +} + + +template<int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +configSetup( Config::ConfigDescription& config ) +{ +} + +template<int Dimension, typename Real, typename Device, typename Index > +bool +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ + return true; +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setDomainDecomposition( const CoordinatesType& domainDecomposition ) +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getDomainDecomposition() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +template< typename CommunicatorType > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setGlobalGrid( const GridType &globalGrid ) +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setOverlaps( const SubdomainOverlapsType& lower, + const SubdomainOverlapsType& upper) +{ +} + + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setupGrid( GridType& grid) +{ +}; + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getSubdomainCoordinates() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::PointType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getLocalOrigin() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::PointType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getSpaceSteps() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +bool +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +isDistributed() const +{ +}; + +template< int Dimension, typename Real, typename Device, typename Index > +bool +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +isBoundarySubdomain() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getLowerOverlap() const +{ +}; + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getUpperOverlap() const +{ +}; + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getLocalSize() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getGlobalSize() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::GridType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getGlobalGrid() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getGlobalBegin() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getLocalGridSize() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const typename DistributedMesh< GridA< Dimension, Real, Device, Index > >::CoordinatesType& +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getLocalBegin() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > + template< int EntityDimension > +Index +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getEntitiesCount() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > + template< typename Entity > +Index +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getEntitiesCount() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setCommunicationGroup(void * group) +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void * +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getCommunicationGroup() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +int +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getRankOfProcCoord(const CoordinatesType &nodeCoordinates) const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +bool +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +isThereNeighbor(const CoordinatesType &direction) const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +setupNeighbors() +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +const int* +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getNeighbors() const +{ + TNL_ASSERT_TRUE(this->isSet,"DistributedGrid is not set, but used by getNeighbors"); + return this->neighbors; +} + +template< int Dimension, typename Real, typename Device, typename Index > +const int* +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +getPeriodicNeighbors() const +{ + TNL_ASSERT_TRUE(this->isSet,"DistributedGrid is not set, but used by getNeighbors"); + return this->periodicNeighbors; +} + +template< int Dimension, typename Real, typename Device, typename Index > + template<typename CommunicatorType, typename DistributedGridType > +bool +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +SetupByCut(DistributedGridType &inputDistributedGrid, + Containers::StaticVector<Dimension, int> savedDimensions, + Containers::StaticVector<DistributedGridType::getMeshDimension()-Dimension,int> reducedDimensions, + Containers::StaticVector<DistributedGridType::getMeshDimension()-Dimension,IndexType> fixedIndexs) +{ + return false; +} + +template< int Dimension, typename Real, typename Device, typename Index > +String +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +printProcessCoords() const +{ +}; + +template< int Dimension, typename Real, typename Device, typename Index > +String +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +printProcessDistr() const +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +writeProlog( Logger& logger ) +{ +} + +template< int Dimension, typename Real, typename Device, typename Index > +void +DistributedMesh< GridA< Dimension, Real, Device, Index > >:: +print( std::ostream& str ) const +{ +} + + } //namespace DistributedMeshes + } // namespace Meshes +} // namespace TNL diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h index 6e346668ccaddcc0b124afc733d1a602d3dfadfa..bf5bbbb591ce6edd72555b692d0e7bfac7d58c24 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.h @@ -1,5 +1,5 @@ /*************************************************************************** - DistributedGrid_Base.h - part common for all Dimensionensions + DistributedGrid.h - part common for all Dimensionensions ------------------- begin : July 07, 2018 copyright : (C) 2018 by Tomas Oberhuber diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp index a91b8a585c01c471b150221c38b724da72ec19e2..dbb3aa0e4873f352b4356dbb30cca7a5608337ba 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGrid.hpp @@ -1,5 +1,5 @@ /*************************************************************************** - DistributedGrid_Base.hpp - description + DistributedGrid.hpp - description ------------------- begin : July 07, 2018 copyright : (C) 2018 by Tomas Oberhuber diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h index 00342c7a948977c2c8c1acbdd313671050ca51a1..197f4992078a9882ae90fdadabcc60e882c5b1d9 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h @@ -17,8 +17,8 @@ namespace Meshes { namespace DistributedMeshes { -/* - * This variant cerate copy of MeshFunction but smaller, reduced to local entities, without overlap. +/**** + * This variant create copy of MeshFunction but smaller, reduced to local entities, without overlap. * It is slow and has high RAM consumption */ template< int Dimension, @@ -140,6 +140,41 @@ class DistributedGridIO< }; +#ifdef HAVE_ADAPTIVE_GRID +template< int Dimension, + int MeshEntityDimension, + typename MeshReal, + typename Device, + typename Index, + typename Real > +class DistributedGridIO< + Functions::MeshFunction< Meshes::GridA< Dimension, MeshReal, Device, Index >, + MeshEntityDimension, + Real >, + LocalCopy > +{ + public: + using MeshType = Meshes::GridA< Dimension, Real, Device, Index >; + using MeshFunctionType = Functions::MeshFunction< MeshType, MeshEntityDimension, Real >; + using CoordinatesType = typename MeshFunctionType::MeshType::CoordinatesType; + using PointType = typename MeshFunctionType::MeshType::PointType; + using VectorType = typename MeshFunctionType::VectorType; + //typedef DistributedGrid< MeshType,MeshFunctionType::getMeshDimension()> DistributedGridType; + + static bool save(const String& fileName, MeshFunctionType &meshFunction) + { + return false; + }; + + static bool load(const String& fileName,MeshFunctionType &meshFunction) + { + return false; + }; + +}; +#endif + + /* * Save distributed data into single file without overlaps using MPIIO and MPI datatypes, * EXPLOSIVE: works with only Grids and MPI @@ -524,6 +559,43 @@ class DistributedGridIO< }; }; + +#ifdef HAVE_ADAPTIVE_GRID +template< int Dimension, + int MeshEntityDimension, + typename MeshReal, + typename Device, + typename Index, + typename Real > +class DistributedGridIO< + Functions::MeshFunction< Meshes::GridA< Dimension, MeshReal, Device, Index >, + MeshEntityDimension, + Real >, + MpiIO > +{ + public: + using MeshType = Meshes::GridA< Dimension, MeshReal, Device, Index >; + using MeshFunctionType = Functions::MeshFunction< MeshType, MeshEntityDimension, Real >; + using CoordinatesType = typename MeshFunctionType::MeshType::CoordinatesType; + using PointType = typename MeshFunctionType::MeshType::PointType; + using VectorType = typename MeshFunctionType::VectorType; + //typedef DistributedGrid< MeshType,MeshFunctionType::getMeshDimension()> DistributedGridType; + + static bool save(const String& fileName, MeshFunctionType &meshFunction) + { + TNL_ASSERT( false, std::cerr << "Not implemented." << std::endl ); + return false; + }; + + static bool load(const String& fileName,MeshFunctionType &meshFunction) + { + TNL_ASSERT( false, std::cerr << "Not implemented." << std::endl ); + return false; + }; +}; +#endif + + } //namespace DistributedMeshes } //namespace Meshes } //namespace TNL diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h index 6f058a801572a9b7de229e3cb3054777553dd321..dea65815a0d8f8604133bdd187c3a0e0b050893b 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h @@ -17,6 +17,10 @@ #include <TNL/Meshes/DistributedMeshes/Directions.h> #include <TNL/Communicators/MPIPrint.h> +#ifdef HAVE_ADAPTIVE_GRID +#include <TNL/Meshes/GridAdaptive.h> +#endif + namespace TNL { namespace Functions{ template< typename Mesh, @@ -312,6 +316,82 @@ class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension, bool isSet; }; +#ifdef HAVE_ADAPTIVE_GRID + +template <typename RealType, + int EntityDimension, + int MeshDimension, + typename Index, + typename Device, + typename GridReal> +class DistributedMeshSynchronizer< Functions::MeshFunction< GridA< MeshDimension, GridReal, Device, Index >,EntityDimension, RealType>> +{ + + public: + static constexpr int getMeshDimension() { return MeshDimension; }; + static constexpr int getNeighborCount() {return DirectionCount<MeshDimension>::get();}; + + typedef typename GridA< MeshDimension, GridReal, Device, Index >::Cell Cell; + // FIXME: clang does not like this (incomplete type error) + typedef typename GridA< MeshDimension, GridReal, Device, Index >::DistributedMeshType DistributedGridType; + typedef typename DistributedGridType::CoordinatesType CoordinatesType; + using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; + + enum PeriodicBoundariesCopyDirection + { + BoundaryToOverlap, + OverlapToBoundary + }; + + DistributedMeshSynchronizer() + { + }; + + DistributedMeshSynchronizer( DistributedGridType *distributedGrid ) + { + }; + + void setPeriodicBoundariesCopyDirection( const PeriodicBoundariesCopyDirection dir ) + { + } + + void setDistributedGrid( DistributedGridType *distributedGrid ) + { + } + + template< typename CommunicatorType, + typename MeshFunctionType, + typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > + void startSynchronization( MeshFunctionType &meshFunction, + std::list< typename CommunicatorType::Request >& requests, + bool periodicBoundaries = false, + const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) + { + } + + template< typename CommunicatorType, + typename MeshFunctionType, + typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > + void finishSynchronization( MeshFunctionType &meshFunction, + std::list< typename CommunicatorType::Request >& requests, + bool periodicBoundaries = false, + const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) + { + } + + + template< typename CommunicatorType, + typename MeshFunctionType, + typename PeriodicBoundariesMaskPointer = Pointers::SharedPointer< MeshFunctionType > > + void synchronize( MeshFunctionType &meshFunction, + bool periodicBoundaries = false, + const PeriodicBoundariesMaskPointer& mask = PeriodicBoundariesMaskPointer( nullptr ) ) + { + } +}; + +#endif + } // namespace DistributedMeshes } // namespace Meshes diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedMesh.h b/src/TNL/Meshes/DistributedMeshes/DistributedMesh.h index c029cdc50fef8ac03b55ddf559be547421d3fb53..084dd06b04a9a9d0deddf8840c6fff81f3522ce1 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedMesh.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedMesh.h @@ -34,3 +34,4 @@ public: } // namespace TNL #include <TNL/Meshes/DistributedMeshes/DistributedGrid.h> +#include <TNL/Meshes/DistributedMeshes/DistributedAdaptiveGrid.h> diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index d75b9dec66710fad33109ceb23d757c15b2ff1f6..b7e85be0ed71642e9e15c74a03c6dffca49b2db5 100644 --- a/src/TNL/Meshes/Readers/TNLReader.h +++ b/src/TNL/Meshes/Readers/TNLReader.h @@ -53,6 +53,18 @@ public: else if( meshDimension == 3 ) cellShape = EntityShape::Hexahedron; } + else if( meshType == "Meshes::AdaptiveGrid" ) { + meshDimension = worldDimension = std::atoi( parsedMeshType[ 1 ].getString() ); + realType = parsedMeshType[ 2 ]; + globalIndexType = localIndexType = idType = parsedMeshType[ 4 ]; + // populate entity types (not necessary for GridTypeResolver, but while we're at it...) + if( meshDimension == 1 ) + cellShape = EntityShape::Line; + else if( meshDimension == 2 ) + cellShape = EntityShape::Quad; + else if( meshDimension == 3 ) + cellShape = EntityShape::Hexahedron; + } else if( meshType == "Meshes::Mesh" ) { const std::vector< String > parsedMeshConfig = parseObjectType( parsedMeshType[ 1 ] ); if( ! parsedMeshConfig.size() ) { diff --git a/src/TNL/Meshes/TypeResolver/TypeResolver_impl.h b/src/TNL/Meshes/TypeResolver/TypeResolver_impl.h index 79e8e89f7130a0fa97241dae59a496e376fa368b..6e70940a34f5182f2eece0299d23aaa70a5f7a05 100644 --- a/src/TNL/Meshes/TypeResolver/TypeResolver_impl.h +++ b/src/TNL/Meshes/TypeResolver/TypeResolver_impl.h @@ -20,6 +20,10 @@ #include <TNL/Meshes/TypeResolver/GridTypeResolver.h> #include <TNL/Meshes/TypeResolver/MeshTypeResolver.h> +#ifdef HAVE_ADAPTIVE_GRID +#include <TNL/Meshes/GridAdaptive.h> +#endif + // TODO: implement this in TNL::String inline bool ends_with( const std::string& value, const std::string& ending ) { @@ -163,6 +167,53 @@ loadMesh( const String& fileName, return true; } +#ifdef HAVE_ADAPTIVE_GRID +// Specializations for adaptive grid +template< typename CommunicatorType, + int Dimension, + typename Real, + typename Device, + typename Index > +bool +loadMesh( const String& fileName, + GridA< Dimension, Real, Device, Index >& mesh, + DistributedMeshes::DistributedMesh< GridA< Dimension, Real, Device, Index > > &distributedMesh ) +{ + + if( CommunicatorType::isDistributed() ) + { + /*std::cout << "Loading a global mesh from the file " << fileName << "..."; + GridA< Dimension, Real, Device, Index > globalGrid; + if( ! globalGrid.load( fileName ) ) + { + std::cerr << std::endl; + std::cerr << "I am not able to load the global mesh from the file " << fileName << "." << std::endl; + return false; + } + std::cout << " [ OK ] " << std::endl; + + typename Meshes::DistributedMeshes::DistributedMesh<GridA< Dimension, Real, Device, Index >>::SubdomainOverlapsType overlap; + distributedMesh.template setGlobalGrid< CommunicatorType >( globalGrid ); + distributedMesh.setupGrid(mesh); + return true;*/ + } + else + { + std::cout << "Loading a mesh from the file " << fileName << "..."; + if( ! mesh.load( fileName ) ) + { + std::cerr << std::endl; + std::cerr << "I am not able to load the mesh from the file " << fileName << "." << std::endl; + std::cerr << " You may create it with tools like tnl-grid-setup or tnl-mesh-convert." << std::endl; + return false; + } + std::cout << " [ OK ] " << std::endl; + return true; + } +} +#endif + + template< typename Problem, typename MeshConfig, typename Device > @@ -278,5 +329,33 @@ decomposeMesh( const Config::ParameterContainer& parameters, return true; } +#ifdef HAVE_ADAPTIVE_GRID +template< typename Problem, + int Dimension, + typename Real, + typename Device, + typename Index > +bool +decomposeMesh( const Config::ParameterContainer& parameters, + const String& prefix, + GridA< Dimension, Real, Device, Index >& mesh, + DistributedMeshes::DistributedMesh< GridA< Dimension, Real, Device, Index > > &distributedMesh, + Problem& problem ) +{ + using GridType = GridA< Dimension, Real, Device, Index >; + using DistributedGridType = DistributedMeshes::DistributedMesh< GridType >; + using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType; + using CommunicatorType = typename Problem::CommunicatorType; + + if( CommunicatorType::isDistributed() ) + { + return false; + } + else + return true; +} +#endif + + } // namespace Meshes } // namespace TNL diff --git a/src/TNL/Solvers/PDE/MeshDependentTimeSteps.h b/src/TNL/Solvers/PDE/MeshDependentTimeSteps.h index 143c4b7f02755057238ca878c52b75ae0a57a32e..6aec5cc21cf5b8178b2a6294f83d15eb8f433747 100644 --- a/src/TNL/Solvers/PDE/MeshDependentTimeSteps.h +++ b/src/TNL/Solvers/PDE/MeshDependentTimeSteps.h @@ -56,6 +56,42 @@ protected: Real timeStepOrder = 0.0; }; +#ifdef HAVE_ADAPTIVE_GRID +template< int Dimension, + typename MeshReal, + typename Device, + typename MeshIndex, + typename Real > +class MeshDependentTimeSteps< TNL::Meshes::GridA< Dimension, MeshReal, Device, MeshIndex >, Real > +{ +public: + using MeshType = TNL::Meshes::GridA< Dimension, MeshReal, Device, MeshIndex >; + + bool setTimeStepOrder( const Real& timeStepOrder ) + { + if( timeStepOrder < 0 ) { + std::cerr << "The time step order for PDESolver must be zero or positive value." << std::endl; + return false; + } + this->timeStepOrder = timeStepOrder; + return true; + } + + const Real& getTimeStepOrder() const + { + return timeStepOrder; + } + + Real getRefinedTimeStep( const MeshType& mesh, const Real& timeStep ) + { + return timeStep * std::pow( mesh.getSmallestSpaceStep(), this->timeStepOrder ); + } + +protected: + Real timeStepOrder = 0.0; +}; +#endif + template< typename MeshConfig, typename Device, typename Real >