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<int> numFieldsPerID(numIDs, 1);
00217   std::vector<int> fieldIDs(numIDs, 0);
00218   std::vector<int> fieldSizes(numIDs, 1);
00219 
00220   fei::Pattern pattern(numIDs, &idTypes[0],
00221          &numFieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);
00222 
00223   fei::Pattern::PatternType pType = pattern.getPatternType();
00224 
00225   if (pType != fei::Pattern::SIMPLE) {
00226     ERReturn(-1);
00227   }
00228 
00229   return(0);
00230 }
00231 
00232 int test_MatrixGraph::test1()
00233 {
00234   testData* testdata = new testData(localProc_, numProcs_);
00235   std::vector<int>& ids = testdata->ids;
00236 
00237   fei::SharedPtr<LibraryWrapper> wrapper;
00238   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00239 
00240   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00241     test_VectorSpace::create_VectorSpace(comm_,
00242            testdata, localProc_, numProcs_,
00243            false, //defineBothFields
00244            false, //initSolnBothFields
00245            "U_MatGrph", factory);
00246 
00247   int dofPerID = 1;
00248 
00249   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00250     create_MatrixGraph(testdata, localProc_, numProcs_,
00251            false, false, "U_MatGrph", vectorSpacePtr, factory, path_);
00252 
00253   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00254 
00255   CHK_ERR( matrixGraphPtr->initComplete() );
00256 
00257   std::vector<int> globalIndexOffsets;
00258 
00259   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00260 
00261   int numRowLengths = globalIndexOffsets[localProc_+1] -
00262      globalIndexOffsets[localProc_];
00263 
00264   int numLocalRows;
00265 
00266   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00267     matrixGraphPtr->createGraph(false);
00268 
00269   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00270   numLocalRows = rowOffsets.size()-1;
00271 
00272   if (numLocalRows != numRowLengths) ERReturn(-1);
00273 
00274   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00275   correctNumLocalRows *= dofPerID;
00276 
00277   if (numLocalRows != correctNumLocalRows) {
00278     ERReturn(-1);
00279   }
00280 
00281   int numNonzeros = localgraph->packedColumnIndices.size();
00282 
00283   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00284   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID;
00285 
00286   if (numNonzeros != correctNumNonzeros) {
00287     ERReturn(-1);
00288   }
00289 
00290   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00291 
00292   int offset = 0;
00293   for(int i=0; i<numLocalRows; ++i) {
00294     int globalRow = globalIndexOffsets[localProc_]+i;
00295     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00296 
00297     int correctRowLength = 4*dofPerID;
00298     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00299       correctRowLength += 2*dofPerID;
00300     }
00301 
00302     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00303       FEI_CERR << "localProc " << localProc_ << ", i: " << i
00304      << ", correctRowLength: " << correctRowLength << ", "
00305      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00306       ERReturn(-1);
00307     }
00308 
00309     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00310       if (nonzeros[offset++] != ids[0]+j) {
00311   ERReturn(-1);
00312       }
00313     }
00314   }
00315 
00316   delete testdata;
00317 
00318   return(0);
00319 }
00320 
00321 int test_MatrixGraph::test2()
00322 {
00323   return(0);
00324 }
00325 
00326 int init_nonsymmetric_block(testData* testdata,
00327           fei::MatrixGraph* matrixGraph)
00328 {
00329   int rowPatternID = matrixGraph->definePattern(1, 0,
00330            testdata->fieldIDs[0]);
00331   int colPatternID = matrixGraph->definePattern(1, 0,
00332            testdata->fieldIDs[1]);
00333 
00334   CHK_ERR( matrixGraph->initConnectivityBlock(2, 1, rowPatternID, colPatternID) );
00335 
00336   CHK_ERR( matrixGraph->initConnectivity(2, 0,
00337            &(testdata->ids[0]),
00338            &(testdata->ids[0])) );
00339   return(0);
00340 }
00341 
00342 int test_MatrixGraph::test3()
00343 {
00344   testData* testdata = new testData(localProc_, numProcs_);
00345   std::vector<int>& ids = testdata->ids;
00346 
00347   fei::SharedPtr<LibraryWrapper> wrapper;
00348   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00349 
00350   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00351     test_VectorSpace::create_VectorSpace(comm_,
00352            testdata, localProc_, numProcs_,
00353            true, //defineBothFields
00354            true, //initSolnBothFields
00355            "U_MatGrph3", factory);
00356 
00357   int dofPerID = 4;
00358 
00359   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00360     create_MatrixGraph(testdata, localProc_, numProcs_,
00361            true, true, //non-symmetric
00362            "U_MatGrph3", vectorSpacePtr,
00363            factory, path_);
00364 
00365   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00366 
00367   CHK_ERR( init_nonsymmetric_block(testdata, matrixGraphPtr.get()) );
00368 
00369   CHK_ERR( matrixGraphPtr->initComplete() );
00370 
00371   std::vector<int> globalIndexOffsets;
00372 
00373   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00374 
00375   int numRowLengths = globalIndexOffsets[localProc_+1] -
00376      globalIndexOffsets[localProc_];
00377 
00378   int numLocalRows;
00379 
00380   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00381     matrixGraphPtr->createGraph(false);
00382 
00383   int numGrphLocalRows = localgraph->rowNumbers.size();
00384 
00385   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00386   numLocalRows = rowOffsets.size()-1;
00387 
00388   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00389   correctNumLocalRows *= dofPerID;
00390 
00391   if (numLocalRows != correctNumLocalRows) {
00392     ERReturn(-1);
00393   }
00394 
00395   if (numLocalRows != numRowLengths) ERReturn(-1);
00396   if (numLocalRows != numGrphLocalRows) ERReturn(-1);
00397 
00398   int numNonzeros = localgraph->packedColumnIndices.size();
00399 
00400   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00401   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
00402 
00403   if (numNonzeros != correctNumNonzeros) {
00404     ERReturn(-1);
00405   }
00406 
00407   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00408 
00409   std::vector<int> rowindices;
00410   int offset = 0;
00411   for(int i=0; i<numLocalRows; ++i) {
00412     int globalRow = globalIndexOffsets[localProc_]+i;
00413     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00414 
00415     int correctRowLength = 4*dofPerID;
00416     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00417       correctRowLength += 2*dofPerID;
00418     }
00419 
00420     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00421       FEI_CERR << "localProc " << localProc_ << ", i: " << i
00422      << ", correctRowLength: " << correctRowLength << ", "
00423      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00424       ERReturn(-1);
00425     }
00426 
00427     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00428       if (nonzeros[offset++] != ids[0]*dofPerID+j) {
00429   ERReturn(-1);
00430       }
00431     }
00432   }
00433 
00434   delete testdata;
00435 
00436   return(0);
00437 }
00438 
00439 int test_MatrixGraph::test4()
00440 {
00441   testData* testdata = new testData(localProc_, numProcs_);
00442   std::vector<int>& ids = testdata->ids;
00443 
00444   fei::SharedPtr<LibraryWrapper> wrapper;
00445   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00446 
00447   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00448     test_VectorSpace::create_VectorSpace(comm_,
00449                                          testdata, localProc_, numProcs_,
00450            false, //defineBothFields
00451            false, //initSolnBothFields
00452            "U_MatGrph4", factory);
00453 
00454   int dofPerID = 1;
00455 
00456   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00457     create_MatrixGraph(testdata, localProc_, numProcs_,
00458            false, true, //non-symmetric
00459            "U_MatGrph4", vectorSpacePtr, factory, path_);
00460 
00461   fei::VectorSpace& vectorSpace = *vectorSpacePtr;
00462 
00463   CHK_ERR( matrixGraphPtr->initComplete() );
00464 
00465   std::vector<int> globalIndexOffsets;
00466 
00467   vectorSpace.getGlobalIndexOffsets(globalIndexOffsets);
00468 
00469   int numRowLengths = globalIndexOffsets[localProc_+1] -
00470      globalIndexOffsets[localProc_];
00471 
00472   int numLocalRows;
00473 
00474   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00475     matrixGraphPtr->createGraph(false);
00476 
00477   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00478   numLocalRows = rowOffsets.size()-1;
00479 
00480   int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
00481   correctNumLocalRows *= dofPerID;
00482 
00483   if (numLocalRows != correctNumLocalRows) {
00484     ERReturn(-1);
00485   }
00486 
00487   if (numLocalRows != numRowLengths) ERReturn(-1);
00488 
00489   int numNonzeros = localgraph->packedColumnIndices.size();
00490 
00491   int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
00492   if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
00493 
00494   if (numNonzeros != correctNumNonzeros) {
00495     ERReturn(-1);
00496   }
00497 
00498   std::vector<int>& nonzeros = localgraph->packedColumnIndices;
00499 
00500   int offset = 0;
00501   for(int i=0; i<numLocalRows; ++i) {
00502     int globalRow = globalIndexOffsets[localProc_]+i;
00503     int globalEndRow = globalIndexOffsets[numProcs_]-1;
00504 
00505     int correctRowLength = 4*dofPerID;
00506     if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
00507       correctRowLength += 2*dofPerID;
00508     }
00509 
00510     if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
00511       FEI_CERR << "localProc " << localProc_ << ", i: " << i
00512      << ", correctRowLength: " << correctRowLength << ", "
00513      << "rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
00514       ERReturn(-1);
00515     }
00516 
00517     for(int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
00518       if (nonzeros[offset++] != ids[0]*dofPerID+j) {
00519   ERReturn(-1);
00520       }
00521     }
00522   }
00523 
00524   delete testdata;
00525 
00526   return(0);
00527 }
00528 
00529 int test_MatrixGraph::test5()
00530 {
00531   testData* testdata = new testData(localProc_, numProcs_);
00532   std::vector<int>& fieldIDs = testdata->fieldIDs;
00533   std::vector<int>& idTypes = testdata->idTypes;
00534   std::vector<int>& ids = testdata->ids;
00535 
00536   fei::SharedPtr<LibraryWrapper> wrapper;
00537   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper));
00538 
00539   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00540     test_VectorSpace::create_VectorSpace(comm_,
00541                                          testdata, localProc_, numProcs_,
00542            true, //defineBothFields
00543            true, //initSolnBothFields
00544            "U_MatGrph5",
00545            factory,true);
00546 
00547   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00548     create_MatrixGraph(testdata, localProc_, numProcs_,
00549            true, false, "U_MatGrph5", vectorSpacePtr,
00550            factory, path_, true);
00551 
00552   if (localProc_ == 0) {
00553     int offsetOfSlave = 0;
00554     int offsetIntoSlaveField = 0;
00555     std::vector<double> weights(6, 0.0);
00556     weights[3] = 1.0;
00557     double rhsValue = 0.0;
00558     std::vector<int> cr_idTypes(2, idTypes[0]);
00559     std::vector<int> cr_fieldIDs(2, fieldIDs[1]);
00560 
00561     CHK_ERR( matrixGraphPtr->initSlaveConstraint(2,
00562                  &cr_idTypes[0],
00563                  &ids[2],
00564                  &cr_fieldIDs[0],
00565                  offsetOfSlave,
00566                  offsetIntoSlaveField,
00567                  &weights[0],
00568                  rhsValue) );
00569 
00570     weights[3] = 0.0;
00571     weights[4] = 1.0;
00572     offsetIntoSlaveField = 1;
00573     CHK_ERR( matrixGraphPtr->initSlaveConstraint(2,
00574                  &cr_idTypes[0],
00575                  &ids[2],
00576                  &cr_fieldIDs[0],
00577                  offsetOfSlave,
00578                  offsetIntoSlaveField,
00579                  &weights[0],
00580                  rhsValue) );
00581   }
00582 
00583   CHK_ERR( matrixGraphPtr->initComplete() );
00584 
00585   fei::SharedPtr<fei::VectorSpace> reducedSolnSpacePtr =
00586     matrixGraphPtr->getRowSpace();
00587 
00588   std::vector<int> globalIndexOffsets;
00589 
00590   reducedSolnSpacePtr->getGlobalIndexOffsets(globalIndexOffsets);
00591 
00592   int numRows_unreduced = globalIndexOffsets[localProc_+1] -
00593      globalIndexOffsets[localProc_];
00594 
00595   fei::SharedPtr<fei::SparseRowGraph> localgraph =
00596     matrixGraphPtr->createGraph(false);
00597 
00598   std::vector<int>& rowOffsets = localgraph->rowOffsets;
00599   int numReducedRows = rowOffsets.size()-1;
00600 
00601   if (localProc_ == 0) {
00602     if (numReducedRows != numRows_unreduced-2) ERReturn(-1);
00603   }
00604   else {
00605     if (numReducedRows != numRows_unreduced) ERReturn(-1);
00606   }
00607 
00608   delete testdata;
00609 
00610   return(0);
00611 }
00612 
00613 fei::SharedPtr<fei::MatrixGraph> test_MatrixGraph::create_MatrixGraph(testData* testdata,
00614            int localProc, int numProcs,
00615            bool bothFields, bool nonSymmetric,
00616            const char* name,
00617            fei::SharedPtr<fei::VectorSpace> vectorSpacePtr,
00618            fei::SharedPtr<fei::Factory> factory,
00619                                          const std::string& path,
00620            bool turnOnDebugOutput)
00621 {
00622   //
00623   //This function creates a MatrixGraph object, and initializes it as follows:
00624   //
00625   //setRowSpace(vectorSpacePtr)
00626   //
00627   //definePattern patternID=0, numIDs=4, idType=testdata->idTypes[0]
00628   //      fieldID=testdata->fieldIDs[0] if !bothFields, else
00629   //      fieldIDs=testdata->fieldIDs
00630   //
00631   //initConnectivityBlock blockID=0, numConnectivityLists=1
00632   //
00633   //initConnectivity blockID, 0, testdata->ids
00634   //
00635   //If nonSymmetric==true, then also do the following:
00636   //  definePattern patternID=1, numIDs=1, idType=testdata->idTypes[0]
00637   //     fieldID=testdata->fieldIDs[0] if !bothFields, else
00638   //      fieldIDs=testdata->fieldIDs
00639   //  definePattern patternID=2, numIDs=4, idType=testdata->idTypes[0]
00640   //     fieldID=testdata->fieldIDs[0] if !bothFields, else
00641   //      fieldIDs=testdata->fieldIDs
00642   //
00643   //initConnectivityBlock blockID=1, patterns 1 and 2
00644   //
00645   //initConnectivity blockID, 0, testdata->ids
00646   //
00647   fei::SharedPtr<fei::MatrixGraph> mgptr;
00648   if (factory.get() == NULL) {
00649     fei::SharedPtr<fei::MatrixGraph> tmp(new fei::MatrixGraph_Impl2(vectorSpacePtr,
00650                     vectorSpacePtr, name));
00651     mgptr = tmp;
00652   }
00653   else {
00654     mgptr = factory->createMatrixGraph(vectorSpacePtr, vectorSpacePtr, name);
00655   }
00656 
00657   fei::ParameterSet paramset;
00658   fei::Param param1("name", name);
00659   paramset.add(param1);
00660   if (turnOnDebugOutput) {
00661     if (path.empty()) {
00662       fei::Param param2("debugOutput", ".");
00663       paramset.add(param2);
00664     }
00665     else {
00666       fei::Param param2("debugOutput", path.c_str());
00667       paramset.add(param2);
00668     }
00669   }
00670 
00671   fei::MatrixGraph* matrixGraphPtr = mgptr.get();
00672 
00673   matrixGraphPtr->setParameters(paramset);
00674 
00675   matrixGraphPtr->setRowSpace(vectorSpacePtr);
00676 
00677   int patternID = 0;
00678   int numIDs = 4;
00679   int idType = testdata->idTypes[0];
00680   int fieldID = testdata->fieldIDs[0];
00681 
00682   if (bothFields) {
00683     std::vector<int> numFieldsPerID(numIDs, 2);
00684     std::vector<int> fieldIDsArray(numIDs*2);
00685     for(int i=0; i<numIDs; ++i) {
00686       fieldIDsArray[i*2] = testdata->fieldIDs[0];
00687       fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
00688     }
00689 
00690     patternID = matrixGraphPtr->definePattern(numIDs, idType,
00691            &numFieldsPerID[0],
00692            &fieldIDsArray[0]);
00693   }
00694   else {
00695     patternID = matrixGraphPtr->definePattern(numIDs, idType, fieldID);
00696   }
00697 
00698   int blockID = 0;
00699   int numConnectivityLists = 1;
00700 
00701   matrixGraphPtr->initConnectivityBlock(blockID,
00702              numConnectivityLists,
00703              patternID);
00704 
00705   matrixGraphPtr->initConnectivity(blockID, 0, &(testdata->ids[0]));
00706 
00707   if (!nonSymmetric) {
00708     return(mgptr);
00709   }
00710 
00711   int patternID1 = 1, patternID2 = 2;
00712   int numRowIDs = 1, numColIDs = 4;
00713 
00714   if (bothFields) {
00715     std::vector<int> numFieldsPerID(numIDs, 2);
00716     std::vector<int> fieldIDsArray(numIDs*2);
00717     for(int i=0; i<numIDs; ++i) {
00718       fieldIDsArray[i*2] = testdata->fieldIDs[0];
00719       fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
00720     }
00721 
00722     patternID1 = matrixGraphPtr->definePattern(numRowIDs, idType,
00723            &numFieldsPerID[0],
00724            &fieldIDsArray[0]);
00725     patternID2 = matrixGraphPtr->definePattern(numColIDs, idType,
00726            &numFieldsPerID[0],
00727            &fieldIDsArray[0]);
00728   }
00729   else {
00730     patternID1 = matrixGraphPtr->definePattern(numRowIDs,
00731              idType, fieldID);
00732     patternID2 = matrixGraphPtr->definePattern(numColIDs,
00733              idType, fieldID);
00734   }
00735 
00736   blockID = 1;
00737 
00738   matrixGraphPtr->initConnectivityBlock(blockID,
00739              numConnectivityLists,
00740              patternID1, patternID2);
00741 
00742   matrixGraphPtr->initConnectivity(blockID, 0,
00743             &(testdata->ids[0]),
00744             &(testdata->ids[0]));
00745 
00746   return(mgptr);
00747 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends