packages feed

casadi-bindings-control-2.0.0.1: Casadi/Control/Data.hs

{-# OPTIONS_GHC -Wall #-}
{-# Language FlexibleInstances #-}
{-# Language MultiParamTypeClasses #-}

module Casadi.Control.Data where

import Prelude hiding ( Functor )

import Foreign.Ptr ( Ptr, FunPtr )
import Foreign.ForeignPtr ( ForeignPtr, castForeignPtr, newForeignPtr, touchForeignPtr )
import Foreign.ForeignPtr.Unsafe ( unsafeForeignPtrToPtr )

import Casadi.Internal.Marshal (  Marshal(..) )
import Casadi.Internal.WrapReturn ( WrapReturn(..) )
import Casadi.Core.Data

-- raw decl
data DpleSolver'
-- data decl
{-|
>Base class for Discrete Periodic Lyapunov Equation Solvers.
>
>Given matrices $A_k$ and symmetric $V_k, k = 0..K-1$
>
>
>
>::
>
>  A_k in R^(n x n)
>  V_k in R^n
>  
>
>
>
>provides all of $P_k$ that satisfy:
>
>
>
>::
>
>  P_0 = A_(K-1)*P_(K-1)*A_(K-1)' + V_k
>  P_k+1 = A_k*P_k*A_k' + V_k  for k = 1..K-1
>  
>
>
>
>General information
>===================
>
>
>
>>Input scheme: casadi::DPLEInput (DPLE_NUM_IN = 2) [dpleIn]
>
>+------------------------+------------------------+------------------------+
>|       Full name        |         Short          |      Description       |
>+========================+========================+========================+
>| DPLE_A                 | a                      | A matrices (horzcat    |
>|                        |                        | when const_dim,        |
>|                        |                        | blkdiag otherwise) .   |
>+------------------------+------------------------+------------------------+
>| DPLE_V                 | v                      | V matrices (horzcat    |
>|                        |                        | when const_dim,        |
>|                        |                        | blkdiag otherwise) .   |
>+------------------------+------------------------+------------------------+
>
>>Output scheme: casadi::DPLEOutput (DPLE_NUM_OUT = 1) [dpleOut]
>
>+------------------------+------------------------+------------------------+
>|       Full name        |         Short          |      Description       |
>+========================+========================+========================+
>| DPLE_P                 | p                      | Lyapunov matrix        |
>|                        |                        | (horzcat when          |
>|                        |                        | const_dim, blkdiag     |
>|                        |                        | otherwise) (Cholesky   |
>|                        |                        | of P if pos_def) .     |
>+------------------------+------------------------+------------------------+
>
>>List of available options
>
>+--------------+--------------+--------------+--------------+--------------+
>|      Id      |     Type     |   Default    | Description  |   Used in    |
>+==============+==============+==============+==============+==============+
>| ad_mode      | OT_STRING    | "automatic"  | How to       | casadi::Func |
>|              |              |              | calculate    | tionInternal |
>|              |              |              | the          |              |
>|              |              |              | Jacobians.   |              |
>|              |              |              | (forward:    |              |
>|              |              |              | only forward |              |
>|              |              |              | mode|reverse |              |
>|              |              |              | : only       |              |
>|              |              |              | adjoint mode |              |
>|              |              |              | |automatic:  |              |
>|              |              |              | a heuristic  |              |
>|              |              |              | decides      |              |
>|              |              |              | which is     |              |
>|              |              |              | more         |              |
>|              |              |              | appropriate) |              |
>+--------------+--------------+--------------+--------------+--------------+
>| const_dim    | OT_BOOLEAN   | true         | Assume       | casadi::Dple |
>|              |              |              | constant     | Internal     |
>|              |              |              | dimension of |              |
>|              |              |              | P            |              |
>+--------------+--------------+--------------+--------------+--------------+
>| derivative_g | OT_DERIVATIV | GenericType( | Function     | casadi::Func |
>| enerator     | EGENERATOR   | )            | that returns | tionInternal |
>|              |              |              | a derivative |              |
>|              |              |              | function     |              |
>|              |              |              | given a      |              |
>|              |              |              | number of    |              |
>|              |              |              | forward and  |              |
>|              |              |              | reverse      |              |
>|              |              |              | directional  |              |
>|              |              |              | derivative,  |              |
>|              |              |              | overrides    |              |
>|              |              |              | internal     |              |
>|              |              |              | routines.    |              |
>|              |              |              | Check docume |              |
>|              |              |              | ntation of D |              |
>|              |              |              | erivativeGen |              |
>|              |              |              | erator .     |              |
>+--------------+--------------+--------------+--------------+--------------+
>| eps_unstable | OT_REAL      | 0.000        | A margin for | casadi::Dple |
>|              |              |              | unstability  | Internal     |
>|              |              |              | detection    |              |
>+--------------+--------------+--------------+--------------+--------------+
>| error_unstab | OT_BOOLEAN   | false        | Throw an     | casadi::Dple |
>| le           |              |              | exception    | Internal     |
>|              |              |              | when it is   |              |
>|              |              |              | detected     |              |
>|              |              |              | that         |              |
>|              |              |              | Product(A_i, |              |
>|              |              |              | i=N..1) has  |              |
>|              |              |              | eigenvalues  |              |
>|              |              |              | greater than |              |
>|              |              |              | 1-eps_unstab |              |
>|              |              |              | le           |              |
>+--------------+--------------+--------------+--------------+--------------+
>| gather_stats | OT_BOOLEAN   | false        | Flag to      | casadi::Func |
>|              |              |              | indicate     | tionInternal |
>|              |              |              | whether      |              |
>|              |              |              | statistics   |              |
>|              |              |              | must be      |              |
>|              |              |              | gathered     |              |
>+--------------+--------------+--------------+--------------+--------------+
>| inputs_check | OT_BOOLEAN   | true         | Throw        | casadi::Func |
>|              |              |              | exceptions   | tionInternal |
>|              |              |              | when the     |              |
>|              |              |              | numerical    |              |
>|              |              |              | values of    |              |
>|              |              |              | the inputs   |              |
>|              |              |              | don't make   |              |
>|              |              |              | sense        |              |
>+--------------+--------------+--------------+--------------+--------------+
>| monitor      | OT_STRINGVEC | GenericType( | Monitors to  | casadi::Func |
>|              | TOR          | )            | be activated | tionInternal |
>|              |              |              | (inputs|outp |              |
>|              |              |              | uts)         |              |
>+--------------+--------------+--------------+--------------+--------------+
>| name         | OT_STRING    | "unnamed_sha | name of the  | casadi::Opti |
>|              |              | red_object"  | object       | onsFunctiona |
>|              |              |              |              | lityNode     |
>+--------------+--------------+--------------+--------------+--------------+
>| pos_def      | OT_BOOLEAN   | false        | Assume P     | casadi::Dple |
>|              |              |              | positive     | Internal     |
>|              |              |              | definite     |              |
>+--------------+--------------+--------------+--------------+--------------+
>| regularity_c | OT_BOOLEAN   | true         | Throw        | casadi::Func |
>| heck         |              |              | exceptions   | tionInternal |
>|              |              |              | when NaN or  |              |
>|              |              |              | Inf appears  |              |
>|              |              |              | during       |              |
>|              |              |              | evaluation   |              |
>+--------------+--------------+--------------+--------------+--------------+
>| user_data    | OT_VOIDPTR   | GenericType( | A user-      | casadi::Func |
>|              |              | )            | defined      | tionInternal |
>|              |              |              | field that   |              |
>|              |              |              | can be used  |              |
>|              |              |              | to identify  |              |
>|              |              |              | the function |              |
>|              |              |              | or pass      |              |
>|              |              |              | additional   |              |
>|              |              |              | information  |              |
>+--------------+--------------+--------------+--------------+--------------+
>| verbose      | OT_BOOLEAN   | false        | Verbose      | casadi::Func |
>|              |              |              | evaluation   | tionInternal |
>|              |              |              | for          |              |
>|              |              |              | debugging    |              |
>+--------------+--------------+--------------+--------------+--------------+
>
>List of plugins
>===============
>
>
>
>- <a href='#plugin_DpleSolver_simple'>simple</a>
>
>- <a href='#plugin_DpleSolver_slicot'>slicot</a>
>
>Note: some of the plugins in this list might not be available on your
>system. Also, there might be extra plugins available to you that are not
>listed here. You can obtain their documentation with
>DpleSolver.doc("myextraplugin")
>
>
>
>--------------------------------------------------------------------------------
>
>simple
>------
>
>
>
>Solving the Discrete Periodic Lyapunov Equations with a regular LinearSolver
>
>>List of available options
>
>+-----------------+-----------------+-----------------+-----------------+
>|       Id        |      Type       |     Default     |   Description   |
>+=================+=================+=================+=================+
>| linear_solver   | OT_STRING       | GenericType()   | User-defined    |
>|                 |                 |                 | linear solver   |
>|                 |                 |                 | class. Needed   |
>|                 |                 |                 | for             |
>|                 |                 |                 | sensitivities.  |
>+-----------------+-----------------+-----------------+-----------------+
>| linear_solver_o | OT_DICTIONARY   | GenericType()   | Options to be   |
>| ptions          |                 |                 | passed to the   |
>|                 |                 |                 | linear solver.  |
>+-----------------+-----------------+-----------------+-----------------+
>
>--------------------------------------------------------------------------------
>
>
>
>--------------------------------------------------------------------------------
>
>slicot
>------
>
>
>
>An efficient solver for Discrete Periodic Lyapunov Equations using SLICOT
>
>Uses Periodic Schur Decomposition ('psd') and does not assume positive
>definiteness. Based on Periodic Lyapunov equations: some applications and
>new algorithms. Int. J. Control, vol. 67, pp. 69-87, 1997.
>
>>List of available options
>
>+-----------------+-----------------+-----------------+-----------------+
>|       Id        |      Type       |     Default     |   Description   |
>+=================+=================+=================+=================+
>| linear_solver   | OT_STRING       | GenericType()   | User-defined    |
>|                 |                 |                 | linear solver   |
>|                 |                 |                 | class. Needed   |
>|                 |                 |                 | for             |
>|                 |                 |                 | sensitivities.  |
>+-----------------+-----------------+-----------------+-----------------+
>| linear_solver_o | OT_DICTIONARY   | GenericType()   | Options to be   |
>| ptions          |                 |                 | passed to the   |
>|                 |                 |                 | linear solver.  |
>+-----------------+-----------------+-----------------+-----------------+
>| psd_num_zero    | OT_REAL         | 0.000           | Numerical zero  |
>|                 |                 |                 | used in         |
>|                 |                 |                 | Periodic Schur  |
>|                 |                 |                 | decomposition   |
>|                 |                 |                 | with            |
>|                 |                 |                 | slicot.This     |
>|                 |                 |                 | option is       |
>|                 |                 |                 | needed when     |
>|                 |                 |                 | your systems    |
>|                 |                 |                 | has Floquet     |
>|                 |                 |                 | multiplierszero |
>|                 |                 |                 | or close to     |
>|                 |                 |                 | zero            |
>+-----------------+-----------------+-----------------+-----------------+
>
>>List of available stats
>
>+----------------+
>|       Id       |
>+================+
>| t_linear_solve |
>+----------------+
>| t_psd          |
>+----------------+
>| t_total        |
>+----------------+
>
>--------------------------------------------------------------------------------
>
>
>
>Joris Gillis
>Diagrams
>--------
>
>
>
>C++ includes: dple_solver.hpp 
-}
newtype DpleSolver = DpleSolver (ForeignPtr DpleSolver')
-- typeclass decl
class DpleSolverClass a where
  castDpleSolver :: a -> DpleSolver
instance DpleSolverClass DpleSolver where
  castDpleSolver = id

-- baseclass instances
instance FunctionClass DpleSolver where
  castFunction (DpleSolver x) = Function (castForeignPtr x)


-- helper instances
instance Marshal DpleSolver (Ptr DpleSolver') where
  marshal (DpleSolver x) = return (unsafeForeignPtrToPtr x)
  marshalFree (DpleSolver x) _ = touchForeignPtr x
foreign import ccall unsafe "&delete_casadi__DpleSolver" 
  c_delete_casadi__DpleSolver :: FunPtr (Ptr DpleSolver' -> IO ())
instance WrapReturn (Ptr DpleSolver') DpleSolver where
  wrapReturn = (fmap DpleSolver) . (newForeignPtr c_delete_casadi__DpleSolver)