FEI Version of the Day
test_SNL_FEI_Structure.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 #include <fei_mpi.h>
00045 
00046 #include <test_utils/test_SNL_FEI_Structure.hpp>
00047 
00048 #include <SNL_FEI_Structure.hpp>
00049 
00050 #include <test_utils/testData.hpp>
00051 
00052 #undef fei_file
00053 #define fei_file "test_SNL_FEI_Structure.cpp"
00054 #include <fei_ErrMacros.hpp>
00055 
00056 test_SNL_FEI_Structure::test_SNL_FEI_Structure(MPI_Comm comm)
00057  : tester(comm)
00058 {
00059 }
00060 
00061 test_SNL_FEI_Structure::~test_SNL_FEI_Structure()
00062 {
00063 }
00064 
00065 int test_SNL_FEI_Structure::runtests()
00066 {
00067   CHK_ERR( test1() );
00068   CHK_ERR( test2() );
00069   CHK_ERR( test3() );
00070   CHK_ERR( test4() );
00071   return(0);
00072 }
00073 
00074 int test_SNL_FEI_Structure::test1()
00075 {
00076   testData* testdata = new testData(localProc_, numProcs_);
00077 
00078   SNL_FEI_Structure structure(comm_);
00079 
00080   CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
00081         &(testdata->fieldSizes[0]),
00082         &(testdata->fieldIDs[0])) );
00083 
00084   int numNodesPerElem = testdata->ids.size();
00085   std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
00086   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00087 
00088   CHK_ERR( structure.initElemBlock(0, //blockID
00089            1, //numElements
00090            numNodesPerElem,
00091            &numFieldsPerNode[0],
00092            &nodalFieldIDs[0],
00093            0, //numElemDofFieldsPerElement
00094            NULL, //elemDofFieldIDs
00095            0)); //interleaveStrategy
00096 
00097   CHK_ERR( structure.initElem(0, //blockID
00098             0, //elemID
00099             &(testdata->ids[0])) );
00100 
00101   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00102   int i, offset = 0;
00103   for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00104     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00105     offset += testdata->numSharingProcsPerID[i];
00106   }
00107 
00108   if (testdata->sharedIDs.size() > 0) {
00109     CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
00110       testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
00111       testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
00112       &sharingProcs2D[0]) );
00113   }
00114 
00115   CHK_ERR( structure.initComplete() );
00116 
00117   int numActiveNodes = structure.getNumActiveNodes();
00118   if (numActiveNodes != (int)testdata->ids.size()) {
00119     ERReturn(-1);
00120   }
00121 
00122   int fieldSize = structure.getFieldSize(testdata->fieldIDs[0]);
00123 
00124   int numLocalEqns = fieldSize*2;
00125   if (localProc_ == 0) numLocalEqns += 2;
00126   int checkNumLocalEqns = structure.getNumLocalEqns();
00127   if (numLocalEqns != checkNumLocalEqns) {
00128     ERReturn(-1);
00129   }
00130 
00131   int numGlobalEqns = fieldSize*(numProcs_*2 + 2);
00132   int checkNumGlobalEqns = structure.getNumGlobalEqns();
00133   if (checkNumGlobalEqns != numGlobalEqns) {
00134     ERReturn(-1);
00135   }
00136 
00137   std::vector<int> rowLengths;
00138   CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
00139 
00140   int numNonzeros = 0;
00141   for(size_t j=0; j<rowLengths.size(); ++j) {
00142     numNonzeros += rowLengths[j];
00143   }
00144 
00145   std::vector<int> colIndices_1d(numNonzeros);
00146   std::vector<int*> colIndPtrs(rowLengths.size());
00147 
00148   offset = 0;
00149   for(size_t j=0; j<rowLengths.size(); ++j) {
00150     colIndPtrs[j] = &(colIndices_1d[offset]);
00151     offset += rowLengths[j];
00152   }
00153 
00154   CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
00155           rowLengths) );
00156 
00157   delete testdata;
00158 
00159   return(0);
00160 }
00161 
00162 int test_SNL_FEI_Structure::test2()
00163 {
00164   testData* testdata = new testData(localProc_, numProcs_);
00165 
00166   SNL_FEI_Structure structure(comm_);
00167 
00168   CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
00169         &(testdata->fieldSizes[0]),
00170         &(testdata->fieldIDs[0])) );
00171 
00172   int numNodesPerElem = testdata->ids.size();
00173   std::vector<int> numFieldsPerNode(numNodesPerElem, testdata->fieldIDs.size());
00174   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00175   std::vector<int> elemDofFieldIDs = testdata->fieldIDs;
00176 
00177   CHK_ERR( structure.initElemBlock(0, //blockID
00178            1, //numElements
00179            numNodesPerElem,
00180            &numFieldsPerNode[0],
00181            &nodalFieldIDs[0],
00182            elemDofFieldIDs.size(),
00183            &elemDofFieldIDs[0],
00184            0)); //interleaveStrategy
00185 
00186   CHK_ERR( structure.initElem(0, //blockID
00187             0, //elemID
00188             &(testdata->ids[0])) );
00189 
00190   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00191   int i, offset = 0;
00192   for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00193     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00194     offset += testdata->numSharingProcsPerID[i];
00195   }
00196 
00197   if (testdata->sharedIDs.size() > 0) {
00198     CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
00199       testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
00200       testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
00201       &sharingProcs2D[0]) );
00202   }
00203 
00204   CHK_ERR( structure.initComplete() );
00205 
00206   int numActiveNodes = structure.getNumActiveNodes();
00207   if (numActiveNodes != (int)testdata->ids.size()) {
00208     ERReturn(-1);
00209   }
00210 
00211   int numEqnsPerNode = 0;
00212   for(i=0; i<(int)testdata->fieldSizes.size(); ++i) {
00213     numEqnsPerNode += testdata->fieldSizes[i];
00214   }
00215 
00216   int numLocalEqns = 3*numEqnsPerNode;//2 nodes + elem-dofs
00217 
00218   if (localProc_ == 0) numLocalEqns += 2*numEqnsPerNode;
00219   int checkNumLocalEqns = structure.getNumLocalEqns();
00220   if (numLocalEqns != checkNumLocalEqns) {
00221     ERReturn(-1);
00222   }
00223 
00224   int numGlobalEqns = (numProcs_*3+2)*numEqnsPerNode;
00225   int checkNumGlobalEqns = structure.getNumGlobalEqns();
00226   if (checkNumGlobalEqns != numGlobalEqns) {
00227     ERReturn(-1);
00228   }
00229 
00230   std::vector<int> rowLengths;
00231   CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
00232 
00233   int numNonzeros = 0;
00234   for(size_t j=0; j<rowLengths.size(); ++j) {
00235     numNonzeros += rowLengths[j];
00236   }
00237 
00238   std::vector<int> colIndices_1d(numNonzeros);
00239   std::vector<int*> colIndPtrs(rowLengths.size());
00240 
00241   offset = 0;
00242   for(size_t j=0; j<rowLengths.size(); ++j) {
00243     colIndPtrs[j] = &(colIndices_1d[offset]);
00244     offset += rowLengths[j];
00245   }
00246 
00247   CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
00248           rowLengths) );
00249 
00250   delete testdata;
00251 
00252   return(0);
00253 }
00254 
00255 int test_SNL_FEI_Structure::test3()
00256 {
00257   return(0);
00258 }
00259 
00260 int test_SNL_FEI_Structure::test4()
00261 {
00262   return(0);
00263 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends