LCOV - code coverage report
Current view: top level - src/cpu - array.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 36 100.0 %
Date: 2019-07-29 15:26:30 Functions: 81 181 44.8 %

          Line data    Source code
       1             : ///////////////////////////////////////////////////////////////////////////////
       2             : // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
       3             : //
       4             : // Redistribution and use in source and binary forms, with or without
       5             : // modification, are permitted provided that the following conditions are
       6             : // met:
       7             : //
       8             : // 1. Redistributions of source code must retain the above copyright notice,
       9             : // this list of conditions and the following disclaimer.
      10             : //
      11             : // 2. Redistributions in binary form must reproduce the above copyright notice,
      12             : // this list of conditions and the following disclaimer in the documentation
      13             : // and/or other materials provided with the distribution.
      14             : //
      15             : // 3. Neither the name of the copyright holder nor the names of its contributors
      16             : // may be used to endorse or promote products derived from this software without
      17             : // specific prior written permission.
      18             : //
      19             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      20             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      21             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      22             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      23             : // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      24             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      25             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      29             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30             : ///////////////////////////////////////////////////////////////////////////////
      31             : 
      32             : #include "gals/utilities/array.h"
      33             : 
      34             : #include "gals/utilities/mat3.h"
      35             : #include "gals/utilities/vec_n.h"
      36             : 
      37             : template <typename T_GRID, typename T_ARRAY>
      38         276 : GALS::CPU::Array<T_GRID, T_ARRAY>::Array(const Grid<typename T_GRID::value_type, T_GRID::dim>& grid)
      39             :     : m_grid(grid),
      40         552 :       m_nx(grid.numCells()[0]),
      41         552 :       m_ny(grid.numCells()[1]),
      42         552 :       m_nz(grid.numCells()[2]),
      43        1380 :       m_pad(grid.getPadding())
      44             : {
      45         276 :   m_data.resize(m_grid.size());
      46             : 
      47     3300906 :   for (int i = 0; i < m_data.size(); ++i) {
      48     1793499 :     m_data[i] = T_ARRAY();
      49             :   }
      50         276 : }
      51             : 
      52             : template <typename T_GRID, typename T_ARRAY>
      53         276 : GALS::CPU::Array<T_GRID, T_ARRAY>::~Array()
      54             : {
      55         276 :   m_data.clear();
      56             :   m_data.shrink_to_fit();
      57         276 : }
      58             : 
      59             : template <typename T_GRID, typename T_ARRAY>
      60           4 : const std::size_t GALS::CPU::Array<T_GRID, T_ARRAY>::size() const
      61             : {
      62           8 :   return m_data.size();
      63             : }
      64             : 
      65             : template <typename T_GRID, typename T_ARRAY>
      66        8158 : const T_GRID& GALS::CPU::Array<T_GRID, T_ARRAY>::grid() const
      67             : {
      68        8158 :   return m_grid;
      69             : }
      70             : 
      71             : template <typename T_GRID, typename T_ARRAY>
      72          39 : const GALS::CPU::Vec3<int> GALS::CPU::Array<T_GRID, T_ARRAY>::numCells() const
      73             : {
      74          39 :   return Vec3<int>(m_nx, m_ny, m_nz);
      75             : }
      76             : 
      77             : template <typename T_GRID, typename T_ARRAY>
      78           1 : const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator[](const std::size_t idx) const
      79             : {
      80           2 :   return m_data[idx];
      81             : }
      82             : 
      83             : template <typename T_GRID, typename T_ARRAY>
      84         404 : T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator[](const std::size_t idx)
      85             : {
      86         808 :   return m_data[idx];
      87             : }
      88             : 
      89             : template <typename T_GRID, typename T_ARRAY>
      90       86557 : const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const int i, const int j, const int k) const
      91             : {
      92       86557 :   const std::size_t idx = m_grid.index(i, j, k);
      93      173114 :   return m_data[idx];
      94             : }
      95             : 
      96             : template <typename T_GRID, typename T_ARRAY>
      97     2826369 : T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const int i, const int j, const int k)
      98             : {
      99     2826369 :   const std::size_t idx = m_grid.index(i, j, k);
     100     5652738 :   return m_data[idx];
     101             : }
     102             : 
     103             : template <typename T_GRID, typename T_ARRAY>
     104      676444 : const T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const Vec3<int> node_id) const
     105             : {
     106     1352888 :   return m_data[m_grid.index(node_id)];
     107             : }
     108             : 
     109             : template <typename T_GRID, typename T_ARRAY>
     110           2 : T_ARRAY& GALS::CPU::Array<T_GRID, T_ARRAY>::operator()(const Vec3<int> node_id)
     111             : {
     112           4 :   return m_data[m_grid.index(node_id)];
     113             : }
     114             : 
     115             : template <typename T_GRID, typename T_ARRAY>
     116           7 : void GALS::CPU::Array<T_GRID, T_ARRAY>::operator=(const GALS::CPU::Array<T_GRID, T_ARRAY>& array)
     117             : {
     118           7 :   m_data = array.data();
     119           7 : }
     120             : 
     121             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, double>;
     122             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, double>;
     123             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, double>;
     124             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::Vec3<double>>;
     125             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Vec3<double>>;
     126             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Vec3<double>>;
     127             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::VecN<double, 0>>;
     128             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::VecN<double, 2>>;
     129             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::VecN<double, 1>>;
     130             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::VecN<double, 2>>;
     131             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::VecN<double, 2>>;
     132             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::VecN<double, 4>>;
     133             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::Mat3<double>>;
     134             : template class GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Mat3<double>>;
     135           2 : template class GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Mat3<double>>;

Generated by: LCOV version 1.12