MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
itertest.cc File Reference
#include "mbconfig.h"
#include <iostream>
#include <iomanip>
#include "fullmh.h"
#include "spmapmh.h"
#include "ccmh.h"
#include "dirccmh.h"
#include "naivemh.h"
Include dependency graph for itertest.cc:

Go to the source code of this file.

Functions

int main (void)
 

Variables

static doublereal mat [5][5]
 

Function Documentation

int main ( void  )

Definition at line 52 of file itertest.cc.

References NaiveMatrixHandler::begin(), FullMatrixHandler::begin(), SpMapMatrixHandler::begin(), NaivePermMatrixHandler::begin(), CompactSparseMatrixHandler_tpl< off >::begin(), c, NaiveMatrixHandler::end(), FullMatrixHandler::end(), SpMapMatrixHandler::end(), NaivePermMatrixHandler::end(), CompactSparseMatrixHandler_tpl< off >::end(), SpMapMatrixHandler::MakeCompressedColumnForm(), and mat.

53 {
54  std::vector<integer> perm(5), invperm(5);
55  perm[0] = 4;
56  perm[1] = 3;
57  perm[2] = 2;
58  perm[3] = 1;
59  perm[4] = 0;
60  for (int i = 0; i < 5; i++) {
61  invperm[perm[i]] = i;
62  }
63 
64  FullMatrixHandler fm(5);
65  SpMapMatrixHandler spm(5, 5);
66  NaiveMatrixHandler nm(5);
67  NaivePermMatrixHandler npm(5, perm, invperm);
68 
69  for (int r = 0; r < 5; r++) {
70  for (int c = 0; c < 5; c++) {
71  if (mat[r][c] != 0.) {
72  fm(r + 1, c + 1) = mat[r][c];
73  spm(r + 1, c + 1) = mat[r][c];
74  nm(r + 1, c + 1) = mat[r][c];
75  npm(r + 1, c + 1) = mat[r][c];
76  }
77  }
78  }
79 
80  std::cout << "matrix in full form: " << std::endl
81  << fm << std::endl;
82 
83  std::cout << "matrix in sparse form: " << std::endl
84  << spm << std::endl;
85 
86  std::cout << "matrix in naive form: " << std::endl
87  << nm << std::endl;
88 
89  std::cout << "matrix in naive permuted form: " << std::endl
90  << npm << std::endl;
91 
92  std::vector<doublereal> Ax0;
93  std::vector<integer> Ai0, Ap0;
94  spm.MakeCompressedColumnForm(Ax0, Ai0, Ap0, 0);
95 
96  CColMatrixHandler<0> ccm0(Ax0, Ai0, Ap0);
97 
98  std::cout << "matrix in cc<0> form: " << std::endl
99  << ccm0 << std::endl;
100 
101  std::cout << "matrix in cc<0> form again: " << std::endl;
102  const CColMatrixHandler<0>& const_ccm0 = ccm0;
103  for (int ir = 1; ir <= 5; ir++) {
104  for (int ic = 1; ic <= 5; ic++) {
105  std::cout << std::setw(16) << const_ccm0(ir, ic);
106  }
107  std::cout << std::endl;
108  }
109 
110  std::vector<doublereal> Ax1;
111  std::vector<integer> Ai1, Ap1;
112  spm.MakeCompressedColumnForm(Ax1, Ai1, Ap1, 1);
113 
114  CColMatrixHandler<1> ccm1(Ax1, Ai1, Ap1);
115 
116  std::cout << "matrix in cc<1> form: " << std::endl
117  << ccm1 << std::endl;
118 
119  std::cout << "matrix in cc<1> form again: " << std::endl;
120  const CColMatrixHandler<1>& const_ccm1 = ccm1;
121  for (int ir = 1; ir <= 5; ir++) {
122  for (int ic = 1; ic <= 5; ic++) {
123  std::cout << std::setw(16) << const_ccm1(ir, ic);
124  }
125  std::cout << std::endl;
126  }
127 
128  DirCColMatrixHandler<0> dirm0(Ax0, Ai0, Ap0);
129  std::cout << "matrix in dir<0> form: " << std::endl
130  << dirm0 << std::endl;
131 
132  std::cout << "matrix in dir<0> form again: " << std::endl;
133  const DirCColMatrixHandler<0>& const_dirm0 = dirm0;
134  for (int ir = 1; ir <= 5; ir++) {
135  for (int ic = 1; ic <= 5; ic++) {
136  std::cout << std::setw(16) << const_dirm0(ir, ic);
137  }
138  std::cout << std::endl;
139  }
140 
141  DirCColMatrixHandler<1> dirm1(Ax1, Ai1, Ap1);
142  std::cout << "matrix in dir<1> form: " << std::endl
143  << dirm1 << std::endl;
144 
145  std::cout << "matrix in dir<1> form again: " << std::endl;
146  const DirCColMatrixHandler<1>& const_dirm1 = dirm1;
147  for (int ir = 1; ir <= 5; ir++) {
148  for (int ic = 1; ic <= 5; ic++) {
149  std::cout << std::setw(16) << const_dirm1(ir, ic);
150  }
151  std::cout << std::endl;
152  }
153 
154  std::cout << "***************************" << std::endl
155  << "full matrix handler:" << std::endl;
156 
157  for (FullMatrixHandler::const_iterator i = fm.begin();
158  i != fm.end(); ++i)
159  {
160  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
161  if (mat[i->iRow][i->iCol] != i->dCoef) {
162  std::cout << "==> failed!" << std::endl;
163  }
164  }
165 
166  std::cout << "***************************" << std::endl
167  << "sparse map matrix handler:" << std::endl;
168 
169  for (SpMapMatrixHandler::const_iterator i = spm.begin();
170  i != spm.end(); ++i)
171  {
172  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
173  if (mat[i->iRow][i->iCol] != i->dCoef) {
174  std::cout << "==> failed!" << std::endl;
175  }
176  }
177 
178  std::cout << "***************************" << std::endl
179  << "naive sparse matrix handler:" << std::endl;
180  for (NaiveMatrixHandler::const_iterator i = nm.begin();
181  i != nm.end(); ++i)
182  {
183  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
184  if (mat[i->iRow][i->iCol] != i->dCoef) {
185  std::cout << "==> failed!" << std::endl;
186  }
187  }
188 
189  std::cout << "***************************" << std::endl
190  << "naive permuted sparse matrix handler:" << std::endl;
191  for (NaivePermMatrixHandler::const_iterator i = npm.begin();
192  i != npm.end(); ++i)
193  {
194  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
195  if (mat[i->iRow][i->iCol] != i->dCoef) {
196  std::cout << "==> failed!" << std::endl;
197  }
198  }
199 
200  std::cout << "***************************" << std::endl
201  << "column compressed <0> sparse matrix handler:" << std::endl;
202  for (CColMatrixHandler<0>::const_iterator i = ccm0.begin();
203  i != ccm0.end(); ++i)
204  {
205  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
206  if (mat[i->iRow][i->iCol] != i->dCoef) {
207  std::cout << "==> failed!" << std::endl;
208  }
209  }
210 
211  std::cout << "***************************" << std::endl
212  << "column compressed <1> sparse matrix handler:" << std::endl;
213  for (CColMatrixHandler<1>::const_iterator i = ccm1.begin();
214  i != ccm1.end(); ++i)
215  {
216  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
217  if (mat[i->iRow][i->iCol] != i->dCoef) {
218  std::cout << "==> failed!" << std::endl;
219  }
220  }
221 
222  std::cout << "***************************" << std::endl
223  << "dir column compressed <0> sparse matrix handler:" << std::endl;
224  for (DirCColMatrixHandler<0>::const_iterator i = dirm0.begin();
225  i != dirm0.end(); ++i)
226  {
227  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
228  if (mat[i->iRow][i->iCol] != i->dCoef) {
229  std::cout << "==> failed!" << std::endl;
230  }
231  }
232 
233  std::cout << "***************************" << std::endl
234  << "dir column compressed <1> sparse matrix handler:" << std::endl;
235  for (DirCColMatrixHandler<1>::const_iterator i = dirm1.begin();
236  i != dirm1.end(); ++i)
237  {
238  std::cout << "(" << i->iRow << ", " << i->iCol << ", " << i->dCoef << ")" << std::endl;
239  if (mat[i->iRow][i->iCol] != i->dCoef) {
240  std::cout << "==> failed!" << std::endl;
241  }
242  }
243 
244  return 0;
245 }
static std::stack< cleanup * > c
Definition: cleanup.cc:59
static doublereal mat[5][5]
Definition: itertest.cc:43

Here is the call graph for this function:

Variable Documentation

doublereal mat[5][5]
static
Initial value:
= {
{ 11., 0., 13., 0., 15. },
{ 0., 22., 0., 24., 0. },
{ 31., 0., 33., 0., 35. },
{ 0., 42., 0., 44., 0. },
{ 51., 0., 53., 0., 55. }
}

Definition at line 43 of file itertest.cc.

Referenced by main().