You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.9 KiB

  1. //=====================================================
  2. // File : tvmet_interface.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002
  5. //=====================================================
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. #ifndef TVMET_INTERFACE_HH
  21. #define TVMET_INTERFACE_HH
  22. #include <tvmet/tvmet.h>
  23. #include <tvmet/Vector.h>
  24. #include <tvmet/Matrix.h>
  25. #include <vector>
  26. using namespace tvmet;
  27. template<class real, int SIZE>
  28. class tvmet_interface{
  29. public :
  30. typedef real real_type ;
  31. typedef std::vector<real> stl_vector;
  32. typedef std::vector<stl_vector > stl_matrix;
  33. typedef Vector<real,SIZE> gene_vector;
  34. typedef Matrix<real,SIZE,SIZE> gene_matrix;
  35. static inline std::string name() { return "tiny_tvmet"; }
  36. static void free_matrix(gene_matrix & A, int N){}
  37. static void free_vector(gene_vector & B){}
  38. static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
  39. for (int j=0; j<A_stl.size() ; j++)
  40. for (int i=0; i<A_stl[j].size() ; i++)
  41. A(i,j) = A_stl[j][i];
  42. }
  43. static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
  44. for (int i=0; i<B_stl.size() ; i++)
  45. B[i]=B_stl[i];
  46. }
  47. static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
  48. for (int i=0; i<B_stl.size() ; i++){
  49. B_stl[i]=B[i];
  50. }
  51. }
  52. static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
  53. int N = A_stl.size();
  54. for (int j=0;j<N;j++){
  55. A_stl[j].resize(N);
  56. for (int i=0;i<N;i++)
  57. A_stl[j][i] = A(i,j);
  58. }
  59. }
  60. static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
  61. cible = source;
  62. }
  63. static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
  64. cible = source;
  65. }
  66. static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  67. X = prod(A,B);
  68. }
  69. static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  70. X = prod(A,B);
  71. }
  72. static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  73. X = prod(trans(A),B);
  74. }
  75. static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
  76. Y+=coef*X;
  77. }
  78. };
  79. #endif