hp2FEM
0.1
|
00001 #ifndef _SYMMETRICSPARSE_H_ 00002 #define _SYMMETRICSPARSE_H_ 00003 // --------------------------------------------- 00004 // company : 00005 // user : 00006 // date : 22 Mar 2015 17:21 00007 // file : SymmetricSparse.h 00008 // markers : Full 00009 // language : C++ 00010 // generator : Metamill 6.0 00011 // --------------------------------------------- 00012 00013 //#UBLK-BEG-HEADERH 00014 //============================================================== 00015 // Description : 00016 //-------------------------------------------------------------- 00017 // Author : Gilberto Luis 00018 // Created : 16 Dez 2010 00019 //-------------------------------------------------------------- 00020 // Change history : 00021 // 16 Dez 2010 (Gilberto Luis) Initial version generated 00022 // 00023 //============================================================== 00024 //#UBLK-END-HEADERH 00025 00026 /*================================================================================================= 00027 = = 00028 = Copyright 2010-2015 Marco Lucio Bittencourt / Fabiano Fernandes Bargos = 00029 = Gilberto Luis Valente / Jorge Luis Suzuki / Allan Patrick Cordeiro Dias = 00030 = = 00031 = Licensed under the Apache License, Version 2.0 (the "License"); = 00032 = you may not use this file except in compliance with the License. = 00033 = You may obtain a copy of the License at = 00034 = = 00035 = http://www.apache.org/licenses/LICENSE-2.0 = 00036 = = 00037 = Unless required by applicable law or agreed to in writing, software = 00038 = distributed under the License is distributed on an "AS IS" BASIS, = 00039 = WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. = 00040 = See the License for the specific language governing permissions and = 00041 = limitations under the License. = 00042 = = 00043 =================================================================================================*/ 00044 00045 00046 typedef struct { 00047 double Value; 00048 long Col; 00049 #ifdef __16BITS__ 00050 long dummy; 00051 #endif 00052 } SSM_T; 00053 00054 00055 #include <cstdio> 00056 #include "ds/SymmetricMatrix.h" 00057 00058 00063 class SymmetricSparse 00064 { 00065 //#UBLK-BEG-CLASSDEF mm:22ed489e-c5b9-11df-8d40-e1925b19f1b8 00066 //#UBLK-END-CLASSDEF 00067 00068 public: 00069 00070 // METHOD=mm:22ed4a4c-c5b9-11df-8d40-e1925b19f1b8 00071 SymmetricSparse(); 00072 00073 // METHOD=mm:22ed4a4d-c5b9-11df-8d40-e1925b19f1b8 00074 SymmetricSparse(long MatrixOrder, long* Diagonal, long* Columns, double InitValue = 0.0); 00075 00076 // METHOD=mm:22ed4a4e-c5b9-11df-8d40-e1925b19f1b8 00077 SymmetricSparse(long MatrixOrder, long* Diagonal, long* Columns, double* Elements); 00078 00079 // METHOD=mm:22ed4a4f-c5b9-11df-8d40-e1925b19f1b8 00080 SymmetricSparse(FILE* File); 00081 00082 // METHOD=mm:22ed4a54-c5b9-11df-8d40-e1925b19f1b8 00083 SymmetricSparse(SymmetricSparse& Instance); 00084 00085 // METHOD=mm:22ed4a55-c5b9-11df-8d40-e1925b19f1b8 00086 ~SymmetricSparse(); 00087 00088 // METHOD=mm:22ed4a56-c5b9-11df-8d40-e1925b19f1b8 00089 SymmetricSparse& operator=(SymmetricSparse& Instance); 00090 00091 // METHOD=mm:22ed4a57-c5b9-11df-8d40-e1925b19f1b8 00092 SymmetricSparse& Equal(SymmetricSparse& Instance); 00093 00094 // METHOD=mm:22ed4a58-c5b9-11df-8d40-e1925b19f1b8 00095 operator SSM_T*const(); 00096 00097 // METHOD=mm:22ed4a59-c5b9-11df-8d40-e1925b19f1b8 00098 operator long*const(); 00099 00100 // METHOD=mm:22ed4a5e-c5b9-11df-8d40-e1925b19f1b8 00101 double& operator()(long Row, long Col); 00102 00103 // METHOD=mm:22ed4a5f-c5b9-11df-8d40-e1925b19f1b8 00104 double& GetElement(unsigned long Row, unsigned long Column); 00105 00106 // METHOD=mm:22ed4a60-c5b9-11df-8d40-e1925b19f1b8 00107 void SetOrder(unsigned long MatrixOrder, long* Diagonal = NULL, double Value = 0.0); 00108 00109 // METHOD=mm:22ed4a61-c5b9-11df-8d40-e1925b19f1b8 00110 void SetOrder(unsigned long MatrixOrder, long NumberElements, double Value = 0.0); 00111 00112 // METHOD=mm:22ed4a62-c5b9-11df-8d40-e1925b19f1b8 00113 unsigned long GetOrder(); 00114 00115 // METHOD=mm:22ed4a63-c5b9-11df-8d40-e1925b19f1b8 00116 unsigned long GetNumberElements(); 00117 00118 // METHOD=mm:22ed4a68-c5b9-11df-8d40-e1925b19f1b8 00119 long GetAverElementsLine(); 00120 00121 // METHOD=mm:22ed4a69-c5b9-11df-8d40-e1925b19f1b8 00122 void GetMaxMinDiagElems(double& MinDiagValue, double& MaxDiagValue); 00123 00124 // METHOD=mm:22ed4a6a-c5b9-11df-8d40-e1925b19f1b8 00125 void GetTopology(long& MatrixOrder, long& NumberElements, long& MaxNumberElLine, long& MinNumberElLine, long& AverNumberElLine); 00126 00127 // METHOD=mm:22ed4a6b-c5b9-11df-8d40-e1925b19f1b8 00128 long SizeOf(); 00129 00130 // METHOD=mm:22ed4a6c-c5b9-11df-8d40-e1925b19f1b8 00131 void Reset(double Value = 0.0); 00132 00133 // METHOD=mm:22ed4a6d-c5b9-11df-8d40-e1925b19f1b8 00134 void Insert(SymmetricMatrix& SubMatrix, long* LineCol); 00135 00136 // METHOD=mm:250c04f5-c154-49fb-ad30-5c374b38c041 00137 void Insert(SymmetricMatrix& SubMatrix, long* LineCol, unsigned long InitLineCol); 00138 00139 // METHOD=mm:22ed4a72-c5b9-11df-8d40-e1925b19f1b8 00140 void Multiplicate(double* X, double* Y); 00141 00142 // METHOD=mm:b2849a7e-eacf-44ce-9c01-197ceaa7220d 00143 void Multiplicate(double scalar); 00144 00145 // METHOD=mm:a0e491d5-7354-426c-a8fc-f05bd66ccd04 00146 void Add(SymmetricSparse& A, SymmetricSparse& B); 00147 00148 // METHOD=mm:84f41d88-7532-4caa-b7e5-4deb903a9e11 00149 void Add(SymmetricSparse& A); 00150 00151 // METHOD=mm:22ed4a73-c5b9-11df-8d40-e1925b19f1b8 00152 void Save(FILE* File); 00153 00154 // METHOD=mm:22ed4a74-c5b9-11df-8d40-e1925b19f1b8 00155 void Save(char* TabName, int Version, char* Filename); 00156 00157 // METHOD=mm:22ed4a75-c5b9-11df-8d40-e1925b19f1b8 00158 void Restore(FILE* File); 00159 00160 // METHOD=mm:22ed4a76-c5b9-11df-8d40-e1925b19f1b8 00161 void Restore(char* TabName, int Version, char* Filename); 00162 00163 // METHOD=mm:22ed4a77-c5b9-11df-8d40-e1925b19f1b8 00164 void Print(FILE* File, int Mant, int Dec); 00165 00166 // METHOD=mm:22ed4a7c-c5b9-11df-8d40-e1925b19f1b8 00167 void Print(FILE* File = stdout, const char* Message = "", int NumMaxCols = 5, int Mant = 14, int Dec = 7); 00168 00169 // METHOD=mm:22ed4a7d-c5b9-11df-8d40-e1925b19f1b8 00170 void PrintTopology(FILE* File); 00171 00172 // METHOD=mm:22ed4a7e-c5b9-11df-8d40-e1925b19f1b8 00173 void Free(); 00174 00175 // METHOD=mm:22ed4a7f-c5b9-11df-8d40-e1925b19f1b8 00176 void GaussSolver(double* U, double* B, double Precision); 00177 00178 // METHOD=mm:22ed4a80-c5b9-11df-8d40-e1925b19f1b8 00179 void GaussSolver(double Precision = 1e-12); 00180 00181 // METHOD=mm:22ed4a81-c5b9-11df-8d40-e1925b19f1b8 00182 void GaussSolver(double* U, double* B); 00183 00184 // METHOD=mm:22ed4a86-c5b9-11df-8d40-e1925b19f1b8 00185 long Jacobi(double* U, double* B, unsigned long MaxNumberIter, double& NormRes, double Precision = 1e-4, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00186 00187 // METHOD=mm:22ed4a87-c5b9-11df-8d40-e1925b19f1b8 00188 long Jacobi(double* U, double* B, unsigned long MaxNumberIter); 00189 00190 // METHOD=mm:22ed4a88-c5b9-11df-8d40-e1925b19f1b8 00191 long GaussSeidel(double* U, double* B, unsigned long MaxNumberIter, double& NormRes, double Precision = 1e-4, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00192 00193 // METHOD=mm:22ed4a89-c5b9-11df-8d40-e1925b19f1b8 00194 long GaussSeidel(double* U, double* B, unsigned long NumberIter); 00195 00196 // METHOD=mm:22ed4a8a-c5b9-11df-8d40-e1925b19f1b8 00197 long SOR(double* U, double* B, long MaxNumberIter, double& NormRes, double Precision = 1e-4, double Omega = 1.81, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00198 00199 // METHOD=mm:22ed4a90-c5b9-11df-8d40-e1925b19f1b8 00200 long CG(double* U, double* B, long MaxNumberIter, double& NormRes, double Precision = 1e-4, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00201 00202 // METHOD=mm:22ed4a91-c5b9-11df-8d40-e1925b19f1b8 00203 long CGDiagonal(double* U, double* B, long MaxNumberIter, double& NormRes, double Precision = 1e-4, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00204 00205 // METHOD=mm:22ed4a92-c5b9-11df-8d40-e1925b19f1b8 00206 long CGPreConditionated(double* U, double* B, long MaxNumberIter, double& NormRes, double Precision = 1e-4, double Omega = 1.81, PreMatrix_E PreMatrix = SGS, ConvCriterion_E Crit = WEIGHT_RESIDUE, NormDS_E Norm = EUCLID); 00207 00208 00209 protected: 00210 00211 // METHOD=mm:22ed4a38-c5b9-11df-8d40-e1925b19f1b8 00212 void FreeAuxVectors(); 00213 00214 // METHOD=mm:22ed4a39-c5b9-11df-8d40-e1925b19f1b8 00215 void AllocDiag(long* Diagonal = NULL); 00216 00217 // METHOD=mm:22ed4a3a-c5b9-11df-8d40-e1925b19f1b8 00218 void Alloc(double InitValue = 0.0); 00219 00220 // METHOD=mm:22ed4a3b-c5b9-11df-8d40-e1925b19f1b8 00221 unsigned long GetNumElLine(long Lin); 00222 00223 // METHOD=mm:22ed4a40-c5b9-11df-8d40-e1925b19f1b8 00224 void TopologyEvaluation(); 00225 00226 // METHOD=mm:22ed4a41-c5b9-11df-8d40-e1925b19f1b8 00227 void MaxMinDiagEvaluation(); 00228 00229 // METHOD=mm:22ed4a42-c5b9-11df-8d40-e1925b19f1b8 00230 int ConvCriteria(double* U, double* Un, double* b, double Prec, double Normb, ConvCriterion_E Crit, NormDS_E Norm, double& NormRes); 00231 00232 // METHOD=mm:22ed4a43-c5b9-11df-8d40-e1925b19f1b8 00233 void prodauxsk(double* X, double* Y, double cte); 00234 00235 // METHOD=mm:22ed4a44-c5b9-11df-8d40-e1925b19f1b8 00236 void bcksbstsk(double* U, double* B, double omega); 00237 00238 // METHOD=mm:22ed4a45-c5b9-11df-8d40-e1925b19f1b8 00239 void fwdsbstsk(double* U, double* B, double omega); 00240 00241 // METHOD=mm:22ed4a4a-c5b9-11df-8d40-e1925b19f1b8 00242 void prodfx(double* Z, double* X, double Omega); 00243 00244 // METHOD=mm:22ed4a4b-c5b9-11df-8d40-e1925b19f1b8 00245 void prauxsk(double* U, double* B); 00246 00247 // METHOD=mm:51bfc0d4-4c15-4e46-ac19-3b8fd4906c2c 00248 double norinfv(double* u, long dim); 00249 00250 // METHOD=mm:85936cd7-b174-47a2-987c-df62b345065b 00251 double scalv(double* x, double* y, unsigned long dim); 00252 00253 // METHOD=mm:0a638307-7e42-4649-8dde-d16b47fb1898 00254 double normaev(double* u, long dim); 00255 00256 00260 // attr=mm:22ed4a23-c5b9-11df-8d40-e1925b19f1b8 00261 unsigned long PolyOrder; 00262 00266 // attr=mm:22ed4a25-c5b9-11df-8d40-e1925b19f1b8 00267 unsigned long MaxNumElLine; 00268 00272 // attr=mm:22ed4a26-c5b9-11df-8d40-e1925b19f1b8 00273 unsigned long MinNumElLine; 00274 00279 // attr=mm:22ed4a2f-c5b9-11df-8d40-e1925b19f1b8 00280 long* Pos; 00281 00285 // attr=mm:22ed4a24-c5b9-11df-8d40-e1925b19f1b8 00286 long* Diag; 00287 00292 // attr=mm:22ed4a30-c5b9-11df-8d40-e1925b19f1b8 00293 double* d; 00294 00299 // attr=mm:22ed4a31-c5b9-11df-8d40-e1925b19f1b8 00300 double* f; 00301 00306 // attr=mm:22ed4a36-c5b9-11df-8d40-e1925b19f1b8 00307 double* g; 00308 00313 // attr=mm:22ed4a37-c5b9-11df-8d40-e1925b19f1b8 00314 double* h; 00315 00319 // attr=mm:22ed4a2d-c5b9-11df-8d40-e1925b19f1b8 00320 SSM_T* SSMatrix; 00321 00325 // attr=mm:22ed4a27-c5b9-11df-8d40-e1925b19f1b8 00326 double MaxDiagElem; 00327 00331 // attr=mm:22ed4a2c-c5b9-11df-8d40-e1925b19f1b8 00332 double MinDiagElem; 00333 00337 // attr=mm:22ed4a2e-c5b9-11df-8d40-e1925b19f1b8 00338 static double Zero; 00339 00340 00341 private: 00342 00343 //#UBLK-BEG-CLASSMEMB mm:22ed489e-c5b9-11df-8d40-e1925b19f1b8 00344 //#UBLK-END-CLASSMEMB 00345 }; 00346 00347 //#UBLK-BEG-GLOBALH 00348 //*** Removed methods: 15 Mar 2011 15:51 00349 //--- 00350 //uuid=mm:22ed4a8b-c5b9-11df-8d40-e1925b19f1b8 00351 // long ChebyshevSSOR(double* U, double* B, long MaxNumberIter, double& NormRes, double me, double Me, double F = 0.8, double d = 0.1, double Precision = 1e-4, double Omega = 1.81, ConvCriterion_E Crit = WEIGHT_RESIDUE, Norm_E Norm = EUCLIDEAN); 00352 00353 //*** Removed methods: 30 Dec 2014 15:52 00354 //--- 00355 //uuid=mm:e94730c7-bd1a-46db-b698-2725f62386a1 00356 // void SparseToMatrix(FILE* File, int Mant, int Dec); 00357 00358 //*** Removed methods: 21 Mar 2015 21:18 00359 //--- 00360 //uuid=mm:fd6f875b-073f-4761-a964-6b8880a2641a 00361 // void SparseToMatrix(FILE* File = stdout, const char* Message = "", int NumMaxCols = 5, int Mant = 14, int Dec = 7); 00362 00363 //#UBLK-END-GLOBALH 00364 00365 00366 #endif // _SYMMETRICSPARSE_H_