FEI Version of the Day
test_Vector.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 <cmath>
00045 #include <test_utils/test_Vector.hpp>
00046 #include <test_utils/test_VectorSpace.hpp>
00047 #include <test_utils/test_MatrixGraph.hpp>
00048 
00049 #include <fei_Factory.hpp>
00050 #include <snl_fei_Factory.hpp>
00051 #include <fei_Vector_Impl.hpp>
00052 
00053 #include <test_utils/LibraryFactory.hpp>
00054 
00055 #ifdef HAVE_FEI_AZTECOO
00056 #include <fei_Aztec_LinSysCore.hpp>
00057 #endif
00058 #include <fei_Factory_Trilinos.hpp>
00059 
00060 #undef fei_file
00061 #define fei_file "test_Vector.cpp"
00062 #include <fei_ErrMacros.hpp>
00063 
00064 
00065 test_Vector::test_Vector(MPI_Comm comm)
00066   : tester(comm)
00067 {
00068 }
00069 
00070 test_Vector::~test_Vector()
00071 {
00072 }
00073 
00074 int test_Vector::runtests()
00075 {
00076   //-------------------------------
00077   // We'll test the vector produced by Factory_Trilinos 
00078   fei::SharedPtr<fei::Factory> factory_trilinos(new Factory_Trilinos(comm_));
00079 
00080   if (localProc_==0) FEI_COUT << "getting fei::Vector from Factory_Trilinos..."
00081             << FEI_ENDL;
00082   fei::SharedPtr<fei::Vector> fei_vec = create_vector(factory_trilinos);
00083 
00084   vector_test1(fei_vec);
00085 
00086   if (localProc_==0) FEI_COUT << FEI_ENDL;
00087 
00088   return(0);
00089 }
00090 
00091 fei::SharedPtr<fei::Vector>
00092 test_Vector::create_vector(fei::SharedPtr<fei::Factory> factory)
00093 {
00094   testData test_data(localProc_, numProcs_);
00095 
00096   fei::SharedPtr<fei::VectorSpace> vspace =
00097     test_VectorSpace::create_VectorSpace(comm_, &test_data, localProc_, numProcs_,
00098            false, false, (const char*)0, factory);
00099   int err = vspace->initComplete();
00100   if (err != 0) {
00101     FEI_COUT << "ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL;
00102     throw std::runtime_error("test_Vector::create_vector: ERROR, failed to create valid fei::VectorSpace.");
00103   }
00104 
00105   if (localProc_==0) FEI_COUT << "  creating fei::Vector instance... ";
00106 
00107   fei::SharedPtr<fei::Vector> vec = factory->createVector(vspace);
00108 
00109   if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
00110 
00111   return(vec);
00112 }
00113 
00114 void test_Vector::vector_test1(fei::SharedPtr<fei::Vector> fei_vec)
00115 {
00116   if (localProc_==0)
00117   FEI_COUT << "  vector_test1: testing fei::Vector with type '"
00118      << fei_vec->typeName() << "':"<<FEI_ENDL;
00119 
00120   fei::SharedPtr<fei::VectorSpace> vspace = fei_vec->getVectorSpace();
00121 
00122   std::vector<int> global_offsets;
00123   vspace->getGlobalIndexOffsets(global_offsets);
00124 
00125   int i, my_first_offset = global_offsets[localProc_];
00126   int my_last_offset = global_offsets[localProc_+1]-1;
00127   int num_local_indices = my_last_offset - my_first_offset + 1;
00128 
00129   std::vector<double> coefs(num_local_indices, 1.0);
00130   std::vector<double> check_coefs(num_local_indices);
00131   std::vector<int> indices(num_local_indices);
00132   for(i=0; i<num_local_indices; ++i) {
00133     indices[i] = my_first_offset + i;
00134   }
00135 
00136   if (localProc_==0)
00137     FEI_COUT << "   testing fei::Vector::copyIn/copyOut...";
00138 
00139   int errcode = fei_vec->copyIn(num_local_indices, &indices[0], &coefs[0]);
00140   if (errcode != 0) {
00141     throw std::runtime_error("nonzero errcode from fei_vec->copyIn");
00142   }
00143 
00144   errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
00145   if (errcode != 0) {
00146     throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
00147   }
00148 
00149   if (coefs != check_coefs) {
00150     throw std::runtime_error("fei_vec->copyOut didn't produce the right coefs");
00151   }
00152 
00153   if (localProc_==0)
00154     FEI_COUT << "ok"<<FEI_ENDL << "   testing fei::Vector::putScalar...";
00155 
00156   errcode = fei_vec->putScalar(0.0);
00157 
00158   if (errcode != 0) {
00159     throw std::runtime_error("nonzero errcode from fei_vec->putScalar");
00160   }
00161 
00162   errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
00163   if (errcode != 0) {
00164     throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
00165   }
00166 
00167   for(i=0; i<num_local_indices; ++i) {
00168     if (std::abs(check_coefs[i]) > 1.e-38) {
00169       throw std::runtime_error("fei_vec->putScalar(0.0) didn't zero the vector");
00170     }
00171   }
00172 
00173   if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
00174 }
00175 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends