MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mh.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/mh.h,v 1.29 2017/01/12 14:43:54 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 /*****************************************************************************
33  * *
34  * SOLUTION MANAGER *
35  * *
36  *****************************************************************************/
37 
38 /* Pierangelo Masarati */
39 
40 
41 #ifndef MH_H
42 #define MH_H
43 
44 #include <cmath>
45 #include <iostream>
46 #include "ac/f2c.h"
47 
48 /* per il debugging */
49 #include "myassert.h"
50 #include "mynewmem.h"
51 #include "except.h"
52 
53 #include "vh.h"
54 
55 class SubMatrixHandler;
57 
58 /* MatrixHandler - begin */
59 
61 public:
62  enum Norm_t { NORM_1, NORM_INF };
63 
64  class ErrGeneric : public MBDynErrBase {
65  public:
67  };
68  class ErrRebuildMatrix : public MBDynErrBase {
69  public:
71  };
73  public:
75  };
76 
77 public:
78  virtual ~MatrixHandler(void);
79 
80 #ifdef DEBUG
81  /* Usata per il debug */
82  virtual void IsValid(void) const = 0;
83 #endif /* DEBUG */
84 
85  /* Ridimensiona la matrice */
86  virtual void Resize(integer, integer) = 0;
87 
88  /* Ridimensiona ed inizializza. */
89  virtual void ResizeReset(integer, integer);
90 
91  /* Restituisce un puntatore all'array di reali della matrice */
92  virtual inline const doublereal* pdGetMat(void) const;
93  virtual inline doublereal* pdGetMat(void);
94 
95  /* Restituisce un puntatore al vettore delle righe */
96  virtual inline integer* piGetRows(void) const;
97 
98  /* Restituisce un puntatore al vettore delle colonne */
99  virtual inline integer* piGetCols(void) const;
100 
101  /* Impacchetta la matrice; restituisce il numero di elementi
102  * diversi da zero */
103  virtual integer PacMat(void);
104 
105  /* Resetta la matrice ecc. */
106  virtual void Reset(void) = 0;
107 
108  /* Inserisce un coefficiente */
109  virtual void
110  PutCoef(integer iRow, integer iCol, const doublereal& dCoef);
111 
112  /* Incrementa un coefficiente - se non esiste lo crea */
113  virtual void
114  IncCoef(integer iRow, integer iCol, const doublereal& dCoef);
115 
116  /* Decrementa un coefficiente - se non esiste lo crea */
117  virtual void
118  DecCoef(integer iRow, integer iCol, const doublereal& dCoef);
119 
120  /* Restituisce un coefficiente - zero se non e' definito */
121  virtual const doublereal&
122  dGetCoef(integer iRow, integer iCol) const;
123 
124  virtual const doublereal&
125  operator () (integer iRow, integer iCol) const = 0;
126 
127  virtual doublereal&
128  operator () (integer iRow, integer iCol) = 0;
129 
130  /* dimensioni */
131  virtual integer iGetNumRows(void) const = 0;
132  virtual integer iGetNumCols(void) const = 0;
133 
134  /* Overload di = */
135  virtual MatrixHandler& operator = (const MatrixHandler& MH);
136 
137  /* Overload di += usato per l'assemblaggio delle matrici */
138  virtual MatrixHandler& operator += (const SubMatrixHandler& SubMH);
139 
140  /* Overload di -= usato per l'assemblaggio delle matrici */
141  virtual MatrixHandler& operator -= (const SubMatrixHandler& SubMH);
142 
143  /* Overload di += usato per l'assemblaggio delle matrici
144  * questi li vuole ma non so bene perche'; forse per la doppia
145  * derivazione di VariableSubMatrixHandler */
146  virtual MatrixHandler&
148  virtual MatrixHandler&
150 
151  /* */
152  virtual MatrixHandler& ScalarMul(const doublereal& d);
153 
154  /* Matrix Matrix product */
155 protected:
156  virtual MatrixHandler&
157  MatMatMul_base(void (MatrixHandler::*op)(integer iRow, integer iCol,
158  const doublereal& dCoef),
159  MatrixHandler& out, const MatrixHandler& in) const;
160  virtual MatrixHandler&
161  MatTMatMul_base(void (MatrixHandler::*op)(integer iRow, integer iCol,
162  const doublereal& dCoef),
163  MatrixHandler& out, const MatrixHandler& in) const;
164 
165 public:
166  virtual MatrixHandler&
167  MatMatMul(MatrixHandler& out, const MatrixHandler& in) const;
168  virtual MatrixHandler&
169  MatTMatMul(MatrixHandler& out, const MatrixHandler& in) const;
170  virtual MatrixHandler&
171  MatMatIncMul(MatrixHandler& out, const MatrixHandler& in) const;
172  virtual MatrixHandler&
173  MatTMatIncMul(MatrixHandler& out, const MatrixHandler& in) const;
174  virtual MatrixHandler&
175  MatMatDecMul(MatrixHandler& out, const MatrixHandler& in) const;
176  virtual MatrixHandler&
177  MatTMatDecMul(MatrixHandler& out, const MatrixHandler& in) const;
178 
179  /* Matrix Vector product */
180 protected:
181  virtual VectorHandler&
182  MatVecMul_base(void (VectorHandler::*op)(integer iRow,
183  const doublereal& dCoef),
184  VectorHandler& out, const VectorHandler& in) const;
185  virtual VectorHandler&
186  MatTVecMul_base(void (VectorHandler::*op)(integer iRow,
187  const doublereal& dCoef),
188  VectorHandler& out, const VectorHandler& in) const;
189 
190 public:
191  virtual VectorHandler&
192  MatVecMul(VectorHandler& out, const VectorHandler& in) const;
193  virtual VectorHandler&
194  MatTVecMul(VectorHandler& out, const VectorHandler& in) const;
195  virtual VectorHandler&
196  MatVecIncMul(VectorHandler& out, const VectorHandler& in) const;
197  virtual VectorHandler&
198  MatTVecIncMul(VectorHandler& out, const VectorHandler& in) const;
199  virtual VectorHandler&
200  MatVecDecMul(VectorHandler& out, const VectorHandler& in) const;
201  virtual VectorHandler&
202  MatTVecDecMul(VectorHandler& out, const VectorHandler& in) const;
203  virtual doublereal ConditionNumber(enum Norm_t eNorm = NORM_1) const;
204  virtual doublereal Norm(enum Norm_t eNorm = NORM_1) const;
205 };
206 
207 /* Restituisce un puntatore all'array di reali della matrice */
208 inline const doublereal*
210 {
211  return NULL;
212 }
213 
214 inline doublereal*
216 {
217  return NULL;
218 }
219 
220 /* Restituisce un puntatore al vettore delle righe */
221 inline integer*
223 {
224  return NULL;
225 }
226 
227 /* Restituisce un puntatore al vettore delle colonne */
228 inline integer*
230 {
231  return NULL;
232 }
233 
234 extern std::ostream&
235 operator << (std::ostream& out, const MatrixHandler& MH);
236 
237 /* MatrixHandler - end */
238 
239 #endif /* MH_H */
240 
virtual MatrixHandler & MatMatIncMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:250
virtual integer iGetNumCols(void) const =0
virtual const doublereal & dGetCoef(integer iRow, integer iCol) const
Definition: mh.cc:389
virtual void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:374
virtual MatrixHandler & MatMatDecMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:262
#define MBDYN_EXCEPT_ARGS_PASSTHRU
Definition: except.h:55
virtual VectorHandler & MatVecMul_base(void(VectorHandler::*op)(integer iRow, const doublereal &dCoef), VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:275
virtual integer PacMat(void)
Definition: mh.cc:65
virtual VectorHandler & MatVecIncMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:350
virtual VectorHandler & MatTVecDecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:368
virtual MatrixHandler & operator-=(const SubMatrixHandler &SubMH)
Definition: mh.cc:99
virtual void DecCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:379
#define MBDYN_EXCEPT_ARGS_DECL
Definition: except.h:43
std::ostream & operator<<(std::ostream &out, const MatrixHandler &MH)
Definition: mh.cc:524
virtual VectorHandler & MatTVecIncMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:356
virtual doublereal Norm(enum Norm_t eNorm=NORM_1) const
Definition: mh.cc:512
virtual VectorHandler & MatVecDecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:362
virtual doublereal ConditionNumber(enum Norm_t eNorm=NORM_1) const
Definition: mh.cc:451
virtual void Reset(void)=0
ErrMatrixIsSingular(MBDYN_EXCEPT_ARGS_DECL)
Definition: mh.h:74
virtual MatrixHandler & MatTMatMul_base(void(MatrixHandler::*op)(integer iRow, integer iCol, const doublereal &dCoef), MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:183
virtual MatrixHandler & operator+=(const SubMatrixHandler &SubMH)
Definition: mh.cc:92
virtual const doublereal & operator()(integer iRow, integer iCol) const =0
ErrRebuildMatrix(MBDYN_EXCEPT_ARGS_DECL)
Definition: mh.h:70
virtual ~MatrixHandler(void)
Definition: mh.cc:49
virtual void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:384
virtual integer * piGetRows(void) const
Definition: mh.h:222
virtual VectorHandler & MatTVecMul_base(void(VectorHandler::*op)(integer iRow, const doublereal &dCoef), VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:304
virtual MatrixHandler & MatMatMul_base(void(MatrixHandler::*op)(integer iRow, integer iCol, const doublereal &dCoef), MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:135
ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)
Definition: mh.h:66
virtual void ResizeReset(integer, integer)
Definition: mh.cc:56
virtual MatrixHandler & MatTMatIncMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:256
virtual void Resize(integer, integer)=0
virtual MatrixHandler & MatTMatDecMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:268
virtual const doublereal * pdGetMat(void) const
Definition: mh.h:209
virtual VectorHandler & MatTVecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:341
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual MatrixHandler & MatMatMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:232
virtual MatrixHandler & MatTMatMul(MatrixHandler &out, const MatrixHandler &in) const
Definition: mh.cc:241
virtual VectorHandler & MatVecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:332
virtual MatrixHandler & operator=(const MatrixHandler &MH)
Definition: mh.cc:72
virtual integer * piGetCols(void) const
Definition: mh.h:229
virtual integer iGetNumRows(void) const =0
virtual MatrixHandler & ScalarMul(const doublereal &d)
Definition: mh.cc:119