test_FEI_Impl.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_sstream.hpp>
00012 
00013 #include <test_utils/test_FEI_Impl.hpp>
00014 
00015 #include <fei_FEI_Impl.hpp>
00016 #ifdef HAVE_FEI_AZTECOO
00017 #include <fei_Aztec_LinSysCore.hpp>
00018 #endif
00019 #include <test_utils/FEData.hpp>
00020 #include <fei_LibraryWrapper.hpp>
00021 
00022 #include <test_utils/testData.hpp>
00023 
00024 #undef fei_file
00025 #define fei_file "test_FEI_Impl.cpp"
00026 #include <fei_ErrMacros.hpp>
00027 
00028 test_FEI_Impl::test_FEI_Impl(MPI_Comm comm)
00029  : tester(comm)
00030 {
00031 }
00032 
00033 test_FEI_Impl::~test_FEI_Impl()
00034 {
00035 }
00036 
00037 int test_FEI_Impl::runtests()
00038 {
00039   if (numProcs_<2) {
00040     CHK_ERR( serialtest1() );
00041   }
00042 
00043   CHK_ERR( test1() );
00044   CHK_ERR( test2() );
00045   CHK_ERR( test3() );
00046   CHK_ERR( test4() );
00047   return(0);
00048 }
00049 
00050 int test_FEI_Impl::serialtest1()
00051 {
00052   return(0);
00053 }
00054 
00055 int test_FEI_Impl::compareCoefs(int n,
00056            const double*const* coefs1,
00057            const double*const* coefs2)
00058 {
00059   for(int i=0; i<n; ++i) {
00060     for(int j=0; j<n; ++j) {
00061       double diff = coefs1[i][j] - coefs2[i][j];
00062       if (diff > 1.e-20 || diff < -1.e-20) {
00063   return(-1);
00064       }
00065     }
00066   }
00067 
00068   return(0);
00069 }
00070 
00071 int test_FEI_Impl::test1()
00072 {
00073   if (numProcs_ > 1) {
00074     return(0);
00075   }
00076 #ifdef HAVE_FEI_AZTECOO
00077   testData* testdata = new testData(localProc_, numProcs_);
00078 
00079   fei::SharedPtr<LinearSystemCore> linSys(new fei_trilinos::Aztec_LinSysCore(comm_));
00080   fei::SharedPtr<LibraryWrapper> wrapper(new LibraryWrapper(linSys));
00081   fei::SharedPtr<fei::FEI_Impl> fei(new fei::FEI_Impl(wrapper, comm_, 0));
00082 
00083   std::string param0("name test1");
00084   FEI_OSTRINGSTREAM osstr;
00085   osstr << "debugOutput ";
00086   if (path_.empty()) osstr << ".";
00087   else osstr << path_;
00088 
00089   std::string param1 = osstr.str();
00090 
00091   int numParams = 2;
00092   char** params = new char*[numParams];
00093   params[0] = const_cast<char*>(param0.c_str());
00094   params[1] = const_cast<char*>(param1.c_str());
00095 
00096   //call the parameters function a couple of times to test the fei's internal
00097   //method for merging string lists when parameters is called more than once.
00098   CHK_ERR( fei->parameters(1, &params[0]) );
00099   CHK_ERR( fei->parameters(1, &params[1]) );
00100   CHK_ERR( fei->parameters(2, params) );
00101 
00102   delete [] params;
00103 
00104   CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
00105          1, &(testdata->ids[0])) );
00106 
00107   CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
00108         &(testdata->fieldSizes[0]),
00109         &(testdata->fieldIDs[0])) );
00110 
00111   int numNodesPerElem = testdata->ids.size();
00112   std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
00113   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00114 
00115   CHK_ERR( fei->initElemBlock(0, //blockID
00116            1, //numElements
00117            numNodesPerElem,
00118            &numFieldsPerNode[0],
00119            &nodalFieldIDs[0],
00120            0, //numElemDofFieldsPerElement
00121            NULL, //elemDofFieldIDs
00122            0)); //interleaveStrategy
00123 
00124   CHK_ERR( fei->initElem(0, //blockID
00125             0, //elemID
00126             &(testdata->ids[0])) );
00127 
00128   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00129   int offset = 0;
00130   for(int i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00131     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00132     offset += testdata->numSharingProcsPerID[i];
00133   }
00134 
00135   if (testdata->sharedIDs.size() > 0) {
00136     CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
00137              &(testdata->sharedIDs[0]),
00138              &(testdata->numSharingProcsPerID[0]),
00139              &sharingProcs2D[0]) );
00140   }
00141 
00142   CHK_ERR( fei->initComplete() );
00143 
00144   std::vector<double> rhsData(testdata->ids.size(), 1.0);
00145 
00146   double one = 1.0;
00147   CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
00148   CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
00149 
00150   CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
00151   CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
00152 
00153   CHK_ERR( fei->putIntoRHS(FEI_NODE, testdata->fieldIDs[0],
00154          testdata->ids.size(),
00155          &(testdata->ids[0]),
00156          &rhsData[0]) );
00157 
00158   int numBCNodes = 2;
00159   GlobalID* BCNodeIDs = &(testdata->ids[0]);
00160   int BCFieldID = testdata->fieldIDs[0];
00161   double* values = new double[numBCNodes];
00162   int* offsetsIntoField = new int[numBCNodes];
00163   for(int ii=0; ii<numBCNodes; ++ii) {
00164     values[ii] = 1.0;
00165     offsetsIntoField[ii] = 0;
00166   }
00167 
00168   CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
00169           offsetsIntoField, values) );
00170 
00171   delete [] offsetsIntoField;
00172   delete [] values;
00173 
00174   CHK_ERR( fei->loadComplete() );
00175 
00176   int numActiveNodes = 0;
00177   CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
00178   if (numActiveNodes != (int)testdata->ids.size()) {
00179     ERReturn(-1);
00180   }
00181 
00182   GlobalID* localNodes = new GlobalID[numActiveNodes];
00183   CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
00184 
00185   int totalFieldSize = 0;
00186   for(int ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
00187     totalFieldSize += testdata->fieldSizes[ii];
00188   }
00189 
00190   double* soln = new double[numActiveNodes*totalFieldSize];
00191   int* offsets = new int[numActiveNodes+1];
00192 
00193   CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
00194          offsets, soln) );
00195   delete [] offsets;
00196   delete [] soln;
00197   delete [] localNodes;
00198 
00199   CHK_ERR( fei->resetInitialGuess() );
00200 
00201   int fieldSize = 0;
00202   CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
00203 
00204   double initTime, loadTime, solveTime, solnReturnTime;
00205   CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
00206               solnReturnTime) );
00207 
00208   delete testdata;
00209 #endif
00210   return(0);
00211 }
00212 
00213 int test_FEI_Impl::test2()
00214 {
00215   fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
00216   fei::SharedPtr<FiniteElementData> fedata(new FEData(comm_));
00217   fei::SharedPtr<LibraryWrapper> wrapper(new LibraryWrapper(fedata));
00218   fei::SharedPtr<fei::FEI_Impl> fei(new fei::FEI_Impl(wrapper, comm_, 0));
00219 
00220   std::string param0("name test1");
00221   FEI_OSTRINGSTREAM osstr;
00222   osstr << "debugOutput ";
00223   if (path_.empty()) osstr << ".";
00224   else osstr << path_;
00225 
00226   std::string param1 = osstr.str();
00227 
00228   int numParams = 2;
00229   char** params = new char*[numParams];
00230   params[0] = const_cast<char*>(param0.c_str());
00231   params[1] = const_cast<char*>(param1.c_str());
00232 
00233   //call the parameters function a couple of times to test the fei's internal
00234   //method for merging string lists when parameters is called more than once.
00235   CHK_ERR( fei->parameters(1, &params[0]) );
00236   CHK_ERR( fei->parameters(1, &params[1]) );
00237   CHK_ERR( fei->parameters(2, params) );
00238 
00239   delete [] params;
00240 
00241   CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
00242          1, &(testdata->ids[0])) );
00243   CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
00244         &(testdata->fieldSizes[0]),
00245         &(testdata->fieldIDs[0])) );
00246 
00247   int numNodesPerElem = testdata->ids.size();
00248   std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
00249   std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
00250 
00251   CHK_ERR( fei->initElemBlock(0, //blockID
00252            1, //numElements
00253            numNodesPerElem,
00254            &numFieldsPerNode[0],
00255            &nodalFieldIDs[0],
00256            0, //numElemDofFieldsPerElement
00257            NULL, //elemDofFieldIDs
00258            0)); //interleaveStrategy
00259 
00260   CHK_ERR( fei->initElem(0, //blockID
00261             0, //elemID
00262             &(testdata->ids[0])) );
00263 
00264   std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
00265   int i, offset = 0;
00266   for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
00267     sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
00268     offset += testdata->numSharingProcsPerID[i];
00269   }
00270 
00271   if (testdata->sharedIDs.size() > 0) {
00272     CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
00273              &(testdata->sharedIDs[0]),
00274              &(testdata->numSharingProcsPerID[0]),
00275              &sharingProcs2D[0]) );
00276   }
00277 
00278   CHK_ERR( fei->initComplete() );
00279 
00280   std::vector<double> rhsData(testdata->ids.size(), 1.0);
00281 
00282   double one = 1.0;
00283   CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
00284   CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
00285 
00286   CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
00287   CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
00288 
00289   int ii;
00290 
00291   int numBCNodes = 2;
00292   GlobalID* BCNodeIDs = &(testdata->ids[0]);
00293   int BCFieldID = testdata->fieldIDs[0];
00294   double* values = new double[numBCNodes];
00295   int* offsetsIntoField = new int[numBCNodes];
00296   for(ii=0; ii<numBCNodes; ++ii) {
00297     values[ii] = 1.0;
00298     offsetsIntoField[ii] = 0;
00299   }
00300 
00301   CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
00302           offsetsIntoField, values) );
00303 
00304   delete [] values;
00305   delete [] offsetsIntoField;
00306 
00307   CHK_ERR( fei->loadComplete() );
00308 
00309   int numActiveNodes = 0;
00310   CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
00311   if (numActiveNodes != (int)testdata->ids.size()) {
00312     ERReturn(-1);
00313   }
00314 
00315   GlobalID* localNodes = new GlobalID[numActiveNodes];
00316   CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
00317 
00318   int totalFieldSize = 0;
00319   for(ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
00320     totalFieldSize += testdata->fieldSizes[ii];
00321   }
00322 
00323   double* soln = new double[numActiveNodes*totalFieldSize];
00324   int* offsets = new int[numActiveNodes+1];
00325 
00326   CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
00327          offsets, soln) );
00328   delete [] offsets;
00329   delete [] soln;
00330   delete [] localNodes;
00331 
00332   CHK_ERR( fei->resetInitialGuess() );
00333 
00334   int fieldSize = 0;
00335   CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
00336 
00337   double initTime, loadTime, solveTime, solnReturnTime;
00338   CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
00339               solnReturnTime) );
00340 
00341   return(0);
00342 }
00343 
00344 int test_FEI_Impl::test3()
00345 {
00346   return(0);
00347 }
00348 
00349 int test_FEI_Impl::test4()
00350 {
00351   return(0);
00352 }

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