test_Algebraic.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_Algebraic.hpp>
00013 
00014 #include <fei_VectorSpace.hpp>
00015 #include <fei_MatrixGraph_Impl2.hpp>
00016 #include <fei_SparseRowGraph.hpp>
00017 
00018 #undef fei_file
00019 #define fei_file "test_Algebraic.cpp"
00020 #include <fei_ErrMacros.hpp>
00021 
00022 test_Algebraic::test_Algebraic(MPI_Comm comm)
00023  : tester(comm)
00024 {
00025 }
00026 
00027 test_Algebraic::~test_Algebraic()
00028 {
00029 }
00030 
00031 int test_Algebraic::runtests()
00032 {
00033   if (numProcs_ < 2) {
00034     CHK_ERR( serialtest1() );
00035     CHK_ERR( serialtest2() );
00036   }
00037 
00038   CHK_ERR( test1() );
00039   CHK_ERR( test2() );
00040   CHK_ERR( test3() );
00041   CHK_ERR( test4() );
00042   return(0);
00043 }
00044 
00045 int test_Algebraic::serialtest1()
00046 {
00047   int i, numRows = 10;
00048   fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm_));
00049 
00050   int idType = 0;
00051 
00052   vspace->defineIDTypes(1, &idType);
00053 
00054   std::vector<int> rowNumbers(numRows);
00055   for(i=0; i<numRows; ++i) {
00056     rowNumbers[i] = i;
00057   }
00058 
00059   CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
00060 
00061   CHK_ERR( vspace->initComplete() );
00062 
00063   int index = -1;
00064   CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
00065 
00066   if (index != 3) {
00067     ERReturn(-1);
00068   }
00069 
00070   int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
00071 
00072   if (numDOF != 1) {
00073     ERReturn(-1);
00074   }
00075 
00076   std::vector<int> globalOffsets;
00077 
00078   vspace->getGlobalIndexOffsets(globalOffsets);
00079 
00080   if (globalOffsets[0] != 0) {
00081     ERReturn(-1);
00082   }
00083 
00084   if (globalOffsets[1] != numRows) {
00085     ERReturn(-1);
00086   }
00087 
00088   fei::SharedPtr<fei::VectorSpace> dummy;
00089   fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
00090 
00091   std::vector<int> rowOffsets(numRows+1);
00092   std::vector<int> packedColumnIDs(numRows);
00093   for(i=0; i<numRows; ++i) {
00094     rowOffsets[i] = i;
00095     packedColumnIDs[i] = i;
00096   }
00097   rowOffsets[numRows] = numRows;
00098 
00099   CHK_ERR( mgraph.initConnectivity(idType, numRows,
00100            &rowNumbers[0],
00101            &rowOffsets[0],
00102            &packedColumnIDs[0]) );
00103 
00104   CHK_ERR( mgraph.initComplete() );
00105 
00106   fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
00107 
00108   int mnumRows = localgraph->rowNumbers.size();
00109   int* mrowOffsets = &(localgraph->rowOffsets[0]);
00110   int mnumNonzeros = localgraph->packedColumnIndices.size();
00111   int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
00112 
00113   if (mnumRows != numRows) {
00114     ERReturn(-1);
00115   }
00116 
00117   if (mnumNonzeros != numRows) {
00118     ERReturn(-1);
00119   }
00120 
00121   for(i=0; i<numRows; ++i) {
00122     if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
00123       ERReturn(-1);
00124     }
00125     if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
00126       ERReturn(-1);
00127     }
00128   }
00129 
00130   return(0);
00131 }
00132 
00133 int test_Algebraic::serialtest2()
00134 {
00135   int i, numRows = 10;
00136   fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm_));
00137 
00138   int idType = 0;
00139 
00140   vspace->defineIDTypes(1, &idType);
00141 
00142   std::vector<int> rowNumbers(numRows);
00143   for(i=0; i<numRows; ++i) {
00144     rowNumbers[i] = i;
00145   }
00146 
00147   CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
00148 
00149   CHK_ERR( vspace->initComplete() );
00150 
00151   int index = -1;
00152   CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
00153 
00154   if (index != 3) {
00155     ERReturn(-1);
00156   }
00157 
00158   int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
00159 
00160   if (numDOF != 1) {
00161     ERReturn(-1);
00162   }
00163 
00164   std::vector<int> globalOffsets;
00165 
00166   vspace->getGlobalIndexOffsets(globalOffsets);
00167 
00168   if (globalOffsets[0] != 0) {
00169     ERReturn(-1);
00170   }
00171 
00172   if (globalOffsets[1] != numRows) {
00173     ERReturn(-1);
00174   }
00175 
00176   fei::SharedPtr<fei::VectorSpace> dummy;
00177   fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
00178 
00179   std::vector<int> rowLengths(numRows);
00180   std::vector<int> packedColumnIDs(numRows);
00181   std::vector<int*> columnIDs(numRows);
00182 
00183   for(i=0; i<numRows; ++i) {
00184     rowLengths[i] = 1;
00185     packedColumnIDs[i] = i;
00186     columnIDs[i] = &(packedColumnIDs[i]);
00187   }
00188 
00189   CHK_ERR( mgraph.initConnectivity(idType, numRows,
00190            &rowNumbers[0],
00191            &rowLengths[0],
00192            &columnIDs[0]) );
00193 
00194   CHK_ERR( mgraph.initComplete() );
00195 
00196   fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
00197 
00198   int mnumRows = localgraph->rowNumbers.size();
00199   int* mrowOffsets = &(localgraph->rowOffsets[0]);
00200   int mnumNonzeros = localgraph->packedColumnIndices.size();
00201   int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
00202 
00203   if (mnumRows != numRows) {
00204     ERReturn(-1);
00205   }
00206 
00207   if (mnumNonzeros != numRows) {
00208     ERReturn(-1);
00209   }
00210 
00211   for(i=0; i<numRows; ++i) {
00212     if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
00213       ERReturn(-1);
00214     }
00215     if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
00216       ERReturn(-1);
00217     }
00218   }
00219 
00220   return(0);
00221 }
00222 
00223 int test_Algebraic::test1()
00224 {
00225   return(0);
00226 }
00227 
00228 int test_Algebraic::test2()
00229 {
00230   return(0);
00231 }
00232 
00233 int test_Algebraic::test3()
00234 {
00235   return(0);
00236 }
00237 
00238 int test_Algebraic::test4()
00239 {
00240   return(0);
00241 }

Generated on Wed May 12 21:30:42 2010 for FEI by  doxygen 1.4.7