FEI Version of the Day
test_MatrixGraph.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 
00010 #include <fei_macros.hpp>
00011 
00012 #include <test_utils/test_MatrixGraph.hpp>
00013 
00014 #include <test_utils/test_VectorSpace.hpp>
00015 
00016 #include <snl_fei_Factory.hpp>
00017 #include <fei_Pattern.hpp>
00018 #include <fei_MatrixGraph_Impl2.hpp>
00019 #include <fei_SparseRowGraph.hpp>
00020 #include <fei_LibraryWrapper.hpp>
00021 
00022 #undef fei_file
00023 #define fei_file "test_MatrixGraph.cpp"
00024 #include <fei_ErrMacros.hpp>
00025 
00026 test_MatrixGraph::test_MatrixGraph(MPI_Comm comm)
00027  : tester(comm)
00028 {
00029 }
00030 
00031 test_MatrixGraph::~test_MatrixGraph()
00032 {
00033 }
00034 
00035 int test_MatrixGraph_test6(MPI_Comm comm, int numProcs, int localProc,
00036                            const std::string& path)
00037 {
00038   testData* testdata = new testData(localProc, numProcs);
00039   std::vector<int>& ids = testdata->ids;
00040 
00041   fei::SharedPtr<LibraryWrapper> wrapper;
00042   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm, wrapper));
00043 
00044   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00045     test_VectorSpace::create_VectorSpace(comm,
00046            testdata, localProc, numProcs,
00047            false, //defineBothFields
00048            false, //initSolnBothFields
00049            "U_MatGrph", factory);
00050 
00051   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00052     test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
00053            false, false, "U_MatGrph",
00054            vectorSpacePtr, factory, path);
00055 
00056   CHK_ERR( matrixGraphPtr->initComplete() );
00057 
00058   fei::SharedPtr<fei::MatrixGraph> matrixGraph2Ptr =
00059     test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
00060            false, false, "U_MatGrph2",
00061            vectorSpacePtr, factory, path);
00062 
00063   CHK_ERR( matrixGraph2Ptr->initComplete() );
00064 
00065   bool equivalent = false;
00066   CHK_ERR( matrixGraphPtr->compareStructure(*matrixGraph2Ptr, equivalent) );
00067 
00068   if (!equivalent) {
00069     ERReturn(-1);
00070   }
00071 
00072   fei::SharedPtr<fei::MatrixGraph> matrixGraph3Ptr =
00073     test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
00074            false, false, "U_MatGrph3",
00075            vectorSpacePtr, factory, path);
00076 
00077   if (localProc == 0) {
00078     std::vector<int>& fieldIDs = testdata->fieldIDs;
00079     std::vector<int>& idTypes = testdata->idTypes;
00080     int offsetOfSlave = 0;
00081     int offsetIntoSlaveField = 0;
00082     std::vector<double> weights(2, 1.0);
00083     double rhsValue = 0.0;
00084     std::vector<int> cr_idTypes(2, idTypes[0]);
00085     std::vector<int> cr_fieldIDs(2, fieldIDs[0]);
00086 
00087     CHK_ERR( matrixGraph3Ptr->initSlaveConstraint(2,
00088                  &cr_idTypes[0],
00089                  &ids[2],
00090                  &cr_fieldIDs[0],
00091                  offsetOfSlave,
00092                  offsetIntoSlaveField,
00093                  &weights[0],
00094                  rhsValue) );
00095   }
00096 
00097   CHK_ERR( matrixGraph3Ptr->initComplete() );
00098 
00099   CHK_ERR( matrixGraphPtr->compareStructure(*matrixGraph3Ptr, equivalent) );
00100 
00101   if (equivalent) {
00102     ERReturn(-1);
00103   }
00104 
00105   delete testdata;
00106 
00107   return(0);
00108 }
00109 
00110 void test_MatrixGraph_test7(MPI_Comm comm, int numProcs, int localProc)
00111 {
00112   fei::SharedPtr<fei::VectorSpace> rowspace(new fei::VectorSpace(comm));
00113   fei::SharedPtr<fei::VectorSpace> colspace(new fei::VectorSpace(comm));
00114 
00115   int rowfield = 0, rowfieldsize = 1;
00116   int colfield = 1, colfieldsize = 3;
00117   rowspace->defineFields(1, &rowfield, &rowfieldsize);
00118   colspace->defineFields(1, &colfield, &colfieldsize);
00119 
00120   fei::MatrixGraph_Impl2 mgraph(rowspace, colspace);
00121 
00122   int pID = mgraph.definePattern(4, 0, colfield);
00123   fei::Pattern* pattern = mgraph.getPattern(pID);
00124 
00125   if (pattern->getNumIndices() != 4*colfieldsize) {
00126     FEI_COUT << "getNumIndices: " << pattern->getNumIndices()<<", colfieldsize: " << colfieldsize<<FEI_ENDL;
00127     FEI_OSTRINGSTREAM osstr;
00128     osstr << "test_MatrixGraph_test7, line "<<__LINE__<<FEI_ENDL;
00129     throw std::runtime_error(osstr.str());
00130   }
00131 }
00132 
00133 void test_MatrixGraph_test8(MPI_Comm comm, int numProcs, int localProc)
00134 {
00135   FEI_COUT << "testing matrix-graph with 'diagonal' connectivity block...";
00136 
00137   try {
00138 
00139   fei::SharedPtr<fei::VectorSpace> rowspace(new fei::VectorSpace(comm));
00140   fei::SharedPtr<fei::VectorSpace> colspace;
00141 
00142   int rowfield = 0, rowfieldsize = 1;
00143   rowspace->defineFields(1, &rowfield, &rowfieldsize);
00144   int idType = 0;
00145   rowspace->defineIDTypes(1, &idType);
00146 
00147   fei::MatrixGraph_Impl2 mgraph(rowspace, colspace);
00148 
00149   int numIDs = 4;
00150   int patternID = mgraph.definePattern(numIDs, idType, rowfield);
00151   fei::Pattern* pattern = mgraph.getPattern(patternID);
00152 
00153   if (pattern->getNumIndices() != 4*rowfieldsize) {
00154     FEI_OSTRINGSTREAM osstr;
00155     osstr << "test_MatrixGraph_test8, line "<<__LINE__<<FEI_ENDL;
00156     throw std::runtime_error(osstr.str());
00157   }
00158 
00159   int blockID = 0;
00160   int numConnLists = 1;
00161   bool diagonal = true;
00162   mgraph.initConnectivityBlock(blockID, numConnLists, patternID, diagonal);
00163 
00164   std::vector<int> ids(numIDs);
00165   for(int i=0; i<numIDs; ++i) {
00166     ids[i] = i;
00167   }
00168 
00169   mgraph.initConnectivity(blockID, 0, &ids[0]);
00170 
00171   mgraph.initComplete();
00172 
00173   fei::SharedPtr<fei::SparseRowGraph> localSRGraph =
00174     mgraph.createGraph(false);
00175 
00176   if ((int)localSRGraph->packedColumnIndices.size() != numIDs) {
00177     FEI_OSTRINGSTREAM osstr;
00178     osstr << "test_MatrixGraph_test8, line "<<__LINE__<<FEI_ENDL;
00179     throw std::runtime_error(osstr.str());
00180   }
00181 
00182   }
00183   catch(std::runtime_error& exc) {
00184     FEI_OSTRINGSTREAM osstr;
00185     osstr << "test_MatrixGraph_test8, caught exception: " << exc.what();
00186     throw std::runtime_error(osstr.str());
00187   }
00188 
00189   FEI_COUT << "ok" << FEI_ENDL;
00190 }
00191 
00192 int test_MatrixGraph::runtests()
00193 {
00194   if (numProcs_ < 2) {
00195     CHK_ERR( serialtest1() );
00196   }
00197 
00198   CHK_ERR( test1() );
00199   CHK_ERR( test2() );
00200   CHK_ERR( test3() );
00201   CHK_ERR( test4() );
00202   CHK_ERR( test5() );
00203 
00204   CHK_ERR( test_MatrixGraph_test6(comm_, numProcs_, localProc_, path_) );
00205 
00206   test_MatrixGraph_test7(comm_, numProcs_, localProc_);
00207   test_MatrixGraph_test8(comm_, numProcs_, localProc_);
00208 
00209   return(0);
00210 }
00211 
00212 int test_MatrixGraph::serialtest1()
00213 {
00214   int numIDs = 2;
00215   std::vector<int> idTypes(numIDs, 1);
00216   std::vector<snl_fei::RecordCollection*> recColls(numIDs, (snl_fei::RecordCollection*)NULL);
00217   std::vector<int> numFieldsPerID(numIDs, 1);
00218   std::vector<int> fieldIDs(numIDs, 0);
00219   std::vector<int> fieldSizes(numIDs, 1);
00220 
00221   fei::Pattern pattern(numIDs, &idTypes[0], &recColls[0],
00222          &numFieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);
00223 
00224   fei::Pattern::PatternType pType = pattern.getPatternType();
00225 
00226   if (pType != fei::Pattern::SIMPLE) {
00227     ERReturn(-1);
00228   }
00229 
00230   return(0);
00231 }
00232 
00233 int test_MatrixGraph::test1()
00234 {
00235   testData* testdata = new testData(localProc_, numProcs_);
00236   std::vector<int>& ids = testdata->ids;
00237 
00238   fei::SharedPtr<LibraryWrapper> wrapper;
00239   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00240 
00241   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00242     test_VectorSpace::create_VectorSpace(comm_,
00243            testdata, localProc_, numProcs_,
00244            false, //defineBothFields
00245            false, //initSolnBothFields
00246            "U_MatGrph", factory);
00247 
00248   int dofPerID = 1;
00249 
00250   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00251     create_MatrixGraph(testdata, localProc_, numProcs_,
00252            false, false, "U_MatGrph", vectorSpacePtr, factory, path_);
00253 
00254   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00255 
00256   CHK_ERR( matrixGraphPtr->initComplete() );
00257 
00258   std::vector<int> globalIndexOffsets;
00259 
00260   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00261 
00262   int numRowLengths = globalIndexOffsets[localProc_+1] -
00263      globalIndexOffsets[localProc_];
00264 
00265   int numLocalRows;
00266 
00267   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00268     matrixGraphPtr->createGraph(false);
00269 
00270   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00271   numLocalRows = rowOffsets.size()-1;
00272 
00273   if (numLocalRows != numRowLengths) ERReturn(-1);
00274 
00275   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00276   correctNumLocalRows *= dofPerID;
00277 
00278   if (numLocalRows != correctNumLocalRows) {
00279     ERReturn(-1);
00280   }
00281 
00282   int numNonzeros = localgraph->packedColumnIndices.size();
00283 
00284   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00285   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID;
00286 
00287   if (numNonzeros != correctNumNonzeros) {
00288     ERReturn(-1);
00289   }
00290 
00291   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00292 
00293   int offset = 0;
00294   for(int i=0; i<numLocalRows; ++i) {
00295     int globalRow = globalIndexOffsets[localProc_]+i;
00296     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00297 
00298     int correctRowLength = 4*dofPerID;
00299     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00300       correctRowLength += 2*dofPerID;
00301     }
00302 
00303     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00304       fei::console_out() << "localProc " << localProc_ << ", i: " << i
00305      << ", correctRowLength: " << correctRowLength << ", "
00306      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00307       ERReturn(-1);
00308     }
00309 
00310     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00311       if (nonzeros[offset++] != ids[0]+j) {
00312   ERReturn(-1);
00313       }
00314     }
00315   }
00316 
00317   delete testdata;
00318 
00319   return(0);
00320 }
00321 
00322 int test_MatrixGraph::test2()
00323 {
00324   return(0);
00325 }
00326 
00327 int init_nonsymmetric_block(testData* testdata,
00328           fei::MatrixGraph* matrixGraph)
00329 {
00330   int rowPatternID = matrixGraph->definePattern(1, 0,
00331            testdata->fieldIDs[0]);
00332   int colPatternID = matrixGraph->definePattern(1, 0,
00333            testdata->fieldIDs[1]);
00334 
00335   CHK_ERR( matrixGraph->initConnectivityBlock(2, 1, rowPatternID, colPatternID) );
00336 
00337   CHK_ERR( matrixGraph->initConnectivity(2, 0,
00338            &(testdata->ids[0]),
00339            &(testdata->ids[0])) );
00340   return(0);
00341 }
00342 
00343 int test_MatrixGraph::test3()
00344 {
00345   testData* testdata = new testData(localProc_, numProcs_);
00346   std::vector<int>& ids = testdata->ids;
00347 
00348   fei::SharedPtr<LibraryWrapper> wrapper;
00349   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00350 
00351   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00352     test_VectorSpace::create_VectorSpace(comm_,
00353            testdata, localProc_, numProcs_,
00354            true, //defineBothFields
00355            true, //initSolnBothFields
00356            "U_MatGrph3", factory);
00357 
00358   int dofPerID = 4;
00359 
00360   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00361     create_MatrixGraph(testdata, localProc_, numProcs_,
00362            true, true, //non-symmetric
00363            "U_MatGrph3", vectorSpacePtr,
00364            factory, path_);
00365 
00366   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00367 
00368   CHK_ERR( init_nonsymmetric_block(testdata, matrixGraphPtr.get()) );
00369 
00370   CHK_ERR( matrixGraphPtr->initComplete() );
00371 
00372   std::vector<int> globalIndexOffsets;
00373 
00374   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00375 
00376   int numRowLengths = globalIndexOffsets[localProc_+1] -
00377      globalIndexOffsets[localProc_];
00378 
00379   int numLocalRows;
00380 
00381   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00382     matrixGraphPtr->createGraph(false);
00383 
00384   int numGrphLocalRows = localgraph->rowNumbers.size();
00385 
00386   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00387   numLocalRows = rowOffsets.size()-1;
00388 
00389   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00390   correctNumLocalRows *= dofPerID;
00391 
00392   if (numLocalRows != correctNumLocalRows) {
00393     ERReturn(-1);
00394   }
00395 
00396   if (numLocalRows != numRowLengths) ERReturn(-1);
00397   if (numLocalRows != numGrphLocalRows) ERReturn(-1);
00398 
00399   int numNonzeros = localgraph->packedColumnIndices.size();
00400 
00401   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00402   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
00403 
00404   if (numNonzeros != correctNumNonzeros) {
00405     ERReturn(-1);
00406   }
00407 
00408   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00409 
00410   std::vector<int> rowindices;
00411   int offset = 0;
00412   for(int i=0; i<numLocalRows; ++i) {
00413     int globalRow = globalIndexOffsets[localProc_]+i;
00414     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00415 
00416     int correctRowLength = 4*dofPerID;
00417     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00418       correctRowLength += 2*dofPerID;
00419     }
00420 
00421     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00422       fei::console_out() << "localProc " << localProc_ << ", i: " << i
00423      << ", correctRowLength: " << correctRowLength << ", "
00424      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00425       ERReturn(-1);
00426     }
00427 
00428     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00429       if (nonzeros[offset++] != ids[0]*dofPerID+j) {
00430   ERReturn(-1);
00431       }
00432     }
00433   }
00434 
00435   delete testdata;
00436 
00437   return(0);
00438 }
00439 
00440 int test_MatrixGraph::test4()
00441 {
00442   testData* testdata = new testData(localProc_, numProcs_);
00443   std::vector<int>& ids = testdata->ids;
00444 
00445   fei::SharedPtr<LibraryWrapper> wrapper;
00446   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00447 
00448   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00449     test_VectorSpace::create_VectorSpace(comm_,
00450                                          testdata, localProc_, numProcs_,
00451            false, //defineBothFields
00452            false, //initSolnBothFields
00453            "U_MatGrph4", factory);
00454 
00455   int dofPerID = 1;
00456 
00457   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00458     create_MatrixGraph(testdata, localProc_, numProcs_,
00459            false, true, //non-symmetric
00460            "U_MatGrph4", vectorSpacePtr, factory, path_);
00461 
00462   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00463 
00464   CHK_ERR( matrixGraphPtr->initComplete() );
00465 
00466   std::vector<int> globalIndexOffsets;
00467 
00468   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00469 
00470   int numRowLengths = globalIndexOffsets[localProc_+1] -
00471      globalIndexOffsets[localProc_];
00472 
00473   int numLocalRows;
00474 
00475   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00476     matrixGraphPtr->createGraph(false);
00477 
00478   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00479   numLocalRows = rowOffsets.size()-1;
00480 
00481   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00482   correctNumLocalRows *= dofPerID;
00483 
00484   if (numLocalRows != correctNumLocalRows) {
00485     ERReturn(-1);
00486   }
00487 
00488   if (numLocalRows != numRowLengths) ERReturn(-1);
00489 
00490   int numNonzeros = localgraph->packedColumnIndices.size();
00491 
00492   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00493   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
00494 
00495   if (numNonzeros != correctNumNonzeros) {
00496     ERReturn(-1);
00497   }
00498 
00499   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00500 
00501   int offset = 0;
00502   for(int i=0; i<numLocalRows; ++i) {
00503     int globalRow = globalIndexOffsets[localProc_]+i;
00504     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00505 
00506     int correctRowLength = 4*dofPerID;
00507     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00508       correctRowLength += 2*dofPerID;
00509     }
00510 
00511     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00512       fei::console_out() << "localProc " << localProc_ << ", i: " << i
00513      << ", correctRowLength: " << correctRowLength << ", "
00514      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00515       ERReturn(-1);
00516     }
00517 
00518     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00519       if (nonzeros[offset++] != ids[0]*dofPerID+j) {
00520   ERReturn(-1);
00521       }
00522     }
00523   }
00524 
00525   delete testdata;
00526 
00527   return(0);
00528 }
00529 
00530 int test_MatrixGraph::test5()
00531 {
00532   testData* testdata = new testData(localProc_, numProcs_);
00533   std::vector<int>& fieldIDs = testdata->fieldIDs;
00534   std::vector<int>& idTypes = testdata->idTypes;
00535   std::vector<int>& ids = testdata->ids;
00536 
00537   fei::SharedPtr<LibraryWrapper> wrapper;
00538   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00539 
00540   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00541     test_VectorSpace::create_VectorSpace(comm_,
00542                                          testdata, localProc_, numProcs_,
00543            true, //defineBothFields
00544            true, //initSolnBothFields
00545            "U_MatGrph5",
00546            factory,true);
00547 
00548   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00549     create_MatrixGraph(testdata, localProc_, numProcs_,
00550            true, false, "U_MatGrph5", vectorSpacePtr,
00551            factory, path_, true);
00552 
00553   if (localProc_ == 0) {
00554     int offsetOfSlave = 0;
00555     int offsetIntoSlaveField = 0;
00556     std::vector<double> weights(6, 0.0);
00557     weights[3] = 1.0;
00558     double rhsValue = 0.0;
00559     std::vector<int> cr_idTypes(2, idTypes[0]);
00560     std::vector<int> cr_fieldIDs(2, fieldIDs[1]);
00561 
00562     CHK_ERR( matrixGraphPtr->initSlaveConstraint(2,
00563                  &cr_idTypes[0],
00564                  &ids[2],
00565                  &cr_fieldIDs[0],
00566                  offsetOfSlave,
00567                  offsetIntoSlaveField,
00568                  &weights[0],
00569                  rhsValue) );
00570 
00571     weights[3] = 0.0;
00572     weights[4] = 1.0;
00573     offsetIntoSlaveField = 1;
00574     CHK_ERR( matrixGraphPtr->initSlaveConstraint(2,
00575                  &cr_idTypes[0],
00576                  &ids[2],
00577                  &cr_fieldIDs[0],
00578                  offsetOfSlave,
00579                  offsetIntoSlaveField,
00580                  &weights[0],
00581                  rhsValue) );
00582   }
00583 
00584   CHK_ERR( matrixGraphPtr->initComplete() );
00585 
00586   fei::SharedPtr<fei::VectorSpace> reducedSolnSpacePtr =
00587     matrixGraphPtr->getRowSpace();
00588 
00589   std::vector<int> globalIndexOffsets;
00590 
00591   reducedSolnSpacePtr->getGlobalIndexOffsets(globalIndexOffsets);
00592 
00593   int numRows_unreduced = globalIndexOffsets[localProc_+1] -
00594      globalIndexOffsets[localProc_];
00595 
00596   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00597     matrixGraphPtr->createGraph(false);
00598 
00599   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00600   int numReducedRows = rowOffsets.size()-1;
00601 
00602   if (localProc_ == 0) {
00603     if (numReducedRows != numRows_unreduced-2) ERReturn(-1);
00604   }
00605   else {
00606     if (numReducedRows != numRows_unreduced) ERReturn(-1);
00607   }
00608 
00609   delete testdata;
00610 
00611   return(0);
00612 }
00613 
00614 fei::SharedPtr<fei::MatrixGraph> test_MatrixGraph::create_MatrixGraph(testData* testdata,
00615            int localProc, int numProcs,
00616            bool bothFields, bool nonSymmetric,
00617            const char* name,
00618            fei::SharedPtr<fei::VectorSpace> vectorSpacePtr,
00619            fei::SharedPtr<fei::Factory> factory,
00620                                          const std::string& path,
00621            bool turnOnDebugOutput)
00622 {
00623   //
00624   //This function creates a MatrixGraph object, and initializes it as follows:
00625   //
00626   //setRowSpace(vectorSpacePtr)
00627   //
00628   //definePattern patternID=0, numIDs=4, idType=testdata->idTypes[0]
00629   //      fieldID=testdata->fieldIDs[0] if !bothFields, else
00630   //      fieldIDs=testdata->fieldIDs
00631   //
00632   //initConnectivityBlock blockID=0, numConnectivityLists=1
00633   //
00634   //initConnectivity blockID, 0, testdata->ids
00635   //
00636   //If nonSymmetric==true, then also do the following:
00637   //  definePattern patternID=1, numIDs=1, idType=testdata->idTypes[0]
00638   //     fieldID=testdata->fieldIDs[0] if !bothFields, else
00639   //      fieldIDs=testdata->fieldIDs
00640   //  definePattern patternID=2, numIDs=4, idType=testdata->idTypes[0]
00641   //     fieldID=testdata->fieldIDs[0] if !bothFields, else
00642   //      fieldIDs=testdata->fieldIDs
00643   //
00644   //initConnectivityBlock blockID=1, patterns 1 and 2
00645   //
00646   //initConnectivity blockID, 0, testdata->ids
00647   //
00648   fei::SharedPtr<fei::MatrixGraph> mgptr;
00649   if (factory.get() == NULL) {
00650     fei::SharedPtr<fei::MatrixGraph> tmp(new fei::MatrixGraph_Impl2(vectorSpacePtr,
00651                     vectorSpacePtr, name));
00652     mgptr = tmp;
00653   }
00654   else {
00655     mgptr = factory->createMatrixGraph(vectorSpacePtr, vectorSpacePtr, name);
00656   }
00657 
00658   fei::ParameterSet paramset;
00659   fei::Param param1("name", name);
00660   paramset.add(param1);
00661   if (turnOnDebugOutput) {
00662     if (path.empty()) {
00663       fei::Param param2("debugOutput", ".");
00664       paramset.add(param2);
00665     }
00666     else {
00667       fei::Param param2("debugOutput", path.c_str());
00668       paramset.add(param2);
00669     }
00670   }
00671 
00672   fei::MatrixGraph* matrixGraphPtr = mgptr.get();
00673 
00674   matrixGraphPtr->setParameters(paramset);
00675 
00676   matrixGraphPtr->setRowSpace(vectorSpacePtr);
00677 
00678   int patternID = 0;
00679   int numIDs = 4;
00680   int idType = testdata->idTypes[0];
00681   int fieldID = testdata->fieldIDs[0];
00682 
00683   if (bothFields) {
00684     std::vector<int> numFieldsPerID(numIDs, 2);
00685     std::vector<int> fieldIDsArray(numIDs*2);
00686     for(int i=0; i<numIDs; ++i) {
00687       fieldIDsArray[i*2] = testdata->fieldIDs[0];
00688       fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
00689     }
00690 
00691     patternID = matrixGraphPtr->definePattern(numIDs, idType,
00692            &numFieldsPerID[0],
00693            &fieldIDsArray[0]);
00694   }
00695   else {
00696     patternID = matrixGraphPtr->definePattern(numIDs, idType, fieldID);
00697   }
00698 
00699   int blockID = 0;
00700   int numConnectivityLists = 1;
00701 
00702   matrixGraphPtr->initConnectivityBlock(blockID,
00703              numConnectivityLists,
00704              patternID);
00705 
00706   matrixGraphPtr->initConnectivity(blockID, 0, &(testdata->ids[0]));
00707 
00708   if (!nonSymmetric) {
00709     return(mgptr);
00710   }
00711 
00712   int patternID1 = 1, patternID2 = 2;
00713   int numRowIDs = 1, numColIDs = 4;
00714 
00715   if (bothFields) {
00716     std::vector<int> numFieldsPerID(numIDs, 2);
00717     std::vector<int> fieldIDsArray(numIDs*2);
00718     for(int i=0; i<numIDs; ++i) {
00719       fieldIDsArray[i*2] = testdata->fieldIDs[0];
00720       fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
00721     }
00722 
00723     patternID1 = matrixGraphPtr->definePattern(numRowIDs, idType,
00724            &numFieldsPerID[0],
00725            &fieldIDsArray[0]);
00726     patternID2 = matrixGraphPtr->definePattern(numColIDs, idType,
00727            &numFieldsPerID[0],
00728            &fieldIDsArray[0]);
00729   }
00730   else {
00731     patternID1 = matrixGraphPtr->definePattern(numRowIDs,
00732              idType, fieldID);
00733     patternID2 = matrixGraphPtr->definePattern(numColIDs,
00734              idType, fieldID);
00735   }
00736 
00737   blockID = 1;
00738 
00739   matrixGraphPtr->initConnectivityBlock(blockID,
00740              numConnectivityLists,
00741              patternID1, patternID2);
00742 
00743   matrixGraphPtr->initConnectivity(blockID, 0,
00744             &(testdata->ids[0]),
00745             &(testdata->ids[0]));
00746 
00747   return(mgptr);
00748 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends