Skip to content
Snippets Groups Projects
Grid1D.h 6.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • /***************************************************************************
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
                              Grid1D.h  -  description
    
                                 -------------------
        begin                : Feb 13, 2015
        copyright            : (C) 2015 by Tomas Oberhuber
        email                : tomas.oberhuber@fjfi.cvut.cz
     ***************************************************************************/
    
    
    /* See Copyright Notice in tnl/Copyright */
    
    #pragma once
    
    #include <TNL/Logger.h>
    
    #include <TNL/Meshes/Grid.h>
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    #include <TNL/Meshes/GridDetails/GridEntityTopology.h>
    #include <TNL/Meshes/GridDetails/GridEntityGetter.h>
    
    #include <TNL/Meshes/GridDetails/NeighborGridEntityGetter.h>
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    #include <TNL/Meshes/GridEntity.h>
    #include <TNL/Meshes/GridEntityConfig.h>
    
    #include <TNL/Meshes/DistributedMeshes/DistributedMesh.h>
    
    namespace TNL {
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    namespace Meshes {
    
    template< typename Real,
              typename Device,
              typename Index >
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    class Grid< 1, Real, Device, Index > : public Object
    
    {
       public:
    
       typedef Real RealType;
       typedef Device DeviceType;
    
       typedef Index GlobalIndexType;
    
       typedef Containers::StaticVector< 1, Real > PointType;
    
       typedef Containers::StaticVector< 1, Index > CoordinatesType;
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
       typedef Grid< 1, Real, Devices::Host, Index > HostType;
       typedef Grid< 1, Real, Devices::Cuda, Index > CudaType;
       typedef Grid< 1, Real, Device, Index > ThisType;
    
       typedef DistributedMeshes::DistributedMesh <ThisType> DistributedMeshType;
    
    
       // TODO: deprecated and to be removed (GlobalIndexType shall be used instead)
       typedef Index IndexType;
    
       /**
        * \brief Returns number of this mesh grid dimensions.
        */
    
       static constexpr int getMeshDimension() { return 1; };
    
       template< int EntityDimension,
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
                 typename Config = GridEntityCrossStencilStorage< 1 > >
    
       using EntityType = GridEntity< ThisType, EntityDimension, Config >;
    
       typedef EntityType< getMeshDimension(), GridEntityCrossStencilStorage< 1 > > Cell;
       typedef EntityType< 0 > Face;
       typedef EntityType< 0 > Vertex;
    
       /**
        * \brief Basic constructor.
        */
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
       Grid();
    
       /**
        * \brief Returns type of grid Real (value), Device type and the type of Index.
        */
    
       static String getType();
    
       /**
        * \brief Returns type of grid Real (value), Device type and the type of Index.
        */
    
       String getTypeVirtual() const;
    
       /**
        * \brief Returns (host) type of grid Real (value), Device type and the type of Index.
        */
    
       static String getSerializationType();
    
       /**
        * \brief Returns (host) type of grid Real (value), Device type and the type of Index.
        */
    
       virtual String getSerializationTypeVirtual() const;
    
       /**
        * \brief Sets the number of dimensions.
        * \param xSize Number of dimensions.
        */
    
       /**
        * \brief Sets the number of dimensions.
        * \param xSize Number of dimensions.
        */
    
       void setDimensions( const CoordinatesType& dimensions );
    
    
       /**
        * \brief Returns number of dimensions of entities in this grid.
        */
    
       __cuda_callable__
    
       const CoordinatesType& getDimensions() const;
    
    
       /**
        * \brief Sets the origin.
        * \param origin Starting point of this grid.
        */
    
       void setOrigin( const PointType& origin);
    
       /**
        * \brief Sets the origin and proportions of this grid.
        * \param origin Point where this grid starts.
        * \param proportions Total length of this grid.
        */
    
       void setDomain( const PointType& origin,
                       const PointType& proportions );
    
        * \brief Returns the origin.
    
        * \param origin Starting point of this grid.
        */
    
       inline const PointType& getOrigin() const;
    
       /**
        * \brief Gets length of one entity of this grid.
        */
    
       inline const PointType& getProportions() const;
    
    
       /**
        * \brief Gets number of entities in this grid.
        * \tparam EntityDimension Integer specifying dimension of the entity.
        */
    
       template< int EntityDimension >
    
       IndexType getEntitiesCount() const;
    
       /**
        * \brief Gets number of entities in this grid.
        * \tparam Entity Type of the entity.
        */
    
       template< typename Entity >
    
       __cuda_callable__
       IndexType getEntitiesCount() const;
    
       /**
        * \brief Gets entity type using entity index.
        * \param entityIndex Index of entity.
        * \tparam Entity Type of the entity.
        */
    
       template< typename Entity >
    
       inline Entity getEntity( const IndexType& entityIndex ) const;
    
        /**
        * \brief Gets entity index using entity type.
        * \param entity Type of entity.
        * \tparam Entity Type of the entity.
        */
    
       template< typename Entity >
    
       inline Index getEntityIndex( const Entity& entity ) const;
    
        * \brief Returns the length of one step.
    
       inline const PointType& getSpaceSteps() const;
    
        * \brief Sets the length of steps.
    
        * \param steps Length of one step.
        */
    
       inline void setSpaceSteps(const PointType& steps);
    
       /**
        * \brief Returns product of space steps to the xPow.
        * \tparam xPow Exponent.
        */
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
       template< int xPow >
    
       const RealType& getSpaceStepsProducts() const;
    
       /**
        * \breif Returns the measure (length) of a cell in this grid.
        */
    
       inline const RealType& getCellMeasure() const;
    
        * \brief Returns the smallest length of step out of all coordinates (axes).
    
       inline RealType getSmallestSpaceStep() const;
    
    
    
       template< typename GridFunction >
       typename GridFunction::RealType getDifferenceAbsMax( const GridFunction& f1,
                                                            const GridFunction& f2 ) const;
    
       template< typename GridFunction >
       typename GridFunction::RealType getDifferenceLpNorm( const GridFunction& f1,
                                                            const GridFunction& f2,
                                                            const typename GridFunction::RealType& p ) const;
    
       void setDistMesh(DistributedMeshType * distMesh);
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
       DistributedMeshType * getDistributedMesh() const;
    
    
       /****
        *  Method for saving the object to a file as a binary data
        */
    
       bool save( File& file ) const;
    
       /**
        * \brief Method for restoring the object from a file.
    
       bool load( File& file );
    
       /**
        * \brief Method for saving the object to a file.
        */
    
       bool save( const String& fileName ) const;
    
       /**
        * \brief Method for restoring the object from a file.
        */
    
       bool load( const String& fileName );
    
       void writeProlog( Logger& logger ) const;
    
       void computeProportions();
           
       void computeSpaceStepPowers();
    
    
       void computeSpaceSteps();
    
       CoordinatesType dimensions;
    
       IndexType numberOfCells, numberOfVertices;
    
    
       PointType origin, proportions;
    
       PointType spaceSteps;
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
       RealType spaceStepsProducts[ 5 ];
    
       DistributedMeshType *distGrid;
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    } // namespace Meshes
    
    } // namespace TNL
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    #include <TNL/Meshes/GridDetails/Grid1D_impl.h>