MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
vh.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/vh.h,v 1.23 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 VH_H
42 #define VH_H
43 
44 #include <iostream>
45 #include "ac/f2c.h"
46 
47 /* per il debugging */
48 #include "myassert.h"
49 #include "mynewmem.h"
50 #include "except.h"
51 
52 class Vec3;
53 class SubVectorHandler;
54 
55 /* VectorHandler - begin */
56 
57 /* Gestore di vettori. Usa spazio messo a disposizione da altri. */
58 
59 /* questa classe non e' virtuale pura, ma viene definita nel caso banale di
60  * vettore pieno in quanto e' di interesse pratico. Il pacchetto <harwrap>
61  * si basa su questa per la gestione dei vettori residuo e soluzione */
62 
64 public:
65  virtual ~VectorHandler(void);
66 
67 #ifdef DEBUG
68  /* Usata per il debug */
69  virtual void IsValid(void) const = 0;
70 #endif /* DEBUG */
71 
72  virtual doublereal* pdGetVec(void) const = 0;
73 
74  virtual integer iGetSize(void) const = 0;
75 
76  virtual void Reset(void) = 0;
77 
78  virtual void Resize(integer iNewSize) = 0;
79 
80  virtual void ResizeReset(integer);
81 
82  virtual void PutCoef(integer iRow, const doublereal& dCoef) = 0;
83 
84  virtual void IncCoef(integer iRow, const doublereal& dCoef) = 0;
85 
86  virtual void DecCoef(integer iRow, const doublereal& dCoef) = 0;
87 
88  virtual const doublereal& dGetCoef(integer iRow) const = 0;
89 
90  virtual const doublereal& operator () (integer iRow) const = 0;
91 
92  virtual doublereal& operator () (integer iRow) = 0;
93 
94  /* Somma un Vec3 nella posizione desiderata */
95  virtual void Add(integer iRow, const Vec3& v);
96 
97  /* Sottrae un Vec3 nella posizione desiderata */
98  virtual void Sub(integer iRow, const Vec3& v);
99 
100  /* Scrive un Vec3 nella posizione desiderata */
101  virtual void Put(integer iRow, const Vec3& v);
102 
103  /* Somma e moltiplica per uno scalare */
104  virtual VectorHandler&
105  ScalarAddMul(const VectorHandler& VH, const doublereal& d);
106 
107  /* Somma e moltiplica per uno scalare v = VH + d * VH1 */
108  virtual VectorHandler&
109  ScalarAddMul(const VectorHandler& VH, const VectorHandler& VH1,
110  const doublereal& d);
111 
112  /* Moltiplica per uno scalare */
113  virtual VectorHandler&
114  ScalarMul(const VectorHandler& VH, const doublereal& d);
115 
116  /* Overload di += usato per la correzione della soluzione */
117  virtual VectorHandler& operator += (const VectorHandler& VH);
118 
119  /* Overload di += usato per l'assemblaggio del residuo */
120  virtual VectorHandler& operator += (const SubVectorHandler& SubVH);
121 
122  /* Overload di -= */
123  virtual VectorHandler& operator -= (const VectorHandler& VH);
124 
125  /* Overload di *= */
126  virtual VectorHandler& operator *= (const doublereal &d);
127 
128  /* Assegnazione che copia il contenuto della memoria di due handlers */
129  virtual VectorHandler& operator = (const VectorHandler& VH);
130 
131  /* Norma 2 del vettore */
132  virtual doublereal Dot(void) const;
133 
134  /* Norma del vettore */
135  virtual doublereal Norm(void) const;
136 
137  /* Prodotto Scalare di due vettori */
138  virtual doublereal InnerProd(const VectorHandler& VH) const;
139 };
140 
141 extern std::ostream&
142 operator << (std::ostream& out, const VectorHandler& VH);
143 
144 /* VectorHandler - end */
145 
146 
147 /* MyVectorHandler - begin */
148 
150  friend class FullMatrixHandler;
151 protected:
153 
154 protected:
157 
159 
160 public: // needed by Shell4 :(
162 
163 public:
164  MyVectorHandler(integer iSize = 0, doublereal* pdTmpVec = NULL);
165 
166  virtual ~MyVectorHandler(void);
167 
168  virtual void Resize(integer iSize);
169 
170  void Detach(void);
171 
172  void Attach(integer iSize, doublereal* pd, integer iMSize = 0);
173 
174 #ifdef DEBUG
175  /* Usata per il debug */
176  virtual void IsValid(void) const;
177 #endif /* DEBUG */
178 
179  virtual inline doublereal* pdGetVec(void) const;
180 
181  virtual inline integer iGetSize(void) const;
182 
183  virtual void Reset(void);
184 
185  virtual inline void PutCoef(integer iRow, const doublereal& dCoef);
186 
187  virtual inline void IncCoef(integer iRow, const doublereal& dCoef);
188 
189  virtual inline void DecCoef(integer iRow, const doublereal& dCoef);
190 
191  virtual inline const doublereal& dGetCoef(integer iRow) const;
192 
193  virtual inline const doublereal& operator () (integer iRow) const;
194 
195  virtual inline doublereal& operator () (integer iRow);
196 
197  /* Somma un Vec3 nella posizione desiderata */
198  virtual void Add(integer iRow, const Vec3& v);
199 
200  /* Sottrae un Vec3 nella posizione desiderata */
201  virtual void Sub(integer iRow, const Vec3& v);
202 
203  /* Scrive un Vec3 nella posizione desiderata */
204  virtual void Put(integer iRow, const Vec3& v);
205 
206  /* Somma e moltiplica per uno scalare v = VH + d * VH1 */
207  virtual VectorHandler&
208  ScalarAddMul(const VectorHandler& VH, const VectorHandler& VH1,
209  const doublereal& d);
210 
211  /* Somma e moltiplica per uno scalare */
212  virtual VectorHandler&
213  ScalarAddMul(const VectorHandler& VH, const doublereal& d);
214 
215  /* Moltiplica per uno scalare */
216  virtual VectorHandler&
217  ScalarMul(const VectorHandler& VH, const doublereal& d);
218 
219  /* Overload di += usato per la correzione della soluzione */
220  virtual VectorHandler& operator += (const VectorHandler& VH);
221 
222  /* Overload di += usato per la correzione della soluzione */
223  virtual MyVectorHandler& operator += (const MyVectorHandler& VH);
224 
225  /* Overload di -= */
226  virtual VectorHandler& operator -= (const VectorHandler& VH);
227 
228  /* Overload di *= */
229  virtual VectorHandler& operator *= (const doublereal& d);
230 
231  /* Overload di -= */
232  virtual MyVectorHandler& operator -= (const MyVectorHandler& VH);
233 
234  /* Assegnazione che copia il contenuto della memoria di due handlers */
235  virtual VectorHandler& operator = (const VectorHandler& VH);
236 
237  /* Assegnazione che copia il contenuto della memoria di due handlers */
238  virtual MyVectorHandler& operator = (const MyVectorHandler& VH);
239 
240  /* Norma 2 del vettore */
241  doublereal Dot(void) const;
242 };
243 
244 inline doublereal*
246 {
247 #ifdef DEBUG
248  IsValid();
249 #endif /* DEBUG */
250 
251  return &pdVecm1[1];
252 }
253 
254 inline integer
256 {
257  return iCurSize;
258 }
259 
260 inline void
262 {
263  /* Nota: il flag di ritorno e' pleonastico. Lo si e' messo per
264  * analogia con le matrici sparse, in cui l'aggiunta
265  * di un coefficiente puo' risultare in un errore.
266  * Qui, per motivi di efficienza, il controllo sulla validita'
267  * dell'indice e del vettore viene svolto solo in debug */
268 
269 #ifdef DEBUG
270  IsValid();
271  ASSERT((iRow > 0) && (iRow <= iCurSize));
272 #endif /* DEBUG */
273 
274  pdVecm1[iRow] = dCoef;
275 }
276 
277 inline void
279 {
280  /* Vedi nota di PutCoef() */
281 
282 #ifdef DEBUG
283  IsValid();
284  ASSERT((iRow > 0) && (iRow <= iCurSize));
285 #endif /* DEBUG */
286 
287  pdVecm1[iRow] += dCoef;
288 }
289 
290 inline void
292 {
293  /* Vedi nota di PutCoef() */
294 
295 #ifdef DEBUG
296  IsValid();
297  ASSERT((iRow > 0) && (iRow <= iCurSize));
298 #endif /* DEBUG */
299 
300  pdVecm1[iRow] -= dCoef;
301 }
302 
303 inline const doublereal&
305 {
306  /* Vedi nota di PutCoef() */
307 
308 #ifdef DEBUG
309  IsValid();
310  ASSERT((iRow > 0) && (iRow <= iCurSize));
311 #endif /* DEBUG */
312 
313  return pdVecm1[iRow];
314 }
315 
316 inline const doublereal&
318 {
319  /* Vedi nota di PutCoef() */
320 
321 #ifdef DEBUG
322  IsValid();
323  ASSERT((iRow > 0) && (iRow <= iCurSize));
324 #endif /* DEBUG */
325 
326  return pdVecm1[iRow];
327 }
328 
329 inline doublereal&
331 {
332  /* Vedi nota di PutCoef() */
333 
334 #ifdef DEBUG
335  IsValid();
336  ASSERT((iRow > 0) && (iRow <= iCurSize));
337 #endif /* DEBUG */
338 
339  return pdVecm1[iRow];
340 }
341 
342 /* MyVectorHandler - end */
343 
344 #endif /* VH_H */
345 
virtual void Reset(void)=0
integer iCurSize
Definition: vh.h:156
Definition: matvec3.h:98
virtual doublereal * pdGetVec(void) const =0
virtual void ResizeReset(integer)
Definition: vh.cc:55
virtual VectorHandler & operator*=(const doublereal &d)
Definition: vh.cc:212
virtual const doublereal & operator()(integer iRow) const =0
virtual VectorHandler & operator=(const VectorHandler &VH)
Definition: vh.cc:635
virtual void Sub(integer iRow, const Vec3 &v)
Definition: vh.cc:78
virtual void IncCoef(integer iRow, const doublereal &dCoef)=0
virtual doublereal InnerProd(const VectorHandler &VH) const
Definition: vh.cc:269
void Detach(void)
Definition: vh.cc:403
virtual VectorHandler & ScalarAddMul(const VectorHandler &VH, const VectorHandler &VH1, const doublereal &d)
Definition: vh.cc:499
virtual const doublereal & dGetCoef(integer iRow) const =0
virtual void Put(integer iRow, const Vec3 &v)
Definition: vh.cc:699
virtual doublereal Dot(void) const
Definition: vh.cc:244
virtual integer iGetSize(void) const =0
virtual doublereal Norm(void) const
Definition: vh.cc:262
doublereal * pdVecm1
Definition: vh.h:158
virtual VectorHandler & operator-=(const VectorHandler &VH)
Definition: vh.cc:581
virtual ~VectorHandler(void)
Definition: vh.cc:49
virtual VectorHandler & operator+=(const VectorHandler &VH)
Definition: vh.cc:163
virtual void PutCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:261
virtual VectorHandler & ScalarMul(const VectorHandler &VH, const doublereal &d)
Definition: vh.cc:519
virtual ~MyVectorHandler(void)
Definition: vh.cc:341
virtual void Resize(integer iSize)
Definition: vh.cc:347
virtual const doublereal & dGetCoef(integer iRow) const
Definition: vh.h:304
integer iMaxSize
Definition: vh.h:155
virtual integer iGetSize(void) const
Definition: vh.h:255
virtual void DecCoef(integer iRow, const doublereal &dCoef)=0
virtual const doublereal & operator()(integer iRow) const
Definition: vh.h:317
virtual void DecCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:291
doublereal Dot(void) const
Definition: vh.cc:713
virtual VectorHandler & operator-=(const VectorHandler &VH)
Definition: vh.cc:195
virtual void Add(integer iRow, const Vec3 &v)
Definition: vh.cc:673
virtual VectorHandler & operator=(const VectorHandler &VH)
Definition: vh.cc:227
virtual VectorHandler & ScalarMul(const VectorHandler &VH, const doublereal &d)
Definition: vh.cc:145
MyVectorHandler(const MyVectorHandler &)
Definition: vh.cc:321
#define ASSERT(expression)
Definition: colamd.c:977
virtual void PutCoef(integer iRow, const doublereal &dCoef)=0
virtual void Reset(void)
Definition: vh.cc:459
virtual void Add(integer iRow, const Vec3 &v)
Definition: vh.cc:63
virtual VectorHandler & ScalarAddMul(const VectorHandler &VH, const doublereal &d)
Definition: vh.cc:108
virtual void Put(integer iRow, const Vec3 &v)
Definition: vh.cc:93
virtual VectorHandler & operator*=(const doublereal &d)
Definition: vh.cc:600
virtual VectorHandler & operator+=(const VectorHandler &VH)
Definition: vh.cc:542
void Attach(integer iSize, doublereal *pd, integer iMSize=0)
Definition: vh.cc:418
double doublereal
Definition: colamd.c:52
virtual doublereal * pdGetVec(void) const
Definition: vh.h:245
long int integer
Definition: colamd.c:51
virtual void Resize(integer iNewSize)=0
std::ostream & operator<<(std::ostream &out, const VectorHandler &VH)
Definition: vh.cc:287
bool bOwnsMemory
Definition: vh.h:152
virtual void Sub(integer iRow, const Vec3 &v)
Definition: vh.cc:686
virtual void IncCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:278