Commit 56b2bbb3 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Cleaning up mesh initializer

parent 49e7bb6a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ class Mesh

   protected:
      // Methods for the mesh initializer
      using StorageBaseType::getPoints;
      using StorageBaseType::setEntitiesCount;
      using StorageBaseType::getSubentityStorageNetwork;
      using StorageBaseType::getSuperentityStorageNetwork;
+5 −0
Original line number Diff line number Diff line
@@ -105,6 +105,11 @@ public:
      return points;
   }

   typename MeshTraitsType::PointArrayType& getPoints()
   {
      return points;
   }

   template< int Dimension >
   void setEntitiesCount( const typename MeshTraitsType::GlobalIndexType& entitiesCount )
   {
+0 −18
Original line number Diff line number Diff line
@@ -59,8 +59,6 @@ class EntityInitializer
   using MeshTraitsType   = MeshTraits< MeshConfig >;
   using GlobalIndexType  = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType   = typename MeshTraitsType::LocalIndexType;
   using EntityTraitsType = typename MeshTraitsType::template EntityTraits< EntityTopology::dimension >;
   using EntityType       = typename EntityTraitsType::EntityType;

   using SeedType         = EntitySeed< MeshConfig, EntityTopology >;
   using InitializerType  = Initializer< MeshConfig >;
@@ -74,22 +72,6 @@ public:
   }
};

template< typename MeshConfig >
class EntityInitializer< MeshConfig, Topologies::Vertex >
   : public EntityInitializerLayer< MeshConfig,
                                    DimensionTag< 0 >,
                                    DimensionTag< MeshTraits< MeshConfig >::meshDimension > >
{
public:
   using VertexType      = typename MeshTraits< MeshConfig >::VertexType;
   using GlobalIndexType = typename MeshTraits< MeshConfig >::GlobalIndexType;
   using InitializerType = Initializer< MeshConfig >;

   static void initEntity( const GlobalIndexType& entityIndex, InitializerType& initializer)
   {
   }
};


