// GenFem - A high-level finite element library
// Copyright (C) 2010-2026 Eric Bechet
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//
// Initial design: Eric Bechet and Frederic Duboeuf (rev.1011)


#ifndef _GEN_TENSORFULLCONTRPROD__H_
#define _GEN_TENSORFULLCONTRPROD__H_

#include "genTraits.h"

// generic version
template<class T1,class T2> class FullContrProdOp
{
public :
  typedef typename TensorialTraitsBinary<T1,T2>::FullContrProdType ValType;
  void operator ()(const T1 &a, const T2 &b, ValType &r) const
  {
    r=a*b;
  }
};

// new genTensor
template<int order1,int order2,class scalar,int N> class FullContrProdOp<genTensor<order1,scalar,N>,genTensor<order2,scalar,N> >
{
public :
  typedef typename TensorialTraitsBinary<genTensor<order1,scalar,N>,genTensor<order2,scalar,N> >::FullContrProdType ValType;
  void operator ()(const genTensor<order1,scalar,N> &a, const genTensor<order2,scalar,N> &b, ValType &r) const
  {
    r.ContractedProduct(a,b);
  }
};

#ifdef USE_FTENSOR
#include "FTensor.hpp"
using namespace FTensor;

template<class scalar,int N> class FullContrProdOp<scalar,Tensor1<scalar,N> >
{
public :
  typedef typename TensorialTraitsBinary<scalar,Tensor1<scalar,N> >::ContrProdType ValType;
  void operator ()( const scalar &a,const Tensor1<scalar,N>  &b, ValType &r) const 
  {
    Index<'i',N> i;
    r(i)=a*b(i);
  }
};


template<class scalar,int N> class FullContrProdOp<Tensor1<scalar,N>,scalar>
{
public :
  typedef typename TensorialTraitsBinary<Tensor1<scalar,N>,scalar>::ContrProdType ValType;
  void operator ()( const Tensor1<scalar,N>  &a,const scalar &b, ValType &r) const 
  {
    Index<'i',N> i;
    r(i)=a(i)*b;
  }
};

template<class scalar,int N> class FullContrProdOp<Tensor1<scalar,N>,Tensor1<scalar,N> >
{
public :
  typedef typename TensorialTraitsBinary<Tensor1<scalar,N>,Tensor1<scalar,N> >::ContrProdType ValType;
  void operator ()( const Tensor1<scalar,N>  &a,const Tensor1<scalar,N>  &b, ValType &r) const 
  {
    Index<'i',N> i;
    r=a(i)*b(i);
  }
};


#endif //USE_FTENSOR


#endif //GEN_TENSORFULLCONTRPROD