// 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 _POLAR_VECTOR_H
#define _POLAR_VECTOR_H

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

template<class T> class radialVector : public genSimpleFunction<T>
{
public :
  typedef typename TensorialTraits<T>::Scalar Scalar;
  typedef typename TensorialTraits<T>::ScalarType ScalarType;
  typedef typename TensorialTraits<T>::ValType ValType;
  typedef typename TensorialTraits<T>::GradType GradType;
  typedef typename TensorialTraits<T>::HessType HessType;
  genSimpleFunction<T> *polar;
    
public :
  radialVector() {
        polar = new genSimpleFunctionCylindricalCoordSyst<T>();
  };
  virtual ValType operator()(double x, double y, double z) const {
    
    std::vector<double> polar_coor = vectorize((*polar)(x,y,z));
    double r = polar_coor[0];
    double theta = polar_coor[1];
    Scalar ux, uy;    
    ux = cos(theta);
    uy = sin(theta);
    std::vector<Scalar> res;
    res.push_back(ux);
    res.push_back(uy);
    return ValType(res);

  };
  
  virtual GradType grad(double x, double y, double z) const { return GradType(); };
  virtual HessType hess(double x, double y, double z) const { return HessType(); };
  ~radialVector(){ delete polar;}
};

template<class T> class tangentVector : public genSimpleFunction<T>
{
public :
  typedef typename TensorialTraits<T>::Scalar Scalar;
  typedef typename TensorialTraits<T>::ScalarType ScalarType;
  typedef typename TensorialTraits<T>::ValType ValType;
  typedef typename TensorialTraits<T>::GradType GradType;
  typedef typename TensorialTraits<T>::HessType HessType;
  
  genSimpleFunction<T> *polar;
    
public :
  tangentVector() {
        polar = new genSimpleFunctionCylindricalCoordSyst<T>();
  };
  virtual ValType operator()(double x, double y, double z) const {
    
    std::vector<double> polar_coor = vectorize((*polar)(x,y,z));
    double r = polar_coor[0];
    double theta = polar_coor[1];
    Scalar ux, uy;    
    ux = -sin(theta);
    uy = cos(theta);
    std::vector<Scalar> res;
    res.push_back(ux);
    res.push_back(uy);
    return ValType(res);

  };
  
  virtual GradType grad(double x, double y, double z) const { return GradType(); };
  virtual HessType hess(double x, double y, double z) const { return HessType(); };
  ~tangentVector(){ delete polar;}
};



#endif 