Commit 183033f2 authored by Ján Bobot's avatar Ján Bobot Committed by Jakub Klinkovský
Browse files

Added EntityInitializerLayer specialization for initializing polyhedron...

Added EntityInitializerLayer specialization for initializing polyhedron subentites 3 -> 2 from cell seeds + other minor mesh refactoring
parent 041d6070
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ template< typename CellTopology,
bool
setMeshParameters( Params&&... params )
{
   bool status = MeshBenchmarksRunner< MinimalConfig, CellTopology, SpaceDimension, float, int, int >::run( std::forward<Params>(params)... ) &&
                 MeshBenchmarksRunner< FullConfig, CellTopology, SpaceDimension, float, int, int >::run( std::forward<Params>(params)... );
   bool status = MeshBenchmarksRunner< MinimalConfig, CellTopology, SpaceDimension, float, int, short int >::run( std::forward<Params>(params)... ) &&
                 MeshBenchmarksRunner< FullConfig, CellTopology, SpaceDimension, float, int, short int >::run( std::forward<Params>(params)... );
   return status;
}

+4 −0
Original line number Diff line number Diff line
@@ -43,10 +43,14 @@ public:

   Index insert( const Key& key );

   Index insert( Key&& key );

   std::pair< Index, bool > try_insert( const Key& key );

   bool find( const Key& key, Index& index ) const;

   void reserve( size_type count );

   size_type count( const Key& key ) const;

   size_type erase( const Key& key );
+23 −0
Original line number Diff line number Diff line
@@ -49,6 +49,18 @@ UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::insert( const Key&
   return iter->second;
}

template< class Key,
          class Index,
          class Hash,
          class KeyEqual,
          class Allocator >
Index
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::insert( Key&& key )
{
   auto iter = map.insert( value_type( std::move( key ), size() ) ).first;
   return iter->second;
}

template< class Key,
          class Index,
          class Hash,
@@ -76,6 +88,17 @@ UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::find( const Key& k
   return true;
}

template< class Key,
          class Index,
          class Hash,
          class KeyEqual,
          class Allocator >
void
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::reserve( size_type count )
{
   map.reserve( count );
}

template< class Key,
          class Index,
          class Hash,
+182 −12
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ class Initializer;
template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperdimensionTag,
          typename SuperentityTopology = typename MeshTraits< MeshConfig >::template EntityTraits< SuperdimensionTag::value >::EntityTopology,
          // storage in the superentity
          bool SubentityStorage = MeshConfig::subentityStorage( SuperdimensionTag::value, SubdimensionTag::value ),
          // storage in the subentity
@@ -57,7 +58,7 @@ class EntityInitializer
   using NeighborCountsArray = typename MeshTraitsType::NeighborCountsArray;

public:
   static void initSubvertexMatrix( const NeighborCountsArray& capacities, InitializerType& initializer )
   static void initSubvertexMatrix( NeighborCountsArray& capacities, InitializerType& initializer )
   {
      initializer.template initSubentityMatrix< EntityTopology::dimension, 0 >( capacities );
   }
@@ -97,10 +98,12 @@ public:
 */
template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperdimensionTag >
          typename SuperdimensionTag,
          typename SuperentityTopology >
class EntityInitializerLayer< MeshConfig,
                              SubdimensionTag,
                              SuperdimensionTag,
                              SuperentityTopology,
                              true,
                              true,
                              true >
@@ -120,7 +123,6 @@ class EntityInitializerLayer< MeshConfig,
   using SubentityTraitsType        = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using SubentityTopology          = typename SubentityTraitsType::EntityTopology;
   using SuperentityTraitsType      = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology        = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType  = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using SuperentityMatrixType      = typename MeshTraitsType::SuperentityMatrixType;
   using NeighborCountsArray        = typename MeshTraitsType::NeighborCountsArray;
@@ -182,6 +184,101 @@ public:
   }
};

/****
 *       Mesh entity initializer layer with specializations
 *
 *  SUBENTITY STORAGE     SUPERENTITY STORAGE     Subdimension     Superdimension     SUPERENTITY TOPOLOGY
 *      TRUE                    TRUE                  2                 3                POLYHEDRON
 */
