test_Factory.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 #include <fei_macros.hpp>
00010 #include <fei_mpi.h>
00011 
00012 #include <test_utils/test_Factory.hpp>
00013 
00014 #include <test_utils/LibraryFactory.hpp>
00015 
00016 #include <test_utils/test_VectorSpace.hpp>
00017 #include <test_utils/test_MatrixGraph.hpp>
00018 
00019 #include <fei_Factory.hpp>
00020 #include <snl_fei_Factory.hpp>
00021 
00022 #include <test_utils/test_Factory_helper.hpp>
00023 
00024 #ifdef HAVE_FEI_AZTECOO
00025 #include <fei_Aztec_LinSysCore.hpp>
00026 #endif
00027 
00028 #include <fei_Factory_Trilinos.hpp>
00029 
00030 #undef fei_file
00031 #define fei_file "test_Factory.cpp"
00032 #include <fei_ErrMacros.hpp>
00033 
00034 test_Factory::test_Factory(MPI_Comm comm)
00035   : tester(comm)
00036 {
00037 }
00038 
00039 test_Factory::~test_Factory()
00040 {
00041 }
00042 
00043 int test_Factory::runtests()
00044 {
00046   {
00047   if (localProc_==0) FEI_COUT << "constructing Factory_Trilinos...";
00048 
00049   fei::SharedPtr<fei::Factory> factory(new Factory_Trilinos(comm_)); 
00050 
00051   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00052 
00053   factory_test1(factory);
00054 
00055   if (localProc_==0) FEI_COUT << "testing fei::Factory::clone..." << FEI_ENDL;
00056 
00057   fei::SharedPtr<fei::Factory> clone(factory->clone());
00058 
00059   factory_test1(clone);
00060 
00061   FEI_COUT << FEI_ENDL;
00062   }
00063 
00064 #ifdef HAVE_FEI_AZTECOO
00066   {
00067   if (localProc_==0) FEI_COUT << "constructing snl_fei::Factory(Aztec)...";
00068 
00069   fei::SharedPtr<LinearSystemCore> az_lsc(new fei_trilinos::Aztec_LinSysCore(comm_));
00070 
00071   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, az_lsc));
00072 
00073   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00074 
00075   factory_test1(factory);
00076 
00077   if (localProc_==0) FEI_COUT << "testing fei::Factory::clone..." << FEI_ENDL;
00078 
00079   fei::SharedPtr<fei::Factory> clone(factory->clone());
00080 
00081   factory_test1(clone);
00082 
00083   FEI_COUT << FEI_ENDL;
00084   }
00085 
00086 #endif
00087   return(0);
00088 }
00089 
00090 void test_Factory::factory_test1(fei::SharedPtr<fei::Factory> factory)
00091 {
00092   if (localProc_==0) FEI_COUT << "  testing factory->createVectorSpace...";
00093 
00094   fei::SharedPtr<fei::VectorSpace> vecspace =
00095     factory->createVectorSpace(comm_, "dummy_Name");
00096 
00097   if (vecspace.get() == 0) {
00098     FEI_COUT << "no"<<FEI_ENDL;
00099     throw std::runtime_error("factory failed to create a fei::VectorSpace");
00100   }
00101 
00102   //do an extremely simple test to make sure the vector-space
00103   //is 'alive'.
00104   int fieldID = 0;
00105   int fieldSize = 3;
00106   vecspace->defineFields(1, &fieldID, &fieldSize);
00107 
00108   if (vecspace->getNumFields() != 1) {
00109     FEI_COUT << "no"<<FEI_ENDL;
00110     throw std::runtime_error("vecspace->defineFields/getNumFields failed.");
00111   }
00112 
00113   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00114 
00115   if (localProc_==0) FEI_COUT << "  testing factory->createFEI...";
00116 
00117   fei::SharedPtr<FEI> fei = factory->createFEI(comm_);
00118 
00119   //again, do a simple test to make sure the FEI instance is alive...
00120 
00121   int err = fei->initFields(1, &fieldSize, &fieldID);
00122   if (err != 0) {
00123     FEI_COUT << "failed"<<FEI_ENDL;
00124     throw std::runtime_error("fei->initFields() failed.");
00125   }
00126 
00127   int testFieldSize = -1;
00128   err = fei->getFieldSize(fieldID, testFieldSize);
00129   if (err != 0 || testFieldSize != fieldSize) {
00130     FEI_COUT << "failed"<<FEI_ENDL;
00131     throw std::runtime_error("fei->getFieldSize() failed.");
00132   }
00133 
00134   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00135 }

Generated on Wed May 12 21:30:42 2010 for FEI by  doxygen 1.4.7