Commit 12915957 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber

Getting ready for adaptive grid.

parent eb61fb7d
......@@ -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
......
/***************************************************************************
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>
/***************************************************************************
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
/***************************************************************************
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
......
/***************************************************************************
DistributedGrid_Base.hpp - description
DistributedGrid.hpp - description
-------------------
begin : July 07, 2018
copyright : (C) 2018 by Tomas Oberhuber
......
......@@ -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
......@@ -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