FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_Vector.cpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 #include <cmath>
14 
15 #include <fei_Factory.hpp>
16 #include <snl_fei_Factory.hpp>
17 #include <fei_Vector_Impl.hpp>
18 
20 
21 #ifdef HAVE_FEI_AZTECOO
22 #include <fei_Aztec_LinSysCore.hpp>
23 #endif
24 #include <fei_Factory_Trilinos.hpp>
25 
26 #undef fei_file
27 #define fei_file "test_Vector.cpp"
28 #include <fei_ErrMacros.hpp>
29 
30 
32  : tester(comm)
33 {
34 }
35 
37 {
38 }
39 
41 {
42  //-------------------------------
43  // We'll test the vector produced by Factory_Trilinos
45 
46  if (localProc_==0) FEI_COUT << "getting fei::Vector from Factory_Trilinos..."
47  << FEI_ENDL;
48  fei::SharedPtr<fei::Vector> fei_vec = create_vector(factory_trilinos);
49 
50  vector_test1(fei_vec);
51 
52  if (localProc_==0) FEI_COUT << FEI_ENDL;
53 
54  return(0);
55 }
56 
59 {
60  testData test_data(localProc_, numProcs_);
61 
64  false, false, (const char*)0, factory);
65  int err = vspace->initComplete();
66  if (err != 0) {
67  FEI_COUT << "ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL;
68  throw std::runtime_error("test_Vector::create_vector: ERROR, failed to create valid fei::VectorSpace.");
69  }
70 
71  if (localProc_==0) FEI_COUT << " creating fei::Vector instance... ";
72 
73  fei::SharedPtr<fei::Vector> vec = factory->createVector(vspace);
74 
75  if (localProc_==0) FEI_COUT << "ok" << FEI_ENDL;
76 
77  return(vec);
78 }
79 
81 {
82  if (localProc_==0)
83  FEI_COUT << " vector_test1: testing fei::Vector with type '"
84  << fei_vec->typeName() << "':"<<FEI_ENDL;
85 
87 
88  std::vector<int> global_offsets;
89  vspace->getGlobalIndexOffsets(global_offsets);
90 
91  int i, my_first_offset = global_offsets[localProc_];
92  int my_last_offset = global_offsets[localProc_+1]-1;
93  int num_local_indices = my_last_offset - my_first_offset + 1;
94 
95  std::vector<double> coefs(num_local_indices, 1.0);
96  std::vector<double> check_coefs(num_local_indices);
97  std::vector<int> indices(num_local_indices);
98  for(i=0; i<num_local_indices; ++i) {
99  indices[i] = my_first_offset + i;
100  }
101 
102  if (localProc_==0)
103  FEI_COUT << " testing fei::Vector::copyIn/copyOut...";
104 
105  int errcode = fei_vec->copyIn(num_local_indices, &indices[0], &coefs[0]);
106  if (errcode != 0) {
107  throw std::runtime_error("nonzero errcode from fei_vec->copyIn");
108  }
109 
110  errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
111  if (errcode != 0) {
112  throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
113  }
114 
115  if (coefs != check_coefs) {
116  throw std::runtime_error("fei_vec->copyOut didn't produce the right coefs");
117  }
118 
119  if (localProc_==0)
120  FEI_COUT << "ok"<<FEI_ENDL << " testing fei::Vector::putScalar...";
121 
122  errcode = fei_vec->putScalar(0.0);
123 
124  if (errcode != 0) {
125  throw std::runtime_error("nonzero errcode from fei_vec->putScalar");
126  }
127 
128  errcode = fei_vec->copyOut(num_local_indices, &indices[0], &check_coefs[0]);
129  if (errcode != 0) {
130  throw std::runtime_error("nonzero errcode from fei_vec->copyOut");
131  }
132 
133  for(i=0; i<num_local_indices; ++i) {
134  if (std::abs(check_coefs[i]) > 1.e-38) {
135  throw std::runtime_error("fei_vec->putScalar(0.0) didn't zero the vector");
136  }
137  }
138 
139  if (localProc_==0) FEI_COUT << "ok"<<FEI_ENDL;
140 }
141 
#define FEI_COUT
virtual fei::SharedPtr< fei::VectorSpace > getVectorSpace() const =0
MPI_Comm comm_
Definition: tester.hpp:37
virtual int copyIn(int numValues, const int *indices, const double *values, int vectorIndex=0)=0
test_Vector(MPI_Comm comm)
Definition: test_Vector.cpp:31
int localProc_
Definition: tester.hpp:38
fei::SharedPtr< fei::Vector > create_vector(fei::SharedPtr< fei::Factory > factory)
Definition: test_Vector.cpp:58
virtual int putScalar(double scalar)=0
#define MPI_Comm
Definition: fei_mpi.h:56
virtual ~test_Vector()
Definition: test_Vector.cpp:36
int runtests()
Definition: test_Vector.cpp:40
int numProcs_
Definition: tester.hpp:38
virtual fei::SharedPtr< fei::Vector > createVector(fei::SharedPtr< fei::VectorSpace > vecSpace, int numVectors=1)=0
virtual const char * typeName() const =0
#define FEI_ENDL
void getGlobalIndexOffsets(std::vector< int > &globalOffsets) const
void vector_test1(fei::SharedPtr< fei::Vector > fei_vec)
Definition: test_Vector.cpp:80
virtual int copyOut(int numValues, const int *indices, double *values, int vectorIndex=0) const =0
static fei::SharedPtr< fei::VectorSpace > create_VectorSpace(MPI_Comm comm)