FEI Version of the Day
test_Matrix.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 #include <fei_macros.hpp>
00010 #include <cmath>
00011 #include <fei_mpi.h>
00012 #include <test_utils/fei_test_utils.hpp>
00013 #include <test_utils/LibraryFactory.hpp>
00014 #include <test_utils/test_Matrix.hpp>
00015 #include <test_utils/test_VectorSpace.hpp>
00016 #include <test_utils/test_MatrixGraph.hpp>
00017 #include <fei_MatrixGraph_Impl2.hpp>
00018 #include <fei_Factory.hpp>
00019 #include <fei_defs.h>
00020 #include <snl_fei_Factory.hpp>
00021 #include <fei_Vector_Impl.hpp>
00022 #include <fei_Matrix_Impl.hpp>
00023 
00024 #ifdef HAVE_FEI_AZTECOO
00025 #include <fei_Aztec_LinSysCore.hpp>
00026 #endif
00027 #include <fei_Factory_Trilinos.hpp>
00028 
00029 #ifdef HAVE_FEI_FETI
00030 #include <FETI_DP_FiniteElementData.h>
00031 #endif
00032 
00033 #undef fei_file
00034 #define fei_file "test_Matrix.cpp"
00035 #include <fei_ErrMacros.hpp>
00036 
00037 int test_matrix_unit1()
00038 {
00039   std::vector<double> data1D;
00040   std::vector<const double*>data2D;
00041 
00042   int numRows = 2;
00043   int numCols = 3;
00044   double** values = new double*[numRows];
00045   int i, j;
00046   for(i=0; i<numRows; ++i) {
00047     values[i] = new double[numCols];
00048     for(j=0; j<numCols; ++j) {
00049       values[i][j] = i*1.0;
00050     }
00051   }
00052 
00053   fei::Matrix_core::copyTransposeToWorkArrays(numRows, numCols,
00054              values, data1D, data2D);
00055 
00056   for(i=0; i<numRows; ++i) {
00057     for(j=0; j<numCols; ++j) {
00058       if (std::abs(values[i][j] - (data2D[j])[i]) > 1.e-49) {
00059   ERReturn(-1);
00060       }
00061     }
00062     delete [] values[i];
00063   }
00064 
00065   delete [] values;
00066 
00067   return(0);
00068 }
00069 
00070 void test_Matrix_unit2(MPI_Comm comm, int numProcs, int localProc)
00071 {
00072   if (numProcs > 1) {
00073     return;
00074   }
00075 
00076   FEI_COUT << "testing fei::Matrix_Impl...";
00077 
00078   fei::SharedPtr<fei::VectorSpace> rowspace(new fei::VectorSpace(comm));
00079   fei::SharedPtr<fei::VectorSpace> colspace;
00080 
00081   int rowfield = 0, rowfieldsize = 1;
00082   int idType = 0;
00083   rowspace->defineFields(1, &rowfield, &rowfieldsize);
00084   rowspace->defineIDTypes(1, &idType);
00085 
00086   fei::SharedPtr<fei::MatrixGraph> mgraph(new fei::MatrixGraph_Impl2(rowspace, colspace));
00087 
00088   int patternID1 = mgraph->definePattern(2, idType, rowfield);
00089 
00090   fei::Pattern* rowpattern = mgraph->getPattern(patternID1);
00091 
00092   mgraph->initConnectivityBlock(0, 1, patternID1);
00093 
00094   std::vector<int> ids(2);
00095   ids[0] = 0; ids[1] = 1;
00096 
00097   int err = mgraph->initConnectivity(0, 0, &ids[0]);
00098   if (err) {
00099     FEI_OSTRINGSTREAM osstr;
00100     osstr << "test_Matrix_unit2, initConnectivity returned err="<<err;
00101     throw std::runtime_error(osstr.str());
00102   }
00103 
00104   err = mgraph->initComplete();
00105   if (err) {
00106     FEI_OSTRINGSTREAM osstr;
00107     osstr << "test_Matrix_unit2, initComplete returned err="<<err;
00108     throw std::runtime_error(osstr.str());
00109   }
00110 
00111   bool factory_created = false;
00112   fei::SharedPtr<fei::Factory> factory;
00113   try {
00114     factory = fei::create_fei_Factory(comm, "Trilinos");
00115     factory_created = true;
00116   }
00117   catch(...) {}
00118 
00119   if (!factory_created) {
00120     FEI_COUT << "failed to create Trilinos factory."<<FEI_ENDL;
00121     return;
00122   }
00123 
00124   fei::SharedPtr<fei::Matrix> feimat = factory->createMatrix(mgraph);
00125 
00126   int numrowindices = rowpattern->getNumIndices();
00127 
00128   std::vector<double> coefs(numrowindices*numrowindices, 1.0);
00129   std::vector<double*> coefs_2D(numrowindices);
00130   for(int i=0; i<numrowindices; ++i) {
00131     coefs_2D[i] = &(coefs[i*numrowindices]);
00132   }
00133 
00134   err = feimat->sumIn(0, 0, &coefs_2D[0]);
00135   if (err) {
00136     FEI_OSTRINGSTREAM osstr;
00137     osstr << "test_Matrix_unit2, feimat->sumIn returned err="<<err;
00138     throw std::runtime_error(osstr.str());
00139   }
00140 
00141   err = feimat->globalAssemble();
00142   if (err) {
00143     FEI_OSTRINGSTREAM osstr;
00144     osstr << "test_Matrix_unit2, feimat->globalAssemble returned err="<<err;
00145     throw std::runtime_error(osstr.str());
00146   }
00147 
00148   err = feimat->writeToFile("feimat2.mtx", false);
00149   if (err) {
00150     FEI_OSTRINGSTREAM osstr;
00151     osstr << "test_Matrix_unit2, feimat->writeToFile returned err="<<err;
00152     throw std::runtime_error(osstr.str());
00153   }
00154 
00155   fei::FillableMat feimat_ss;
00156   err = fei_test_utils::copy_feiMatrix_to_FillableMat(*feimat, feimat_ss);
00157   if (err) {
00158     FEI_OSTRINGSTREAM osstr;
00159     osstr << "test_Matrix_unit2, copy_feiMatrix_to_FillableMat returned err="<<err;
00160     throw std::runtime_error(osstr.str());
00161   }
00162 
00163   fei_test_utils::writeMatrix("feimat_ss2.mtx", feimat_ss);
00164 
00165   FEI_COUT << "ok"<<FEI_ENDL;
00166 }
00167 
00168 void test_Matrix_unit4(MPI_Comm comm, int numProcs, int localProc)
00169 {
00170   if (numProcs > 1) {
00171     return;
00172   }
00173 
00174   FEI_COUT << "testing fei::Matrix_Impl with FEI_BLOCK_DIAGONAL_ROW...";
00175 
00176   fei::SharedPtr<fei::VectorSpace> rowspace(new fei::VectorSpace(comm));
00177   fei::SharedPtr<fei::VectorSpace> colspace;
00178 
00179   int rowfield = 0, rowfieldsize = 2;
00180   int idType = 0;
00181   rowspace->defineFields(1, &rowfield, &rowfieldsize);
00182   rowspace->defineIDTypes(1, &idType);
00183 
00184   fei::SharedPtr<fei::MatrixGraph> mgraph(new fei::MatrixGraph_Impl2(rowspace, colspace));
00185 
00186   int patternID1 = mgraph->definePattern(2, idType, rowfield);
00187 
00188   fei::Pattern* rowpattern = mgraph->getPattern(patternID1);
00189 
00190   bool diagonal = true;
00191   mgraph->initConnectivityBlock(0, 1, patternID1, diagonal);
00192 
00193   std::vector<int> ids(2);
00194   ids[0] = 0; ids[1] = 1;
00195 
00196   int err = mgraph->initConnectivity(0, 0, &ids[0]);
00197   if (err) {
00198     FEI_OSTRINGSTREAM osstr;
00199     osstr << "test_Matrix_unit4, initConnectivity returned err="<<err;
00200     throw std::runtime_error(osstr.str());
00201   }
00202 
00203   err = mgraph->initComplete();
00204   if (err) {
00205     FEI_OSTRINGSTREAM osstr;
00206     osstr << "test_Matrix_unit4, initComplete returned err="<<err;
00207     throw std::runtime_error(osstr.str());
00208   }
00209 
00210   fei::SharedPtr<fei::Factory> factory;
00211   try {
00212     factory = fei::create_fei_Factory(comm, "Trilinos");
00213   }
00214   catch(...) {
00215     FEI_COUT << "Trilinos not available."<<FEI_ENDL;
00216     return;
00217   }
00218 
00219   fei::Param blktrue("BLOCK_MATRIX", true);
00220   fei::Param blkfalse("BLOCK_MATRIX", false);
00221 
00222   fei::ParameterSet paramset;
00223   paramset.add(blktrue);
00224   factory->parameters(paramset);
00225 
00226   fei::SharedPtr<fei::Matrix> feiblkmat = factory->createMatrix(mgraph);
00227 
00228   paramset.add(blkfalse);
00229   factory->parameters(paramset);
00230 
00231   fei::SharedPtr<fei::Matrix> feimat = factory->createMatrix(mgraph);
00232 
00233   int numrowindices = rowpattern->getNumIndices();
00234 
00235   std::vector<double> coefs(numrowindices*rowfieldsize*rowfieldsize, 1.0);
00236   std::vector<double*> coefs_2D(numrowindices*rowfieldsize);
00237   int offset = 0;
00238   for(int i=0; i<numrowindices*rowfieldsize; ++i) {
00239     coefs_2D[i] = &(coefs[offset]);
00240     offset += rowfieldsize;
00241   }
00242 
00243   err = feimat->sumIn(0, 0, &coefs_2D[0], FEI_BLOCK_DIAGONAL_ROW);
00244   if (err) {
00245     FEI_OSTRINGSTREAM osstr;
00246     osstr << "test_Matrix_unit4, feimat->sumIn returned err="<<err;
00247     throw std::runtime_error(osstr.str());
00248   }
00249 
00250   err = feiblkmat->sumIn(0, 0, &coefs_2D[0], FEI_BLOCK_DIAGONAL_ROW);
00251   if (err) {
00252     FEI_OSTRINGSTREAM osstr;
00253     osstr << "test_Matrix_unit4, feiblkmat->sumIn returned err="<<err;
00254     throw std::runtime_error(osstr.str());
00255   }
00256 
00257   err = feimat->globalAssemble();
00258   if (err) {
00259     FEI_OSTRINGSTREAM osstr;
00260     osstr << "test_Matrix_unit4, feimat->globalAssemble returned err="<<err;
00261     throw std::runtime_error(osstr.str());
00262   }
00263 
00264   err = feiblkmat->globalAssemble();
00265   if (err) {
00266     FEI_OSTRINGSTREAM osstr;
00267     osstr << "test_Matrix_unit4, feimat->globalAssemble returned err="<<err;
00268     throw std::runtime_error(osstr.str());
00269   }
00270 
00271   feimat->writeToFile("feimat_blkdiag.mtx");
00272   feiblkmat->writeToFile("feiblkmat_blkdiag.mtx");
00273 
00274   FEI_COUT << "ok"<<FEI_ENDL;
00275 }
00276 
00277 test_Matrix::test_Matrix(MPI_Comm comm)
00278   : tester(comm)
00279 {
00280 }
00281 
00282 test_Matrix::~test_Matrix()
00283 {
00284 }
00285 
00286 int test_Matrix::runtests()
00287 {
00288 
00289   //-------------------------------
00290   // Test a Factory_Trilinos matrix.
00291   if (localProc_==0) FEI_COUT << "Testing Factory_Trilinos fei::Matrix..." << FEI_ENDL;
00292   fei::SharedPtr<fei::Factory> factory_trilinos(new Factory_Trilinos(comm_));
00293 
00294   fei::SharedPtr<fei::Matrix> mat = create_matrix(factory_trilinos);
00295 
00296   matrix_test1(mat);
00297 
00298   if (localProc_==0) FEI_COUT << FEI_ENDL;
00299 
00300 #ifdef HAVE_FEI_AZTECOO
00301   //-------------------------------
00302   // Test a matrix from a "snl_fei::Factory", which was created by the
00303   // test-util function create_fei_Factory for library "Aztec", which causes
00304   // an "old" LinearSystemCore object to be used as the underlying assembly layer.
00305   // (It still ends up using Aztec if you create a solver and solve the linear-
00306   // system, but it assembles data into non-Trilinos matrix/vector data structures.)
00307   if (localProc_==0) FEI_COUT << "Testing 'old' factory_aztec fei::Matrix..." << FEI_ENDL;
00308   fei::SharedPtr<fei::Factory> factory_aztec =
00309     fei::create_fei_Factory(comm_, "Aztec");
00310 
00311   fei::SharedPtr<fei::Matrix> mat1 = create_matrix(factory_aztec);
00312 
00313   matrix_test1(mat1);
00314 #endif
00315 
00316   return(0);
00317 }
00318 
00319 fei::SharedPtr<fei::Matrix>
00320 test_Matrix::create_matrix(fei::SharedPtr<fei::Factory> factory)
00321 {
00322   testData test_data(localProc_, numProcs_);
00323 
00324   fei::SharedPtr<fei::VectorSpace> vspace =
00325     test_VectorSpace::create_VectorSpace(comm_, &test_data, localProc_, numProcs_,
00326            false, false, (const char*)0, factory);
00327   int err = vspace->initComplete();
00328   if (err != 0) {
00329     FEI_COUT << "ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL;
00330     throw std::runtime_error("test_Vector::vector_test1: ERROR, failed to create valid fei::VectorSpace.");
00331   }
00332 
00333   fei::SharedPtr<fei::MatrixGraph> mgraph =
00334     factory->createMatrixGraph(vspace, vspace, NULL);
00335 
00336   std::vector<int>& fieldIDs = test_data.fieldIDs;
00337   std::vector<int>& idTypes = test_data.idTypes;
00338   std::vector<int>& ids = test_data.ids;
00339 
00340   int numIDs = ids.size();
00341   int fieldID = fieldIDs[0];
00342   int idType = idTypes[0];
00343 
00344   int patternID = mgraph->definePattern(numIDs, idType, fieldID);
00345 
00346   mgraph->initConnectivityBlock(0, 1, patternID);
00347 
00348   mgraph->initConnectivity(0, 0, &ids[0]);
00349 
00350   mgraph->initComplete();
00351 
00352   fei::SharedPtr<fei::Matrix> matrix = factory->createMatrix(mgraph);
00353   return(matrix);
00354 }
00355 
00356 void test_Matrix::matrix_test1(fei::SharedPtr<fei::Matrix> mat)
00357 {
00358   if (localProc_==0)
00359     FEI_COUT << "  matrix_test1: testing fei::Matrix with type '"
00360      << mat->typeName() << "':"<<FEI_ENDL;
00361 
00362   fei::SharedPtr<fei::MatrixGraph> mgraph = mat->getMatrixGraph();
00363 
00364   fei::SharedPtr<fei::VectorSpace> rspace = mgraph->getRowSpace();
00365 
00366   if (localProc_==0)
00367     FEI_COUT << "   testing get{Global/Local}NumRows,getRowLength...";
00368 
00369   int mglobalrows = mat->getGlobalNumRows();
00370   int vglobaleqns = rspace->getGlobalNumIndices();
00371 
00372   if (mglobalrows != vglobaleqns) {
00373     throw std::runtime_error("mat reports different num rows than vector-space eqns");
00374   }
00375 
00376   std::vector<int> global_offsets;
00377   rspace->getGlobalIndexOffsets(global_offsets);
00378 
00379   int my_num_rows = mat->getLocalNumRows();
00380   if (my_num_rows != global_offsets[localProc_+1]-global_offsets[localProc_]) {
00381     throw std::runtime_error("num-local-rows mis-match between mat and vector-space");
00382   }
00383 
00384   int i, my_first_row = global_offsets[localProc_];
00385   std::vector<int> row_lengths(my_num_rows);
00386 
00387   for(i=0; i<my_num_rows; ++i) {
00388     int errcode = mat->getRowLength(i+my_first_row, row_lengths[i]);
00389     if (errcode != 0) {
00390       throw std::runtime_error("nonzero errcode from mat->getRowLength");
00391     }
00392   }
00393 
00394   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00395 }
00396 
00397 int test_Matrix::serialtest1()
00398 {
00399   fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
00400   std::vector<int>& fieldIDs = testdata->fieldIDs;
00401   std::vector<int>& fieldSizes = testdata->fieldSizes;
00402   std::vector<int>& idTypes = testdata->idTypes;
00403   std::vector<int>& ids = testdata->ids;
00404 
00405   fei::SharedPtr<fei::VectorSpace> vspc(new fei::VectorSpace(comm_, "sU_Mat"));
00406 
00407   vspc->defineFields(fieldIDs.size(),
00408          &fieldIDs[0],
00409          &fieldSizes[0]);
00410 
00411   vspc->defineIDTypes(idTypes.size(), &idTypes[0]);
00412 
00413   fei::SharedPtr<fei::MatrixGraph>
00414     matgraph(new fei::MatrixGraph_Impl2(vspc, vspc, "sU_Mat"));
00415 
00416   int numIDs = ids.size();
00417   int fieldID = fieldIDs[0];
00418   int idType = idTypes[0];
00419 
00420   int patternID = matgraph->definePattern(numIDs, idType, fieldID);
00421 
00422   CHK_ERR( matgraph->initConnectivityBlock(0, 1, patternID) );
00423 
00424   CHK_ERR( matgraph->initConnectivity(0, 0, &ids[0]) );
00425 
00426   CHK_ERR( matgraph->initComplete() );
00427 
00428   fei::SharedPtr<fei::FillableMat> ssmat(new fei::FillableMat), ssmatT(new fei::FillableMat);
00429   int localsize = matgraph->getRowSpace()->getNumIndices_Owned();
00430   fei::SharedPtr<fei::Matrix> matrix(new fei::Matrix_Impl<fei::FillableMat>(ssmat, matgraph, localsize));
00431 
00432   fei::SharedPtr<fei::Matrix> matrixT(new fei::Matrix_Impl<fei::FillableMat>(ssmatT, matgraph, localsize));
00433 
00434   std::vector<int> indices(numIDs);
00435   CHK_ERR( matgraph->getConnectivityIndices(0, 0, numIDs, &indices[0], numIDs) );
00436 
00437   std::vector<double> data1(numIDs*numIDs);
00438   std::vector<double*> data2d(numIDs);
00439 
00440   int i;
00441   for(i=0; i<numIDs; ++i) {
00442     data2d[i] = &(data1[i*numIDs]);
00443   }
00444 
00445   for(i=0; i<numIDs*numIDs; ++i) {
00446     data1[i] = 1.0*i;
00447   }
00448 
00449   CHK_ERR( matrix->sumIn(numIDs, &indices[0], numIDs, &indices[0],
00450        &data2d[0], 0) );
00451 
00452   CHK_ERR( matrix->sumIn(0, 0, &data2d[0], 0) );
00453 
00454   CHK_ERR( matrixT->sumIn(numIDs, &indices[0],
00455        numIDs, &indices[0], &data2d[0], 3) );
00456 
00457   CHK_ERR( matrixT->sumIn(0, 0, &data2d[0], 3) );
00458 
00459   if (*ssmat != *ssmatT) {
00460     ERReturn(-1);
00461   }
00462 
00463   return(0);
00464 }
00465 
00466 int test_Matrix::serialtest2()
00467 {
00468   testData* testdata = new testData(localProc_, numProcs_);
00469   std::vector<int>& idTypes = testdata->idTypes;
00470   std::vector<int>& ids = testdata->ids;
00471 
00472   fei::SharedPtr<fei::VectorSpace> vspc(new fei::VectorSpace(comm_, "sU_Mat"));
00473 
00474   vspc->defineIDTypes(idTypes.size(), &idTypes[0]);
00475 
00476   fei::SharedPtr<fei::MatrixGraph> matgraph(new fei::MatrixGraph_Impl2(vspc, vspc, "sU_Mat"));
00477 
00478   int numIDs = ids.size();
00479   int idType = idTypes[0];
00480 
00481   int patternID = matgraph->definePattern(numIDs, idType);
00482 
00483   CHK_ERR( matgraph->initConnectivityBlock(0, 1, patternID) );
00484 
00485   CHK_ERR( matgraph->initConnectivity(0, 0, &ids[0]) );
00486 
00487   CHK_ERR( matgraph->initComplete() );
00488 
00489   fei::SharedPtr<fei::FillableMat> ssmat(new fei::FillableMat), ssmatT(new fei::FillableMat);
00490   int localsize = matgraph->getRowSpace()->getNumIndices_Owned();
00491   fei::Matrix* matrix = new fei::Matrix_Impl<fei::FillableMat>(ssmat, matgraph, localsize);
00492 
00493   fei::Matrix* matrixT = new fei::Matrix_Impl<fei::FillableMat>(ssmatT, matgraph, localsize);
00494 
00495   std::vector<int> indices(numIDs);
00496   CHK_ERR( matgraph->getConnectivityIndices(0, 0, numIDs, &indices[0], numIDs) );
00497 
00498   std::vector<double> data1(numIDs*numIDs);
00499   std::vector<double*> data2d(numIDs);
00500 
00501   int i;
00502   for(i=0; i<numIDs; ++i) {
00503     data2d[i] = &(data1[i*numIDs]);
00504   }
00505 
00506   for(i=0; i<numIDs*numIDs; ++i) {
00507     data1[i] = 1.0*i;
00508   }
00509 
00510   CHK_ERR( matrix->sumIn(numIDs, &indices[0],
00511        numIDs, &indices[0], &data2d[0], 0) );
00512 
00513   CHK_ERR( matrixT->sumIn(numIDs, &indices[0],
00514        numIDs, &indices[0], &data2d[0], 3) );
00515 
00516   if (*ssmat != *ssmatT) {
00517     ERReturn(-1);
00518   }
00519 
00520   delete matrix;
00521   delete matrixT;
00522   delete testdata;
00523 
00524   return(0);
00525 }
00526 
00527 int test_Matrix::serialtest3()
00528 {
00529   testData* testdata = new testData(localProc_, numProcs_);
00530   std::vector<int>& fieldIDs = testdata->fieldIDs;
00531   std::vector<int>& fieldSizes = testdata->fieldSizes;
00532   std::vector<int>& idTypes = testdata->idTypes;
00533   std::vector<int>& ids = testdata->ids;
00534 
00535   fei::SharedPtr<fei::VectorSpace> vspc(new fei::VectorSpace(comm_, "sU_Mat3"));
00536 
00537   vspc->defineFields(fieldIDs.size(), &fieldIDs[0], &fieldSizes[0]);
00538 
00539   vspc->defineIDTypes(idTypes.size(), &idTypes[0]);
00540 
00541   fei::SharedPtr<fei::MatrixGraph>
00542     matgraph(new fei::MatrixGraph_Impl2(vspc, vspc, "sU_Mat3"));
00543 
00544   int numIDs = ids.size();
00545   int fieldID = fieldIDs[0];
00546   int idType = idTypes[0];
00547 
00548   int patternID = matgraph->definePattern(numIDs, idType, fieldID);
00549 
00550   CHK_ERR( matgraph->initConnectivityBlock(0, 1, patternID) );
00551 
00552   CHK_ERR( matgraph->initConnectivity(0, 0, &ids[0]) );
00553 
00554   //set up a slave constraint that defines id 2, field 0 to be equal to
00555   //id 1, field 0.
00556   int offsetOfSlave = 1;
00557   int offsetIntoSlaveField = 0;
00558   std::vector<double> weights(2);
00559   weights[0] = 1.0;
00560   weights[1] = -1.0;
00561   double rhsValue = 0.0;
00562   std::vector<int> cr_idtypes(2, idTypes[0]);
00563   std::vector<int> cr_fieldIDs(2, fieldIDs[0]);
00564 
00565   CHK_ERR( matgraph->initSlaveConstraint(2, //numIDs
00566           &cr_idtypes[0],
00567           &ids[1],
00568           &cr_fieldIDs[0],
00569           offsetOfSlave,
00570           offsetIntoSlaveField,
00571           &weights[0],
00572           rhsValue) );
00573 
00574   CHK_ERR( matgraph->initComplete() );
00575 
00576   fei::SharedPtr<fei::FillableMat> ssmat(new fei::FillableMat);
00577   int localsize = matgraph->getRowSpace()->getNumIndices_Owned();
00578   localsize -= 1;//subtract the slave
00579   fei::Matrix* matrix = new fei::Matrix_Impl<fei::FillableMat>(ssmat, matgraph, localsize);
00580 
00581   if (matrix == NULL) {
00582     ERReturn(-1);
00583   }
00584 
00585   std::vector<int> indices(numIDs);
00586   CHK_ERR( matgraph->getConnectivityIndices(0, 0, numIDs,
00587              &indices[0], numIDs) );
00588 
00589   std::vector<double> data1(numIDs*numIDs);
00590   std::vector<double*> data2d(numIDs);
00591 
00592   int i;
00593   for(i=0; i<numIDs; ++i) {
00594     data2d[i] = &(data1[i*numIDs]);
00595   }
00596 
00597   for(i=0; i<numIDs*numIDs; ++i) {
00598     data1[i] = 1.0*i;
00599   }
00600 
00601   CHK_ERR( matrix->sumIn(numIDs, &indices[0],
00602        numIDs, &indices[0], &data2d[0], 0) );
00603 
00604   CHK_ERR( matrix->sumIn(0, 0, &data2d[0], 0) );
00605 
00606   delete matrix;
00607   delete testdata;
00608 
00609   return(0);
00610 }
00611 
00612 int test_Matrix::test1()
00613 {
00614   return(0);
00615 }
00616 
00617 int test_Matrix::test2()
00618 {
00619  return(0);
00620 }
00621 
00622 int test_Matrix::test3()
00623 {
00624 #ifdef HAVE_FEI_FETI
00625   testData* testdata = new testData(localProc_, numProcs_);
00626   std::vector<int>& idTypes = testdata->idTypes;
00627   std::vector<int>& ids = testdata->ids;
00628 
00629   fei::SharedPtr<FiniteElementData> fedata(new FETI_DP_FiniteElementData(comm_));
00630 
00631   std::string paramstr("debugOutput .");
00632   char* param = const_cast<char*>(paramstr.c_str());
00633 
00634   CHK_ERR( fedata->parameters(1, &param) );
00635 
00636   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(fedata, idTypes[0]));
00637 
00638   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00639     test_VectorSpace::create_VectorSpace(comm_,
00640            testdata, localProc_, numProcs_,
00641            false, false, "U_FEMat", factory);
00642 
00643   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00644     test_MatrixGraph::create_MatrixGraph(testdata, localProc_, numProcs_,
00645            false, false, "U_FEMat", vectorSpacePtr,
00646            factory);
00647 
00648   CHK_ERR( matrixGraphPtr->initComplete() );
00649 
00650   fei::SharedPtr<fei::Vector> vec_fed = factory->createVector(vectorSpacePtr);
00651 
00652   fei::SharedPtr<fei::Matrix> mat_fed = factory->createMatrix(matrixGraphPtr);
00653 
00654   fei::Matrix_Impl<FiniteElementData>* smat2 = 
00655     dynamic_cast<fei::Matrix_Impl<FiniteElementData>*>(mat_fed.get());
00656   if (smat2 == NULL) {
00657     ERReturn(-1);
00658   }
00659 
00660   int blockID=0;
00661   int numIndices = matrixGraphPtr->getConnectivityNumIndices(blockID);
00662 
00663   std::vector<int> indicesArray(numIndices);
00664   int* indicesPtr = &indicesArray[0];
00665 
00666   int checkNumIndices = 0;
00667   CHK_ERR( matrixGraphPtr->getConnectivityIndices(blockID, 0,
00668                numIndices, indicesPtr,
00669                checkNumIndices) );
00670 
00671   std::vector<double> data(ids.size(), 1.0);
00672   double* dptr = &data[0];
00673   std::vector<double*> coefPtrs(ids.size(), dptr);
00674 
00675   CHK_ERR( mat_fed->sumIn(blockID, 0, &coefPtrs[0]) );
00676 
00677   CHK_ERR( vec_fed->sumIn(blockID, 0, &data[0]) );
00678 
00679   CHK_ERR( mat_fed->gatherFromOverlap() );
00680 
00681   CHK_ERR( fedata->loadComplete() );
00682 
00683 
00684   delete testdata;
00685 
00686   MPI_Barrier(comm_);
00687 
00688 #endif  //HAVE_FEI_FETI
00689 
00690   return(0);
00691 }
00692 
00693 int test_Matrix::test4()
00694 {
00695   return(0);
00696 }
00697 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends