From 25599f7f94b0f948a234ab9c9966f3b56fd19a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Wed, 19 Oct 2016 20:30:33 +0200 Subject: [PATCH] Fixed MeshSuperentityAccess layer --- src/TNL/Meshes/MeshDetails/MeshEntity_impl.h | 40 ++- .../layers/MeshSuperentityAccess.h | 286 ++++++++++++------ .../layers/MeshSuperentityAccessor.h | 75 ----- .../layers/MeshSuperentityStorageLayer.h | 2 +- .../traits/MeshSuperentityTraits.h | 2 +- src/TNL/Meshes/MeshEntity.h | 12 +- 6 files changed, 244 insertions(+), 173 deletions(-) delete mode 100644 src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccessor.h diff --git a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h index ab4ed9af9f..d21d58267a 100644 --- a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h +++ b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h @@ -194,7 +194,7 @@ typename MeshEntity< MeshConfig, EntityTopology >::LocalIndexType MeshEntity< MeshConfig, EntityTopology >:: getNumberOfSuperentities() const { - static_assert( SuperentityTraits< SuperDimension >::available, "You try to get number of superentities which are not configured for storage." ); + static_assert( SuperentityTraits< SuperDimensions >::storageEnabled, "You try to get number of superentities which are not configured for storage." ); typedef MeshSuperentityAccess< MeshConfig, EntityTopology > SuperentityBaseType; return SuperentityBaseType::getNumberOfSuperentities( MeshDimensionTag< SuperDimension >() ); } @@ -206,7 +206,10 @@ typename MeshEntity< MeshConfig, EntityTopology >::GlobalIndexType MeshEntity< MeshConfig, EntityTopology >:: getSuperentityIndex( const LocalIndexType localIndex ) const { - return this->template getSuperentityIndices< SuperDimensions >().getSuperentityIndex( localIndex ); + static_assert( SuperentityTraits< SuperDimensions >::storageEnabled, "You try to get superentities which are not configured for storage." ); + typedef MeshSuperentityAccess< MeshConfig, EntityTopology > SuperentityBaseType; + return SuperentityBaseType::getSuperentityIndex( MeshDimensionsTag< SuperDimensions >(), + localIndex ); } template< typename MeshConfig, @@ -291,8 +294,8 @@ template< typename MeshConfig, template< int Subdimensions > void MeshEntity< MeshConfig, EntityTopology >:: -setSubentityIndex( const LocalIndexType localIndex, - const GlobalIndexType globalIndex ) +setSubentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) { static_assert( SubentityTraits< Subdimensions >::storageEnabled, "You try to set subentity which is not configured for storage." ); Assert( 0 <= localIndex && localIndex < SubentityTraits< Subdimensions >::count, @@ -305,6 +308,21 @@ setSubentityIndex( const LocalIndexType localIndex, globalIndex ); } +template< typename MeshConfig, + typename EntityTopology > + template< int Superdimensions > +void +MeshEntity< MeshConfig, EntityTopology >:: +setSuperentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) +{ + static_assert( SuperentityTraits< Superdimensions >::storageEnabled, "You try to set number of superentities which are not configured for storage." ); + typedef MeshSuperentityAccess< MeshConfig, EntityTopology > SuperentityBaseType; + SuperentityBaseType::setSuperentityIndex( MeshDimensionsTag< Superdimensions >(), + localIndex, + globalIndex ); +} + template< typename MeshConfig, typename EntityTopology > template< int Subdimensions > @@ -472,6 +490,20 @@ setPoint( const PointType& point ) this->point = point; } +template< typename MeshConfig > + template< int Superdimensions > +void +MeshEntity< MeshConfig, MeshVertexTopology >:: +setSuperentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) +{ + static_assert( SuperentityTraits< Superdimensions >::storageEnabled, "You try to set number of superentities which are not configured for storage." ); + typedef MeshSuperentityAccess< MeshConfig, MeshVertexTopology > SuperentityBaseType; + SuperentityBaseType::setSuperentityIndex( MeshDimensionsTag< Superdimensions >(), + localIndex, + globalIndex ); +} + template< typename MeshConfig > template< int Superdimensions > typename MeshEntity< MeshConfig, MeshVertexTopology >::MeshTraitsType::IdArrayAccessorType& diff --git a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccess.h b/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccess.h index 78af104b41..f41cc24fc4 100644 --- a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccess.h +++ b/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccess.h @@ -22,133 +22,239 @@ namespace TNL { namespace Meshes { template< typename MeshConfig, - typename MeshEntity, - typename DimensionTag, + typename EntityTopology, + typename DimensionsTag, bool SuperentityStorage = - MeshTraits< MeshConfig >::template SuperentityTraits< MeshEntity, DimensionTag::value >::storageEnabled > + MeshTraits< MeshConfig >::template SuperentityTraits< EntityTopology, DimensionsTag::value >::storageEnabled > class MeshSuperentityAccessLayer; template< typename MeshConfig, - typename MeshEntity > + typename EntityTopology > class MeshSuperentityAccess : public MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, + EntityTopology, MeshDimensionsTag< MeshTraits< MeshConfig >::meshDimensions > > { - public: - typedef MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, - MeshDimensionsTag< MeshTraits< MeshConfig >::meshDimensions > > BaseType; - - bool operator == ( const MeshSuperentityAccess< MeshConfig, MeshEntity>& a ) const { return true; } // TODO: fix - - void print( std::ostream& str ) const - { - BaseType::print( str ); - }; + typedef MeshSuperentityAccessLayer< MeshConfig, + EntityTopology, + MeshDimensionsTag< MeshTraits< MeshConfig >::meshDimensions > > BaseType; + + static const int Dimensions = MeshTraits< MeshConfig >::meshDimensions; + typedef MeshTraits< MeshConfig > MeshTraitsType; + + template< int SuperDimensions > + using SuperentityTraits = typename MeshTraitsType::template SuperentityTraits< EntityTopology, SuperDimensions >; + +public: + bool operator == ( const MeshSuperentityAccess< MeshConfig, EntityTopology >& a ) const { return true; } // TODO: fix + + void print( std::ostream& str ) const + { + BaseType::print( str ); + } + + // TODO: probably should be moved to MeshEntity itself - or the related methods could be moved here + template< int SuperDimensions > + void bindSuperentitiesStorageNetwork( const typename SuperentityTraits< SuperDimensions >::SuperentityAccessorType& storage ) + { + static_assert( SuperentityTraits< SuperDimensions >::storageEnabled, "You try to bind superentities which are not configured for storage." ); + BaseType::bindSuperentitiesStorageNetwork( MeshDimensionsTag< SuperDimensions >(), + storage ); + } + + template< int SuperDimensions > + bool setNumberOfSuperentities( const typename SuperentityTraits< SuperDimensions >::LocalIndexType size ) + { + static_assert( SuperentityTraits< SuperDimensions >::storageEnabled, "You try to get number of superentities which are not configured for storage." ); + return BaseType::setNumberOfSuperentities( MeshDimensionsTag< SuperDimensions >(), + size ); + } }; template< typename MeshConfig, - typename MeshEntity, + typename EntityTopology, typename DimensionsTag > class MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, + EntityTopology, DimensionsTag, true > - : public MeshSuperentityAccessLayer< MeshConfig, MeshEntity, typename DimensionsTag::Decrement > + : public MeshSuperentityAccessLayer< MeshConfig, EntityTopology, typename DimensionsTag::Decrement > { - typedef MeshSuperentityAccessLayer< MeshConfig, MeshEntity, typename DimensionsTag::Decrement > BaseType; - - public: - typedef MeshTraits< MeshConfig > MeshTraitsType; - typedef typename MeshTraitsType::template SuperentityTraits< MeshEntity, DimensionsTag::value > SuperentityTraitsType; - typedef typename MeshTraitsType::IdArrayAccessorType IdArrayAccessorType; - typedef typename SuperentityTraitsType::StorageNetworkType StorageNetworkType; - typedef typename SuperentityTraitsType::SuperentityAccessorType SuperentityAccessorType; - //typedef typename StorageNetworkType::PortsType SuperentityAccessorType; - - using BaseType::superentityIds; - IdArrayAccessorType superentityIds( DimensionsTag ) const { return m_superentityIndices; } - - using BaseType::superentityIdsArray; - IdArrayAccessorType &superentityIdsArray( DimensionsTag ) { return m_superentityIndices; } - - using BaseType::getSuperentityIndices; - const SuperentityAccessorType& getSuperentityIndices( DimensionsTag ) const - { - std::cerr << "###" << std::endl; - return this->superentityIndices; - } - - SuperentityAccessorType& getSuperentityIndices( DimensionsTag ) - { - std::cerr << "######" << std::endl; - return this->superentityIndices; - } - - void print( std::ostream& str ) const - { - str << "Superentities with " << DimensionsTag::value << " dimensions are: " << - this->superentityIndices << std::endl; - BaseType::print( str ); - } - - //bool operator == ( const MeshSuperentityAccessLayer< MeshConfig, MeshEntity, Dimension, tnlStorageTraits< true > >& l ) { return true; } // TODO: fix - - private: - IdArrayAccessorType m_superentityIndices; - - SuperentityAccessorType superentityIndices; + typedef MeshSuperentityAccessLayer< MeshConfig, EntityTopology, typename DimensionsTag::Decrement > BaseType; + + typedef MeshTraits< MeshConfig > MeshTraitsType; + typedef typename MeshTraitsType::template SuperentityTraits< EntityTopology, DimensionsTag::value > SuperentityTraitsType; + +public: + typedef typename MeshTraitsType::IdArrayAccessorType IdArrayAccessorType; + typedef typename SuperentityTraitsType::GlobalIndexType GlobalIndexType; + typedef typename SuperentityTraitsType::LocalIndexType LocalIndexType; + typedef typename SuperentityTraitsType::StorageNetworkType StorageNetworkType; + typedef typename SuperentityTraitsType::SuperentityAccessorType SuperentityAccessorType; + + /**** + * Make visible setters and getters of the lower superentities + */ + using BaseType::bindSuperentitiesStorageNetwork; + using BaseType::setNumberOfSuperentities; + using BaseType::getNumberOfSuperentities; + using BaseType::setSuperentityIndex; + using BaseType::getSuperentityIndex; + + /**** + * Define setter/getter for the current level of the superentities + */ + void bindSuperentitiesStorageNetwork( DimensionsTag, + const SuperentityAccessorType& storage ) + { + this->superentityIndices.bind( storage ); + } + + bool setNumberOfSuperentities( DimensionsTag, + const LocalIndexType size ) + { + return this->superentityIndices.setSize( size ); + } + + LocalIndexType getNumberOfSuperentities( DimensionsTag ) const + { + return this->superentityIndices.getSize(); + } + + void setSuperentityIndex( DimensionsTag, + const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) + { + this->superentityIndices[ localIndex ] = globalIndex; + } + + GlobalIndexType getSuperentityIndex( DimensionsTag, + const LocalIndexType localIndex ) const + { + return this->superentityIndices[ localIndex ]; + } + + using BaseType::superentityIds; + IdArrayAccessorType superentityIds( DimensionsTag ) const { return m_superentityIndices; } + + using BaseType::superentityIdsArray; + IdArrayAccessorType &superentityIdsArray( DimensionsTag ) { return m_superentityIndices; } + + using BaseType::getSuperentityIndices; + const SuperentityAccessorType& getSuperentityIndices( DimensionsTag ) const + { + return this->superentityIndices; + } + + SuperentityAccessorType& getSuperentityIndices( DimensionsTag ) + { + return this->superentityIndices; + } + + void print( std::ostream& str ) const + { + str << "Superentities with " << DimensionsTag::value << " dimensions are: " << + this->superentityIndices << std::endl; + BaseType::print( str ); + } + + //bool operator == ( const MeshSuperentityAccessLayer< MeshConfig, EntityTopology, Dimensions, tnlStorageTraits< true > >& l ) { return true; } // TODO: fix + +private: + // TODO: used only in mesh initializer, should be removed + IdArrayAccessorType m_superentityIndices; + + SuperentityAccessorType superentityIndices; }; template< typename MeshConfig, - typename MeshEntity, + typename EntityTopology, typename DimensionsTag > class MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, + EntityTopology, DimensionsTag, false > - : public MeshSuperentityAccessLayer< MeshConfig, MeshEntity, typename DimensionsTag::Decrement > + : public MeshSuperentityAccessLayer< MeshConfig, EntityTopology, typename DimensionsTag::Decrement > { }; template< typename MeshConfig, - typename MeshEntity > + typename EntityTopology > class MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, - MeshDimensionsTag< MeshEntity::dimensions >, + EntityTopology, + MeshDimensionsTag< EntityTopology::dimensions >, false > { - protected: - /*** - * Necessary because of 'using BaseType::...;' in the derived classes - */ - void superentityIds() {} - void superentityIdsArray() {} - - void getSuperentityIndices() {}; - - void print( std::ostream& str ) const {}; + static const int Dimensions = EntityTopology::dimensions; + typedef MeshDimensionsTag< EntityTopology::dimensions > DimensionsTag; + typedef MeshTraits< MeshConfig > MeshTraitsType; + typedef typename MeshTraitsType::template SuperentityTraits< EntityTopology, DimensionsTag::value > SuperentityTraitsType; + +protected: + typedef typename SuperentityTraitsType::GlobalIndexType GlobalIndexType; + typedef typename SuperentityTraitsType::LocalIndexType LocalIndexType; + typedef typename SuperentityTraitsType::SuperentityAccessorType SuperentityAccessorType; + + /*** + * Necessary because of 'using BaseType::...;' in the derived classes + */ + void bindSuperentitiesStorageNetwork( DimensionsTag, + const SuperentityAccessorType& storage ) {} + void setNumberOfSuperentities( DimensionsTag, + const LocalIndexType size ) {} + LocalIndexType getNumberOfSuperentities( DimensionsTag ) const {} + GlobalIndexType getSuperentityIndex( DimensionsTag, + const LocalIndexType localIndex ) {} + void setSuperentityIndex( DimensionsTag, + const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) {} + + void superentityIds() {} + void superentityIdsArray() {} + + void getSuperentityIndices() {} + + void print( std::ostream& str ) const {} }; template< typename MeshConfig, - typename MeshEntity > + typename EntityTopology > class MeshSuperentityAccessLayer< MeshConfig, - MeshEntity, - MeshDimensionsTag< MeshEntity::dimensions >, + EntityTopology, + MeshDimensionsTag< EntityTopology::dimensions >, true > { - protected: - /*** - * Necessary because of 'using BaseType::...;' in the derived classes - */ - void superentityIds() {} - void superentityIdsArray() {} - - void getSuperentityIndices() {}; - - void print( std::ostream& str ) const {}; + static const int Dimensions = EntityTopology::dimensions; + typedef MeshDimensionsTag< EntityTopology::dimensions > DimensionsTag; + typedef MeshTraits< MeshConfig > MeshTraitsType; + typedef typename MeshTraitsType::template SuperentityTraits< EntityTopology, DimensionsTag::value > SuperentityTraitsType; + +protected: + typedef typename SuperentityTraitsType::GlobalIndexType GlobalIndexType; + typedef typename SuperentityTraitsType::LocalIndexType LocalIndexType; + typedef typename SuperentityTraitsType::SuperentityAccessorType SuperentityAccessorType; + + /*** + * Necessary because of 'using BaseType::...;' in the derived classes + */ + void bindSuperentitiesStorageNetwork( DimensionsTag, + const SuperentityAccessorType& storage ) {} + void setNumberOfSuperentities( DimensionsTag, + const LocalIndexType size ) {} + LocalIndexType getNumberOfSuperentities( DimensionsTag ) const {} + GlobalIndexType getSuperentityIndex( DimensionsTag, + const LocalIndexType localIndex ) {} + void setSuperentityIndex( DimensionsTag, + const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ) {} + + void superentityIds() {} + void superentityIdsArray() {} + + void getSuperentityIndices() {} + + void print( std::ostream& str ) const {} }; } // namespace Meshes diff --git a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccessor.h b/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccessor.h deleted file mode 100644 index b39f8cd37b..0000000000 --- a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityAccessor.h +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - MeshSuperentityAccessor.h - description - ------------------- - begin : Sep 11, 2015 - copyright : (C) 2015 by Tomas Oberhuber et al. - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -/*** - * Authors: - * Oberhuber Tomas, tomas.oberhuber@fjfi.cvut.cz - * Zabka Vitezslav, zabkav@gmail.com - */ - -#pragma once - -#include <fstream> - -namespace TNL { -namespace Meshes { - -template< typename IndexMultimapValues > -class MeshSuperentityAccessor -{ - public: - typedef typename IndexMultimapValues::IndexType GlobalIndexType; - typedef typename IndexMultimapValues::LocalIndexType LocalIndexType; - - LocalIndexType getSupernetitiesCount() const - { - return this->indexes.getPortsCount(); - } - - void setSuperentityIndex( const LocalIndexType localIndex, - const GlobalIndexType globalIndex ) - { - indexes.setOutput( localIndex, globalIndex ); - } - - GlobalIndexType getSuperentityIndex( const LocalIndexType localIndex ) const - { - return indexes.getOutput( localIndex ); - } - - GlobalIndexType& operator[]( const LocalIndexType localIndex ) - { - return this->indexes[ localIndex ]; - } - - const GlobalIndexType& operator[]( const LocalIndexType localIndex ) const - { - return this->indexes[ localIndex ]; - } - - void print( std::ostream& str ) const - { - str << indexes; - } - - protected: - IndexMultimapValues indexes; -}; - -template< typename IndexMultimapValues > -std::ostream& operator << ( std::ostream& str, const MeshSuperentityAccessor< IndexMultimapValues >& superentityAccessor ) -{ - superentityAccessor.print( str ); - return str; -} - -} // namespace Meshes -} // namespace TNL - diff --git a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityStorageLayer.h b/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityStorageLayer.h index 5b7525d581..df052e38d8 100644 --- a/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityStorageLayer.h +++ b/src/TNL/Meshes/MeshDetails/layers/MeshSuperentityStorageLayer.h @@ -65,8 +65,8 @@ protected: */ using BaseType::setNumberOfSuperentities; using BaseType::getNumberOfSuperentities; - using BaseType::getSuperentityIndex; using BaseType::setSuperentityIndex; + using BaseType::getSuperentityIndex; using BaseType::getSuperentityIndices; MeshSuperentityStorageLayer() diff --git a/src/TNL/Meshes/MeshDetails/traits/MeshSuperentityTraits.h b/src/TNL/Meshes/MeshDetails/traits/MeshSuperentityTraits.h index a70cc109d2..c70867799a 100644 --- a/src/TNL/Meshes/MeshDetails/traits/MeshSuperentityTraits.h +++ b/src/TNL/Meshes/MeshDetails/traits/MeshSuperentityTraits.h @@ -54,7 +54,7 @@ class MeshSuperentityTraits typedef Containers::Array< GlobalIndexType, Devices::Host, LocalIndexType > StorageArrayType; typedef EllpackIndexMultimap< GlobalIndexType, Devices::Host, LocalIndexType > StorageNetworkType; - typedef MeshSuperentityAccessor< typename StorageNetworkType::ValuesAccessorType > SuperentityAccessorType; + typedef typename StorageNetworkType::ValuesAccessorType SuperentityAccessorType; /**** * Type for passing the superentities indices by the getSuperentityIndices() diff --git a/src/TNL/Meshes/MeshEntity.h b/src/TNL/Meshes/MeshEntity.h index abf5279185..d7963e2945 100644 --- a/src/TNL/Meshes/MeshEntity.h +++ b/src/TNL/Meshes/MeshEntity.h @@ -133,8 +133,12 @@ class MeshEntity typedef MeshSubentityStorageLayers< MeshConfig, EntityTopology > SubentityStorageLayers; template< int Subdimensions > - void setSubentityIndex( const LocalIndexType localIndex, - const GlobalIndexType globalIndex ); + void setSubentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ); + + template< int Superdimensions > + void setSuperentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ); template< int Subdimensions > typename SubentityTraits< Subdimensions >::IdArrayType& subentityIdsArray(); @@ -208,6 +212,10 @@ class MeshEntity< MeshConfig, MeshVertexTopology > typedef typename MeshTraitsType::IdArrayAccessorType IdArrayAccessorType; typedef MeshSuperentityAccess< MeshConfig, MeshVertexTopology > SuperentityAccessBase; + + template< int Superdimensions > + void setSuperentityIndex( const LocalIndexType& localIndex, + const GlobalIndexType& globalIndex ); template< int Superdimensions > IdArrayAccessorType& superentityIdsArray(); -- GitLab