//#####################################################################
// Copyright 2006-2007, Geoffrey Irving, Craig Schroeder, Andrew Selle, Tamar Shinar.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
// Class STATIC_TENSOR
//#####################################################################
#ifndef __STATIC_TENSOR__
#define __STATIC_TENSOR__

#include <Core/Math_Tools/pow.h>
#include <Core/Vectors/VECTOR.h>
namespace PhysBAM{

template<class T,int rank,int dim>
class STATIC_TENSOR
{
    struct UNUSABLE{};
public:
    typedef T SCALAR;
    typedef T ELEMENT;
    typedef VECTOR<int,rank> IV;
    typedef IV INDEX;
    static constexpr int size=pow<rank>(dim);
    
    VECTOR<T,size> x;

    template<int... i>
    static int Flat_Index(const IV& index,std::integer_sequence<int,i...>)
    {
        int k=0;
        (...,(k=k*dim+index(i)));
        return k;
    }
    
    T& operator()(const IV& index)
    {return x(Flat_Index(index,std::make_integer_sequence<int,rank>{}));}

    const T& operator()(const IV& index) const
    {return x(Flat_Index(index,std::make_integer_sequence<int,rank>{}));}
};
}
#endif
