//#####################################################################
// Copyright 2021, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#ifndef __GENERAL_INTERPOLATION_CELL__
#define __GENERAL_INTERPOLATION_CELL__

#include <Core/Arrays/ARRAY.h>
#include <Core/Arrays/ARRAYS_ND.h>
#include <Core/Arrays/FACE_ARRAYS.h>
#include <Core/Interpolation/INTERPOLATION_CELL.h>
#include <Core/Log/DEBUG_UTILITIES.h>
namespace PhysBAM{

template<class TV,class T2,class STENCIL,bool const_extrap=false>
class GENERAL_INTERPOLATION_CELL:public INTERPOLATION_CELL<TV,T2>
{
    static_assert(TV::m>=1 && TV::m<=3);
    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 INTERPOLATION_CELL<TV,T2> BASE;
    constexpr static int ss=STENCIL::stencil_size;
public:
    STENCIL stencil;
    
    GENERAL_INTERPOLATION_CELL() = default;
    GENERAL_INTERPOLATION_CELL(const GENERAL_INTERPOLATION_CELL&) = delete;
    void operator=(const GENERAL_INTERPOLATION_CELL&) = delete;
    virtual ~GENERAL_INTERPOLATION_CELL() = default;

    T2 Interpolate_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;
    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;
    TV2 Gradient_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;
    SM2 Hessian_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;

protected:
    virtual T2 Interpolate_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;
    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;
    virtual TV2 Gradient_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;
    virtual SM2 Hessian_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const;
//#####################################################################
};
}
#endif
