FEI Version of the Day
test_Algebraic.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_Algebraic.hpp>
00046 
00047 #include <fei_VectorSpace.hpp>
00048 #include <fei_MatrixGraph_Impl2.hpp>
00049 #include <fei_SparseRowGraph.hpp>
00050 
00051 #undef fei_file
00052 #define fei_file "test_Algebraic.cpp"
00053 #include <fei_ErrMacros.hpp>
00054 
00055 test_Algebraic::test_Algebraic(MPI_Comm comm)
00056  : tester(comm)
00057 {
00058 }
00059 
00060 test_Algebraic::~test_Algebraic()
00061 {
00062 }
00063 
00064 int test_Algebraic::runtests()
00065 {
00066   if (numProcs_ < 2) {
00067     CHK_ERR( serialtest1() );
00068     CHK_ERR( serialtest2() );
00069   }
00070 
00071   CHK_ERR( test1() );
00072   CHK_ERR( test2() );
00073   CHK_ERR( test3() );
00074   CHK_ERR( test4() );
00075   return(0);
00076 }
00077 
00078 int test_Algebraic::serialtest1()
00079 {
00080   int i, numRows = 10;
00081   fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm_));
00082 
00083   int idType = 0;
00084 
00085   vspace->defineIDTypes(1, &idType);
00086 
00087   std::vector<int> rowNumbers(numRows);
00088   for(i=0; i<numRows; ++i) {
00089     rowNumbers[i] = i;
00090   }
00091 
00092   CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
00093 
00094   CHK_ERR( vspace->initComplete() );
00095 
00096   int index = -1;
00097   CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
00098 
00099   if (index != 3) {
00100     ERReturn(-1);
00101   }
00102 
00103   int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
00104 
00105   if (numDOF != 1) {
00106     ERReturn(-1);
00107   }
00108 
00109   std::vector<int> globalOffsets;
00110 
00111   vspace->getGlobalIndexOffsets(globalOffsets);
00112 
00113   if (globalOffsets[0] != 0) {
00114     ERReturn(-1);
00115   }
00116 
00117   if (globalOffsets[1] != numRows) {
00118     ERReturn(-1);
00119   }
00120 
00121   fei::SharedPtr<fei::VectorSpace> dummy;
00122   fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
00123 
00124   std::vector<int> rowOffsets(numRows+1);
00125   std::vector<int> packedColumnIDs(numRows);
00126   for(i=0; i<numRows; ++i) {
00127     rowOffsets[i] = i;
00128     packedColumnIDs[i] = i;
00129   }
00130   rowOffsets[numRows] = numRows;
00131 
00132   CHK_ERR( mgraph.initConnectivity(idType, numRows,
00133            &rowNumbers[0],
00134            &rowOffsets[0],
00135            &packedColumnIDs[0]) );
00136 
00137   CHK_ERR( mgraph.initComplete() );
00138 
00139   fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
00140 
00141   int mnumRows = localgraph->rowNumbers.size();
00142   int* mrowOffsets = &(localgraph->rowOffsets[0]);
00143   int mnumNonzeros = localgraph->packedColumnIndices.size();
00144   int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
00145 
00146   if (mnumRows != numRows) {
00147     ERReturn(-1);
00148   }
00149 
00150   if (mnumNonzeros != numRows) {
00151     ERReturn(-1);
00152   }
00153 
00154   for(i=0; i<numRows; ++i) {
00155     if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
00156       ERReturn(-1);
00157     }
00158     if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
00159       ERReturn(-1);
00160     }
00161   }
00162 
00163   return(0);
00164 }
00165 
00166 int test_Algebraic::serialtest2()
00167 {
00168   int i, numRows = 10;
00169   fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm_));
00170 
00171   int idType = 0;
00172 
00173   vspace->defineIDTypes(1, &idType);
00174 
00175   std::vector<int> rowNumbers(numRows);
00176   for(i=0; i<numRows; ++i) {
00177     rowNumbers[i] = i;
00178   }
00179 
00180   CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
00181 
00182   CHK_ERR( vspace->initComplete() );
00183 
00184   int index = -1;
00185   CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
00186 
00187   if (index != 3) {
00188     ERReturn(-1);
00189   }
00190 
00191   int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
00192 
00193   if (numDOF != 1) {
00194     ERReturn(-1);
00195   }
00196 
00197   std::vector<int> globalOffsets;
00198 
00199   vspace->getGlobalIndexOffsets(globalOffsets);
00200 
00201   if (globalOffsets[0] != 0) {
00202     ERReturn(-1);
00203   }
00204 
00205   if (globalOffsets[1] != numRows) {
00206     ERReturn(-1);
00207   }
00208 
00209   fei::SharedPtr<fei::VectorSpace> dummy;
00210   fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
00211 
00212   std::vector<int> rowLengths(numRows);
00213   std::vector<int> packedColumnIDs(numRows);
00214   std::vector<int*> columnIDs(numRows);
00215 
00216   for(i=0; i<numRows; ++i) {
00217     rowLengths[i] = 1;
00218     packedColumnIDs[i] = i;
00219     columnIDs[i] = &(packedColumnIDs[i]);
00220   }
00221 
00222   CHK_ERR( mgraph.initConnectivity(idType, numRows,
00223            &rowNumbers[0],
00224            &rowLengths[0],
00225            &columnIDs[0]) );
00226 
00227   CHK_ERR( mgraph.initComplete() );
00228 
00229   fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
00230 
00231   int mnumRows = localgraph->rowNumbers.size();
00232   int* mrowOffsets = &(localgraph->rowOffsets[0]);
00233   int mnumNonzeros = localgraph->packedColumnIndices.size();
00234   int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
00235 
00236   if (mnumRows != numRows) {
00237     ERReturn(-1);
00238   }
00239 
00240   if (mnumNonzeros != numRows) {
00241     ERReturn(-1);
00242   }
00243 
00244   for(i=0; i<numRows; ++i) {
00245     if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
00246       ERReturn(-1);
00247     }
00248     if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
00249       ERReturn(-1);
00250     }
00251   }
00252 
00253   return(0);
00254 }
00255 
00256 int test_Algebraic::test1()
00257 {
00258   return(0);
00259 }
00260 
00261 int test_Algebraic::test2()
00262 {
00263   return(0);
00264 }
00265 
00266 int test_Algebraic::test3()
00267 {
00268   return(0);
00269 }
00270 
00271 int test_Algebraic::test4()
00272 {
00273   return(0);
00274 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends