1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/solman.h,v 1.53 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 SOLMAN_H 42 #define SOLMAN_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 #include "mh.h" 55 56 #include "matvec3.h" 57 58 /* classi virtuali dichiarate in questo file */ 59 class MatrixHandler; /* gestore matrice */ 60 class SparseMatrixHandler; 61 class VectorHandler; /* gestore vettore */ 62 class SolutionManager; /* gestore della soluzione */ 63 64 /* classi usate in questo file */ 65 class SubMatrixHandler; 66 class FullSubMatrixHandler; 67 class SparseSubMatrixHandler; 68 class VariableSubMatrixHandler; 69 class SubVectorHandler; 70 class Vec3; 71 class Mat3x3; 72 class LinearSolver; 73 74 /* SolutionDataManager - begin */ 75 76 class SolutionDataManager { 77 public: 78 virtual ~SolutionDataManager(void); 79 80 struct ChangedEquationStructure: public MBDynErrBase { 81 public: ChangedEquationStructureChangedEquationStructure82 ChangedEquationStructure(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 83 }; 84 85 /* Collega il DataManager ed il DriveHandler ai vettori soluzione */ 86 virtual void 87 LinkToSolution(VectorHandler& XCurr, 88 VectorHandler& XPrimeCurr) = 0; 89 90 /* Assembla il residuo */ 91 virtual void AssRes(VectorHandler& ResHdl, doublereal dCoef) = 0; 92 }; 93 94 /* SolutionDataManager - end */ 95 96 97 /* SolutionManager - begin */ 98 99 class SolutionManager { 100 public: 101 // whether matrix scaling should be performed, and when, using dgeequ() 102 enum ScaleWhen { 103 SCALEW_NEVER = 0, 104 SCALEW_ONCE, 105 SCALEW_ALWAYS 106 }; 107 108 enum ScaleAlgorithm { 109 SCALEA_NONE, 110 SCALEA_UNDEF, 111 SCALEA_ROW_MAX, 112 SCALEA_ROW_SUM, 113 SCALEA_COL_MAX, 114 SCALEA_COL_SUM, 115 SCALEA_LAPACK, 116 SCALEA_ITERATIVE, 117 SCALEA_ROW_MAX_COL_MAX 118 }; 119 120 enum ScaleFlags { 121 SCALEF_DEFAULT = 0x0u, 122 SCALEF_WARN = 0x1u, 123 SCALEF_VERBOSE = 0x2u, 124 SCALEF_COND_NUM_1 = 0x4u, 125 SCALEF_COND_NUM_INF = 0x8u, 126 SCALEF_COND_NUM = SCALEF_COND_NUM_1 | SCALEF_COND_NUM_INF 127 }; 128 129 struct ScaleOpt { 130 ScaleOpt(ScaleWhen when = SCALEW_NEVER, 131 ScaleAlgorithm alg = SCALEA_UNDEF, 132 integer iMaxIter = 100, 133 doublereal dTol = sqrt(std::numeric_limits<doublereal>::epsilon()), 134 unsigned flags = SCALEF_DEFAULT): whenScaleOpt135 when(when), 136 algorithm(alg), 137 iMaxIter(iMaxIter), 138 dTol(dTol), 139 uFlags(flags) 140 { 141 142 } 143 144 ScaleWhen when; 145 ScaleAlgorithm algorithm; 146 integer iMaxIter; 147 doublereal dTol; 148 unsigned uFlags; 149 }; 150 protected: 151 LinearSolver *pLS; 152 153 public: 154 SolutionManager(void); 155 156 /* Distruttore: dealloca le matrici e distrugge gli oggetti propri */ 157 virtual ~SolutionManager(void); 158 159 virtual void 160 LinkToSolution(VectorHandler& XCurr, 161 VectorHandler& XPrimeCurr); 162 163 #ifdef DEBUG 164 virtual void IsValid(void) const = 0; 165 #endif /* DEBUG */ 166 167 /* Inizializzatore generico */ 168 virtual void MatrReset(void) = 0; 169 170 /* Inizializzatore "speciale" */ 171 virtual void MatrInitialize(void); 172 173 /* Risolve il sistema */ 174 virtual void Solve(void) = 0; 175 virtual void SolveT(void); 176 177 /* Rende disponibile l'handler per la matrice */ 178 virtual MatrixHandler* pMatHdl(void) const = 0; 179 180 /* Rende disponibile l'handler per il termine noto */ 181 virtual VectorHandler* pResHdl(void) const = 0; 182 183 /* Rende disponibile l'handler per la soluzione (e' lo stesso 184 * del termine noto, ma concettualmente sono separati) */ 185 virtual VectorHandler* pSolHdl(void) const = 0; 186 187 /* sposta il puntatore al vettore del residuo */ 188 doublereal *pdSetResVec(doublereal* pd); 189 190 /* sposta il puntatore al vettore della soluzione */ 191 doublereal *pdSetSolVec(doublereal* pd); 192 193 /* return true if the condition number is available */ 194 bool bGetConditionNumber(doublereal& dCond) const; 195 }; 196 197 /* SolutionManager - end */ 198 199 #endif /* SOLMAN_H */ 200 201