linear_interpolant.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_LINEAR_INTERPOLANT_HPP
27 #define CASADI_LINEAR_INTERPOLANT_HPP
28 
29 #include "casadi/core/interpolant_impl.hpp"
30 #include <casadi/solvers/casadi_interpolant_linear_export.h>
31 
40 
41 namespace casadi {
51  class CASADI_INTERPOLANT_LINEAR_EXPORT LinearInterpolant : public Interpolant {
52  public:
53  // Constructor
54  LinearInterpolant(const std::string& name,
55  const std::vector<double>& grid,
56  const std::vector<casadi_int>& offset,
57  const std::vector<double>& values,
58  casadi_int m);
59 
60  // Destructor
61  ~LinearInterpolant() override;
62 
63  // Get name of the plugin
64  const char* plugin_name() const override { return "linear";}
65 
66  // Name of the class
67  std::string class_name() const override { return "LinearInterpolant";}
68 
70  static Interpolant* creator(const std::string& name,
71  const std::vector<double>& grid,
72  const std::vector<casadi_int>& offset,
73  const std::vector<double>& values,
74  casadi_int m) {
75  return new LinearInterpolant(name, grid, offset, values, m);
76  }
77 
78  static Function do_inline(const std::string& name,
79  const std::vector<double>& grid,
80  const std::vector<casadi_int>& offset,
81  const std::vector<double>& values,
82  casadi_int m,
83  const Dict& opts);
84 
85  // Initialize
86  void init(const Dict& opts) override;
87 
89  int eval(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const override;
90 
92 
93  bool has_jacobian() const override { return true;}
94  Function get_jacobian(const std::string& name,
95  const std::vector<std::string>& inames,
96  const std::vector<std::string>& onames,
97  const Dict& opts) const override;
99 
101  bool has_codegen() const override { return true;}
102 
104  void codegen_body(CodeGenerator& g) const override;
105 
107  static const std::string meta_doc;
108 
110 
111  static const Options options_;
112  const Options& get_options() const override { return options_;}
114 
116  void serialize_body(SerializingStream &s) const override;
118  void serialize_type(SerializingStream &s) const override;
119 
121  static ProtoFunction* deserialize(DeserializingStream& s);
122 
123  std::vector<casadi_int> lookup_mode_;
124 
125  protected:
128  };
129 
131  class CASADI_INTERPOLANT_LINEAR_EXPORT LinearInterpolantJac : public FunctionInternal {
132  public:
134  LinearInterpolantJac(const std::string& name) : FunctionInternal(name) {}
135 
137  ~LinearInterpolantJac() override;
138 
140  std::string class_name() const override { return "LinearInterpolantJac";}
141 
143  bool has_codegen() const override { return true;}
144 
146  void codegen_body(CodeGenerator& g) const override;
147 
148  // Initialize
149  void init(const Dict& opts) override;
150 
152  int eval(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const override;
153 
155 
156  bool has_jacobian() const override { return true;}
157  Function get_jacobian(const std::string& name,
158  const std::vector<std::string>& inames,
159  const std::vector<std::string>& onames,
160  const Dict& opts) const override;
162 
164  void serialize_type(SerializingStream &s) const override;
165 
167  bool has_parametric_values() const;
168  bool has_parametric_grid() const;
169 
171  std::string serialize_base_function() const override { return "Interpolant"; }
172 
175  };
176 
177 } // namespace casadi
178 
180 #endif // CASADI_LINEAR_INTERPOLANT_HPP
Helper class for C code generation.
Helper class for Serialization.
Internal class for Function.
Function object.
Definition: function.hpp:60
bool has_codegen() const override
Is codegen supported?
bool has_jacobian() const override
Full Jacobian.
std::string serialize_base_function() const override
String used to identify the immediate FunctionInternal subclass.
LinearInterpolantJac(DeserializingStream &s)
Deserializing constructor.
LinearInterpolantJac(const std::string &name)
Constructor.
std::string class_name() const override
Get type name.
'linear' plugin for Interpolant Implements a multilinear interpolant: For 1D, the interpolating polyn...
static Interpolant * creator(const std::string &name, const std::vector< double > &grid, const std::vector< casadi_int > &offset, const std::vector< double > &values, casadi_int m)
Create a new Interpolant.
const Options & get_options() const override
Options.
static const Options options_
Options.
std::vector< casadi_int > lookup_mode_
const char * plugin_name() const override
bool has_jacobian() const override
Full Jacobian.
bool has_codegen() const override
Is codegen supported?
std::string class_name() const override
Get type name.
static const std::string meta_doc
A documentation string.
Base class for FunctionInternal and LinsolInternal.
Helper class for Serialization.
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
MX do_inline(const MX &x, const std::vector< std::vector< double > > &knots, const MX &coeffs, casadi_int m, const std::vector< casadi_int > &degree, const std::vector< casadi_int > &lookup_mode)
Definition: bspline.cpp:211
Options metadata for a class.
Definition: options.hpp:40