csparse_cholesky_interface.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_CSPARSE_CHOLESKY_INTERFACE_HPP
27 #define CASADI_CSPARSE_CHOLESKY_INTERFACE_HPP
28 
39 #include <cs.h>
40 #include "casadi/core/linsol_internal.hpp"
41 #include <casadi/interfaces/csparse/casadi_linsol_csparsecholesky_export.h>
42 
43 namespace casadi {
44 
45  struct CsparseCholMemory : public LinsolMemory {
46  // Destructor
47  ~CsparseCholMemory();
48 
49  // The transpose of linear system in form (CCS)
50  cs A;
51 
52  // The symbolic factorization
53  css *S;
54 
55  // The numeric factorization
56  csn *L;
57 
58  // Temporary
59  std::vector<double> temp;
60 
61  std::vector<int> colind;
62  std::vector<int> row;
63 
64  };
65 
73  class
74  CSparseCholeskyInterface : public LinsolInternal {
75  public:
76  // Create a linear solver given a sparsity pattern and a number of right hand sides
77  CSparseCholeskyInterface(const std::string& name, const Sparsity& sp);
78 
80  static LinsolInternal* creator(const std::string& name, const Sparsity& sp) {
81  return new CSparseCholeskyInterface(name, sp);
82  }
83 
84  // Destructor
85  ~CSparseCholeskyInterface() override;
86 
87  // Initialize the solver
88  void init(const Dict& opts) override;
89 
91  void* alloc_mem() const override { return new CsparseCholMemory();}
92 
94  int init_mem(void* mem) const override;
95 
97  void free_mem(void *mem) const override { delete static_cast<CsparseCholMemory*>(mem);}
98 
99  // Symbolic factorization
100  int sfact(void* mem, const double* A) const override;
101 
102  // Factorize the linear system
103  int nfact(void* mem, const double* A) const override;
104 
105  // Solve the linear system
106  int solve(void* mem, const double* A, double* x, casadi_int nrhs, bool tr) const override;
107 
109  static const std::string meta_doc;
110 
111  // Get name of the plugin
112  const char* plugin_name() const override { return "csparsecholesky";}
113 
114  // Get name of the class
115  std::string class_name() const override { return "CSparseCholeskyInterface";}
116 
118  static ProtoFunction* deserialize(DeserializingStream& s) {
119  return new CSparseCholeskyInterface(s);
120  }
121 
122  protected:
124  explicit CSparseCholeskyInterface(DeserializingStream& s) : LinsolInternal(s) {}
125  };
126 
127 } // namespace casadi
128 
130 #endif // CASADI_CSPARSE_CHOLESKY_INTERFACE_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.