MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
lapackwrap.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/lapackwrap.cc,v 1.27 2017/01/12 14:44:25 masarati Exp $ */
2 /*
3  * HmFe (C) is a FEM analysis code.
4  *
5  * Copyright (C) 1996-2017
6  *
7  * Marco Morandini <morandini@aero.polimi.it>
8  *
9  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
10  * via La Masa, 34 - 20156 Milano, Italy
11  * http://www.aero.polimi.it
12  *
13  * Changing this copyright notice is forbidden.
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  */
19 /* December 2001
20  * Modified to add a Sparse matrix in row form and to implement methods
21  * to be used in the parallel MBDyn Solver.
22  *
23  * Copyright (C) 2001-2017
24  *
25  * Giuseppe Quaranta <quaranta@aero.polimi.it>
26  *
27  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
28  * via La Masa, 34 - 20156 Milano, Italy
29  * http://www.aero.polimi.it
30  *
31  */
32 /*
33  * MBDyn (C) is a multibody analysis code.
34  * http://www.mbdyn.org
35  *
36  * Copyright (C) 1996-2017
37  *
38  * Pierangelo Masarati <masarati@aero.polimi.it>
39  * Paolo Mantegazza <mantegazza@aero.polimi.it>
40  *
41  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
42  * via La Masa, 34 - 20156 Milano, Italy
43  * http://www.aero.polimi.it
44  *
45  * Changing this copyright notice is forbidden.
46  *
47  * This program is free software; you can redistribute it and/or modify
48  * it under the terms of the GNU General Public License as published by
49  * the Free Software Foundation (version 2 of the License).
50  *
51  *
52  * This program is distributed in the hope that it will be useful,
53  * but WITHOUT ANY WARRANTY; without even the implied warranty of
54  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55  * GNU General Public License for more details.
56  *
57  * You should have received a copy of the GNU General Public License
58  * along with this program; if not, write to the Free Software
59  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60  */
61 
62 /*
63  * Lapack is used by permission; please read its Copyright,
64  * License and Availability note.
65  */
66 
67 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
68 
69 #ifdef USE_LAPACK
70 #include "solman.h"
71 #include "lapackwrap.h"
72 
73 #include "ac/lapack.h"
74 
75 /* LapackSolver - begin */
76 
77 LapackSolver::LapackSolver(const integer &size, const doublereal &dPivot,
78  doublereal *pa, doublereal *pb)
79 : LinearSolver(0),
80 iSize(size),
81 pA(pa),
82 pB(pb),
83 piIPIV(0)
84 {
85  ASSERT(pA);
86 
87  SAFENEWARR(piIPIV, integer, iSize);
88 }
89 
90 LapackSolver::~LapackSolver(void)
91 {
92  if (piIPIV) {
93  SAFEDELETEARR(piIPIV);
94  }
95 }
96 
97 void
99 {
100  bHasBeenReset = true;
101 }
102 
103 void
104 LapackSolver::Solve(void) const
105 {
106  if (bHasBeenReset) {
107  const_cast<LapackSolver *>(this)->Factor();
108  bHasBeenReset = false;
109  }
110 
111  integer iNRHS = 1, iINFO = 0;
112  integer iN = iSize;
113 
114  static char sMessage[] = "No transpose";
115  __FC_DECL__(dgetrs)(sMessage, &iN, &iNRHS, pA, &iN, piIPIV, pB, &iN, &iINFO);
116 }
117 
118 void
119 LapackSolver::Factor(void)
120 {
121  integer iINFO = 0;
122 
123  __FC_DECL__(dgetrf)(&iSize, &iSize, pA, &iSize, piIPIV, &iINFO);
124 }
125 
126 /* LapackSolver - end */
127 
128 /* LapackSolutionManager - begin */
129 
130 LapackSolutionManager::LapackSolutionManager(integer Dim, doublereal dPivot)
131 : A(Dim),
132 VH(Dim)
133 {
134  SAFENEWWITHCONSTRUCTOR(pLS, LapackSolver,
135  LapackSolver(Dim, dPivot, A.pdGetMat(), VH.pdGetVec()));
136 
137  (void)pLS->pdSetResVec(VH.pdGetVec());
138  (void)pLS->pdSetSolVec(VH.pdGetVec());
139 
140  pLS->SetSolutionManager(this);
141 }
142 
143 LapackSolutionManager::~LapackSolutionManager(void)
144 {
145  NO_OP;
146 }
147 
148 void
149 LapackSolutionManager::MatrReset(void)
150 {
151  pLS->Reset();
152 }
153 
154 /* Risolve il sistema Fattorizzazione + Backward Substitution */
155 void
156 LapackSolutionManager::Solve(void)
157 {
158  pLS->Solve();
159 }
160 
161 /* Rende disponibile l'handler per la matrice */
163 LapackSolutionManager::pMatHdl(void) const
164 {
165  return &A;
166 }
167 
168 /* Rende disponibile l'handler per il termine noto */
170 LapackSolutionManager::pResHdl(void) const
171 {
172  return &VH;
173 }
174 
175 /* Rende disponibile l'handler per la soluzione */
177 LapackSolutionManager::pSolHdl(void) const
178 {
179  return &VH;
180 }
181 
182 /* LapackSolutionManager - end */
183 
184 #endif /* USE_LAPACK */
185 
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
#define NO_OP
Definition: myassert.h:74
void Reset(scalar_func_type &d)
Definition: gradient.h:2836
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51