state_algebra_operations.qbk 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. [/============================================================================
  2. Boost.odeint
  3. Copyright 2011 Mario Mulansky
  4. Copyright 2012 Karsten Ahnert
  5. Copyright 2013 Pascal Germroth
  6. Use, modification and distribution is subject to the Boost Software License,
  7. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. http://www.boost.org/LICENSE_1_0.txt)
  9. =============================================================================/]
  10. [section State Algebra Operations]
  11. [note The following does not apply to implicit steppers like implicit_euler or Rosenbrock 4 as there the `state_type` can not be changed from `ublas::vector` and no algebra/operations are used.]
  12. [heading Description]
  13. The `State`, `Algebra` and `Operations` together define a concept describing how the mathematical vector operations required for the stepper algorithms are performed.
  14. The typical vector operation done within steppers is
  15. ['*y* = __Sigma __alpha[sub i] [*x[sub i]]].
  16. The `State` represents the state variable of an ODE, usually denoted with /x/.
  17. Algorithmically, the state is often realized as a `vector< double >` or `array< double , N >`, however, the genericity of odeint enables you to basically use anything as a state type.
  18. The algorithmic counterpart of such mathematical expressions is divided into two parts.
  19. First, the `Algebra` is used to account for the vector character of the equation.
  20. In the case of a `vector` as state type this means the `Algebra` is responsible for iteration over all vector elements.
  21. Second, the `Operations` are used to represent the actual operation applied to each of the vector elements.
  22. So the `Algebra` iterates over all elements of the `State`s and calls an operation taken from the `Operations` for each element.
  23. This is where `State`, `Algebra` and `Operations` have to work together to make odeint running.
  24. Please have a look at the `range_algebra` and `default_operations` to see an example how this is implemented.
  25. In the following we describe how `State`, `Algebra` and `Operations` are used together within the stepper implementations.
  26. [section Operations]
  27. [heading Notation]
  28. [variablelist
  29. [[`Operations`] [The operations type]]
  30. [/[`Time`] [A type representing the time type of steppers]]
  31. [[`Value1`, ... , `ValueN`] [Types representing the value or time type of stepper]]
  32. [[`Scale`] [Type of the scale operation]]
  33. [[`scale`] [Object of type `Scale`]]
  34. [[[^ScaleSum['N]]] [Type that represents a general scale_sum operation, [^/N/] should be replaced by a number from 1 to 14.]]
  35. [[[^scale_sum['N]]] [Object of type [^ScaleSum['N]], [^/N/] should be replaced by a number from 1 to 14.]]
  36. [[`ScaleSumSwap2`] [Type of the scale sum swap operation]]
  37. [[`scale_sum_swap2`] [Object of type `ScaleSumSwap2`]]
  38. [[`a1, a2, ...`] [Objects of type `Value1`, `Value2`, ...]]
  39. [[`y, x1, x2, ...`] [Objects of `State`'s value type]]
  40. ]
  41. [heading Valid Expressions]
  42. [table
  43. [[Name] [Expression] [Type] [Semantics]]
  44. [[Get scale operation] [`Operations::scale< Value >`] [`Scale`] [Get `Scale` from `Operations`]]
  45. [[`Scale` constructor] [`Scale< Value >( a )`] [`Scale`] [Constructs a `Scale` object]]
  46. [[`Scale` operation] [`scale( x )`] [`void`] [Calculates `x *= a`]]
  47. [[Get general `scale_sum` operation] [[^Operations::scale_sum['N]< Value1 , ... , ValueN >]] [[^ScaleSum['N]]] [Get the [^ScaleSum['N]] type from `Operations`, [^/N/] should be replaced by a number from 1 to 14.]]
  48. [[`scale_sum` constructor] [[^ScaleSum['N]< Value1 , ... , ValueN >( a1 , ... , aN )]] [[^ScaleSum['N]]] [Constructs a `scale_sum` object given [^/N/] parameter values with [^/N/] between 1 and 14.]]
  49. [[`scale_sum` operation] [[^scale_sum['N]( y , x1 , ... , xN )]] [`void`] [Calculates `y = a1*x1 + a2*x2 + ... + aN*xN`. Note that this is an [^/N/+1]-ary function call.]]
  50. [[Get scale sum swap operation] [`Operations::scale_sum_swap2< Value1 , Value2 >`] [`ScaleSumSwap2`] [Get scale sum swap from operations]]
  51. [[`ScaleSumSwap2` constructor] [`ScaleSumSwap2< Value1 , Value2 >( a1 , a2 )`] [`ScaleSumSwap2`] [Constructor]]
  52. [[`ScaleSumSwap2` operation] [`scale_sum_swap2( x1 , x2 , x3 )`] [`void`] [Calculates `tmp = x1`, `x1 = a1*x2 + a2*x3` and `x2 = tmp`.]]
  53. ]
  54. [endsect]
  55. [section Algebra]
  56. [heading Notation]
  57. [variablelist
  58. [[`State`] [The state type]]
  59. [[`Algebra`] [The algebra type]]
  60. [[[^Operation['N]]] [An [^/N/]-ary operation type, [^/N/] should be a number from 1 to 14.]]
  61. [[`algebra`] [Object of type `Algebra`]]
  62. [[[^operation['N]]] [Object of type [^Operation['N]]]]
  63. [[`y, x1, x2, ...`] [Objects of type `State`]]
  64. ]
  65. [heading Valid Expressions]
  66. [table
  67. [[Name] [Expression] [Type] [Semantics]]
  68. [[Vector Operation with arity 2] [`algebra.for_each2( y , x , operation2 )`] [void] [Calls `operation2( y_i , x_i )` for each element `y_i` of `y` and `x_i` of `x`.]]
  69. [[Vector Operation with arity 3] [`algebra.for_each3( y , x1 , x2 , operation3 )`] [void] [Calls `operation3( y_i , x1_i , x2_i )` for each element `y_i` of `y` and `x1_i` of `x1` and `x2_i` of `x2`.]]
  70. [[Vector Operation with arity [^/N/]] [[^algebra.for_each['N]( y , x1 , ... , xN , operation['N] )]] [void] [Calls [^operation['N]( y_i , x1_i , ... , xN_i )] for each element `y_i` of `y` and `x1_i` of `x1` and so on. [^/N/] should be replaced by a number between 1 and 14.]]
  71. ]
  72. [endsect]
  73. [section Pre-Defined implementations]
  74. As standard configuration odeint uses the `range_algebra` and `default_operations` which suffices most situations.
  75. However, a few more possibilities exist either to gain better performance or to ensure interoperability with other libraries.
  76. In the following we list the existing `Algebra`/`Operations` configurations that can be used in the steppers.
  77. [table
  78. [[`State`] [`Algebra`] [`Operations`] [Remarks]]
  79. [[Anything supporting __boost_range, like `std::vector`, `std::list`, `boost::array`,... based on a `value_type` that supports operators +,* (typically `double`)] [`range_algebra`] [`default_operations`] [Standard implementation, applicable for most typical situations.]]
  80. [[`boost::array` based on a `value_type` that supports operators +,*] [`array_algebra`] [`default_operations`] [Special implementation for boost::array with better performance than `range_algebra`]]
  81. [[Anything that defines operators + within itself and * with scalar (Mathematically spoken, anything that is a vector space).] [`vector_space_algebra`] [`default_operations`] [For the use of __controlled_stepper, the template `vector_space_reduce` has to be instantiated.]]
  82. [[`thrust::device_vector`, `thrust::host_vector`] [`thrust_algebra`] [`thrust_operations`] [For running odeint on CUDA devices by using __thrust]]
  83. [[Any RandomAccessRange] [`openmp_range_algebra`] [`default_operations`] [OpenMP-parallelised range algebra]]
  84. [[`openmp_state`] [`openmp_algebra`] [`default_operations`] [OpenMP-parallelised algebra for split data]]
  85. [[`boost::array` or anything which allocates the elements in a C-like manner] [`vector_space_algebra`] [`mkl_operations`] [Using the __intel_mkl in odeint for maximum performance. Currently, only the RK4 stepper is supported.]]
  86. ]
  87. [endsect]
  88. [section Example expressions]
  89. [table
  90. [[Name] [Expression] [Type] [Semantics]]
  91. [[Vector operation] [`algebra.for_each3( y , x1 , x2 , Operations::scale_sum2< Value1 , Value2 >( a1 , a2 ) )`] [void] [Calculates ['*y* = a1 *x1* + a2 *x2*]]]
  92. ]
  93. [endsect]
  94. [endsect]