MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mschwrap.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/mschwrap.h,v 1.34 2017/01/12 14:44:25 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #ifndef MSCHWRAP_H
33 #define MSCHWRAP_H
34 
35 #ifdef USE_MESCHACH
36 
37 #include <iostream>
38 
39 #include <solman.h>
40 #include <submat.h>
41 
42 extern "C" {
43 #include <meschach/sparse2.h>
44 }
45 
46 /*
47  * Meschach defines "catch" as a macro,
48  * which conflicts with the reserved C++ word
49  */
50 #undef catch
51 
52 /* MeschachVectorHandler - begin */
53 
54 class MeschachVectorHandler : public VectorHandler {
55 protected:
56  VEC* pv;
57  doublereal* pdVecm1;
58 
59 public:
60  MeschachVectorHandler(integer iSize = 0);
61  virtual ~MeschachVectorHandler(void);
62 
63 #ifdef DEBUG
64  /* Usata per il debug */
65  virtual void IsValid(void) const;
66 #endif /* DEBUG */
67 
68  virtual inline doublereal* pdGetVec(void) const;
69  inline VEC* pGetMeschachVEC(void) const;
70 
71  virtual inline integer iGetSize(void) const;
72 
73  virtual void Resize(integer iNewSize);
74  virtual void Reset(void);
75 
76  virtual inline flag PutCoef(integer iRow, const doublereal& dCoef);
77  virtual inline flag IncCoef(integer iRow, const doublereal& dCoef);
78  virtual inline flag DecCoef(integer iRow, const doublereal& dCoef);
79  virtual inline const doublereal& dGetCoef(integer iRow) const;
80 
81  virtual inline const doublereal& operator () (integer iRow) const;
82  virtual inline doublereal& operator () (integer iRow);
83 };
84 
85 
86 inline doublereal*
87 MeschachVectorHandler::pdGetVec(void) const
88 {
89 #ifdef DEBUG
90  IsValid();
91 #endif /* DEBUG */
92  return pv->ve;
93 }
94 
95 inline VEC*
96 MeschachVectorHandler::pGetMeschachVEC(void) const
97 {
98 #ifdef DEBUG
99  IsValid();
100 #endif /* DEBUG */
101  return pv;
102 }
103 
104 inline integer
105 MeschachVectorHandler::iGetSize(void) const
106 {
107 #ifdef DEBUG
108  IsValid();
109 #endif /* DEBUG */
110  return integer(pv->dim);
111 }
112 
113 inline flag
114 MeschachVectorHandler::PutCoef(integer iRow, const doublereal& dCoef)
115 {
116 #ifdef DEBUG
117  IsValid();
118 #endif /* DEBUG */
119  pdVecm1[iRow] = dCoef;
120  return flag(1);
121 }
122 
123 inline flag
124 MeschachVectorHandler::IncCoef(integer iRow, const doublereal& dCoef)
125 {
126 #ifdef DEBUG
127  IsValid();
128 #endif /* DEBUG */
129  pdVecm1[iRow] += dCoef;
130  return flag(1);
131 }
132 
133 inline flag
134 MeschachVectorHandler::DecCoef(integer iRow, const doublereal& dCoef)
135 {
136 #ifdef DEBUG
137  IsValid();
138 #endif /* DEBUG */
139  pdVecm1[iRow] -= dCoef;
140  return flag(1);
141 }
142 
143 inline const doublereal&
144 MeschachVectorHandler::dGetCoef(integer iRow) const
145 {
146 #ifdef DEBUG
147  IsValid();
148 #endif /* DEBUG */
149  return pdVecm1[iRow];
150 }
151 
152 inline const doublereal&
153 MeschachVectorHandler::operator () (integer iRow) const
154 {
155 #ifdef DEBUG
156  IsValid();
157 #endif /* DEBUG */
158  return pdVecm1[iRow];
159 }
160 
161 inline doublereal&
162 MeschachVectorHandler::operator () (integer iRow)
163 {
164 #ifdef DEBUG
165  IsValid();
166 #endif /* DEBUG */
167  return pdVecm1[iRow];
168 }
169 
170 /* MeschachVectorHandler - end */
171 
172 /* MeschachSparseMatrixHandler - begin */
173 
174 class MeschachSparseMatrixHandler : public MatrixHandler {
175 private:
176  doublereal dDmy;
177 
178  protected:
179  SPMAT* mat;
180 
181 public:
182  MeschachSparseMatrixHandler(integer m, integer n, integer maxlen = 0);
183  ~MeschachSparseMatrixHandler(void);
184 
185  /* helpers */
186  inline integer iGetNumRows(void) const;
187  inline integer iGetNumCols(void) const;
188 
189  /* costruisce la matrice */
190  void Create(integer m, integer n, integer maxlen = 0);
191 #ifdef DEBUG
192  void IsValid(void) const;
193 #endif /* DEBUG */
194  void Reset(void);
195 
196  /* Inserisce un coefficiente */
197  inline flag PutCoef(integer iRow, integer iCol,
198  const doublereal& dCoef);
199 
200  /* Incrementa un coefficiente - se non esiste lo crea */
201  inline flag IncCoef(integer iRow, integer iCol,
202  const doublereal& dCoef);
203 
204  /* Decrementa un coefficiente - se non esiste lo crea */
205  inline flag DecCoef(integer iRow, integer iCol,
206  const doublereal& dCoef);
207 
208  /* Restituisce un coefficiente - zero se non e' definito */
209  inline const doublereal& dGetCoef(integer iRow, integer iCol) const;
210 
211  inline SPMAT* pGetMAT(void) const;
212 };
213 
214 /* helpers */
215 inline integer
216 MeschachSparseMatrixHandler::iGetNumRows(void) const
217 {
218 #ifdef DEBUG
219  IsValid();
220 #endif /* DEBUG */
221  return integer(mat->m);
222 }
223 
224 inline integer
225 MeschachSparseMatrixHandler::iGetNumCols(void) const
226 {
227 #ifdef DEBUG
228  IsValid();
229 #endif /* DEBUG */
230  return integer(mat->n);
231 }
232 
233 /* Inserisce un coefficiente */
234 inline flag
235 MeschachSparseMatrixHandler::PutCoef(integer iRow, integer iCol,
236  const doublereal& dCoef)
237 {
238 #ifdef DEBUG
239  IsValid();
240 #endif /* DEBUG */
241  if (dCoef != 0.) {
242  sp_set_val(mat, --iRow, --iCol, dCoef);
243  return flag(0);
244  }
245  return flag(1);
246 }
247 
248 /* Incrementa un coefficiente - se non esiste lo crea */
249 inline flag
250 MeschachSparseMatrixHandler::IncCoef(integer iRow, integer iCol,
251  const doublereal& dCoef)
252 {
253 #ifdef DEBUG
254  IsValid();
255 #endif /* DEBUG */
256  if (dCoef != 0.) {
257  /* FIXME: this is an extension to Meschach */
258  sp_inc_val(mat, --iRow, --iCol, dCoef);
259  return flag(0);
260  }
261  return flag(1);
262 }
263 
264 /* Decrementa un coefficiente - se non esiste lo crea */
265 inline flag
266 MeschachSparseMatrixHandler::DecCoef(integer iRow, integer iCol,
267  const doublereal& dCoef)
268 {
269 #ifdef DEBUG
270  IsValid();
271 #endif /* DEBUG */
272  if (dCoef != 0.) {
273  /* FIXME: this is an extension to Meschach */
274  sp_dec_val(mat, --iRow, --iCol, dCoef);
275  return flag(0);
276  }
277  return flag(1);
278 }
279 
280 /* Restituisce un coefficiente - zero se non e' definito */
281 inline const doublereal&
282 MeschachSparseMatrixHandler::dGetCoef(integer iRow, integer iCol) const
283 {
284 #ifdef DEBUG
285  IsValid();
286 #endif /* DEBUG */
287  return ((doublereal&)dDmy = sp_get_val(mat, --iRow, --iCol));
288 }
289 
290 inline SPMAT*
291 MeschachSparseMatrixHandler::pGetMAT(void) const
292 {
293 #ifdef DEBUG
294  IsValid();
295 #endif /* DEBUG */
296  return mat;
297 }
298 
299 extern std::ostream&
300 operator << (std::ostream& out, const MeschachSparseMatrixHandler& MH);
301 
302 
303 
304 /* MeschachSparseMatrixHandler -end */
305 
306 /* MeschachSparseSolutionManager - begin */
307 
308 class MeschachSparseSolutionManager : public SolutionManager {
309 protected:
310  MeschachVectorHandler* prhs;
311  PERM* pivot;
312  MeschachSparseMatrixHandler* pmh;
313 
314  enum { RESET, FACTORED } fStatus;
315  doublereal alpha;
316 
317  void Create(integer iSize, integer iMaxSize);
318  void Factor(void);
319 
320 public:
321  MeschachSparseSolutionManager(integer iSize,
322  integer iMaxSize = 0,
323  const doublereal& a = 1.);
324  ~MeschachSparseSolutionManager(void);
325 
326 #ifdef DEBUG
327  void IsValid(void) const;
328 #endif /* DEBUG */
329  void MatrReset(void);
330 
331  void Solve(void);
332 
333  /* sposta il puntatore al vettore del residuo */
334  void pdSetResVec(doublereal* pRes){
335  silent_cerr("Sorry Meschach is not available as local parallel solver. "
336  << "Aborting" << std::endl);
338  };
339 
340  /* sposta il puntatore al vettore del residuo */
341  void pdSetSolVec(doublereal* pSol) {
342  silent_cerr("Sorry Meschach is not available as local parallel solver. "
343  << "Aborting" << std::endl);
345  };
346 
347  /* Rende disponibile l'handler per la matrice */
348  virtual MatrixHandler* pMatHdl(void) const;
349 
350  /* Rende disponibile l'handler per il termine noto */
351  virtual VectorHandler* pResHdl(void) const;
352 
353  /* Rende disponibile l'handler per la soluzione (e' lo stesso
354  * del termine noto, ma concettualmente sono separati) */
355  virtual VectorHandler* pSolHdl(void) const;
356 };
357 
358 /* MeschachSparseSolutionManager - end */
359 
360 #endif /* USE_MESCHACH */
361 
362 #endif /* MSCHWRAP_H */
virtual void Reset(void)=0
virtual VectorHandler * pResHdl(void) const =0
virtual integer iGetNumCols(void) const =0
virtual const doublereal & dGetCoef(integer iRow, integer iCol) const
Definition: mh.cc:389
long int flag
Definition: mbdyn.h:43
virtual void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:374
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual doublereal * pdGetVec(void) const =0
doublereal * pdSetSolVec(doublereal *pd)
Definition: solman.cc:101
virtual const doublereal & operator()(integer iRow) const =0
virtual void IncCoef(integer iRow, const doublereal &dCoef)=0
virtual void DecCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:379
virtual const doublereal & dGetCoef(integer iRow) const =0
virtual integer iGetSize(void) const =0
virtual void Reset(void)=0
virtual void DecCoef(integer iRow, const doublereal &dCoef)=0
virtual MatrixHandler * pMatHdl(void) const =0
std::ostream & operator<<(std::ostream &out, const FullMatrixHandler &m)
Definition: fullmh.cc:352
doublereal * pdSetResVec(doublereal *pd)
Definition: solman.cc:93
static doublereal mat[5][5]
Definition: dgeequtest.cc:45
virtual void MatrReset(void)=0
virtual void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:384
virtual void Solve(void)=0
virtual void PutCoef(integer iRow, const doublereal &dCoef)=0
static const doublereal a
Definition: hfluid_.h:289
virtual VectorHandler * pSolHdl(void) const =0
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual void Resize(integer iNewSize)=0
virtual integer iGetNumRows(void) const =0