// elastic_genTerm - A linear solver for elastic problems using FEM
// 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>.


#ifndef CONVERT_GENTERM_H
#define CONVERT_GENTERM_H

# include "genTerm.h"

template<class T1, class T2> class genConvertTerm  : public genTerm<T1,0>
{
public:
  typedef typename TensorialTraits<T1>::Scalar Scalar;
  typedef typename TensorialTraits<T1>::ScalarType ScalarType;
  typedef typename TensorialTraits<T1>::ValType ValType;
  typedef typename ContainerTraits<ValType,0>::Container ContainerValType;
  typedef typename TensorialTraits<T2>::Scalar Scalar2;
  typedef typename TensorialTraits<T2>::ScalarType ScalarType2;
  typedef typename TensorialTraits<T2>::ValType ValType2;
  typedef typename ContainerTraits<ValType2,0>::Container ContainerValType2;
  static const int Nsp=0;
  
  typename genTerm< ValType2,0>::ConstHandle convertTerm;
  
  genConvertTerm( const typename genTerm< ValType2 , 0>::ConstHandle convertTerm_ ) : convertTerm(convertTerm_) {}

  virtual int getNumKeys(MElement *ele,int k=0) const  {return convertTerm->getNumKeys(ele);}
  virtual void getKeys(MElement *ele, std::vector<Dof> &keys, int k=0) const { convertTerm->getKeys(ele, keys);}
  virtual int getIncidentSpaceTag(int k=0) const { return convertTerm->getIncidentSpaceTag(); }
  virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<ContainerValType> &vvals) const{
    std::vector<ContainerValType2> vvals2(npts);
    convertTerm->get(ele, npts, GP, vvals2);
    for (int i=0;i<npts;++i)
      Apply(vvals2[i],vvals[i],BuildFromOneOp<ValType2,ValType>());
  }
  virtual void get(MElement *ele, int npts, IntPt *GP, ContainerValType &vals) const {
    ContainerValType2 vals2;
    convertTerm->get(ele, npts, GP, vals2);
      Apply(vals2,vals,BuildFromOneOp<ValType2,ValType>());
  }
};


#endif // CONVERT_GENTERM_H