MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
harwrap.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/harwrap.cc,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 /*****************************************************************************
33  * *
34  * HARWLIB C++ WRAPPER *
35  * *
36  *****************************************************************************/
37 
38 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
39 
40 #ifdef USE_HARWELL
41 
42 #include "harwrap.h"
43 
44 /* HarwellSparseSolutionManager - begin: code */
45 
46 /* Costruttore */
47 HarwellSparseSolutionManager::HarwellSparseSolutionManager(integer iSize,
48  integer iWorkSpaceSize,
49  const doublereal& dPivotFactor) :
50 iMatMaxSize(iSize),
51 iMatSize(iSize),
52 iColStart(iSize + 1),
53 MH(iSize),
54 pVH(NULL), pLU(NULL),
55 fHasBeenReset(1)
56 {
57  ASSERT(iSize > 0);
58  ASSERT((dPivotFactor >= 0.0) && (dPivotFactor <= 1.0));
59 
60  /* Valore di default */
61  if (iWorkSpaceSize == 0) {
62  iWorkSpaceSize = iSize*iSize;
63  }
64 
65  /* Alloca arrays */
66  dVec.resize(iMatSize,0.);
67 
68  /* Alloca handlers ecc. */
71  MyVectorHandler(iMatSize, &(dVec[0])));
72  iRow.reserve(iWorkSpaceSize);
73  iCol.reserve(iWorkSpaceSize);
74  dMat.reserve(iWorkSpaceSize);
76  HarwellSolver,
77  HarwellSolver(iMatSize, iWorkSpaceSize,
78  &iRow, &iCol,
79  &dMat, &(dVec[0]), dPivotFactor));
80 
81 #ifdef DEBUG
82  IsValid();
83 #endif /* DEBUG */
84 }
85 
86 
87 /* Distruttore; verificare la distruzione degli oggetti piu' complessi */
88 HarwellSparseSolutionManager::~HarwellSparseSolutionManager(void)
89 {
90 #ifdef DEBUG
91  IsValid();
92 #endif /* DEBUG */
93 
94  /* Dealloca oggetti strani */
95  if (pLU != NULL) {
96  SAFEDELETE(pLU);
97  }
98  if (pVH != NULL) {
99  SAFEDELETE(pVH);
100  }
101 }
102 
103 #ifdef DEBUG
104 /* Test di validita' del manager */
105 void
106 HarwellSparseSolutionManager::IsValid(void) const
107 {
108  ASSERT(iMatMaxSize > 0);
109  ASSERT(iMatSize > 0);
110 
111 #ifdef DEBUG_MEMMANAGER
112  ASSERT(defaultMemoryManager.fIsPointerToBlock(pVH));
113  ASSERT(defaultMemoryManager.fIsPointerToBlock(pLU));
114 #endif /* DEBUG_MEMMANAGER */
115 
116  ASSERT((pVH->IsValid(), 1));
117  ASSERT((pLU->IsValid(), 1));
118 }
119 #endif /* DEBUG */
120 
121 /* Prepara i vettori e la matrice per il solutore */
122 void
123 HarwellSparseSolutionManager::PacVec(void)
124 {
125 #ifdef DEBUG
126  IsValid();
127 #endif /* DEBUG */
128 
129  ASSERT(fHasBeenReset == 1);
130 
131  pLU->iNonZeroes = MH.MakeIndexForm(dMat, iRow, iCol, iColStart, 1);
132 }
133 
134 /* Inizializza il gestore delle matrici */
135 void
136 HarwellSparseSolutionManager::MatrReset()
137 {
138 #ifdef DEBUG
139  IsValid();
140 #endif /* DEBUG */
141 
142  /* FIXME: TOTALLY UNTESTED */
143  pLS->Reset();
144  fHasBeenReset = flag(1);
145 }
146 
147 /* Risolve il problema */
148 void
149 HarwellSparseSolutionManager::Solve(void)
150 {
151 #ifdef DEBUG
152  IsValid();
153 #endif /* DEBUG */
154 
155  if (fHasBeenReset == 1) {
156  PacVec();
157  fHasBeenReset = flag(0);
158  if (!pLU->bLUFactor()) {
159  throw HarwellSparseSolutionManager::ErrGeneric(MBDYN_EXCEPT_ARGS);
160  }
161  }
162  pLU->Solve();
163 }
164 
165 /* HarwellSparseSolutionManager - end */
166 
167 #endif /* USE_HARWELL */
168 
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
#define defaultMemoryManager
Definition: mynewmem.h:691
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710