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

#include <Core/Arrays/ARRAY.h>
#include <Core/Grids/GRID.h>
#include <Core/Log/DEBUG_UTILITIES.h>
namespace PhysBAM{

template<class TV,class T2>
class INTERPOLATION_CELL
{
    typedef typename TV::SCALAR T;typedef VECTOR<int,TV::m> IV;
    typedef VECTOR<T2,TV::m> TV2;typedef SYMMETRIC_MATRIX<T2,TV::m> SM2;
public:
    INTERPOLATION_CELL() = default;
    INTERPOLATION_CELL(const INTERPOLATION_CELL&) = delete;
    void operator=(const INTERPOLATION_CELL&) = delete;
    virtual ~INTERPOLATION_CELL() = default;
    
    // These are overridden by each base class to allow compile-time function
    // calls to implementations.  The base class implementation calls the
    // virtual versions below to do dynamic lookup when the base type is not
    // known.
    T2 Interpolate_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Interpolate_Cell_V(grid,u,X);}
    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
    {return Extrema_Cell_V(grid,u0,u1,X);}
    TV2 Gradient_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Gradient_Cell_V(grid,u,X);}
    SM2 Hessian_Cell(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const
    {return Hessian_Cell_V(grid,u,X);}

protected:
    // These are virtual versions of the above; base classes should implement
    // these by calling overridden versions of the routines above.
    virtual T2 Interpolate_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const = 0;
    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 = 0;
    virtual TV2 Gradient_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const = 0;
    virtual SM2 Hessian_Cell_V(const GRID<TV>& grid,const ARRAYS_ND_BASE<T2,IV>& u,const TV& X) const = 0;
};
}
#endif
