// 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>.

#ifndef _GEN_SIMPLE_FUNCTION_Utot_H_
#define _GEN_SIMPLE_FUNCTION_Utot_H_


#include "genSimpleFunction.h"
#include "genSimpleFunctionExtended.h"
#include <cmath>

template<class T1> class genSimpleFunctionUtot : public genSimpleFunction<T1>
{
public :
  typedef typename TensorialTraits<T1>::Scalar Scalar;
  typedef typename TensorialTraits<T1>::ScalarType ScalarType;
  typedef typename TensorialTraits<T1>::ValType ValType;
  typedef typename TensorialTraits<T1>::GradType GradType;
  typedef typename TensorialTraits<T1>::HessType HessType;
  typedef typename TensorialTraits<ScalarType>::GradType ValTensor;
  genSimpleFunction<ValTensor> *Uref, *Uinc;
  int comp;
  public :
  genSimpleFunctionUtot(genSimpleFunction<ValTensor>* Uinc_, genSimpleFunction<ValTensor>* Uref_, int comp_ = -1) : Uinc(Uinc_), Uref(Uref_) ,  comp(comp_)  {}
  
  virtual ValType operator()(double x, double y, double z) const {
      ValTensor Uinc_coor = (*Uinc)(x,y,z);
      ValTensor Uref_coor = (*Uref)(x,y,z);
      
      Scalar u_x = Uinc_coor[0] + Uref_coor[0];
      Scalar u_y = Uinc_coor[1] + Uref_coor[1];
      std::vector<Scalar> res;
      res.push_back(u_x);
      res.push_back(u_y);
      if(comp<0)return ValType(res);
      else return ValType(res[comp]);
   }
   
  virtual GradType grad(double x, double y, double z) const { return GradType(); };
  virtual HessType hess(double x, double y, double z) const { return HessType(); };
  ~genSimpleFunctionUtot(){ }
};
 
#endif