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.

165 lines
4.0 KiB

  1. //=====================================================
  2. // File : action_matrix_matrix_product.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:19 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 ACTION_TRISOLVE_MATRIX_PRODUCT
  21. #define ACTION_TRISOLVE_MATRIX_PRODUCT
  22. #include "utilities.h"
  23. #include "STL_interface.hh"
  24. #include <string>
  25. #include "init/init_function.hh"
  26. #include "init/init_vector.hh"
  27. #include "init/init_matrix.hh"
  28. using namespace std;
  29. template<class Interface>
  30. class Action_trisolve_matrix {
  31. public :
  32. // Ctor
  33. Action_trisolve_matrix( int size ):_size(size)
  34. {
  35. MESSAGE("Action_trisolve_matrix Ctor");
  36. // STL matrix and vector initialization
  37. init_matrix<pseudo_random>(A_stl,_size);
  38. init_matrix<pseudo_random>(B_stl,_size);
  39. init_matrix<null_function>(X_stl,_size);
  40. init_matrix<null_function>(resu_stl,_size);
  41. for (int j=0; j<_size; ++j)
  42. {
  43. for (int i=0; i<j; ++i)
  44. A_stl[j][i] = 0;
  45. A_stl[j][j] += 3;
  46. }
  47. // generic matrix and vector initialization
  48. Interface::matrix_from_stl(A_ref,A_stl);
  49. Interface::matrix_from_stl(B_ref,B_stl);
  50. Interface::matrix_from_stl(X_ref,X_stl);
  51. Interface::matrix_from_stl(A,A_stl);
  52. Interface::matrix_from_stl(B,B_stl);
  53. Interface::matrix_from_stl(X,X_stl);
  54. _cost = 0;
  55. for (int j=0; j<_size; ++j)
  56. {
  57. _cost += 2*j + 1;
  58. }
  59. _cost *= _size;
  60. }
  61. // invalidate copy ctor
  62. Action_trisolve_matrix( const Action_trisolve_matrix & )
  63. {
  64. INFOS("illegal call to Action_trisolve_matrix Copy Ctor");
  65. exit(0);
  66. }
  67. // Dtor
  68. ~Action_trisolve_matrix( void ){
  69. MESSAGE("Action_trisolve_matrix Dtor");
  70. // deallocation
  71. Interface::free_matrix(A,_size);
  72. Interface::free_matrix(B,_size);
  73. Interface::free_matrix(X,_size);
  74. Interface::free_matrix(A_ref,_size);
  75. Interface::free_matrix(B_ref,_size);
  76. Interface::free_matrix(X_ref,_size);
  77. }
  78. // action name
  79. static inline std::string name( void )
  80. {
  81. return "trisolve_matrix_"+Interface::name();
  82. }
  83. double nb_op_base( void ){
  84. return _cost;
  85. }
  86. inline void initialize( void ){
  87. Interface::copy_matrix(A_ref,A,_size);
  88. Interface::copy_matrix(B_ref,B,_size);
  89. Interface::copy_matrix(X_ref,X,_size);
  90. }
  91. inline void calculate( void ) {
  92. Interface::trisolve_lower_matrix(A,B,X,_size);
  93. }
  94. void check_result( void ){
  95. // calculation check
  96. // Interface::matrix_to_stl(X,resu_stl);
  97. //
  98. // STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,_size);
  99. //
  100. // typename Interface::real_type error=
  101. // STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
  102. //
  103. // if (error>1.e-6){
  104. // INFOS("WRONG CALCULATION...residual=" << error);
  105. // // exit(1);
  106. // }
  107. }
  108. private :
  109. typename Interface::stl_matrix A_stl;
  110. typename Interface::stl_matrix B_stl;
  111. typename Interface::stl_matrix X_stl;
  112. typename Interface::stl_matrix resu_stl;
  113. typename Interface::gene_matrix A_ref;
  114. typename Interface::gene_matrix B_ref;
  115. typename Interface::gene_matrix X_ref;
  116. typename Interface::gene_matrix A;
  117. typename Interface::gene_matrix B;
  118. typename Interface::gene_matrix X;
  119. int _size;
  120. double _cost;
  121. };
  122. #endif