MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
cctest.cc File Reference
#include "mbconfig.h"
#include <cstring>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include "ac/getopt.h"
#include "solman.h"
#include "spmapmh.h"
#include "ccmh.h"
#include "dirccmh.h"
#include "y12wrap.h"
#include "harwrap.h"
#include "mschwrap.h"
#include "umfpackwrap.h"
#include "parsuperluwrap.h"
#include "superluwrap.h"
Include dependency graph for cctest.cc:

Go to the source code of this file.

Functions

static void usage (void)
 
int main (int argc, char *argv[])
 

Variables

const char * solvers []
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 85 of file cctest.cc.

References count, getopt(), SolutionManager::MatrInitialize(), SolutionManager::MatrReset(), optarg, SolutionManager::pMatHdl(), SolutionManager::pResHdl(), SolutionManager::pSolHdl(), MatrixHandler::Reset(), SAFENEWWITHCONSTRUCTOR, SolutionManager::Solve(), solver, and usage().

86 {
87  SolutionManager *pSM = NULL;
88  char *solver = NULL;
89  bool dir(false);
90  unsigned nt = 1;
91  const int size(3);
92 
93  while (1) {
94  int opt = getopt(argc, argv, "dm:t:");
95 
96  if (opt == EOF) {
97  break;
98  }
99 
100  switch (opt) {
101  case 'd':
102  dir = true;
103  break;
104 
105  case 'm':
106  solver = optarg;
107  break;
108 
109  case 't':
110  nt = atoi(optarg);
111  if (nt < 1) {
112  nt = 1;
113  }
114  break;
115 
116  default:
117  usage();
118  }
119  }
120 
121  if (solver == NULL) {
122  usage();
123  }
124 
125  if (strcasecmp(solver, "superlu") == 0) {
126 #ifdef USE_SUPERLU
127 #ifdef USE_SUPERLU_MT
128  if (dir) {
129  typedef ParSuperLUSparseCCSolutionManager<DirCColMatrixHandler<0> > CCMH;
130  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(nt, size));
131 
132  } else {
133  typedef ParSuperLUSparseCCSolutionManager<CColMatrixHandler<0> > CCMH;
134  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(nt, size));
135  }
136 #else /* !USE_SUPERLU_MT */
137  if (dir) {
138  typedef SuperLUSparseCCSolutionManager<DirCColMatrixHandler<0> > CCMH;
139  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
140 
141  } else {
142  typedef SuperLUSparseCCSolutionManager<CColMatrixHandler<0> > CCMH;
143  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
144  }
145 #endif /* USE_SUPERLU_MT */
146 #else /* !USE_SUPERLU */
147  std::cerr << "need --with-superlu to use SuperLU library"
148  << std::endl;
149  usage();
150 #endif /* !USE_SUPERLU */
151 
152  } else if (strcasecmp(solver, "y12") == 0) {
153 #ifdef USE_Y12
154  if (dir) {
155  typedef Y12SparseCCSolutionManager<DirCColMatrixHandler<1> > CCMH;
156  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
157 
158  } else {
159  typedef Y12SparseCCSolutionManager<CColMatrixHandler<1> > CCMH;
160  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
161  }
162 #else /* !USE_Y12 */
163  std::cerr << "need --with-y12 to use y12m library"
164  << std::endl;
165  usage();
166 #endif /* !USE_Y12 */
167 
168  } else if (strcasecmp(solver, "umfpack") == 0
169  || strcasecmp(solver, "umfpack3") == 0) {
170 #ifdef USE_UMFPACK
171  if (dir) {
172  typedef UmfpackSparseCCSolutionManager<DirCColMatrixHandler<0> > CCMH;
173  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
174 
175  } else {
176  typedef UmfpackSparseCCSolutionManager<CColMatrixHandler<0> > CCMH;
177  SAFENEWWITHCONSTRUCTOR(pSM, CCMH, CCMH(size));
178  }
179 #else /* !USE_UMFPACK */
180  std::cerr << "need --with-umfpack to use Umfpack library"
181  << std::endl;
182  usage();
183 #endif /* !USE_UMFPACK */
184 
185  } else {
186  std::cerr << "unknown solver '" << solver << "'" << std::endl;
187  usage();
188  }
189 
190  std::cout << "using " << solver << " solver..." << std::endl;
191 
192  MatrixHandler *pM = pSM->pMatHdl();
193  VectorHandler *pV = pSM->pResHdl();
194  VectorHandler *px = pSM->pSolHdl();
195 
196  int count = 0;
197 
198  int p = 2;
199  int w = 7 + p;
200  std::cout.setf(std::ios::scientific);
201  std::cout.precision(p);
202 
203  double m11 = 4.,
204  m22 = 4.,
205  m33 = 2.,
206  d = 0.,
207  b1 = 0.,
208  b2 = 0.,
209  b3 = 1.;
210 
211 retry:;
212  pSM->MatrReset();
213 
214  try {
215  pM = pSM->pMatHdl();
216  pM->Reset();
217 
218  pM->operator()(1, 1) = m11;
219  pM->operator()(2, 2) = m22;
220  pM->operator()(3, 3) = m33;
221  if (d) {
222  pM->operator()(1, 2) = d;
223  pM->operator()(2, 1) = d;
224  pM->operator()(2, 3) = d;
225  pM->operator()(3, 2) = d;
226  }
227 
228  pV->operator()(1) = b1;
229  pV->operator()(2) = b2;
230  pV->operator()(3) = b3;
231 
233  std::cerr << "need to rebuild matrix..." << std::endl;
234  pSM->MatrInitialize();
235  goto retry;
236 
237  } catch (...) {
238  std::cerr << "build failure" << std::endl;
239  exit(EXIT_FAILURE);
240  }
241 
242  try {
243  count++;
244  std::cout << "solution " << count << "..." << std::endl;
245 
246  pSM->Solve();
247 
248  } catch (...) {
249  std::cerr << "solution failure" << std::endl;
250  exit(EXIT_FAILURE);
251  }
252 
253  std::cout
254  << "{x1} [" << std::setw(w) << m11
255  << "," << std::setw(w) << d
256  << "," << std::setw(w) << 0.
257  << "]^-1 {" << std::setw(w) << b1
258  << "} {" << std::setw(w) << (*px)(1) << "}" << std::endl
259  << "{x2} = ["<< std::setw(w) << d
260  << "," << std::setw(w) << m22
261  << "," << std::setw(w) << d
262  << "] {" << std::setw(w) << b2
263  << "} = {" << std::setw(w) << (*px)(2) << "}" << std::endl
264  << "{x3} [" << std::setw(w) << 0.
265  << "," << std::setw(w) << d
266  << "," << std::setw(w) << m33
267  << "] {" << std::setw(w) << b3
268  << "} {" << std::setw(w) << (*px)(3) << "}" << std::endl;
269 
270  switch (count) {
271  case 1:
272  d = -2.;
273  break;
274 
275  case 2:
276  d = 0.;
277  break;
278 
279  case 3:
280  return 0;
281  }
282 
283  goto retry;
284 }
virtual VectorHandler * pResHdl(void) const =0
virtual void Reset(void)=0
const LinSol::solver_t solver[]
Definition: linsol.cc:58
virtual MatrixHandler * pMatHdl(void) const =0
static int count
Definition: modules.cc:41
virtual void MatrReset(void)=0
virtual void Solve(void)=0
static void usage(void)
Definition: cctest.cc:65
virtual void MatrInitialize(void)
Definition: solman.cc:72
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
int getopt(int argc, char *const argv[], const char *opts)
Definition: getopt.c:93
char * optarg
Definition: getopt.c:74
virtual VectorHandler * pSolHdl(void) const =0

Here is the call graph for this function:

static void usage ( void  )
static

Definition at line 65 of file cctest.cc.

References solvers.

Referenced by main().

66 {
67  std::cerr << "usage: cctest [-d] [-m <solver>] [-t <nthreads>]"
68  << std::endl;
69 
70  if (!solvers[0]) {
71  std::cerr << "\tno solvers available!!!" << std::endl;
72 
73  } else {
74  std::cerr << "\t<solver>={" << solvers[0];
75  for (unsigned i = 1; solvers[i]; i++) {
76  std::cerr << "|" << solvers[i];
77  }
78  std::cerr << "}" << std::endl;
79  }
80 
81  exit(EXIT_FAILURE);
82 }
const char * solvers[]
Definition: cctest.cc:51

Variable Documentation

const char* solvers[]
Initial value:
= {
NULL
}

Definition at line 51 of file cctest.cc.

Referenced by usage().