FEI Version of the Day
test_Vector.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 <cmath>
00011 #include <test_utils/test_Vector.hpp>
00012 #include <test_utils/test_VectorSpace.hpp>
00013 #include <test_utils/test_MatrixGraph.hpp>
00014 
00015 #include <fei_Factory.hpp>
00016 #include <snl_fei_Factory.hpp>
00017 #include <fei_Vector_Impl.hpp>
00018 
00019 #include <test_utils/LibraryFactory.hpp>
00020 
00021 #ifdef HAVE_FEI_AZTECOO
00022 #include <fei_Aztec_LinSysCore.hpp>
00023 #endif
00024 #include <fei_Factory_Trilinos.hpp>
00025 
00026 #undef fei_file
00027 #define fei_file "test_Vector.cpp"
00028 #include <fei_ErrMacros.hpp>
00029 
00030 
00031 test_Vector::test_Vector(MPI_Comm comm)
00032   : tester(comm)
00033 {
00034 }
00035 
00036 test_Vector::~test_Vector()
00037 {
00038 }
00039 
00040 int test_Vector::runtests()
00041 {
00042   //-------------------------------
00043   // We'll test the vector produced by Factory_Trilinos 
00044   fei::SharedPtr<fei::Factory> factory_trilinos(new Factory_Trilinos(comm_));
00045 
00046   if (localProc_==0) FEI_COUT << "getting fei::Vector from Factory_Trilinos..."
00047             << FEI_ENDL;
00048   fei::SharedPtr<fei::Vector> fei_vec = create_vector(factory_trilinos);
00049 
00050   vector_test1(fei_vec);
00051 
00052   if (localProc_==0) FEI_COUT << FEI_ENDL;
00053 
00054   return(0);
00055 }
00056 
00057 fei::SharedPtr<fei::Vector>
00058 test_Vector::create_vector(fei::SharedPtr<fei::Factory> factory)
00059 {
00060   testData test_data(localProc_, numProcs_);
00061 
00062   fei::SharedPtr<fei::VectorSpace> vspace =
00063     test_VectorSpace::create_VectorSpace(comm_, &test_data, localProc_, numProcs_,
00064            false, false, (const char*)0, factory);
00065   int err = vspace->initComplete();
00066   if (err != 0) {
00067     FEI_COUT << "ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL;
00068     throw std::runtime_error("test_Vector::create_vector: ERROR, failed to create valid fei::VectorSpace.");
00069   }
00070 
00071   if (localProc_==0) FEI_COUT << "  creating fei::Vector instance... ";
00072 
00073   fei::SharedPtr<fei::Vector> vec = factory->createVector(vspace);
00074 
00075   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00076 
00077   return(vec);
00078 }
00079 
00080 void test_Vector::vector_test1(fei::SharedPtr<fei::Vector> fei_vec)
00081 {
00082   if (localProc_==0)
00083   FEI_COUT << "  vector_test1: testing fei::Vector with type '"
00084      << fei_vec->typeName() << "':"<<FEI_ENDL;
00085 
00086   fei::SharedPtr<fei::VectorSpace> vspace = fei_vec->getVectorSpace();
00087 
00088   std::vector<int> global_offsets;
00089   vspace->getGlobalIndexOffsets(global_offsets);
00090 
00091   int i, my_first_offset = global_offsets[localProc_];
00092   int my_last_offset = global_offsets[localProc_+1]-1;
00093   int num_local_indices = my_last_offset - my_first_offset + 1;
00094 
00095   std::vector<double> coefs(num_local_indices, 1.0);
00096   std::vector<double> check_coefs(num_local_indices);
00097   std::vector<int> indices(num_local_indices);
00098   for(i=0; i<num_local_indices; ++i) {
00099     indices[i] = my_first_offset + i;
00100   }
00101 
00102   if (localProc_==0)
00103     FEI_COUT << "   testing fei::Vector::copyIn/copyOut...";
00104 
00105   int errcode = fei_vec->copyIn(num_local_indices, &indices[0], &coefs[0]);
00106   if (errcode != 0) {
00107     throw std::runtime_error("nonzero errcode from fei_vec->copyIn");
00108   }
00109 
00110   errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
00111   if (errcode != 0) {
00112     throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
00113   }
00114 
00115   if (coefs != check_coefs) {
00116     throw std::runtime_error("fei_vec->copyOut didn't produce the right coefs");
00117   }
00118 
00119   if (localProc_==0)
00120     FEI_COUT << "ok"<<FEI_ENDL << "   testing fei::Vector::putScalar...";
00121 
00122   errcode = fei_vec->putScalar(0.0);
00123 
00124   if (errcode != 0) {
00125     throw std::runtime_error("nonzero errcode from fei_vec->putScalar");
00126   }
00127 
00128   errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
00129   if (errcode != 0) {
00130     throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
00131   }
00132 
00133   for(i=0; i<num_local_indices; ++i) {
00134     if (std::abs(check_coefs[i]) > 1.e-38) {
00135       throw std::runtime_error("fei_vec->putScalar(0.0) didn't zero the vector");
00136     }
00137   }
00138 
00139   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00140 }
00141 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends