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

New topologies for Mesh: Wedge and Pyramid

- added wedge and pyramid topologies
- modified mesh initialization related classes to handle wedge and pyramid topologies
- added entries for wedge and pyramid into VTKTraits, MeshTypeResolver, tnl-mesh-converter
- added unit tests for mesh with two wedges and mesh with two pyramids
parent cd968f70
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
#pragma once

#include <TNL/Algorithms/TemplateStaticFor.h>
#include <TNL/Algorithms/staticFor.h>
#include <TNL/Meshes/EntityShapeGroup.h>

namespace TNL {
@@ -22,7 +22,14 @@ public:
      else
      {
         bool result = false;
         Algorithms::TemplateStaticFor< int, 0, EntityShapeGroup< GeneralShape >::size, OtherEntitiesChecker >::execHost( result, shape );

         Algorithms::staticFor< int, 0, EntityShapeGroup< GeneralShape >::size >(
            [&] ( auto index ) {
               EntityShape groupShape = EntityShapeGroupElement< GeneralShape, index >::shape;
               result = result || ( shape == groupShape );
            }
         );

         return result;
      }
   }
@@ -31,18 +38,6 @@ public:
   {
      return belong( shape1 ) && belong( shape2 );
   }

private:
   template< int index >
   class OtherEntitiesChecker
   {
      public:
         static void exec( bool& result, EntityShape shape )
         {
            EntityShape groupShape = EntityShapeGroupElement< GeneralShape, index >::shape;
            result = result || ( shape == groupShape );
         }
   };
};

} // namespace VTK
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ class MeshInitializableBase

      // The points and cellSeeds arrays will be reset when not needed to save memory.
      void init( typename MeshTraitsType::PointArrayType& points,
                 typename MeshTraitsType::FaceSeedArrayType& faceSeeds,
                 typename MeshTraitsType::CellSeedArrayType& cellSeeds );
};

+2 −1
Original line number Diff line number Diff line
@@ -27,11 +27,12 @@ template< typename MeshConfig, typename Device, typename MeshType >
void
MeshInitializableBase< MeshConfig, Device, MeshType >::
init( typename MeshTraitsType::PointArrayType& points,
      typename MeshTraitsType::FaceSeedArrayType& faceSeeds,
      typename MeshTraitsType::CellSeedArrayType& cellSeeds )
{
   MeshType* mesh = static_cast< MeshType* >( this );
   Initializer< typename MeshType::Config > initializer;
   initializer.createMesh( points, cellSeeds, *mesh );
   initializer.createMesh( points, faceSeeds, cellSeeds, *mesh );
   // init boundary tags
   static_cast< EntityTags::LayerFamily< MeshConfig, Device, MeshType >* >( mesh )->initLayer();
   // init dual graph
+70 −11
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public:
   using PointType       = typename MeshTraitsType::PointType;
   using CellTopology    = typename MeshTraitsType::CellTopology;
   using CellSeedType    = typename MeshTraitsType::CellSeedType;
   using FaceSeedType    = typename MeshTraitsType::FaceSeedType;

   void setPointsCount( const GlobalIndexType& points )
   {
@@ -40,6 +41,11 @@ public:
      pointsSet.setValue( false );
   }

   void setFacesCount( const GlobalIndexType& facesCount )
   {
      this->faceSeeds.setSize( facesCount );
   }

   void setCellsCount( const GlobalIndexType& cellsCount )
   {
      this->cellSeeds.setSize( cellsCount );
@@ -50,6 +56,11 @@ public:
      return this->points.getSize();
   }

   GlobalIndexType getFacesCount() const
   {
      return this->faceSeeds.getSize();
   }

   GlobalIndexType getCellsCount() const
   {
      return this->cellSeeds.getSize();
@@ -62,6 +73,11 @@ public:
      this->pointsSet[ index ] = true;
   }

   FaceSeedType& getFaceSeed( GlobalIndexType index )
   {
      return this->faceSeeds[ index ];
   }

   CellSeedType& getCellSeed( GlobalIndexType index )
   {
      return this->cellSeeds[ index ];
@@ -71,13 +87,14 @@ public:
   {
      if( ! this->validate() )
         return false;
      mesh.init( this->points, this->cellSeeds );
      mesh.init( this->points, this->faceSeeds, this->cellSeeds );
      return true;
   }

private:
   using PointArrayType    = typename MeshTraitsType::PointArrayType;
   using CellSeedArrayType = typename MeshTraitsType::CellSeedArrayType;
   using FaceSeedArrayType = typename MeshTraitsType::FaceSeedArrayType;
   using BoolVector        = Containers::Vector< bool, Devices::Host, GlobalIndexType >;

   bool validate() const
@@ -91,6 +108,8 @@ private:
      assignedPoints.setLike( pointsSet );
      assignedPoints.setValue( false );

      if( faceSeeds.empty() )
      {
         for( GlobalIndexType i = 0; i < getCellsCount(); i++ ) {
            const auto& cornerIds = this->cellSeeds[ i ].getCornerIds();
            for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ ) {
@@ -106,11 +125,51 @@ private:
            std::cerr << "Mesh builder error: Some points were not used for cells." << std::endl;
            return false;
         }
      }
      else
      {
         for( GlobalIndexType i = 0; i < getFacesCount(); i++ ) {
            const auto& cornerIds = this->faceSeeds[ i ].getCornerIds();
            for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ ) {
               if( cornerIds[ j ] < 0 || getPointsCount() <= cornerIds[ j ] ) {
                  std::cerr << "face seed " << i << " is referencing unavailable point " << cornerIds[ j ] << std::endl;
                  return false;
               }
               assignedPoints[ cornerIds[ j ] ] = true;
            }
         }

         if( min( assignedPoints ) != true ) {
            std::cerr << "Mesh builder error: Some points were not used for faces." << std::endl;
            return false;
         }

         BoolVector assignedFaces;
         assignedFaces.setLike( faceSeeds );
         assignedFaces.setValue( false );

         for( GlobalIndexType i = 0; i < getCellsCount(); i++ ) {
            const auto& cornerIds = this->cellSeeds[ i ].getCornerIds();
            for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ ) {
               if( cornerIds[ j ] < 0 || getFacesCount() <= cornerIds[ j ] ) {
                  std::cerr << "cell seed " << i << " is referencing unavailable face " << cornerIds[ j ] << std::endl;
                  return false;
               }
               assignedFaces[ cornerIds[ j ] ] = true;
            }
         }

         if( min( assignedFaces ) != true ) {
            std::cerr << "Mesh builder error: Some faces were not used for cells." << std::endl;
            return false;
         }
      }

      return true;
   }

   PointArrayType points;
   FaceSeedArrayType faceSeeds;
   CellSeedArrayType cellSeeds;
   BoolVector pointsSet;
};
+24 −25
Original line number Diff line number Diff line
@@ -113,16 +113,16 @@ class EntityInitializerLayer< MeshConfig,
                                            typename SuperdimensionTag::Decrement >;
   using InitializerType            = Initializer< MeshConfig >;
   using MeshType                   = typename InitializerType::MeshType;
   using MeshTraitsType            = typename MeshType::MeshTraitsType;
   using MeshTraitsType             = MeshTraits< MeshConfig >;

   using GlobalIndexType            = typename MeshTraits< MeshConfig >::GlobalIndexType;
   using LocalIndexType             = typename MeshTraits< MeshConfig >::LocalIndexType;
   using SubentityTraitsType        = typename MeshTraits< MeshConfig >::template EntityTraits< SubdimensionTag::value >;
   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 MeshTraits< MeshConfig >::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTraitsType      = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology        = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType  = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using SuperentityMatrixType      = typename MeshTraits< MeshConfig >::SuperentityMatrixType;
   using SuperentityMatrixType      = typename MeshTraitsType::SuperentityMatrixType;
   using NeighborCountsArray        = typename MeshTraitsType::NeighborCountsArray;

public:
@@ -133,12 +133,12 @@ public:
      const GlobalIndexType subentitiesCount = mesh.template getEntitiesCount< SubdimensionTag::value >();
      const GlobalIndexType superentitiesCount = mesh.template getEntitiesCount< SuperdimensionTag::value >();

      if( SubdimensionTag::value > 0 )
      if( SubdimensionTag::value > 0 || std::is_same< SuperentityTopology, Topologies::Polyhedron >::value )
      {
         NeighborCountsArray capacities( superentitiesCount );

         for( GlobalIndexType superentityIndex = 0; superentityIndex < capacities.getSize(); superentityIndex++ )
            capacities[ superentityIndex ] = SubentitySeedsCreatorType::getSubentitiesCount( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );
            capacities[ superentityIndex ] = SubentitySeedsCreatorType::getSubentitiesCount( meshInitializer, mesh, superentityIndex );

         meshInitializer.template initSubentityMatrix< SuperdimensionTag::value, SubdimensionTag::value >( capacities, subentitiesCount );
      }