/****
 *       Mesh entity initializer layer with specializations
+27 −36
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@
 * not allocated at once, but by parts (by dimensions). The flow is roughly the
 * following:
 *
 *  - Allocate vertices and set their physical coordinates, deallocate input
 *    array of points.
 *  - Allocate cells and set their subvertex indices (but not other subentity
 *    indices), deallocate cell seeds (the cells will be used later).
 *  - For all dimensions D from (cell dimension - 1) to 1:
@@ -43,8 +45,6 @@
 *        - For entities with dimension D, initialize their superentity indices
 *          with dimension S.
 *     - Deallocate all intermediate data structures.
 *  - Allocate vertices and set their physical coordinates, deallocate input
 *    array of points.
 *  - For all superdimensions S > 0, repeat the same steps as above.
 *
 * Optimization notes:
@@ -95,8 +95,13 @@ class Initializer
                       CellSeedArrayType& cellSeeds,
                       MeshType& mesh )
      {
         // copy points
         mesh.template setEntitiesCount< 0 >( points.getSize() );
         mesh.getPoints() = points;
         points.reset();

         this->mesh = &mesh;
         BaseType::initEntities( *this, points, cellSeeds, mesh );
         BaseType::initEntities( *this, cellSeeds, mesh );
      }

      template< int Dimension >
@@ -123,11 +128,12 @@ class Initializer
         return mesh->template getSubentityStorageNetwork< Dimension, 0 >().getValues( entityIndex );
      }

      template< typename EntityTopology, int Superdimension >
      typename MeshTraitsType::template SuperentityTraits< EntityTopology, Superdimension >::StorageNetworkType&
      template< int Dimension, int Superdimension >
      auto
      meshSuperentityStorageNetwork()
         -> decltype( this->mesh->template getSuperentityStorageNetwork< Dimension, Superdimension >() )
      {
         return mesh->template getSuperentityStorageNetwork< EntityTopology::dimension, Superdimension >();
         return mesh->template getSuperentityStorageNetwork< Dimension, Superdimension >();
      }


@@ -168,16 +174,15 @@ class InitializerLayer< MeshConfig,
   using EntityTraitsType      = typename MeshTraitsType::template EntityTraits< DimensionTag::value >;
   using EntityTopology        = typename EntityTraitsType::EntityTopology;
   using GlobalIndexType       = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType        = typename MeshTraitsType::LocalIndexType;

   using InitializerType       = Initializer< MeshConfig >;
   using EntityInitializerType = EntityInitializer< MeshConfig, EntityTopology >;
   using CellSeedArrayType     = typename MeshTraitsType::CellSeedArrayType;
   using LocalIndexType        = typename MeshTraitsType::LocalIndexType;
   using PointArrayType        = typename MeshTraitsType::PointArrayType;

   public:

      void initEntities( InitializerType& initializer, PointArrayType& points, CellSeedArrayType& cellSeeds, MeshType& mesh )
      void initEntities( InitializerType& initializer, CellSeedArrayType& cellSeeds, MeshType& mesh )
      {
         //std::cout << " Initiating entities with dimension " << DimensionTag::value << " ... " << std::endl;
         initializer.template setEntitiesCount< DimensionTag::value >( cellSeeds.getSize() );
@@ -185,7 +190,7 @@ class InitializerLayer< MeshConfig,
            EntityInitializerType::initEntity( i, cellSeeds[ i ], initializer );
         cellSeeds.reset();

         BaseType::initEntities( initializer, points, mesh );
         BaseType::initEntities( initializer, mesh );
      }

      using BaseType::findEntitySeedIndex;
@@ -212,11 +217,10 @@ class InitializerLayer< MeshConfig,
   using EntityTraitsType      = typename MeshTraitsType::template EntityTraits< DimensionTag::value >;
   using EntityTopology        = typename EntityTraitsType::EntityTopology;
   using GlobalIndexType       = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType        = typename MeshTraitsType::LocalIndexType;

   using InitializerType       = Initializer< MeshConfig >;
   using EntityInitializerType = EntityInitializer< MeshConfig, EntityTopology >;
   using LocalIndexType        = typename MeshTraitsType::LocalIndexType;
   using PointArrayType        = typename MeshTraitsType::PointArrayType;
   using SeedType              = EntitySeed< MeshConfig, EntityTopology >;
   using SeedIndexedSet        = typename MeshTraits< MeshConfig >::template EntityTraits< DimensionTag::value >::SeedIndexedSetType;
   using SeedSet               = typename MeshTraits< MeshConfig >::template EntityTraits< DimensionTag::value >::SeedSetType;
@@ -244,7 +248,7 @@ class InitializerLayer< MeshConfig,
         return this->seedsIndexedSet.insert( seed );
      }

      void initEntities( InitializerType& initializer, PointArrayType& points, MeshType& mesh )
      void initEntities( InitializerType& initializer, MeshType& mesh )
      {
         //std::cout << " Initiating entities with dimension " << DimensionTag::value << " ... " << std::endl;
         const GlobalIndexType numberOfEntities = getEntitiesCount( initializer, mesh );
@@ -269,12 +273,11 @@ class InitializerLayer< MeshConfig,
         EntityInitializerType::initSuperentities( initializer, mesh );
         this->seedsIndexedSet.clear();

         BaseType::initEntities( initializer, points, mesh );
         BaseType::initEntities( initializer, mesh );
      }

      using BaseType::getReferenceOrientation;
      using ReferenceOrientationType = typename EntityTraitsType::ReferenceOrientationType;
      const ReferenceOrientationType& getReferenceOrientation( DimensionTag, GlobalIndexType index ) const {}
      void getReferenceOrientation( DimensionTag, GlobalIndexType index ) const {}

   private:
      SeedIndexedSet seedsIndexedSet;
@@ -301,11 +304,10 @@ class InitializerLayer< MeshConfig,
   using EntityTraitsType              = typename MeshType::template EntityTraits< DimensionTag::value >;
   using EntityTopology                = typename EntityTraitsType::EntityTopology;
   using GlobalIndexType               = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType                = typename MeshTraitsType::LocalIndexType;

   using InitializerType               = Initializer< MeshConfig >;
   using EntityInitializerType         = EntityInitializer< MeshConfig, EntityTopology >;
   using LocalIndexType                = typename MeshTraitsType::LocalIndexType;
   using PointArrayType                = typename MeshTraitsType::PointArrayType;
   using SeedType                      = EntitySeed< MeshConfig, EntityTopology >;
   using SeedIndexedSet                = typename MeshTraits< MeshConfig >::template EntityTraits< DimensionTag::value >::SeedIndexedSetType;
   using SeedSet                       = typename MeshTraits< MeshConfig >::template EntityTraits< DimensionTag::value >::SeedSetType;
@@ -335,7 +337,7 @@ class InitializerLayer< MeshConfig,
         return this->seedsIndexedSet.insert( seed );
      }

      void initEntities( InitializerType& initializer, PointArrayType& points, MeshType& mesh )
      void initEntities( InitializerType& initializer, MeshType& mesh )
      {
         //std::cout << " Initiating entities with dimension " << DimensionTag::value << " ... " << std::endl;
         const GlobalIndexType numberOfEntities = getEntitiesCount( initializer, mesh );
@@ -363,7 +365,7 @@ class InitializerLayer< MeshConfig,
         this->seedsIndexedSet.clear();
         this->referenceOrientations.clear();

         BaseType::initEntities( initializer, points, mesh );
         BaseType::initEntities( initializer, mesh );
      }

      using BaseType::getReferenceOrientation;
@@ -407,11 +409,10 @@ class InitializerLayer< MeshConfig,

   using EntityTraitsType      = typename MeshTraitsType::template EntityTraits< DimensionTag::value >;
   using EntityTopology        = typename EntityTraitsType::EntityTopology;

   using InitializerType       = Initializer< MeshConfig >;
   using GlobalIndexType       = typename MeshTraits< MeshConfig >::GlobalIndexType;
   using LocalIndexType        = typename MeshTraits< MeshConfig >::LocalIndexType;
   using PointArrayType        = typename MeshTraits< MeshConfig >::PointArrayType;

   using InitializerType       = Initializer< MeshConfig >;
   using EntityInitializerType = EntityInitializer< MeshConfig, EntityTopology >;
   using SeedType              = EntitySeed< MeshConfig, EntityTopology >;

@@ -422,24 +423,14 @@ class InitializerLayer< MeshConfig,
         return seed.getCornerIds()[ 0 ];
      }

      void initEntities( InitializerType& initializer, PointArrayType& points, MeshType& mesh )
      void initEntities( InitializerType& initializer, MeshType& mesh )
      {
         //std::cout << " Initiating entities with dimension " << DimensionTag::value << " ... " << std::endl;
         initializer.template setEntitiesCount< 0 >( points.getSize() );
         for( GlobalIndexType i = 0; i < points.getSize(); i++ ) {
            EntityInitializerType::initEntity( i, initializer );
            mesh.getPoint( i ) = points[ i ];
         }
         points.reset();

         EntityInitializerType::initSuperentities( initializer, mesh );
      }

      // This method is due to 'using BaseType::findEntityIndex;' in the derived class.
      void findEntitySeedIndex() {}

      using ReferenceOrientationType = typename EntityTraitsType::ReferenceOrientationType;
      const ReferenceOrientationType& getReferenceOrientation( DimensionTag, GlobalIndexType index ) const {}
      // This method is due to 'using BaseType::getReferenceOrientation;' in the derived class.
      void getReferenceOrientation( DimensionTag, GlobalIndexType index ) const {}
};

} // namespace Meshes
+1 −2
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ class SuperentityStorageInitializer
   using LocalIndexType            = typename MeshTraitsType::LocalIndexType;
   using EntityTraitsType          = typename MeshTraitsType::template EntityTraits< SubdimensionTag::value >;
   using EntityTopology            = typename EntityTraitsType::EntityTopology;
   using EntityType                = typename EntityTraitsType::EntityType;
   using SuperentityTraitsType     = typename MeshTraitsType::template SuperentityTraits< EntityTopology, SuperdimensionTag::value >;
   using SuperentityStorageNetwork = typename SuperentityTraitsType::StorageNetworkType;

@@ -63,7 +62,7 @@ public:
                     "Superentities for some entities are missing. "
                     "This is probably a bug in the mesh initializer." );

      SuperentityStorageNetwork& superentityStorageNetwork = meshInitializer.template meshSuperentityStorageNetwork< EntityTopology, SuperdimensionTag::value >();
      SuperentityStorageNetwork& superentityStorageNetwork = meshInitializer.template meshSuperentityStorageNetwork< SubdimensionTag::value, SuperdimensionTag::value >();
      TNL_ASSERT_EQ( (size_t) superentityStorageNetwork.getKeysRange(), dynamicStorageNetwork.size(),
                     "Sizes of the static and dynamic storage networks don't match. "
                     "This is probably a bug in the mesh initializer." );
Loading