test_SNL_FEI_Structure.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 #include <fei_mpi.h>
00012 
00013 #include <test_utils/test_SNL_FEI_Structure.hpp>
00014 
00015 #include <SNL_FEI_Structure.hpp>
00016 
00017 #include <test_utils/testData.hpp>
00018 
00019 #undef fei_file
00020 #define fei_file "test_SNL_FEI_Structure.cpp"
00021 #include <fei_ErrMacros.hpp>
00022 
00023 test_SNL_FEI_Structure::test_SNL_FEI_Structure(MPI_Comm comm)
00024  : tester(comm)
00025 {
00026 }
00027 
00028 test_SNL_FEI_Structure::~test_SNL_FEI_Structure()
00029 {
00030 }
00031 
00032 int test_SNL_FEI_Structure::runtests()
00033 {
00034   CHK_ERR( test1() );
00035   CHK_ERR( test2() );
00036   CHK_ERR( test3() );
00037   CHK_ERR( test4() );
00038   return(0);
00039 }
00040 
00041 int test_SNL_FEI_Structure::test1()
00042 {
00043   testData* testdata = new testData(localProc_, numProcs_);
00044 
00045   SNL_FEI_Structure structure(comm_);
00046 
00047   CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
00048         &(testdata->fieldSizes[0]),
00049         &(testdata->fieldIDs[0])) );
00050 
00051   int numNodesPerElem = testdata->ids.size();
00052   std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
00053   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00054 
00055   CHK_ERR( structure.initElemBlock(0, //blockID
00056            1, //numElements
00057            numNodesPerElem,
00058            &numFieldsPerNode[0],
00059            &nodalFieldIDs[0],
00060            0, //numElemDofFieldsPerElement
00061            NULL, //elemDofFieldIDs
00062            0)); //interleaveStrategy
00063 
00064   CHK_ERR( structure.initElem(0, //blockID
00065             0, //elemID
00066             &(testdata->ids[0])) );
00067 
00068   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00069   int i, offset = 0;
00070   for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00071     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00072     offset += testdata->numSharingProcsPerID[i];
00073   }
00074 
00075   if (testdata->sharedIDs.size() > 0) {
00076     CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
00077       testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
00078       testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
00079       &sharingProcs2D[0]) );
00080   }
00081 
00082   CHK_ERR( structure.initComplete() );
00083 
00084   int numActiveNodes = structure.getNumActiveNodes();
00085   if (numActiveNodes != (int)testdata->ids.size()) {
00086     ERReturn(-1);
00087   }
00088 
00089   int fieldSize = structure.getFieldSize(testdata->fieldIDs[0]);
00090 
00091   int numLocalEqns = fieldSize*2;
00092   if (localProc_ == 0) numLocalEqns += 2;
00093   int checkNumLocalEqns = structure.getNumLocalEqns();
00094   if (numLocalEqns != checkNumLocalEqns) {
00095     ERReturn(-1);
00096   }
00097 
00098   int numGlobalEqns = fieldSize*(numProcs_*2 + 2);
00099   int checkNumGlobalEqns = structure.getNumGlobalEqns();
00100   if (checkNumGlobalEqns != numGlobalEqns) {
00101     ERReturn(-1);
00102   }
00103 
00104   std::vector<int> rowLengths;
00105   CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
00106 
00107   int numNonzeros = 0;
00108   for(size_t j=0; j<rowLengths.size(); ++j) {
00109     numNonzeros += rowLengths[j];
00110   }
00111 
00112   std::vector<int> colIndices_1d(numNonzeros);
00113   std::vector<int*> colIndPtrs(rowLengths.size());
00114 
00115   offset = 0;
00116   for(size_t j=0; j<rowLengths.size(); ++j) {
00117     colIndPtrs[j] = &(colIndices_1d[offset]);
00118     offset += rowLengths[j];
00119   }
00120 
00121   CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
00122           rowLengths) );
00123 
00124   delete testdata;
00125 
00126   return(0);
00127 }
00128 
00129 int test_SNL_FEI_Structure::test2()
00130 {
00131   testData* testdata = new testData(localProc_, numProcs_);
00132 
00133   SNL_FEI_Structure structure(comm_);
00134 
00135   CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
00136         &(testdata->fieldSizes[0]),
00137         &(testdata->fieldIDs[0])) );
00138 
00139   int numNodesPerElem = testdata->ids.size();
00140   std::vector<int> numFieldsPerNode(numNodesPerElem, testdata->fieldIDs.size());
00141   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00142   std::vector<int> elemDofFieldIDs = testdata->fieldIDs;
00143 
00144   CHK_ERR( structure.initElemBlock(0, //blockID
00145            1, //numElements
00146            numNodesPerElem,
00147            &numFieldsPerNode[0],
00148            &nodalFieldIDs[0],
00149            elemDofFieldIDs.size(),
00150            &elemDofFieldIDs[0],
00151            0)); //interleaveStrategy
00152 
00153   CHK_ERR( structure.initElem(0, //blockID
00154             0, //elemID
00155             &(testdata->ids[0])) );
00156 
00157   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00158   int i, offset = 0;
00159   for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00160     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00161     offset += testdata->numSharingProcsPerID[i];
00162   }
00163 
00164   if (testdata->sharedIDs.size() > 0) {
00165     CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
00166       testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
00167       testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
00168       &sharingProcs2D[0]) );
00169   }
00170 
00171   CHK_ERR( structure.initComplete() );
00172 
00173   int numActiveNodes = structure.getNumActiveNodes();
00174   if (numActiveNodes != (int)testdata->ids.size()) {
00175     ERReturn(-1);
00176   }
00177 
00178   int numEqnsPerNode = 0;
00179   for(i=0; i<(int)testdata->fieldSizes.size(); ++i) {
00180     numEqnsPerNode += testdata->fieldSizes[i];
00181   }
00182 
00183   int numLocalEqns = 3*numEqnsPerNode;//2 nodes + elem-dofs
00184 
00185   if (localProc_ == 0) numLocalEqns += 2*numEqnsPerNode;
00186   int checkNumLocalEqns = structure.getNumLocalEqns();
00187   if (numLocalEqns != checkNumLocalEqns) {
00188     ERReturn(-1);
00189   }
00190 
00191   int numGlobalEqns = (numProcs_*3+2)*numEqnsPerNode;
00192   int checkNumGlobalEqns = structure.getNumGlobalEqns();
00193   if (checkNumGlobalEqns != numGlobalEqns) {
00194     ERReturn(-1);
00195   }
00196 
00197   std::vector<int> rowLengths;
00198   CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
00199 
00200   int numNonzeros = 0;
00201   for(size_t j=0; j<rowLengths.size(); ++j) {
00202     numNonzeros += rowLengths[j];
00203   }
00204 
00205   std::vector<int> colIndices_1d(numNonzeros);
00206   std::vector<int*> colIndPtrs(rowLengths.size());
00207 
00208   offset = 0;
00209   for(size_t j=0; j<rowLengths.size(); ++j) {
00210     colIndPtrs[j] = &(colIndices_1d[offset]);
00211     offset += rowLengths[j];
00212   }
00213 
00214   CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
00215           rowLengths) );
00216 
00217   delete testdata;
00218 
00219   return(0);
00220 }
00221 
00222 int test_SNL_FEI_Structure::test3()
00223 {
00224   return(0);
00225 }
00226 
00227 int test_SNL_FEI_Structure::test4()
00228 {
00229   return(0);
00230 }

Generated on Tue Jul 13 09:27:46 2010 for FEI by  doxygen 1.4.7