1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/naivewrap.h,v 1.38 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 * The Naive Solver is copyright (C) 2004 by 34 * Paolo Mantegazza <mantegazza@aero.polimi.it> 35 */ 36 37 #ifndef NaiveSolutionManager_hh 38 #define NaiveSolutionManager_hh 39 40 #include <iostream> 41 #include <vector> 42 43 #include "myassert.h" 44 #include "mynewmem.h" 45 #include "ls.h" 46 #include "solman.h" 47 #include "naivemh.h" 48 #include "dgeequ.h" 49 50 /* NaiveSolver - begin */ 51 52 class NaiveSolver: public LinearSolver { 53 private: 54 integer iSize; 55 doublereal dMinPiv; 56 mutable std::vector<integer> piv; 57 NaiveMatrixHandler *A; 58 59 void Factor(void) throw(LinearSolver::ErrFactor); 60 61 public: 62 NaiveSolver(const integer &size, const doublereal &dMP, 63 NaiveMatrixHandler *const a = 0); 64 ~NaiveSolver(void); 65 66 void SetMat(NaiveMatrixHandler *const a); 67 void Reset(void); 68 void Solve(void) const; 69 }; 70 71 /* NaiveSolver - end */ 72 73 /* NaiveSparseSolutionManager - begin */ 74 75 class NaiveSparseSolutionManager: public SolutionManager { 76 protected: 77 mutable NaiveMatrixHandler *A; 78 mutable MyVectorHandler VH; 79 80 ScaleOpt scale; 81 MatrixScaleBase* pMatScale; 82 83 template <class MH> 84 void ScaleMatrixAndRightHandSide(MH& mh); 85 86 template <typename MH> 87 MatrixScale<MH>& GetMatrixScale(); 88 89 void ScaleSolution(void); 90 91 public: 92 NaiveSparseSolutionManager(const integer Dim, 93 const doublereal dMP = 1.e-9, 94 const ScaleOpt& scale = ScaleOpt()); 95 virtual ~NaiveSparseSolutionManager(void); 96 #ifdef DEBUG IsValid(void)97 virtual void IsValid(void) const { 98 NO_OP; 99 }; 100 #endif /* DEBUG */ 101 102 /* Inizializzatore generico */ 103 virtual void MatrReset(void); 104 105 /* Risolve il sistema Backward Substitution; fattorizza se necessario */ 106 virtual void Solve(void); 107 108 /* Rende disponibile l'handler per la matrice */ 109 virtual MatrixHandler* pMatHdl(void) const; 110 111 /* Rende disponibile l'handler per il termine noto */ 112 virtual MyVectorHandler* pResHdl(void) const; 113 114 /* Rende disponibile l'handler per la soluzione */ 115 virtual MyVectorHandler* pSolHdl(void) const; 116 }; 117 118 /* NaiveSparseSolutionManager - end */ 119 120 121 /* NaiveSparsePermSolutionManager - begin */ 122 123 template<class T> 124 class NaiveSparsePermSolutionManager: public NaiveSparseSolutionManager { 125 private: 126 const doublereal dMinPiv; 127 mutable MyVectorHandler TmpH; 128 129 void ComputePermutation(void); 130 void BackPerm(void); 131 132 protected: 133 enum { 134 PERM_NO, 135 PERM_INTERMEDIATE, 136 PERM_READY 137 } ePermState; 138 139 mutable std::vector<integer> perm; 140 mutable std::vector<integer> invperm; 141 142 virtual void MatrReset(void); 143 144 public: 145 NaiveSparsePermSolutionManager(const integer Dim, 146 const doublereal dMP = 1.e-9, 147 const ScaleOpt& scale = ScaleOpt()); 148 virtual ~NaiveSparsePermSolutionManager(void); 149 150 /* Risolve il sistema Backward Substitution; fattorizza se necessario */ 151 virtual void Solve(void); 152 153 /* Inizializzatore "speciale" */ 154 virtual void MatrInitialize(void); 155 }; 156 157 // class NaiveSparseCuthillMcKeePermSolutionManager: public NaiveSparseSolutionManager { 158 // private: 159 // const doublereal dMinPiv; 160 // mutable MyVectorHandler TmpH; 161 // 162 // void ComputePermutation(); 163 // void BackPerm(); 164 // 165 // protected: 166 // enum { 167 // PERM_NO, 168 // PERM_INTERMEDIATE, 169 // PERM_READY 170 // } ePermState; 171 // 172 // mutable std::vector<integer> perm; 173 // mutable std::vector<integer> invperm; 174 // 175 // virtual void MatrReset(void); 176 // 177 // public: 178 // NaiveSparseCuthillMcKeePermSolutionManager(const integer Dim, const doublereal dMP = 1.e-9); 179 // virtual ~NaiveSparseCuthillMcKeePermSolutionManager(void); 180 // 181 // /* Risolve il sistema Backward Substitution; fattorizza se necessario */ 182 // virtual void Solve(void); 183 // 184 // /* Inizializzatore "speciale" */ 185 // virtual void MatrInitialize(void); 186 // }; 187 188 /* NaiveSparsePermSolutionManager - end */ 189 190 191 // supported permutations 192 class Colamd_ordering; 193 // #ifdef USE_BOOST 194 class rcmk_ordering; 195 class king_ordering; 196 class sloan_ordering; 197 class md_ordering; 198 // #endif USE_BOOST 199 // #ifdef USE_METIS 200 class metis_ordering; 201 // #endif USE_METIS 202 // #ifdef HAVE_UMFPACK 203 class amd_ordering; 204 // #endif 205 206 207 #endif // NaiveSolutionManager_hh 208 209