Skip to content

Commit

Permalink
replaced calls to linearIndex() with parameter pack
Browse files Browse the repository at this point in the history
  • Loading branch information
rrsettgast committed Dec 3, 2023
1 parent ae81a7c commit 6c81272
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
72 changes: 40 additions & 32 deletions src/common/SequenceUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,49 @@ struct SequenceAlias< Template, std::integer_sequence<int, Seq...> >
using type = Template<Seq...>;
};

template < template <int...> class Template, int... Seq >
struct SequenceAlias< Template, const std::integer_sequence<int, Seq...> >


template< int I, typename T, typename ... Ts>
struct PackPeeler
{
using type = Template<Seq...>;
/// The type of the first value in the pack.
using type = typename PackPeeler< I - 1, Ts... >::type;
};

template< typename T, typename ... Ts>
struct PackPeeler<0,T,Ts...>
{
/// The type of the first value in the pack.
using type = T;
};



template< int I, int FIRST, int ... REST >
struct IntPackPeeler
{
/// The type of the first value in the pack.
static constexpr int value() { return IntPackPeeler< I - 1, REST... >::value(); }
};

template< int FIRST, int ... REST>
struct IntPackPeeler<0,FIRST,REST...>
{
/// The type of the first value in the pack.
static constexpr int value() { return FIRST; }
};


template <typename T, int ...PACK> struct ParameterPacker
{
template <template <typename, int...> typename TT, int ... OTHER_DIMS >
using type = TT<T, PACK..., OTHER_DIMS...>;
};





/**
* @namespace shiva::sequenceUtilities
* @brief The sequenceUtilitiesImpl namespace contains implementation details
Expand Down Expand Up @@ -172,35 +209,6 @@ SHIVA_STATIC_CONSTEXPR_HOSTDEVICE_FORCEINLINE auto forSequence( FUNC && func )
}


template< int I, typename T, typename ... Ts>
struct PackPeeler
{
/// The type of the first value in the pack.
using type = typename PackPeeler< I - 1, Ts... >::type;
};

template< typename T, typename ... Ts>
struct PackPeeler<0,T,Ts...>
{
/// The type of the first value in the pack.
using type = T;
};



template< int I, int FIRST, int ... REST >
struct IntPackPeeler
{
/// The type of the first value in the pack.
static constexpr int value() { return IntPackPeeler< I - 1, REST... >::value(); }
};

template< int FIRST, int ... REST>
struct IntPackPeeler<0,FIRST,REST...>
{
/// The type of the first value in the pack.
static constexpr int value() { return FIRST; }
};


} // namespace shiva
16 changes: 10 additions & 6 deletions src/geometry/mapping/LinearTransform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ class LinearTransform

/// The type used to represent the data stored at the vertices of the cell
// using DataType = CArrayNd<REAL_TYPE, InterpolatedShape::BasisCombinationType::numSupportPoints..., numDims >;
using DataType = CArrayNd<REAL_TYPE, numVertices, numDims >;
// using DataType = CArrayNd<REAL_TYPE, numVertices, numDims >;

// using DataType = typename InterpolatedShape::template numSupportPointsPacker< REAL_TYPE >::template type< CArrayNd, numDims >;

template< int ... NUM_SUPPORT_POINTS >
using RealCArrayDims = CArrayNd< REAL_TYPE, NUM_SUPPORT_POINTS..., numDims >;
using DataType = typename SequenceAlias< RealCArrayDims, typename InterpolatedShape::numSupportPointsSequence >::type;

/// The type used to represent the index space of the cell
using SupportIndexType = typename InterpolatedShape::BasisCombinationType::IndexType;
Expand Down Expand Up @@ -137,13 +143,11 @@ jacobian( LinearTransform< REAL_TYPE, INTERPOLATED_SHAPE > const & transform,
{
using Transform = std::remove_reference_t<decltype(transform)>;
using InterpolatedShape = typename Transform::InterpolatedShape;
using IndexType = typename InterpolatedShape::BasisCombinationType::IndexType;
constexpr int DIMS = Transform::numDims;

auto const & nodeCoords = transform.getData();
InterpolatedShape::template supportLoop( [&] ( auto const ... icNa ) constexpr
{
IndexType index{ { decltype(icNa)::value... } };
CArrayNd< REAL_TYPE, DIMS > const dNadXi = InterpolatedShape::template gradient< decltype(icNa)::value... >( pointCoordsParent );
// dimensional loop from domain to codomain

Expand All @@ -153,22 +157,22 @@ jacobian( LinearTransform< REAL_TYPE, INTERPOLATED_SHAPE > const & transform,
{
constexpr int ijk[DIMS] = { decltype(indices)::value... };
J( decltype(indices)::value... ) = J( decltype(indices)::value... )
+ dNadXi(ijk[1]) * nodeCoords( linearIndex( index ), ijk[0] );
+ dNadXi(ijk[1]) * nodeCoords( decltype(icNa)::value..., ijk[0] );
});
#elif VARIANT==1
forNestedSequence< DIMS, DIMS >( [&] ( auto const ... indices ) constexpr
{
constexpr int i = IntPackPeeler< 0, decltype(indices)::value... >::value();
constexpr int j = IntPackPeeler< 1, decltype(indices)::value... >::value();

J(i,j) = J(i,j) + dNadXi(j) * nodeCoords( linearIndex( index ), i );
J(i,j) = J(i,j) + dNadXi(j) * nodeCoords( decltype(icNa)::value..., i );
});
#else
forNestedSequence< DIMS, DIMS >( [&] ( auto const ici, auto const icj ) constexpr
{
constexpr int i = decltype(ici)::value;
constexpr int j = decltype(icj)::value;
J(i,j) = J(i,j) + dNadXi(j) * nodeCoords( linearIndex( index ), i );
J(i,j) = J(i,j) + dNadXi(j) * nodeCoords( decltype(icNa)::value..., i );
});
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/geometry/mapping/unitTests/testLinearTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SHIVA_HOST_DEVICE auto makeLinearTransform( REAL_TYPE const (&X)[8][3] )

for ( int j = 0; j < 3; ++j )
{
transformData( linearIndex( i ), j ) = X[ a + 2 * b + 4 * c ][j];
transformData( a,b,c, j ) = X[ a + 2 * b + 4 * c ][j];
}
} );

Expand All @@ -133,7 +133,7 @@ void testConstructionAndSettersHelper()

for ( int j = 0; j < 3; ++j )
{
kernelData[ 3 * ( a + 2 * b + 4 * c ) + j ] = transformData( linearIndex( i ), j );
kernelData[ 3 * ( a + 2 * b + 4 * c ) + j ] = transformData( a,b,c, j );
}
} );
} );
Expand Down
8 changes: 7 additions & 1 deletion src/geometry/shapes/InterpolatedShape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ class InterpolatedShape
/// The number of vertices on the InterpolatedShape
static inline constexpr int numVertices = StandardGeom::numVertices();

static inline constexpr std::integer_sequence< int, BASIS_TYPE::numSupportPoints... > basisSupportCounts{};
static inline constexpr std::integer_sequence< int, BASIS_TYPE::numSupportPoints... > basisSupportCounts{};

using numSupportPointsSequence = std::integer_sequence< int, BASIS_TYPE::numSupportPoints... >;

template< typename T >
using numSupportPointsPacker = ParameterPacker< T, BASIS_TYPE::numSupportPoints... >;


static_assert( numDims == StandardGeom::numDims(), "numDims mismatch between cell and number of basis specified" );

Expand Down

0 comments on commit 6c81272

Please sign in to comment.