GEOSX
sliceHelpers.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // Source includes
16 #include "ArraySlice.hpp"
17 
18 namespace LvArray
19 {
20 
29 template< typename T, typename LAMBDA >
31 void forValuesInSlice( T & value, LAMBDA && f )
32 { f( value ); }
33 
45 template< typename T, int NDIM, int USD, typename INDEX_TYPE, typename LAMBDA >
48 {
49  INDEX_TYPE const bounds = slice.size( 0 );
50  for( INDEX_TYPE i = 0; i < bounds; ++i )
51  {
52  forValuesInSlice( slice[ i ], f );
53  }
54 }
55 
66 template< typename T, typename LAMBDA, typename ... INDICES >
68 void forValuesInSliceWithIndices( T & value, LAMBDA && f, INDICES const ... indices )
69 { f( value, indices ... ); }
70 
85 template< typename T, int NDIM, int USD, typename INDEX_TYPE, typename LAMBDA, typename ... INDICES >
88  LAMBDA && f,
89  INDICES const ... indices )
90 {
91  INDEX_TYPE const bounds = slice.size( 0 );
92  for( INDEX_TYPE i = 0; i < bounds; ++i )
93  {
94  forValuesInSliceWithIndices( slice[ i ], f, indices ..., i );
95  }
96 }
97 
107 template< typename T, int USD_SRC, typename INDEX_TYPE >
109  T & dst )
110 {
111  INDEX_TYPE const bounds = src.size( 0 );
112  for( INDEX_TYPE i = 0; i < bounds; ++i )
113  {
114  dst += src( i );
115  }
116 }
117 
128 template< typename T, int NDIM, int USD_SRC, int USD_DST, typename INDEX_TYPE >
131 {
132 #ifdef ARRAY_SLICE_CHECK_BOUNDS
133  for( int i = 1; i < NDIM; ++i )
134  {
135  LVARRAY_ERROR_IF_NE( src.size( i ), dst.size( i - 1 ) );
136  }
137 #endif
138 
139  forValuesInSliceWithIndices( src, [dst] ( T const & value, INDEX_TYPE const, auto const ... indices )
140  {
141  dst( indices ... ) += value;
142  } );
143 }
144 
145 } // namespace LvArray
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
void forValuesInSlice(T &value, LAMBDA &&f)
Apply the given function to the given value.
Contains the implementation of LvArray::ArraySlice.
constexpr INDEX_TYPE size() const noexcept
Definition: ArraySlice.hpp:171
The top level namespace.
Definition: Array.hpp:24
void forValuesInSliceWithIndices(T &value, LAMBDA &&f, INDICES const ... indices)
Apply the function f to the value value also passing f any indices used to reach value.
void sumOverFirstDimension(ArraySlice< T const, 1, USD_SRC, INDEX_TYPE > const src, T &dst)
Add the values in src to dst.
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:401
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:237
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:389