template< typename MeshConfig >
class EntityInitializerLayer< MeshConfig,
                              DimensionTag< 2 >,
                              DimensionTag< 3 >,
                              Topologies::Polyhedron,
                              true,
                              true,
                              true >
   : public EntityInitializerLayer< MeshConfig,
                                    DimensionTag< 2 >,
                                    typename DimensionTag< 3 >::Decrement >
{
   using SubdimensionTag = DimensionTag< 2 >;
   using SuperdimensionTag = DimensionTag< 3 >;

   using BaseType = EntityInitializerLayer< MeshConfig,
                                            SubdimensionTag,
                                            typename SuperdimensionTag::Decrement >;
   using InitializerType            = Initializer< MeshConfig >;
   using MeshType                   = typename InitializerType::MeshType;
   using MeshTraitsType             = MeshTraits< MeshConfig >;

   using GlobalIndexType            = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType             = typename MeshTraitsType::LocalIndexType;
   using SubentityTraitsType        = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using SubentityTopology          = typename SubentityTraitsType::EntityTopology;
   using SuperentityTraitsType      = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology        = typename SuperentityTraitsType::EntityTopology;
   using SuperentityMatrixType      = typename MeshTraitsType::SuperentityMatrixType;
   using NeighborCountsArray        = typename MeshTraitsType::NeighborCountsArray;
   using SeedType                   = EntitySeed< MeshConfig, SubentityTopology >;

public:
   static void initSuperentities( InitializerType& meshInitializer, MeshType& mesh )
   {
      //std::cout << "   Initiating superentities with dimension " << SuperdimensionTag::value << " for subentities with dimension " << SubdimensionTag::value << " ... " << std::endl;

      const GlobalIndexType subentitiesCount = mesh.template getEntitiesCount< SubdimensionTag::value >();
      const GlobalIndexType superentitiesCount = mesh.template getEntitiesCount< SuperdimensionTag::value >();

      auto& cellSeeds = meshInitializer.getCellSeeds();

      NeighborCountsArray capacities( cellSeeds.getSize() );

      for( GlobalIndexType superentityIndex = 0; superentityIndex < capacities.getSize(); superentityIndex++ )
         capacities[ superentityIndex ] = cellSeeds[ superentityIndex ].getCornersCount();

      meshInitializer.template initSubentityMatrix< SuperdimensionTag::value, SubdimensionTag::value >( capacities, subentitiesCount );

      // counter for superentities of each subentity
      auto& superentitiesCounts = meshInitializer.template getSuperentitiesCountsArray< SubdimensionTag::value, SuperdimensionTag::value >();
      superentitiesCounts.setSize( subentitiesCount );
      superentitiesCounts.setValue( 0 );

      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         auto& cellSeed = cellSeeds[ superentityIndex ];
         for( LocalIndexType i = 0; i < cellSeed.getCornersCount(); i++ )
         {
            const GlobalIndexType subentityIndex = cellSeed.getCornerIds()[ i ];
            meshInitializer.template setSubentityIndex< SuperdimensionTag::value, SubdimensionTag::value >( superentityIndex, i, subentityIndex );
            superentitiesCounts[ subentityIndex ]++;
         }
      }
      cellSeeds.reset();

      // allocate superentities storage
      SuperentityMatrixType& matrix = meshInitializer.template getSuperentitiesMatrix< SubdimensionTag::value, SuperdimensionTag::value >();
      matrix.setDimensions( subentitiesCount, superentitiesCount );
      matrix.setRowCapacities( superentitiesCounts );
      superentitiesCounts.setValue( 0 );

      // initialize superentities storage
      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         for( LocalIndexType i = 0;
              i < mesh.template getSubentitiesCount< SuperdimensionTag::value, SubdimensionTag::value >( superentityIndex );
              i++ )
         {
            const GlobalIndexType subentityIndex = mesh.template getSubentityIndex< SuperdimensionTag::value, SubdimensionTag::value >( superentityIndex, i );
            auto row = matrix.getRow( subentityIndex );
            row.setElement( superentitiesCounts[ subentityIndex ]++, superentityIndex, true );
         }
      }

      BaseType::initSuperentities( meshInitializer, mesh );
   }
};

/****
 *       Mesh entity initializer layer with specializations
 *
@@ -190,10 +287,12 @@ public:
 */
template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperdimensionTag >
          typename SuperdimensionTag,
          typename SuperentityTopology >
class EntityInitializerLayer< MeshConfig,
                              SubdimensionTag,
                              SuperdimensionTag,
                              SuperentityTopology,
                              true,
                              false,
                              true >
@@ -213,7 +312,6 @@ class EntityInitializerLayer< MeshConfig,
   using SubentityTraitsType        = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using SubentityTopology          = typename SubentityTraitsType::EntityTopology;
   using SuperentityTraitsType     = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology       = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using NeighborCountsArray       = typename MeshTraitsType::NeighborCountsArray;
   using SeedType                  = EntitySeed< MeshConfig, SubentityTopology >;
