Commit 1575f02f authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Big mesh refactoring

Main changes:

- mesh pointer added to MeshEntity, all topology accessors redirected
  through it to the mesh
- storage of points and subentity orientations moved from MeshEntity to
  Mesh
- removed MeshEntityIndex - MeshEntity always stores its index as the
  GlobalIndexType
- removed entity storage from Mesh - mesh entities can be generated on
  the fly

Plus some minor related simplifications, mainly in the mesh initializer.
parent 5ba08aff
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -13,13 +13,6 @@ namespace py = pybind11;

#include <type_traits>

template< typename MeshEntity >
typename MeshEntity::MeshTraitsType::GlobalIndexType
getIndex( const MeshEntity& entity )
{
    return entity.getIndex();
};

struct _general {};
struct _special : _general {};

@@ -88,9 +81,7 @@ void export_MeshEntity( Scope & scope, const char* name )
{
    auto entity = py::class_< MeshEntity >( scope, name )
        .def_static("getEntityDimension", &MeshEntity::getEntityDimension)
        // FIXME: boost chokes on this
//        .def("getIndex", &MeshEntity::getIndex, py::return_internal_reference<>())
        .def("getIndex", getIndex< MeshEntity >)
        .def("getIndex", &MeshEntity::getIndex)
        // TODO
    ;

@@ -103,9 +94,9 @@ template< typename Mesh >
void export_Mesh( py::module & m, const char* name )
{
    // there are two templates - const and non-const - take only the const
    auto (Mesh::* getEntity_cell)(const typename Mesh::GlobalIndexType&) const = &Mesh::template getEntity<typename Mesh::Cell>;
    auto (Mesh::* getEntity_face)(const typename Mesh::GlobalIndexType&) const = &Mesh::template getEntity<typename Mesh::Face>;
    auto (Mesh::* getEntity_vertex)(const typename Mesh::GlobalIndexType&) const = &Mesh::template getEntity<typename Mesh::Vertex>;
    auto (Mesh::* getEntity_cell)(const typename Mesh::GlobalIndexType) const = &Mesh::template getEntity<typename Mesh::Cell>;
    auto (Mesh::* getEntity_face)(const typename Mesh::GlobalIndexType) const = &Mesh::template getEntity<typename Mesh::Face>;
    auto (Mesh::* getEntity_vertex)(const typename Mesh::GlobalIndexType) const = &Mesh::template getEntity<typename Mesh::Vertex>;

    export_EntityTypes(m);

@@ -116,9 +107,9 @@ void export_Mesh( py::module & m, const char* name )
        .def("getSerializationTypeVirtual", &Mesh::getSerializationTypeVirtual)
        .def("getEntitiesCount", &mesh_getEntitiesCount< Mesh >)
        // TODO: if combined, the return type would depend on the runtime parameter (entity)
        .def("getEntity_cell", getEntity_cell, py::return_value_policy::reference_internal)
        .def("getEntity_face", getEntity_face, py::return_value_policy::reference_internal)
        .def("getEntity_vertex", getEntity_vertex, py::return_value_policy::reference_internal)
        .def("getEntity_cell", getEntity_cell)
        .def("getEntity_face", getEntity_face)
        .def("getEntity_vertex", getEntity_vertex)
        .def("getEntityCenter", []( const Mesh& mesh, const typename Mesh::Cell& cell ){ return getEntityCenter( mesh, cell ); } )
        .def("getEntityCenter", []( const Mesh& mesh, const typename Mesh::Face& face ){ return getEntityCenter( mesh, face ); } )
        .def("getEntityCenter", []( const Mesh& mesh, const typename Mesh::Vertex& vertex ){ return getEntityCenter( mesh, vertex ); } )
+3 −6
Original line number Diff line number Diff line
@@ -24,19 +24,16 @@ using MeshOfEdges = TNL::Meshes::Mesh< TNL::Meshes::DefaultConfig<
                            EdgeTopology::dimension,
                            RealType,
                            IndexType,
                            LocalIndexType,
                            IndexType > >;
                            LocalIndexType > >;
using MeshOfTriangles = TNL::Meshes::Mesh< TNL::Meshes::DefaultConfig<
                            TriangleTopology,
                            TriangleTopology::dimension,
                            RealType,
                            IndexType,
                            LocalIndexType,
                            IndexType > >;
                            LocalIndexType > >;
using MeshOfTetrahedrons = TNL::Meshes::Mesh< TNL::Meshes::DefaultConfig<
                            TetrahedronTopology,
                            TetrahedronTopology::dimension,
                            RealType,
                            IndexType,
                            LocalIndexType,
                            IndexType > >;
                            LocalIndexType > >;
+6 −0
Original line number Diff line number Diff line
@@ -70,6 +70,12 @@ class EllpackIndexMultimap
      __cuda_callable__
      ConstValuesAccessorType getValues( const IndexType& inputIndex ) const;

      __cuda_callable__
      LocalIndexType getValuesCount( const IndexType& inputIndex ) const;

      __cuda_callable__
      IndexType getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const;

      bool operator==( const EllpackIndexMultimap& other ) const;

      void save( File& file ) const;
+37 −0
Original line number Diff line number Diff line
@@ -185,6 +185,43 @@ getValues( const IndexType& inputIndex ) const
   return ConstValuesAccessorType( &this->values[ offset ], &this->valuesCounts[ inputIndex ], this->maxValuesCount );
}

template< typename Index,
          typename Device,
          typename LocalIndex,
          int SliceSize >
__cuda_callable__
LocalIndex
EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >::
getValuesCount( const IndexType& inputIndex ) const
{
   return valuesCounts[ inputIndex ];
}

template< typename Index,
          typename Device,
          typename LocalIndex,
          int SliceSize >
__cuda_callable__
Index
EllpackIndexMultimap< Index, Device, LocalIndex, SliceSize >::
getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const
{
   TNL_ASSERT( inputIndex < this->getKeysRange(),
              std::cerr << "inputIndex = " << inputIndex << std::endl
                        << "this->getKeysRange() = " << this->getKeysRange()
                        << std::endl; );
   TNL_ASSERT( getAllocationKeysRange( this->getKeysRange() ) * this->maxValuesCount == this->values.getSize() && this->getKeysRange() == this->valuesCounts.getSize(),
              std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl
                        << "this->getKeysRange() = " << this->getKeysRange() << std::endl
                        << "this->maxValuesCount = " << this->maxValuesCount << std::endl
                        << "this->values.getSize() = " << this->values.getSize() << std::endl
                        << "this->valuesCounts.getSize() = " << this->valuesCounts.getSize() << std::endl; );
   const IndexType sliceIdx = inputIndex / SliceSize;
   const IndexType sliceOffset = sliceIdx * SliceSize * this->maxValuesCount;
   const IndexType offset = sliceOffset + inputIndex - sliceIdx * SliceSize;
   return this->values[ offset + portIndex * SliceSize ];
}

template< typename Index,
          typename Device,
          typename LocalIndex,
+6 −0
Original line number Diff line number Diff line
@@ -68,6 +68,12 @@ class StaticEllpackIndexMultimap
      __cuda_callable__
      ConstValuesAccessorType getValues( const IndexType& inputIndex ) const;

      __cuda_callable__
      constexpr LocalIndexType getValuesCount( const IndexType& inputIndex ) const;

      __cuda_callable__
      IndexType getValue( const IndexType& inputIndex, const LocalIndexType& portIndex ) const;

      bool operator==( const StaticEllpackIndexMultimap& other ) const;

      void save( File& file ) const;
Loading