FEI Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
test_utils
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>
11
#include <
test_utils/test_Vector.hpp
>
12
#include <
test_utils/test_VectorSpace.hpp
>
13
#include <
test_utils/test_MatrixGraph.hpp
>
14
15
#include <
fei_Factory.hpp
>
16
#include <
snl_fei_Factory.hpp
>
17
#include <
fei_Vector_Impl.hpp
>
18
19
#include <
test_utils/LibraryFactory.hpp
>
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
31
test_Vector::test_Vector
(
MPI_Comm
comm)
32
:
tester
(comm)
33
{
34
}
35
36
test_Vector::~test_Vector
()
37
{
38
}
39
40
int
test_Vector::runtests
()
41
{
42
//-------------------------------
43
// We'll test the vector produced by Factory_Trilinos
44
fei::SharedPtr<fei::Factory>
factory_trilinos(
new
Factory_Trilinos
(
comm_
));
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
57
fei::SharedPtr<fei::Vector>
58
test_Vector::create_vector
(
fei::SharedPtr<fei::Factory>
factory)
59
{
60
testData
test_data(
localProc_
,
numProcs_
);
61
62
fei::SharedPtr<fei::VectorSpace>
vspace =
63
test_VectorSpace::create_VectorSpace
(
comm_
, &test_data,
localProc_
,
numProcs_
,
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
80
void
test_Vector::vector_test1
(
fei::SharedPtr<fei::Vector>
fei_vec)
81
{
82
if
(
localProc_
==0)
83
FEI_COUT
<<
" vector_test1: testing fei::Vector with type '"
84
<< fei_vec->typeName() <<
"':"
<<
FEI_ENDL
;
85
86
fei::SharedPtr<fei::VectorSpace>
vspace = fei_vec->getVectorSpace();
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
LibraryFactory.hpp
Factory_Trilinos
Definition
fei_Factory_Trilinos.hpp:76
fei::SharedPtr
Definition
fei_SharedPtr.hpp:65
testData
Definition
testData.hpp:18
test_VectorSpace::create_VectorSpace
static fei::SharedPtr< fei::VectorSpace > create_VectorSpace(MPI_Comm comm)
Definition
test_VectorSpace.cpp:372
test_Vector::~test_Vector
virtual ~test_Vector()
Definition
test_Vector.cpp:36
test_Vector::create_vector
fei::SharedPtr< fei::Vector > create_vector(fei::SharedPtr< fei::Factory > factory)
Definition
test_Vector.cpp:58
test_Vector::test_Vector
test_Vector(MPI_Comm comm)
Definition
test_Vector.cpp:31
test_Vector::vector_test1
void vector_test1(fei::SharedPtr< fei::Vector > fei_vec)
Definition
test_Vector.cpp:80
test_Vector::runtests
int runtests()
Definition
test_Vector.cpp:40
tester::tester
tester(MPI_Comm comm)
Definition
tester.cpp:17
tester::numProcs_
int numProcs_
Definition
tester.hpp:38
tester::comm_
MPI_Comm comm_
Definition
tester.hpp:37
tester::localProc_
int localProc_
Definition
tester.hpp:38
fei_Aztec_LinSysCore.hpp
fei_ErrMacros.hpp
fei_Factory.hpp
fei_Factory_Trilinos.hpp
fei_Vector_Impl.hpp
FEI_ENDL
#define FEI_ENDL
Definition
fei_iostream.hpp:34
FEI_COUT
#define FEI_COUT
Definition
fei_iostream.hpp:33
fei_macros.hpp
MPI_Comm
#define MPI_Comm
Definition
fei_mpi.h:56
snl_fei_Factory.hpp
test_MatrixGraph.hpp
test_VectorSpace.hpp
test_Vector.hpp
Generated by
1.17.0