//#####################################################################
// Copyright 2023, Mehrnaz Ayazi.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################

#ifndef __WENO_INTERPOLATION_CELL__
#define __WENO_INTERPOLATION_CELL__

#include <Core/Grids/FACE_INDEX.h>
#include <Core/Interpolation/DIV_FREE_BALSARA.h>
#include <Core/Interpolation/INTERPOLATION_CELL.h>
#include <Core/Interpolation/INTERPOLATION_FACE.h>
#include <Core/Interpolation/INTERPOLATION_HELPERS.h>
#include <Core/Interpolation/WENO_INTERPOLATION.h>
#include <Core/Vectors/VECTOR.h>

namespace PhysBAM
{
template<class TV,class T2>
class WENO_INTERPOLATION_CELL:public INTERPOLATION_CELL<TV,T2>
{
    typedef typename TV::SCALAR T;typedef VECTOR<int, TV::m> IV;
    typedef VECTOR<T2,TV::m> TV2;typedef SYMMETRIC_MATRIX<T2,TV::m> SM2;
    typedef MATRIX<T2, TV::m> TM2;typedef DIAGONAL_MATRIX<T2,TV::m> DM2;
    typedef INTERPOLATION_CELL<TV, T2> BASE;

  public:
    T eps=(T)1e-6;
    
    WENO_INTERPOLATION_CELL() = default;

    T2 Interpolate_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {
        auto p=INTERPOLATION_HELPERS::Clamped_Index<2,false>(grid,at_cells,u.domain,X);
        return WENO_Interpolation<T,T2,TV::m>(p.second,u,p.first,eps);
    }

    VECTOR<T2,2> Extrema_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u0,const ARRAYS_ND_BASE<T2,IV>& u1,const TV& X) const
    {PHYSBAM_NOT_IMPLEMENTED();}

    TV2 Gradient_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {PHYSBAM_NOT_IMPLEMENTED();}

    SM2 Hessian_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {PHYSBAM_NOT_IMPLEMENTED();}

  protected:
    virtual T2 Interpolate_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Interpolate_Cell(grid,u,X);}
    virtual VECTOR<T2,2> Extrema_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u0,
        const ARRAYS_ND_BASE<T2,IV>& u1,const TV& X) const
    {return Extrema_Cell(grid,u0,u1,X);}
    virtual TV2 Gradient_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Gradient_Cell(grid,u,X);}
    virtual SM2 Hessian_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Hessian_Cell(grid,u,X);}
//#####################################################################
};
}
#endif