@@ -235,9 +333,7 @@ public:
         meshInitializer.template initSubentityMatrix< SuperdimensionTag::value, SubdimensionTag::value >( capacities, subentitiesCount );
      }

      for( GlobalIndexType superentityIndex = 0;
           superentityIndex < mesh.template getEntitiesCount< SuperdimensionTag::value >();
           superentityIndex++ )
      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         LocalIndexType i = 0;
         SubentitySeedsCreatorType::iterate( meshInitializer, mesh, superentityIndex, [&] ( SeedType& seed ) {
@@ -250,6 +346,75 @@ public:
   }
};

/****
 *       Mesh entity initializer layer with specializations
 *
 *  SUBENTITY STORAGE     SUPERENTITY STORAGE     Subdimension     Superdimension     SUPERENTITY TOPOLOGY
 *      TRUE                   FALSE                   2                 3                POLYHEDRON
 */
template< typename MeshConfig >
class EntityInitializerLayer< MeshConfig,
                              DimensionTag< 2 >,
                              DimensionTag< 3 >,
                              Topologies::Polyhedron,
                              true,
                              false,
                              true >
   : public EntityInitializerLayer< MeshConfig,
                                    DimensionTag< 2 >,
                                    typename DimensionTag< 3 >::Decrement >
{
   using SubdimensionTag = DimensionTag< 2 >;
   using SuperdimensionTag = DimensionTag< 3 >;

   using BaseType = EntityInitializerLayer< MeshConfig,
                                            SubdimensionTag,
                                            typename SuperdimensionTag::Decrement >;
   using InitializerType           = Initializer< MeshConfig >;
   using MeshType                  = typename InitializerType::MeshType;
   using MeshTraitsType            = MeshTraits< MeshConfig >;

   using GlobalIndexType           = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType            = typename MeshTraitsType::LocalIndexType;
   using SubentityTraitsType       = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using SubentityTopology         = typename SubentityTraitsType::EntityTopology;
   using SuperentityTraitsType     = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology       = typename SuperentityTraitsType::EntityTopology;
   using NeighborCountsArray       = typename MeshTraitsType::NeighborCountsArray;
   using SeedType                  = EntitySeed< MeshConfig, SubentityTopology >;

public:
   static void initSuperentities( InitializerType& meshInitializer, MeshType& mesh )
   {
      //std::cout << "   Initiating superentities with dimension " << SuperdimensionTag::value << " for subentities with dimension " << SubdimensionTag::value << " ... " << std::endl;

      const GlobalIndexType subentitiesCount = mesh.template getEntitiesCount< SubdimensionTag::value >();
      const GlobalIndexType superentitiesCount = mesh.template getEntitiesCount< SuperdimensionTag::value >();

      auto& cellSeeds = meshInitializer.getCellSeeds();

      NeighborCountsArray capacities( cellSeeds.getSize() );

      for( GlobalIndexType superentityIndex = 0; superentityIndex < capacities.getSize(); superentityIndex++ )
         capacities[ superentityIndex ] = cellSeeds[ superentityIndex ].getCornersCount();

      meshInitializer.template initSubentityMatrix< SuperdimensionTag::value, SubdimensionTag::value >( capacities, subentitiesCount );

      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         auto& cellSeed = cellSeeds[ superentityIndex ];
         for( LocalIndexType i = 0; i < cellSeed.getCornersCount(); i++ )
         {
            const GlobalIndexType subentityIndex = cellSeed.getCornerIds()[ i ];
            meshInitializer.template setSubentityIndex< SuperdimensionTag::value, SubdimensionTag::value >( superentityIndex, i, subentityIndex );
         }
      }
      cellSeeds.reset();

      BaseType::initSuperentities( meshInitializer, mesh );
   }
};

/****
 *       Mesh entity initializer layer with specializations
 *
@@ -258,10 +423,12 @@ public:
 */
template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperdimensionTag >
          typename SuperdimensionTag,
          typename SuperentityTopology >
class EntityInitializerLayer< MeshConfig,
                              SubdimensionTag,
                              SuperdimensionTag,
                              SuperentityTopology,
                              false,
                              true,
                              true >
@@ -281,7 +448,6 @@ class EntityInitializerLayer< MeshConfig,
   using SubentityTraitsType        = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using SubentityTopology          = typename SubentityTraitsType::EntityTopology;
   using SuperentityTraitsType      = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology        = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType  = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using SuperentityMatrixType      = typename MeshTraitsType::SuperentityMatrixType;
   using SeedType                   = EntitySeed< MeshConfig, SubentityTopology >;
@@ -329,10 +495,12 @@ public:

template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperdimensionTag >
          typename SuperdimensionTag,
          typename SuperentityTopology >
class EntityInitializerLayer< MeshConfig,
                              SubdimensionTag,
                              SuperdimensionTag,
                              SuperentityTopology,
                              false,
                              false,
                              true >
