rosenbrock.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2026 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_ROSENBROCK_HPP
27 #define CASADI_ROSENBROCK_HPP
28 
29 #include "casadi/core/runtime_integrator.hpp"
30 #include <casadi/solvers/casadi_integrator_rosenbrock_export.h>
31 
57 namespace casadi {
58 
59  // Memory
60  struct RosenbrockMemory : public RuntimeIntegratorMemory {
61  // Method data, and of the nominal integration whose steps are replayed
63  };
64 
69  class Rosenbrock : public RuntimeIntegrator {
70  public:
71 
73  Rosenbrock(const std::string& name, const Function& dae, double t0,
74  const std::vector<double>& tout);
75 
77  static Integrator* creator(const std::string& name, const Function& dae,
78  double t0, const std::vector<double>& tout) {
79  return new Rosenbrock(name, dae, t0, tout);
80  }
81 
83  ~Rosenbrock() override;
84 
85  // Get name of the plugin
86  const char* plugin_name() const override { return "rosenbrock";}
87 
88  // Get name of the class
89  std::string class_name() const override { return "Rosenbrock";}
90 
92 
93  static const Options options_;
94  const Options& get_options() const override { return options_;}
96 
98  void init(const Dict& opts) override;
99 
101  void set_work(void* mem, const double**& arg, double**& res,
102  casadi_int*& iw, double*& w) const override;
103 
105  void* alloc_mem() const override { return new RosenbrockMemory();}
106 
108  void free_mem(void *mem) const override { delete static_cast<RosenbrockMemory*>(mem);}
109 
111  static const std::string meta_doc;
112 
114  void serialize_body(SerializingStream &s) const override;
115 
117  static ProtoFunction* deserialize(DeserializingStream& s) { return new Rosenbrock(s); }
118 
119  protected:
120 
122  explicit Rosenbrock(DeserializingStream& s);
123 
124  // The iteration matrix needs the Jacobian
125  bool needs_jacobian() const override { return true;}
126 
127  // Call the kernel
128  int kernel(RuntimeIntegratorMemory* m) const override;
129 
130  // Generate code for the problem and data of the method
131  void codegen_method(CodeGenerator& g) const override;
132 
133  private:
134  // Sparsity of the iteration matrix and symbolic QR factorizations, from the Jacobian blocks
135  void set_iteration_matrix();
136 
137  // Method coefficients in transformed form
138  void set_coefficients();
139 
140  // Problem structure of the method, and of the nominal integration if replayed
141  void set_rosenbrock_prob();
142 
143  // Generate code for the problem structure of the method in variable pe, shared part p
144  void codegen_rosenbrock_prob(CodeGenerator& g, const std::string& pe,
145  const std::string& p) const;
146 
147  // Method coefficients, transformed form, beyond the shared ones
148  std::vector<double> c_, gamma_sum_;
149 
150  // Problem structure of the method, and of the nominal integration
151  casadi_rosenbrock_prob<double> pr_, pr_nom_;
152 
153  // Options
154  double init_tol_;
155  casadi_int init_max_iter_;
156 
157  // Iteration matrix: sparsity, nonzero positions of the Jacobian blocks and x-diagonal
158  Sparsity sp_iter_;
159  std::vector<casadi_int> iter_map_;
160 
161  // Sparse QR of the iteration matrix and of d(alg)/dz
162  Sparsity sp_iter_v_, sp_iter_r_, sp_alg_v_, sp_alg_r_;
163  std::vector<casadi_int> iter_prinv_, iter_pc_, alg_prinv_, alg_pc_;
164  };
165 
166 } // namespace casadi
167 
169 #endif // CASADI_ROSENBROCK_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.