test_LinearSystem.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_LinearSystem.hpp>
00013 #include <test_utils/test_VectorSpace.hpp>
00014 #include <test_utils/test_MatrixGraph.hpp>
00015 #include <snl_fei_Factory.hpp>
00016 #include <fei_Vector.hpp>
00017 #include <fei_Matrix.hpp>
00018 #include <snl_fei_LinearSystem_General.hpp>
00019 
00020 #include <test_utils/LibraryFactory.hpp>
00021 
00022 #ifdef HAVE_FEI_AZTECOO
00023 #include <fei_Aztec_LinSysCore.hpp>
00024 #endif
00025 
00026 #undef fei_file
00027 #define fei_file "test_LinearSystem.cpp"
00028 #include <fei_ErrMacros.hpp>
00029 
00030 test_LinearSystem::test_LinearSystem(MPI_Comm comm)
00031  : tester(comm)
00032 {
00033 }
00034 
00035 test_LinearSystem::~test_LinearSystem()
00036 {
00037 }
00038 
00039 int test_LinearSystem::runtests()
00040 {
00041   CHK_ERR( test1() );
00042   CHK_ERR( test2() );
00043   CHK_ERR( test3() );
00044   CHK_ERR( test4() );
00045   CHK_ERR( test5() );
00046 
00047   return(0);
00048 }
00049 
00050 int test_LinearSystem::test1()
00051 {
00052   return(0);
00053 }
00054 
00055 int test_LinearSystem::test2()
00056 {
00057 #ifdef HAVE_FEI_AZTECOO
00058   fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
00059   std::vector<int>& fieldIDs = testdata->fieldIDs;
00060   std::vector<int>& idTypes = testdata->idTypes;
00061   std::vector<int>& ids = testdata->ids;
00062 
00063   fei::SharedPtr<LinearSystemCore> az_lsc(new fei_trilinos::Aztec_LinSysCore(comm_));
00064 
00065   char* param = new char[64];
00066   sprintf(param,"debugOutput .");
00067 
00068   CHK_ERR( az_lsc->parameters(1, &param) );
00069   delete [] param;
00070 
00071   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, az_lsc));
00072 
00073   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00074     test_VectorSpace::create_VectorSpace(comm_,
00075            testdata.get(), localProc_, numProcs_,
00076            false, false, "U_LS2", factory);
00077 
00078   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00079     test_MatrixGraph::create_MatrixGraph(testdata.get(), localProc_, numProcs_,
00080            false, false, "U_LS2", vectorSpacePtr,
00081            factory, path_);
00082 
00083   std::vector<int> crIDTypes(2);
00084   std::vector<int> crFieldIDs(2);
00085   crIDTypes[0] = idTypes[0]; crIDTypes[1] = idTypes[0];
00086   crFieldIDs[0] = fieldIDs[0]; crFieldIDs[1] = fieldIDs[0];
00087 
00088   CHK_ERR( matrixGraphPtr->initLagrangeConstraint(0, idTypes[1],
00089               2, //numIDs
00090               &crIDTypes[0],
00091               &(ids[1]),
00092               &crFieldIDs[0]) );
00093 
00094   CHK_ERR( matrixGraphPtr->initComplete() );
00095 
00096   fei::SharedPtr<fei::Vector> vec_lsc = factory->createVector(vectorSpacePtr);
00097 
00098   fei::SharedPtr<fei::Vector> vec_lsc2 = factory->createVector(vectorSpacePtr, true);
00099 
00100   fei::SharedPtr<fei::Matrix> mat_lsc = factory->createMatrix(matrixGraphPtr);
00101 
00102   fei::SharedPtr<fei::LinearSystem> linsys = factory->createLinearSystem(matrixGraphPtr);
00103   linsys->setMatrix(mat_lsc);
00104   linsys->setSolutionVector(vec_lsc2);
00105   linsys->setRHS(vec_lsc);
00106 
00107   int blockID=0;
00108   int numIndices = matrixGraphPtr->getConnectivityNumIndices(blockID);
00109 
00110   std::vector<int> indicesArray(numIndices);
00111   int* indicesPtr = &indicesArray[0];
00112 
00113   int checkNumIndices = 0;
00114   CHK_ERR( matrixGraphPtr->getConnectivityIndices(blockID, 0,
00115                numIndices, indicesPtr,
00116                checkNumIndices) );
00117 
00118   std::vector<double> data(ids.size(), 1.0);
00119   double* dptr = &data[0];
00120   std::vector<double*> coefPtrs(ids.size());
00121   std::vector<double> crdata(2);
00122   crdata[0] = 1.0;
00123   crdata[1] = -1.0;
00124 
00125   for(unsigned ii=0; ii<ids.size(); ++ii) coefPtrs[ii] = dptr;
00126 
00127   CHK_ERR( mat_lsc->sumIn(numIndices, indicesPtr, numIndices, indicesPtr,
00128         &coefPtrs[0]) );
00129 
00130   CHK_ERR( vec_lsc->sumInFieldData(fieldIDs[0], idTypes[0],
00131             ids.size(), &ids[0],
00132             &data[0]) );
00133 
00134   CHK_ERR( linsys->loadLagrangeConstraint(0, &crdata[0], 0.0) );
00135 
00136   CHK_ERR( mat_lsc->gatherFromOverlap() );
00137 
00138   CHK_ERR( az_lsc->matrixLoadComplete() );
00139 
00140    CHK_ERR( linsys->loadComplete() );
00141 
00142   std::vector<int> crindices;
00143   linsys->getConstrainedEqns(crindices);
00144   if (crindices.size() != 2) {
00145     ERReturn(-7);
00146   }
00147 
00148   CHK_ERR( az_lsc->writeSystem("U_LS2") );
00149 
00150   MPI_Barrier(comm_);
00151 #endif
00152 
00153   return(0);
00154 }
00155 
00156 int test_LinearSystem::test3()
00157 {
00158 #ifdef HAVE_FEI_AZTECOO
00159   fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
00160   std::vector<int>& fieldIDs = testdata->fieldIDs;
00161   std::vector<int>& idTypes = testdata->idTypes;
00162   std::vector<int>& ids = testdata->ids;
00163 
00164   fei::SharedPtr<LinearSystemCore> az_lsc(new fei_trilinos::Aztec_LinSysCore(comm_));
00165 
00166   char* param = new char[64];
00167   sprintf(param,"debugOutput .");
00168 
00169   CHK_ERR( az_lsc->parameters(1, &param) );
00170 
00171   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, az_lsc));
00172 
00173   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00174     test_VectorSpace::create_VectorSpace(comm_,
00175            testdata.get(), localProc_, numProcs_,
00176            false, false, "U_LS3", factory);
00177 
00178   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00179     test_MatrixGraph::create_MatrixGraph(testdata.get(), localProc_, numProcs_,
00180            false, false, "U_LS3", vectorSpacePtr,
00181            factory, path_);
00182 
00183   std::vector<int> crIDTypes(2);
00184   std::vector<int> crFieldIDs(2);
00185   crIDTypes[0] = idTypes[0]; crIDTypes[1] = idTypes[0];
00186   crFieldIDs[0] = fieldIDs[0]; crFieldIDs[1] = fieldIDs[0];
00187 
00188   CHK_ERR( matrixGraphPtr->initPenaltyConstraint(0, idTypes[1],
00189               2, //numIDs
00190               &crIDTypes[0],
00191               &(ids[1]),
00192               &crFieldIDs[0]) );
00193 
00194   CHK_ERR( matrixGraphPtr->initComplete() );
00195 
00196   fei::SharedPtr<fei::Vector> vec_lsc = factory->createVector(vectorSpacePtr);
00197 
00198   fei::SharedPtr<fei::Vector> vec_lsc2 = factory->createVector(vectorSpacePtr, true);
00199 
00200   fei::SharedPtr<fei::Matrix> mat_lsc = factory->createMatrix(matrixGraphPtr);
00201 
00202   fei::SharedPtr<fei::LinearSystem> linsys = factory->createLinearSystem(matrixGraphPtr);
00203   CHK_ERR( linsys->parameters(1, &param) );
00204   delete [] param;
00205 
00206   linsys->setMatrix(mat_lsc);
00207   linsys->setSolutionVector(vec_lsc2);
00208   linsys->setRHS(vec_lsc);
00209 
00210   int blockID=0;
00211   int numIndices = matrixGraphPtr->getConnectivityNumIndices(blockID);
00212 
00213   std::vector<int> indicesArray(numIndices);
00214   int* indicesPtr = &indicesArray[0];
00215 
00216   int checkNumIndices = 0;
00217   CHK_ERR( matrixGraphPtr->getConnectivityIndices(blockID, 0,
00218                numIndices, indicesPtr,
00219                checkNumIndices) );
00220 
00221   std::vector<double> data(ids.size(), 1.0);
00222   double* dptr = &data[0];
00223   std::vector<double*> coefPtrs(ids.size());
00224   std::vector<double> crdata(2);
00225   crdata[0] = 1.0;
00226   crdata[1] = -1.0;
00227 
00228   for(unsigned ii=0; ii<ids.size(); ++ii) coefPtrs[ii] = dptr;
00229 
00230   CHK_ERR( mat_lsc->sumIn(numIndices, indicesPtr, numIndices, indicesPtr,
00231         &coefPtrs[0]) );
00232 
00233   CHK_ERR( vec_lsc->sumInFieldData(fieldIDs[0], idTypes[0],
00234             ids.size(), &ids[0],
00235             &data[0]) );
00236 
00237   CHK_ERR( linsys->loadPenaltyConstraint(0, &crdata[0], 100.0, 0.0) );
00238 
00239   CHK_ERR( mat_lsc->gatherFromOverlap() );
00240 
00241   CHK_ERR( az_lsc->matrixLoadComplete() );
00242 
00243    CHK_ERR( linsys->loadComplete() );
00244 
00245   CHK_ERR( az_lsc->writeSystem("U_LS3") );
00246 
00247   MPI_Barrier(comm_);
00248 #endif
00249 
00250   return(0);
00251 }
00252 
00253 int test_LinearSystem::test4()
00254 {
00255 #ifdef HAVE_FEI_AZTECOO
00256   fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
00257   std::vector<int>& fieldIDs = testdata->fieldIDs;
00258   std::vector<int>& idTypes = testdata->idTypes;
00259   std::vector<int>& ids = testdata->ids;
00260 
00261   fei::SharedPtr<LinearSystemCore> az_lsc(new fei_trilinos::Aztec_LinSysCore(comm_));
00262 
00263   char* param = new char[64];
00264   sprintf(param,"debugOutput .");
00265 
00266   CHK_ERR( az_lsc->parameters(1, &param) );
00267   delete [] param;
00268 
00269   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, az_lsc));
00270 
00271   fei::SharedPtr<fei::VectorSpace> vectorSpacePtr =
00272     test_VectorSpace::create_VectorSpace(comm_,
00273            testdata.get(), localProc_, numProcs_,
00274            false, false, "U_LS4", factory);
00275 
00276   fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr =
00277     test_MatrixGraph::create_MatrixGraph(testdata.get(), localProc_, numProcs_,
00278            false, false, "U_LS4", vectorSpacePtr,
00279            factory, path_);
00280 
00281   std::vector<int> crIDTypes(2);
00282   std::vector<int> crFieldIDs(2);
00283   crIDTypes[0] = idTypes[0]; crIDTypes[1] = idTypes[0];
00284   crFieldIDs[0] = fieldIDs[0]; crFieldIDs[1] = fieldIDs[0];
00285 
00286   CHK_ERR( matrixGraphPtr->initLagrangeConstraint(0, idTypes[1],
00287               2, //numIDs
00288               &crIDTypes[0],
00289               &(ids[1]),
00290               &crFieldIDs[0]) );
00291 
00292   CHK_ERR( matrixGraphPtr->initComplete() );
00293 
00294   fei::SharedPtr<fei::Vector> vec_lsc = factory->createVector(vectorSpacePtr);
00295 
00296   fei::SharedPtr<fei::Vector> vec_lsc2 = factory->createVector(vectorSpacePtr, true);
00297 
00298   fei::SharedPtr<fei::Matrix> mat_lsc = factory->createMatrix(matrixGraphPtr);
00299 
00300   fei::SharedPtr<fei::LinearSystem> linsys = factory->createLinearSystem(matrixGraphPtr);
00301   linsys->setMatrix(mat_lsc);
00302   linsys->setSolutionVector(vec_lsc2);
00303   linsys->setRHS(vec_lsc);
00304 
00305   int blockID=0;
00306   int numIndices = matrixGraphPtr->getConnectivityNumIndices(blockID);
00307 
00308   std::vector<int> indicesArray(numIndices);
00309   int* indicesPtr = &indicesArray[0];
00310 
00311   int checkNumIndices = 0;
00312   CHK_ERR( matrixGraphPtr->getConnectivityIndices(blockID, 0,
00313                numIndices, indicesPtr,
00314                checkNumIndices) );
00315 
00316   std::vector<double> data(ids.size(), 1.0);
00317   double* dptr = &data[0];
00318   std::vector<double*> coefPtrs(ids.size());
00319   std::vector<double> crdata(2);
00320   crdata[0] = 1.0;
00321   crdata[1] = -1.0;
00322 
00323   for(unsigned ii=0; ii<ids.size(); ++ii) coefPtrs[ii] = dptr;
00324 
00325   CHK_ERR( mat_lsc->sumIn(numIndices, indicesPtr, numIndices, indicesPtr,
00326         &coefPtrs[0]) );
00327 
00328   CHK_ERR( vec_lsc->sumInFieldData(fieldIDs[0], idTypes[0],
00329            ids.size(), &ids[0], &data[0]) );
00330 
00331   CHK_ERR( linsys->loadLagrangeConstraint(0, &crdata[0], 0.0) );
00332 
00333   CHK_ERR( mat_lsc->gatherFromOverlap() );
00334 
00335   CHK_ERR( az_lsc->matrixLoadComplete() );
00336 
00337   CHK_ERR( linsys->loadComplete() );
00338 
00339   CHK_ERR( az_lsc->writeSystem("U_LS4") );
00340 
00341   MPI_Barrier(comm_);
00342 #endif
00343 
00344   return(0);
00345 }
00346 
00347 int test_LinearSystem::test5()
00348 {
00349   return(0);
00350 }
00351 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:25 2011 for FEI by  doxygen 1.6.3