@@ -343,11 +511,13 @@ class EntityInitializerLayer< MeshConfig,

template< typename MeshConfig,
          typename SubdimensionTag,
          typename SuperentityTopology,
          bool SubentityStorage,
          bool SuperentityStorage >
class EntityInitializerLayer< MeshConfig,
                              SubdimensionTag,
                              SubdimensionTag,
                              SuperentityTopology,
                              SubentityStorage,
                              SuperentityStorage,
                              false >
+16 −17
Original line number Diff line number Diff line
@@ -109,14 +109,14 @@ class Initializer
      }

      template< int Dimension, int Subdimension >
      void initSubentityMatrix( const NeighborCountsArray& capacities, GlobalIndexType subentitiesCount = 0 )
      void initSubentityMatrix( NeighborCountsArray& capacities, GlobalIndexType subentitiesCount = 0 )
      {
         if( Subdimension == 0 )
            subentitiesCount = mesh->template getEntitiesCount< 0 >();
         auto& matrix = mesh->template getSubentitiesMatrix< Dimension, Subdimension >();
         matrix.setDimensions( capacities.getSize(), subentitiesCount );
         matrix.setRowCapacities( capacities );
         mesh->template setSubentitiesCounts< Dimension, Subdimension >( capacities );
         mesh->template setSubentitiesCounts< Dimension, Subdimension >( std::move( capacities ) );
      }

      template< int Dimension >
@@ -206,7 +206,7 @@ protected:

         NeighborCountsArray capacities( cellSeeds.getSize() );

         for( LocalIndexType i = 0; i < capacities.getSize(); i++ )
         for( GlobalIndexType i = 0; i < capacities.getSize(); i++ )
            capacities[ i ] = cellSeeds[ i ].getCornersCount();

         EntityInitializerType::initSubvertexMatrix( capacities, initializer );
@@ -259,10 +259,11 @@ protected:

      void createSeeds( InitializerType& initializer, MeshType& mesh )
      {
         this->seedsIndexedSet.reserve( mesh.template getEntitiesCount< MeshTraitsType::meshDimension >() );
         using SubentitySeedsCreator = SubentitySeedsCreator< MeshConfig, typename MeshTraitsType::CellTopology, DimensionTag >;
         for( GlobalIndexType i = 0; i < mesh.template getEntitiesCount< MeshType::getMeshDimension() >(); i++ ) {
            SubentitySeedsCreator::iterate( initializer, mesh, i, [&] ( SeedType& seed ) {
               this->seedsIndexedSet.insert( seed );
               this->seedsIndexedSet.insert( std::move( seed ) );
            });
         }
      }
@@ -306,30 +307,28 @@ protected:
         BaseType::initEntities( initializer, mesh );
      }

      void initEntities( InitializerType& initializer, EntitySeedArrayType& faceSeeds, MeshType& mesh )
      void initEntities( InitializerType& initializer, EntitySeedArrayType& seeds, MeshType& mesh )
      {
         //std::cout << " Initiating entities with dimension " << DimensionTag::value << " ... " << std::endl;

         initializer.template setEntitiesCount< DimensionTag::value >( faceSeeds.getSize() );
         initializer.template setEntitiesCount< DimensionTag::value >( seeds.getSize() );

         // allocate the subvertex matrix
         NeighborCountsArray capacities( faceSeeds.getSize() );
         for( LocalIndexType i = 0; i < capacities.getSize(); i++ ) {
            capacities.setElement( i, faceSeeds[ i ].getCornersCount() );
         NeighborCountsArray capacities( seeds.getSize() );
         for( GlobalIndexType i = 0; i < capacities.getSize(); i++ ) {
            capacities.setElement( i, seeds[ i ].getCornersCount() );
         }
         EntityInitializerType::initSubvertexMatrix( capacities, initializer );

         // initialize the entities
         for( GlobalIndexType i = 0; i < faceSeeds.getSize(); i++ ) {
            const auto& seed = faceSeeds[ i ];
            GlobalIndexType entityIndex = this->seedsIndexedSet.insert( seed );
            EntityInitializerType::initEntity( entityIndex, seed, initializer );
         }
         for( GlobalIndexType i = 0; i < seeds.getSize(); i++ )
            EntityInitializerType::initEntity( i, seeds[ i ], initializer );
         seeds.reset();

         faceSeeds.reset();
         // initialize links between the entities and all superentities
         EntityInitializerType::initSuperentities( initializer, mesh );
         this->seedsIndexedSet.clear();
         initializer.getCellSeeds().reset();

         // continue with the next dimension
         BaseType::initEntities( initializer, mesh );
      }

Loading