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 * 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_ROOTFINDER_HPP 27 #define CASADI_ROOTFINDER_HPP 28 29 #include "function.hpp" 30 #include "linsol.hpp" 31 32 namespace casadi { 33 34 /** \defgroup main_rootfinder 35 * Create a solver for rootfinding problems 36 * Takes a function where one of the inputs is unknown and one of the outputs 37 * is a residual function that is always zero, defines a new function where 38 * the the unknown input has been replaced by a _guess_ for the unknown and the 39 * residual output has been replaced by the calculated value for the input. 40 * 41 * For a function 42 * [y0, y1, ...,yi, .., yn] = F(x0, x1, ..., xj, ..., xm), 43 * where xj is unknown and yi=0, defines a new function 44 * [y0, y1, ...,xj, .., yn] = G(x0, x1, ..., xj_guess, ..., xm), 45 * 46 * xj and yi must have the same dimension and d(yi)/d(xj) must be invertable. 47 * 48 * By default, the first input is unknown and the first output is the residual. 49 * 50 * 51 * \generalsection{Rootfinder} 52 * \pluginssection{Rootfinder} 53 * 54 * \author Joel Andersson 55 * \date 2011-2015 56 */ 57 58 59 /** \defgroup rootfinder 60 * @copydoc main_rootfinder 61 * @{ 62 */ 63 64 /** \if EXPANDED 65 * @copydoc main_rootfinder 66 * \endif 67 */ 68 ///@{ 69 70 ///@{ 71 CASADI_EXPORT Function rootfinder(const std::string& name, const std::string& solver, 72 const SXDict& rfp, const Dict& opts=Dict()); 73 CASADI_EXPORT Function rootfinder(const std::string& name, const std::string& solver, 74 const MXDict& rfp, const Dict& opts=Dict()); 75 CASADI_EXPORT Function rootfinder(const std::string& name, const std::string& solver, 76 const Function& f, const Dict& opts=Dict()); 77 ///@} 78 79 /** \brief Get rootfinder input scheme */ 80 CASADI_EXPORT std::vector<std::string> rootfinder_in(); 81 82 /** \brief Get rootfinder output scheme */ 83 CASADI_EXPORT std::vector<std::string> rootfinder_out(); 84 85 /** \brief Get rootfinder input scheme name by index */ 86 CASADI_EXPORT std::string rootfinder_in(casadi_int ind); 87 88 /** \brief Get rootfinder output scheme name by index */ 89 CASADI_EXPORT std::string rootfinder_out(casadi_int ind); 90 91 /** \brief Number of rootfinder inputs */ 92 CASADI_EXPORT casadi_int rootfinder_n_in(); 93 94 /** \brief Number of rootfinder outputs */ 95 CASADI_EXPORT casadi_int rootfinder_n_out(); 96 97 /** \brief Get all options for a plugin */ 98 CASADI_EXPORT std::vector<std::string> rootfinder_options(const std::string& name); 99 100 /** \brief Get type info for a particular option */ 101 CASADI_EXPORT std::string rootfinder_option_type(const std::string& name, const std::string& op); 102 103 /** \brief Get documentation for a particular option */ 104 CASADI_EXPORT std::string rootfinder_option_info(const std::string& name, const std::string& op); 105 106 /// Check if a particular plugin is available 107 CASADI_EXPORT bool has_rootfinder(const std::string& name); 108 109 /// Explicitly load a plugin dynamically 110 CASADI_EXPORT void load_rootfinder(const std::string& name); 111 112 /// Get the documentation string for a plugin 113 CASADI_EXPORT std::string doc_rootfinder(const std::string& name); 114 /** @} */ 115 116 #ifndef SWIG 117 /// Inputs of the symbolic representation of the rootfinding problem 118 enum RfpIn { 119 RFP_X, 120 RFP_P, 121 RFP_NUM_IN}; 122 123 /// Shortnames for DAE symbolic representation inputs 124 const std::vector<std::string> RFP_INPUTS = {"x", "p"}; 125 126 /// Inputs of the symbolic representation of the rootfinding problem 127 enum RfpOut { 128 RFP_G, 129 RFP_NUM_OUT}; 130 131 /// Shortnames for DAE symbolic representation outputs 132 const std::vector<std::string> RFP_OUTPUTS = {"g"}; 133 134 /// Input arguments of a rootfinder 135 enum RootfinderInput { 136 /// Initial guess for the solution 137 ROOTFINDER_X0, 138 /// Parameters 139 ROOTFINDER_P, 140 /// Number of input arguments of a rootfinder 141 ROOTFINDER_NUM_IN 142 }; 143 144 /// Output arguments of a rootfinder 145 enum RootfinderOutput { 146 /// Solution to the system of equations 147 ROOTFINDER_X, 148 /// Number of output arguments of a rootfinder 149 ROOTFINDER_NUM_OUT 150 }; 151 #endif // SWIG 152 153 } // namespace casadi 154 155 #endif // CASADI_ROOTFINDER_HPP 156