// 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 (rev.1012)


#ifndef _GEN_TENSORADD__H_
#define _GEN_TENSORADD__H_

#include "genTensorialTraits.h" // definition of Scalar0 for ftensor

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

// exists only when T1=T2
template<class T> class PlusOp<T,T>
{
  public :
  typedef T ValType;
  void operator()(const T &a, const T &b, ValType &r) const
  {
    r=a+b;
  }
};



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

// exists only when T1=T2
template<class T> class MinusOp<T,T>
{
  public :
  typedef T ValType;
  void operator()(const T &a, const T &b, ValType &r) const
  {
    r=a-b;
  }
};



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


template<class scalar,int N> class PlusOp<Scalar0<scalar,N> >
{
public :
  typedef Scalar0<scalar,N> ValType;
  void operator()( const Scalar0<scalar,N> &a,const Scalar0<scalar,N> &b, ValType &r) const
  {
    r=a()+b();
  }
};

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

template<class scalar,int N> class PlusOp<Tensor2<scalar,N,N> >
{
public :
  typedef Tensor2<scalar,N, N> ValType;
  void operator()( const Tensor2<scalar,N,N> &a,const Tensor2<scalar,N,N> &b, ValType &r) const
  {
    Index<'i',N> i;
    Index<'j',N> j;
    r(i,j)=a(i,j);
    r(i,j)+=b(i,j);
  }
};

#endif // USE_FTENSOR


#endif // _GEN_TENSORADD__H_
