FEI Version of the Day
test_Factory.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_Factory.hpp>
00047 
00048 #include <test_utils/LibraryFactory.hpp>
00049 
00050 #include <test_utils/test_VectorSpace.hpp>
00051 #include <test_utils/test_MatrixGraph.hpp>
00052 
00053 #include <fei_Factory.hpp>
00054 #include <snl_fei_Factory.hpp>
00055 
00056 #include <test_utils/test_Factory_helper.hpp>
00057 
00058 #ifdef HAVE_FEI_AZTECOO
00059 #include <fei_Aztec_LinSysCore.hpp>
00060 #endif
00061 
00062 #include <fei_Factory_Trilinos.hpp>
00063 
00064 #undef fei_file
00065 #define fei_file "test_Factory.cpp"
00066 #include <fei_ErrMacros.hpp>
00067 
00068 test_Factory::test_Factory(MPI_Comm comm)
00069   : tester(comm)
00070 {
00071 }
00072 
00073 test_Factory::~test_Factory()
00074 {
00075 }
00076 
00077 int test_Factory::runtests()
00078 {
00080   {
00081   if (localProc_==0) FEI_COUT << "constructing Factory_Trilinos...";
00082 
00083   fei::SharedPtr<fei::Factory> factory(new Factory_Trilinos(comm_)); 
00084 
00085   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00086 
00087   factory_test1(factory);
00088 
00089   if (localProc_==0) FEI_COUT << "testing fei::Factory::clone..." << FEI_ENDL;
00090 
00091   fei::SharedPtr<fei::Factory> clone(factory->clone());
00092 
00093   factory_test1(clone);
00094 
00095   FEI_COUT << FEI_ENDL;
00096   }
00097 
00098 #ifdef HAVE_FEI_AZTECOO
00099 
00100   {
00101   if (localProc_==0) FEI_COUT << "constructing snl_fei::Factory(Aztec)...";
00102 
00103   fei::SharedPtr<LinearSystemCore> az_lsc(new fei_trilinos::Aztec_LinSysCore(comm_));
00104 
00105   fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, az_lsc));
00106 
00107   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00108 
00109   factory_test1(factory);
00110 
00111   if (localProc_==0) FEI_COUT << "testing fei::Factory::clone..." << FEI_ENDL;
00112 
00113   fei::SharedPtr<fei::Factory> clone(factory->clone());
00114 
00115   factory_test1(clone);
00116 
00117   FEI_COUT << FEI_ENDL;
00118   }
00119 
00120 #endif
00121   return(0);
00122 }
00123 
00124 void test_Factory::factory_test1(fei::SharedPtr<fei::Factory> factory)
00125 {
00126   if (localProc_==0) FEI_COUT << "  testing factory->createVectorSpace...";
00127 
00128   fei::SharedPtr<fei::VectorSpace> vecspace =
00129     factory->createVectorSpace(comm_, "dummy_Name");
00130 
00131   if (vecspace.get() == 0) {
00132     FEI_COUT << "no"<<FEI_ENDL;
00133     throw std::runtime_error("factory failed to create a fei::VectorSpace");
00134   }
00135 
00136   //do an extremely simple test to make sure the vector-space
00137   //is 'alive'.
00138   int fieldID = 0;
00139   int fieldSize = 3;
00140   vecspace->defineFields(1, &fieldID, &fieldSize);
00141 
00142   if (vecspace->getNumFields() != 1) {
00143     FEI_COUT << "no"<<FEI_ENDL;
00144     throw std::runtime_error("vecspace->defineFields/getNumFields failed.");
00145   }
00146 
00147   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00148 
00149   if (localProc_==0) FEI_COUT << "  testing factory->createFEI...";
00150 
00151   fei::SharedPtr<FEI> fei = factory->createFEI(comm_);
00152 
00153   //again, do a simple test to make sure the FEI instance is alive...
00154 
00155   int err = fei->initFields(1, &fieldSize, &fieldID);
00156   if (err != 0) {
00157     FEI_COUT << "failed"<<FEI_ENDL;
00158     throw std::runtime_error("fei->initFields() failed.");
00159   }
00160 
00161   int testFieldSize = -1;
00162   err = fei->getFieldSize(fieldID, testFieldSize);
00163   if (err != 0 || testFieldSize != fieldSize) {
00164     FEI_COUT << "failed"<<FEI_ENDL;
00165     throw std::runtime_error("fei->getFieldSize() failed.");
00166   }
00167 
00168   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00169 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends