• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Recovery/JacobianRecovery1D.cpp

Go to the documentation of this file.
00001 /************************************************************************************
00002     Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen,
00003     Alex Pothen
00004 
00005     This file is part of ColPack.
00006 
00007     ColPack is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU Lesser General Public License as published
00009     by the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ColPack is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public License
00018     along with ColPack.  If not, see <http://www.gnu.org/licenses/>.
00019 ************************************************************************************/
00020 
00021 #include "ColPackHeaders.h"
00022 
00023 using namespace std;
00024 
00025 namespace ColPack
00026 {
00027 
00028         int JacobianRecovery1D::RecoverD2Row_RowCompressedFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) {
00029                 if(g==NULL) {
00030                         cerr<<"g==NULL"<<endl;
00031                         return _FALSE;
00032                 }
00033 
00034                 if(AF_available) reset();
00035 
00036                 int rowCount = g->GetRowVertexCount();
00037                 vector<int> vi_LeftVertexColors;
00038                 g->GetLeftVertexColors(vi_LeftVertexColors);
00039                 unsigned int numOfNonZeros = 0;
00040 
00041                 //allocate memory for *dp3_JacobianValue. The dp3_JacobianValue and uip2_JacobianSparsityPattern matrices should have the same size
00042                 *dp3_JacobianValue = new double*[rowCount];
00043                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00044                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00045                         (*dp3_JacobianValue)[i] = new double[numOfNonZeros+1];
00046                         (*dp3_JacobianValue)[i][0] = numOfNonZeros; //initialize value of the 1st entry
00047                         for(int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.; //initialize value of other entries
00048                 }
00049 
00050                 //Recover value of the Jacobian
00051                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00052                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00053                         for(int j=1; j <= numOfNonZeros; j++) {
00054                                 (*dp3_JacobianValue)[i][j] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]];
00055                         }
00056 
00057                 }
00058 
00059                 AF_available = true;
00060                 i_AF_rowCount = rowCount;
00061                 dp2_AF_Value = *dp3_JacobianValue;
00062 
00063                 return _TRUE;
00064         }
00065 
00066         int JacobianRecovery1D::RecoverD2Row_SparseSolversFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00067                 if(g==NULL) {
00068                         cerr<<"g==NULL"<<endl;
00069                         return _FALSE;
00070                 }
00071 
00072                 if(SSF_available) reset();
00073 
00074                 int rowCount = g->GetRowVertexCount();
00075                 vector<int> vi_LeftVertexColors;
00076                 g->GetLeftVertexColors(vi_LeftVertexColors);
00077                 unsigned int numOfNonZeros = 0;
00078 
00079                 // Allocate memory and populate ip2_RowIndex and ip2_ColumnIndex
00080                 g->GetRowVertices(ip2_RowIndex);
00081                 numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex);
00082 
00083                 //cout<<"allocate memory for *dp2_JacobianValue rowCount="<<rowCount<<endl;
00084                 //printf("i=%d\tnumOfNonZeros=%d \n", i, numOfNonZeros);
00085                 (*dp2_JacobianValue) = new double[numOfNonZeros]; //allocate memory for *dp2_JacobianValue.
00086                 for(unsigned int i=0; i < numOfNonZeros; i++) (*dp2_JacobianValue)[i] = 0.; //initialize value of other entries
00087 
00088                 //Recover value of the Jacobian
00089                 unsigned int numOfNonZerosInEachRow = 0;
00090                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00091                         numOfNonZerosInEachRow = uip2_JacobianSparsityPattern[i][0];
00092                         for(int j=1; j <= numOfNonZerosInEachRow; j++) {
00093                                 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]];
00094                         }
00095 
00096                 }
00097 
00098                 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers
00099                 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) {
00100                   (*ip2_RowIndex)[i]++;
00101                 }
00102                 for(unsigned int i=0; i < numOfNonZeros; i++) {
00103                   (*ip2_ColumnIndex)[i]++;
00104                 }
00105 
00106                 SSF_available = true;
00107                 i_SSF_rowCount = rowCount;
00108                 ip_SSF_RowIndex = *ip2_RowIndex;
00109                 ip_SSF_ColumnIndex = *ip2_ColumnIndex;
00110                 dp_SSF_Value = *dp2_JacobianValue;
00111 
00112                 return _TRUE;
00113         }
00114 
00115         int JacobianRecovery1D::RecoverD2Row_CoordinateFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00116                 if(g==NULL) {
00117                         cerr<<"g==NULL"<<endl;
00118                         return _FALSE;
00119                 }
00120 
00121                 if(CF_available) reset();
00122 
00123                 int rowCount = g->GetRowVertexCount();
00124                 vector<int> vi_LeftVertexColors;
00125                 g->GetLeftVertexColors(vi_LeftVertexColors);
00126                 unsigned int numOfNonZeros = 0;
00127 
00128                 numOfNonZeros = g->GetEdgeCount();
00129                 (*ip2_RowIndex) = new unsigned int[numOfNonZeros];
00130                 (*ip2_ColumnIndex) = new unsigned int[numOfNonZeros];
00131                 (*dp2_JacobianValue) = new double[numOfNonZeros]; //allocate memory for *dp2_JacobianValue.
00132 
00133                 //Recover value of the Jacobian
00134                 unsigned int numOfNonZeros_count = 0;
00135                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00136                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00137                         for(int j=1; j <= numOfNonZeros; j++) {
00138                                 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]];
00139                                 (*ip2_RowIndex)[numOfNonZeros_count] = i;
00140                                 (*ip2_ColumnIndex)[numOfNonZeros_count] = uip2_JacobianSparsityPattern[i][j];
00141                                 numOfNonZeros_count++;
00142                         }
00143                 }
00144                 /*
00145                 if(numOfNonZeros_count != g->GetEdgeCount()) {
00146                         cout<<"**Something fishing going on"<<endl;
00147                         cout<<"numOfNonZeros_count="<<numOfNonZeros_count<<endl;
00148                         cout<<"numOfNonZeros="<<numOfNonZeros<<endl;
00149                 }
00150                 else cout<<"**Good!!!"<<endl;
00151                 Pause();
00152                 //*/
00153 
00154                 CF_available = true;
00155                 i_CF_rowCount = rowCount;
00156                 ip_CF_RowIndex = *ip2_RowIndex;
00157                 ip_CF_ColumnIndex = *ip2_ColumnIndex;
00158                 dp_CF_Value = *dp2_JacobianValue;
00159 
00160                 return _TRUE;
00161         }
00162 
00163         int JacobianRecovery1D::RecoverD2Cln_RowCompressedFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) {
00164                 if(g==NULL) {
00165                         cerr<<"g==NULL"<<endl;
00166                         return _FALSE;
00167                 }
00168 
00169                 if(AF_available) reset();
00170 
00171                 int rowCount = g->GetRowVertexCount();
00172                 vector<int> vi_RightVertexColors;
00173                 g->GetRightVertexColors(vi_RightVertexColors);
00174                 unsigned int numOfNonZeros = 0;
00175 
00176                 //allocate memory for *dp3_JacobianValue. The dp3_JacobianValue and uip2_JacobianSparsityPattern matrices should have the same size
00177                 //cout<<"allocate memory for *dp3_JacobianValue rowCount="<<rowCount<<endl;
00178                 *dp3_JacobianValue = new double*[rowCount];
00179                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00180                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00181                         //printf("i=%d\tnumOfNonZeros=%d \n", i, numOfNonZeros);
00182                         (*dp3_JacobianValue)[i] = new double[numOfNonZeros+1];
00183                         (*dp3_JacobianValue)[i][0] = numOfNonZeros; //initialize value of the 1st entry
00184                         for(unsigned int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.; //initialize value of other entries
00185                 }
00186 
00187                 //Recover value of the Jacobian
00188                 //cout<<"Recover value of the Jacobian"<<endl;
00189                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00190                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00191                         for(unsigned int j=1; j <= numOfNonZeros; j++) {
00192                                 (*dp3_JacobianValue)[i][j] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]];
00193                         }
00194 
00195                 }
00196 
00197                 AF_available = true;
00198                 i_AF_rowCount = rowCount;
00199                 dp2_AF_Value = *dp3_JacobianValue;
00200 
00201                 return _TRUE;
00202         }
00203 
00204         int JacobianRecovery1D::RecoverD2Cln_SparseSolversFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00205                 if(g==NULL) {
00206                         cerr<<"g==NULL"<<endl;
00207                         return _FALSE;
00208                 }
00209 
00210                 if(SSF_available) reset();
00211 
00212                 int rowCount = g->GetRowVertexCount();
00213                 vector<int> vi_RightVertexColors;
00214                 g->GetRightVertexColors(vi_RightVertexColors);
00215                 unsigned int numOfNonZeros = 0;
00216 
00217                 // Allocate memory and populate ip2_RowIndex and ip2_ColumnIndex
00218                 g->GetRowVertices(ip2_RowIndex);
00219                 numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex);
00220 
00221                 //cout<<"allocate memory for *dp2_JacobianValue rowCount="<<rowCount<<endl;
00222                 //printf("i=%d\tnumOfNonZeros=%d \n", i, numOfNonZeros);
00223                 (*dp2_JacobianValue) = new double[numOfNonZeros]; //allocate memory for *dp2_JacobianValue.
00224                 for(unsigned int i=0; i < numOfNonZeros; i++) (*dp2_JacobianValue)[i] = 0.; //initialize value of other entries
00225 
00226                 //Recover value of the Jacobian
00227                 //cout<<"Recover value of the Jacobian"<<endl;
00228                 unsigned int numOfNonZerosInEachRow = 0;
00229                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00230                         numOfNonZerosInEachRow = uip2_JacobianSparsityPattern[i][0];
00231                         for(unsigned int j=1; j <= numOfNonZerosInEachRow; j++) {
00232                                 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]];
00233                         }
00234                 }
00235 
00236 
00237                 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers
00238                 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) {
00239                   (*ip2_RowIndex)[i]++;
00240                 }
00241                 for(unsigned int i=0; i < numOfNonZeros; i++) {
00242                   (*ip2_ColumnIndex)[i]++;
00243                 }
00244 
00245 
00246                 SSF_available = true;
00247                 i_SSF_rowCount = rowCount;
00248                 ip_SSF_RowIndex = *ip2_RowIndex;
00249                 ip_SSF_ColumnIndex = *ip2_ColumnIndex;
00250                 dp_SSF_Value = *dp2_JacobianValue;
00251 
00252                 return _TRUE;
00253         }
00254 
00255         int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00256                 if(g==NULL) {
00257                         cerr<<"g==NULL"<<endl;
00258                         return _FALSE;
00259                 }
00260 
00261                 if(CF_available) reset();
00262 
00263                 int rowCount = g->GetRowVertexCount();
00264                 vector<int> vi_RightVertexColors;
00265                 g->GetRightVertexColors(vi_RightVertexColors);
00266                 unsigned int numOfNonZeros = 0;
00267 
00268                 numOfNonZeros = g->GetEdgeCount();
00269                 (*ip2_RowIndex) = new unsigned int[numOfNonZeros];
00270                 (*ip2_ColumnIndex) = new unsigned int[numOfNonZeros];
00271                 (*dp2_JacobianValue) = new double[numOfNonZeros]; //allocate memory for *dp2_JacobianValue.
00272 
00273                 //Recover value of the Jacobian
00274                 //cout<<"Recover value of the Jacobian"<<endl;
00275                 unsigned int numOfNonZeros_count = 0;
00276                 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00277                         numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00278                         for(unsigned int j=1; j <= numOfNonZeros; j++) {
00279                                 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]];
00280                                 (*ip2_RowIndex)[numOfNonZeros_count] = i;
00281                                 (*ip2_ColumnIndex)[numOfNonZeros_count] = uip2_JacobianSparsityPattern[i][j];
00282                                 numOfNonZeros_count++;
00283                         }
00284                 }
00285                 /*
00286                 if(numOfNonZeros_count != g->GetEdgeCount()) {
00287                         cout<<"**Something fishing going on"<<endl;
00288                         cout<<"numOfNonZeros_count="<<numOfNonZeros_count<<endl;
00289                         cout<<"numOfNonZeros="<<numOfNonZeros<<endl;
00290                 }
00291                 else cout<<"**Good!!!"<<endl;
00292                 Pause();
00293                 //*/
00294 
00295                 CF_available = true;
00296                 i_CF_rowCount = rowCount;
00297                 ip_CF_RowIndex = *ip2_RowIndex;
00298                 ip_CF_ColumnIndex = *ip2_ColumnIndex;
00299                 dp_CF_Value = *dp2_JacobianValue;
00300 
00301                 return _TRUE;
00302         }
00303 }

Generated on Tue Sep 7 2010 15:28:12 for ColPack by  doxygen 1.7.1