@@ -150,8 +150,7 @@ public:

      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         //TODO: try to pass capacitites in to avoid calculating number of non-zero elements in a row
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer, mesh, superentityIndex );
         for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ )
         {
            const GlobalIndexType subentityIndex = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] );
@@ -207,11 +206,11 @@ class EntityInitializerLayer< MeshConfig,
                                            typename SuperdimensionTag::Decrement >;
   using InitializerType           = Initializer< MeshConfig >;
   using MeshType                  = typename InitializerType::MeshType;
   using MeshTraitsType            = typename MeshType::MeshTraitsType;
   using MeshTraitsType            = MeshTraits< MeshConfig >;

   using GlobalIndexType           = typename MeshTraits< MeshConfig >::GlobalIndexType;
   using LocalIndexType            = typename MeshTraits< MeshConfig >::LocalIndexType;
   using SuperentityTraitsType     = typename MeshTraits< MeshConfig >::template EntityTraits< SuperdimensionTag::value >;
   using GlobalIndexType           = typename MeshTraitsType::GlobalIndexType;
   using LocalIndexType            = typename MeshTraitsType::LocalIndexType;
   using SuperentityTraitsType     = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology       = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using NeighborCountsArray       = typename MeshTraitsType::NeighborCountsArray;
@@ -223,12 +222,12 @@ public:

      const GlobalIndexType subentitiesCount = mesh.template getEntitiesCount< SubdimensionTag::value >();
      const GlobalIndexType superentitiesCount = mesh.template getEntitiesCount< SuperdimensionTag::value >();
      if( SubdimensionTag::value > 0 )
      if( SubdimensionTag::value > 0 || std::is_same< SuperentityTopology, Topologies::Polyhedron >::value )
      {
         NeighborCountsArray capacities( superentitiesCount );

         for( GlobalIndexType superentityIndex = 0; superentityIndex < capacities.getSize(); superentityIndex++ )
            capacities[ superentityIndex ] = SubentitySeedsCreatorType::getSubentitiesCount( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );
            capacities[ superentityIndex ] = SubentitySeedsCreatorType::getSubentitiesCount( meshInitializer, mesh, superentityIndex );

         meshInitializer.template initSubentityMatrix< SuperdimensionTag::value, SubdimensionTag::value >( capacities, subentitiesCount );
      }
@@ -237,8 +236,7 @@ public:
           superentityIndex < mesh.template getEntitiesCount< SuperdimensionTag::value >();
           superentityIndex++ )
      {
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );

         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer, mesh, superentityIndex );
         for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ )
         {
            const GlobalIndexType subentityIndex = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] );
@@ -274,15 +272,16 @@ class EntityInitializerLayer< MeshConfig,
                                            typename SuperdimensionTag::Decrement >;
   using InitializerType            = Initializer< MeshConfig >;
   using MeshType                   = typename InitializerType::MeshType;
   using MeshTraitsType             = MeshTraits< MeshConfig >;

   using GlobalIndexType            = typename MeshTraits< MeshConfig >::GlobalIndexType;
   using LocalIndexType             = typename MeshTraits< MeshConfig >::LocalIndexType;
   using SubentityTraitsType        = typename MeshTraits< MeshConfig >::template EntityTraits< SubdimensionTag::value >;
   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 MeshTraits< MeshConfig >::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTraitsType      = typename MeshTraitsType::template EntityTraits< SuperdimensionTag::value >;
   using SuperentityTopology        = typename SuperentityTraitsType::EntityTopology;
   using SubentitySeedsCreatorType  = SubentitySeedsCreator< MeshConfig, SuperentityTopology, SubdimensionTag >;
   using SuperentityMatrixType      = typename MeshTraits< MeshConfig >::SuperentityMatrixType;
   using SuperentityMatrixType      = typename MeshTraitsType::SuperentityMatrixType;

public:
   static void initSuperentities( InitializerType& meshInitializer, MeshType& mesh )
@@ -299,7 +298,7 @@ public:

      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer, mesh, superentityIndex );
         for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ )
         {
            const GlobalIndexType subentityIndex = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] );
@@ -316,7 +315,7 @@ public:
      // initialize superentities storage
      for( GlobalIndexType superentityIndex = 0; superentityIndex < superentitiesCount; superentityIndex++ )
      {
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer.template getSubvertices< SuperdimensionTag::value >( superentityIndex ) );
         auto subentitySeeds = SubentitySeedsCreatorType::create( meshInitializer, mesh, superentityIndex );
         for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ )
         {
            const GlobalIndexType subentityIndex = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] );
Loading