1 /* 2 * This file is part of CasADi. 3 * 4 * CasADi -- A symbolic framework for dynamic optimization. 5 * Copyright (C) 2010-2014 Joel Andersson, Joris Gillis, Moritz Diehl, 6 * K.U. 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 30 /** \defgroup plugin_Linsol_tridiag 31 * Linear solver for tridiagonal matrices 32 */ 33 34 /** \pluginsection{Linsol,tridiag} */ 35 36 /// \cond INTERNAL 37 #include "casadi/core/linsol_internal.hpp" 38 #include <casadi/solvers/casadi_linsol_tridiag_export.h> 39 40 namespace casadi { 41 struct CASADI_LINSOL_TRIDIAG_EXPORT LinsolTridiagMemory : public LinsolMemory { 42 bool have_c, have_ctr; 43 std::vector<double> c, ctr, d; 44 }; 45 46 /** \brief \pluginbrief{LinsolInternal,tridiag} 47 * @copydoc LinsolInternal_doc 48 * @copydoc plugin_LinsolInternal_tridiag 49 */ 50 class CASADI_LINSOL_TRIDIAG_EXPORT LinsolTridiag : public LinsolInternal { 51 public: 52 53 // Create a linear solver given a sparsity pattern and a number of right hand sides 54 LinsolTridiag(const std::string& name, const Sparsity& sp); 55 56 /** \brief Create a new LinsolInternal */ creator(const std::string & name,const Sparsity & sp)57 static LinsolInternal* creator(const std::string& name, const Sparsity& sp) { 58 return new LinsolTridiag(name, sp); 59 } 60 61 // Destructor 62 ~LinsolTridiag() override; 63 64 // Initialize the solver 65 void init(const Dict& opts) override; 66 67 /** \brief Create memory block */ alloc_mem() const68 void* alloc_mem() const override { return new LinsolTridiagMemory();} 69 70 /** \brief Initalize memory block */ 71 int init_mem(void* mem) const override; 72 73 /** \brief Free memory block */ free_mem(void * mem) const74 void free_mem(void *mem) const override { delete static_cast<LinsolTridiagMemory*>(mem);} 75 76 // Symbolic factorization 77 int nfact(void* mem, const double* A) const override; 78 79 // Factorize the linear system 80 int sfact(void* mem, const double* A) const override; 81 82 // Solve the linear system 83 int solve(void* mem, const double* A, double* x, casadi_int nrhs, bool tr) const override; 84 85 /// Generate C code 86 void generate(CodeGenerator& g, const std::string& A, const std::string& x, 87 casadi_int nrhs, bool tr) const override; 88 89 // Get name of the plugin plugin_name() const90 const char* plugin_name() const override { return "tridiag";} 91 92 // Get name of the class class_name() const93 std::string class_name() const override { return "LinsolTridiag";} 94 95 /// A documentation string 96 static const std::string meta_doc; 97 }; 98 99 } // namespace casadi 100 101 /// \endcond 102 103 #endif // CASADI_LINSOL_TRIDIAG_HPP 104