linsol_tridiag.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  * Copyright (C) 2019 Jorn Baayen, KISTERS AG
9  *
10  * CasADi is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * CasADi is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with CasADi; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 #ifndef CASADI_LINSOL_TRIDIAG_HPP
28 #define CASADI_LINSOL_TRIDIAG_HPP
29 
40 #include "casadi/core/linsol_internal.hpp"
41 #include <casadi/solvers/casadi_linsol_tridiag_export.h>
42 
43 namespace casadi {
44  struct LinsolTridiagMemory : public LinsolMemory {
45  bool have_c, have_ctr;
46  std::vector<double> c, ctr, d;
47  };
48 
53  class LinsolTridiag : public LinsolInternal {
54  public:
55 
56  // Create a linear solver given a sparsity pattern and a number of right hand sides
57  LinsolTridiag(const std::string& name, const Sparsity& sp);
58 
60  static LinsolInternal* creator(const std::string& name, const Sparsity& sp) {
61  return new LinsolTridiag(name, sp);
62  }
63 
64  // Destructor
65  ~LinsolTridiag() override;
66 
67  // Initialize the solver
68  void init(const Dict& opts) override;
69 
71  void* alloc_mem() const override { return new LinsolTridiagMemory();}
72 
74  int init_mem(void* mem) const override;
75 
77  void free_mem(void *mem) const override { delete static_cast<LinsolTridiagMemory*>(mem);}
78 
79  // Symbolic factorization
80  int nfact(void* mem, const double* A) const override;
81 
82  // Factorize the linear system
83  int sfact(void* mem, const double* A) const override;
84 
85  // Solve the linear system
86  int solve(void* mem, const double* A, double* x, casadi_int nrhs, bool tr) const override;
87 
89  void generate(CodeGenerator& g, const std::string& A, const std::string& x,
90  casadi_int nrhs, bool tr) const override;
91 
92  // Get name of the plugin
93  const char* plugin_name() const override { return "tridiag";}
94 
95  // Get name of the class
96  std::string class_name() const override { return "LinsolTridiag";}
97 
99  static const std::string meta_doc;
100  };
101 
102 } // namespace casadi
103 
105 
106 #endif // CASADI_LINSOL_TRIDIAG_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.