gsplines_cpp icon indicating copy to clipboard operation
gsplines_cpp copied to clipboard

Reimplement opeations in GLLSplines

Open rafaelrojasmiliani opened this issue 3 years ago • 1 comments

The actual implementation of functionals in the GLL splace here have the following drawbacks:

  • They have to be constructed with many parameters
    • domain
    • number of intervals
    • dimension of the co-domain
    • number of glp
    • specific constructor values
    • lengths of the domain intervals
  • Memory-related constructor parameters
    • number of intervals
    • dimension of the codomain
    • number of glp.
  • Operation related parameters
    • domain
    • lengths of the domain intervals
  • Many of these parameters can will be obvious from the use of the function object
  • Many of these parameters can will be obvious from the context when using the API
  • Remark In fact, the constructor parameters are given to allocate a memory and build a matrix.
  • Remark The new approach to functionals must allow composition of maps.
  • It is not possible to define Expression
  • It is not possible to compose
template<typename Current, typename Codomain>
class LinearFunctional{
    private:
   static std::unordered_map<DomainGLLSpace, std::variant<Eigen::MatrixXd, Eigen::SparseMatrix>> matrix_database_;
    public:
    Codomain operator()(const GLLSpline &_lhs) const = 0;
};

class Derivative :  public LinearFunctional<Derivative, GLLSpline>
{
private:
     Eigen::SparceMatrix construct(const GLLSpline &_lhs){
            // ...
           result.make_compressed();
           return result;
     }
public:
    GLLSpline operator()(const GLLSpline &_lhs) const {
        if(not matrix_database_.contains(_lhs.space())){ 
              matrix_database_[_lhs.linspace()] = construct(_lhs);
        }
        GLLSpline result = _lhs.linspace().vector_to_spline(matrix_database[_lhs.linspace()]*_lhs.get_coefficients());
    }
template<typename Current, typename Codomain>
class LinearFunctional{
    private:
   static std::unordered_map<DomainGLLSpace, std::variant<Eigen::MatrixXd, Eigen::SparseMatrix>> matrix_database_;
    public:
    Codomain operator()(const GLLSpline &_lhs) const = 0;
};

class Derivative :  public LinearFunctional<Derivative, GLLSpline>
{
private:
     Eigen::SparceMatrix construct(const GLLSpline &_lhs){
            // ...
           result.make_compressed();
           return result;
     }
public:
    GLLSpline operator()(const GLLSpline &_lhs) const {
        if(not matrix_database_.contains(_lhs.space())){ 
              matrix_database_[_lhs.linspace()] = construct(_lhs);
        }
        GLLSpline result = _lhs.linspace().vector_to_spline(matrix_database[_lhs.linspace()]*_lhs.get_coefficients());
    }
template<typename Current, typename Codomain, typename MatrixType>
class LinearFunctional{
    public:
    Codomain operator()(const GLLSpline &_lhs) const = 0;
    const MatrixType& diff_matrix_at(const GLLSpline &_lhs) const = 0;
};




class Derivative :  public LinearFunctional<Derivative, GLLSpline>
{
private:
     Eigen::SparceMatrix construct(const GLLSpline &_lhs){
            // ...
           result.make_compressed();
           return result;
     }
public:
    GLLSpline operator()(const GLLSpline &_lhs) const {
        if(not matrix_database_.contains(_lhs.space())){ 
              matrix_database_[_lhs.linspace()] = construct(_lhs);
        }
        GLLSpline result = _lhs.linspace().vector_to_spline(matrix_database[_lhs.linspace()]*_lhs.get_coefficients());
    }

    
};

rafaelrojasmiliani avatar Jul 26 '22 08:07 rafaelrojasmiliani

Implement Functionals with composite pattern as Functions with


class FunctionalBase{
    std::unique_ptr<std::FunctionalBase> differential_ptr(const GLLSpline& _in){
          return differential_ptr_impl(_in);
    }
    Eigen::VectorXd operator()(const GLLSpline& _in)= 0;
    
protected:
     FunctionalBase *differential_ptr_impl(const GLLSpline& _in)=0;
};

template<typename Current, typename Base,  typename Differential>
class FunctioalBaseInheritanceHelper: public Base{
      public:
          Differential derivate(std::size_t _deg = 1) const {
                return *deriv(_deg);
          }
}

class FunctionalExpression: FunctionalBase<FunctionalExpression, FunctionalBase, FunctionalExpression>{
    private:
         std::vector<std::unique_ptr<FunctionalBase>> container_;
    public:
    const Eigen::VectorXd& operator()(const GLLSpline& _in){
         result_buffer_ = null_element_(*this);
         // ...
        for(const auto& operator : container_){
             result_buffer_ = composer_(operator, _in, result_buffer_);
        }
         return result;
    }
private:
         FunctionalBase *differential_ptr_impl(const GLLSpline& _in){
             return = 0;
             for(const auto& operator : container_){
                  result_buffer_ = composer_(operator, _in, result_buffer_);
             }
         }
};

rafaelrojasmiliani avatar Aug 08 '22 11:08 rafaelrojasmiliani