// 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: Frederic Duboeuf (rev.659)


#ifndef _SAVED_DIFFTERM_H_
#define _SAVED_DIFFTERM_H_

#include <map>
#include "genTerm.h"

class MElement;
template<class T> class SavedDiffTerm : public diffTerm<T,0>
{
public:
  typedef typename TensorialTraits<T>::ValType ValType;
  typedef typename TensorialTraits<T>::GradType GradType;
  typedef typename TensorialTraits<T>::HessType HessType;
  typedef typename ContainerTraits<ValType,0>::Container ContainerValType;
  typedef typename ContainerTraits<GradType,0>::Container ContainerGradType;
  typedef typename ContainerTraits<HessType,0>::Container ContainerHessType;
  static const int Nsp=0;
private:
  std::map< Dof, double > mapval;
  typename diffTerm<T,1>::ConstHandle fs;

public:
  SavedDiffTerm(const typename diffTerm<T,1>::ConstHandle &fs_) : fs(fs_) {}
//  SavedDiffTerm(const std::map< int, ValType > &mapf, getFSpace<T>* fs_) : mapval(mapf), fs(fs_) {}
  virtual int getNumKeys(MElement* ele,int k=0) const {return fs->getNumKeys(ele,k);}
  virtual void getKeys(MElement* ele, std::vector<Dof> &keys, int k=0) const {fs->getKeys(ele,keys,k);}
  virtual int getIncidentSpaceTag(int k=0) const { return fs->getIncidentSpaceTag(k);}
  virtual void get(MElement* ele, int npts, IntPt* GP, std::vector<ContainerValType> &vvals) const;
  virtual void get(MElement* ele, int npts, IntPt* GP, ContainerValType &vals) const;
  virtual void getgradf(MElement* ele, int npts, IntPt* GP, std::vector< ContainerGradType > &vgrads) const;
  virtual void getgradf(MElement* ele, int npts, IntPt* GP, ContainerGradType &grads) const;
  virtual void getgradfuvw(MElement* ele, int npts, IntPt* GP, std::vector< ContainerGradType > &vgrads) const;
  virtual void gethessf(MElement* ele, int npts, IntPt* GP, std::vector< ContainerHessType > &vhesss) const;
  virtual void gethessf(MElement* ele, int npts, IntPt* GP, ContainerHessType &hesss) const;
  virtual SavedDiffTerm<T>* clone () const { return new SavedDiffTerm<T>(fs);}// SavedDiffTerm<T>(_mapf)

  virtual int size() const { return mapval.size(); }
  virtual void set(MElement* ele, int nbdofs, std::vector<Dof> &D, typename ContainerTraits<genTensor0<double>,1>::Container &Dofvals);
  virtual void print(const char* name);
  virtual void printfile(const char* name);
};

#include "savedDiffTerm.hpp"


#endif // _SAVED_DIFFTERM_H_




