Skip to content
Snippets Groups Projects
Select Git revision
  • 6a9f3e72ac873cacaa2ecfe5e980a9141f548239
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

test_DiscreteFunctionDescriptorP0.cpp

Blame
  • ValuePerItem.hpp 3.07 KiB
    #ifndef VALUE_PER_ITEM_HPP
    #define VALUE_PER_ITEM_HPP
    
    #include <ItemType.hpp>
    #include <PastisAssert.hpp>
    
    #include <IConnectivity.hpp>
    
    template <typename DataType,
              ItemType item_type>
    class ValuePerItem
    {
     public:
      static const ItemType item_t{item_type};
    
     private:
      bool m_is_built{false};
    
      Kokkos::View<DataType*> m_values;
    
      // Allows const version to access our data
      friend ValuePerItem<std::add_const_t<DataType>,
                          item_type>;
    
     public:
      KOKKOS_FORCEINLINE_FUNCTION
      const bool& isBuilt() const
      {
        return m_is_built;
      }
    
      KOKKOS_FORCEINLINE_FUNCTION
      DataType& operator()(const size_t& j)
      {
        Assert(m_is_built);
        return m_values(j);
      }
    
      // Following Kokkos logic, these classes are view and const view does allow
      // changes in data
      KOKKOS_FORCEINLINE_FUNCTION
      DataType& operator()(const size_t& j) const
      {
        Assert(m_is_built);
        return m_values(j);
      }
    
      KOKKOS_INLINE_FUNCTION
      size_t numberOfValues() const
      {
        Assert(m_is_built);
        return m_values.extent(0);
      }
    
      KOKKOS_FORCEINLINE_FUNCTION
      DataType& operator[](const size_t& i)
      {
        Assert(m_is_built);
        return m_values[i];
      }
    
      // Following Kokkos logic, these classes are view and const view does allow
      // changes in data
      KOKKOS_FORCEINLINE_FUNCTION
      DataType& operator[](const size_t & i) const
      {
        Assert(m_is_built);
        return m_values[i];
      }
    
      KOKKOS_INLINE_FUNCTION
      size_t numberOfItems() const
      {
        Assert(m_is_built);
        Assert(m_values.extent(0) != 0);
        return m_values.extent(0);
      }
    
      template <typename DataType2>
      KOKKOS_INLINE_FUNCTION
      ValuePerItem&
      operator=(const ValuePerItem<DataType2, item_type>& value_per_item)
      {
        // ensures that DataType is the same as source DataType2
        static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
                      "Cannot assign ValuePerItem of different type");
        // ensures that const is not lost through copy
        static_assert(((std::is_const<DataType2>() and std::is_const<DataType>())
                       or not std::is_const<DataType2>()),
                      "Cannot assign const  ValuePerItem to a non const ValuePerItem");
    
        m_values = value_per_item.m_values;
        m_is_built = value_per_item.m_is_built;
    
        return *this;
      }
    
      template <typename DataType2>
      KOKKOS_INLINE_FUNCTION
      ValuePerItem(const ValuePerItem<DataType2, item_type>& value_per_item)
      {
        this->operator=(value_per_item);
      }
    
      ValuePerItem() = default;
    
      ValuePerItem(const IConnectivity& connectivity)
          : m_is_built{true}
      {
        m_values = Kokkos::View<std::remove_const_t<DataType>*>("values", connectivity.numberOf<item_type>());
      }
    
      ~ValuePerItem() = default;
    };
    
    template <typename DataType>
    using ValuePerNode = ValuePerItem<DataType, ItemType::node>;
    
    template <typename DataType>
    using ValuePerEdge = ValuePerItem<DataType, ItemType::edge>;
    
    template <typename DataType>
    using ValuePerFace = ValuePerItem<DataType, ItemType::face>;
    
    template <typename DataType>
    using ValuePerCell = ValuePerItem<DataType, ItemType::cell>;
    
    #endif // VALUE_PER_ITEM_HPP