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