FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_Algebraic.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 
10 #include <fei_macros.hpp>
11 
13 
14 #include <fei_VectorSpace.hpp>
16 #include <fei_SparseRowGraph.hpp>
17 
18 #undef fei_file
19 #define fei_file "test_Algebraic.cpp"
20 #include <fei_ErrMacros.hpp>
21 
23  : tester(comm)
24 {
25 }
26 
28 {
29 }
30 
32 {
33  if (numProcs_ < 2) {
34  CHK_ERR( serialtest1() );
35  CHK_ERR( serialtest2() );
36  }
37 
38  CHK_ERR( test1() );
39  CHK_ERR( test2() );
40  CHK_ERR( test3() );
41  CHK_ERR( test4() );
42  return(0);
43 }
44 
46 {
47  int i, numRows = 10;
49 
50  int idType = 0;
51 
52  vspace->defineIDTypes(1, &idType);
53 
54  std::vector<int> rowNumbers(numRows);
55  for(i=0; i<numRows; ++i) {
56  rowNumbers[i] = i;
57  }
58 
59  CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
60 
61  CHK_ERR( vspace->initComplete() );
62 
63  int index = -1;
64  CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
65 
66  if (index != 3) {
67  ERReturn(-1);
68  }
69 
70  int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
71 
72  if (numDOF != 1) {
73  ERReturn(-1);
74  }
75 
76  std::vector<int> globalOffsets;
77 
78  vspace->getGlobalIndexOffsets(globalOffsets);
79 
80  if (globalOffsets[0] != 0) {
81  ERReturn(-1);
82  }
83 
84  if (globalOffsets[1] != numRows) {
85  ERReturn(-1);
86  }
87 
89  fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
90 
91  std::vector<int> rowOffsets(numRows+1);
92  std::vector<int> packedColumnIDs(numRows);
93  for(i=0; i<numRows; ++i) {
94  rowOffsets[i] = i;
95  packedColumnIDs[i] = i;
96  }
97  rowOffsets[numRows] = numRows;
98 
99  CHK_ERR( mgraph.initConnectivity(idType, numRows,
100  &rowNumbers[0],
101  &rowOffsets[0],
102  &packedColumnIDs[0]) );
103 
104  CHK_ERR( mgraph.initComplete() );
105 
106  fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
107 
108  int mnumRows = localgraph->rowNumbers.size();
109  int* mrowOffsets = &(localgraph->rowOffsets[0]);
110  int mnumNonzeros = localgraph->packedColumnIndices.size();
111  int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
112 
113  if (mnumRows != numRows) {
114  ERReturn(-1);
115  }
116 
117  if (mnumNonzeros != numRows) {
118  ERReturn(-1);
119  }
120 
121  for(i=0; i<numRows; ++i) {
122  if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
123  ERReturn(-1);
124  }
125  if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
126  ERReturn(-1);
127  }
128  }
129 
130  return(0);
131 }
132 
134 {
135  int i, numRows = 10;
137 
138  int idType = 0;
139 
140  vspace->defineIDTypes(1, &idType);
141 
142  std::vector<int> rowNumbers(numRows);
143  for(i=0; i<numRows; ++i) {
144  rowNumbers[i] = i;
145  }
146 
147  CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) );
148 
149  CHK_ERR( vspace->initComplete() );
150 
151  int index = -1;
152  CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) );
153 
154  if (index != 3) {
155  ERReturn(-1);
156  }
157 
158  int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]);
159 
160  if (numDOF != 1) {
161  ERReturn(-1);
162  }
163 
164  std::vector<int> globalOffsets;
165 
166  vspace->getGlobalIndexOffsets(globalOffsets);
167 
168  if (globalOffsets[0] != 0) {
169  ERReturn(-1);
170  }
171 
172  if (globalOffsets[1] != numRows) {
173  ERReturn(-1);
174  }
175 
177  fei::MatrixGraph_Impl2 mgraph(vspace, dummy);
178 
179  std::vector<int> rowLengths(numRows);
180  std::vector<int> packedColumnIDs(numRows);
181  std::vector<int*> columnIDs(numRows);
182 
183  for(i=0; i<numRows; ++i) {
184  rowLengths[i] = 1;
185  packedColumnIDs[i] = i;
186  columnIDs[i] = &(packedColumnIDs[i]);
187  }
188 
189  CHK_ERR( mgraph.initConnectivity(idType, numRows,
190  &rowNumbers[0],
191  &rowLengths[0],
192  &columnIDs[0]) );
193 
194  CHK_ERR( mgraph.initComplete() );
195 
196  fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false);
197 
198  int mnumRows = localgraph->rowNumbers.size();
199  int* mrowOffsets = &(localgraph->rowOffsets[0]);
200  int mnumNonzeros = localgraph->packedColumnIndices.size();
201  int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]);
202 
203  if (mnumRows != numRows) {
204  ERReturn(-1);
205  }
206 
207  if (mnumNonzeros != numRows) {
208  ERReturn(-1);
209  }
210 
211  for(i=0; i<numRows; ++i) {
212  if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) {
213  ERReturn(-1);
214  }
215  if (mpackedColumnIndices[i] != packedColumnIDs[i]) {
216  ERReturn(-1);
217  }
218  }
219 
220  return(0);
221 }
222 
224 {
225  return(0);
226 }
227 
229 {
230  return(0);
231 }
232 
234 {
235  return(0);
236 }
237 
239 {
240  return(0);
241 }
virtual ~test_Algebraic()
MPI_Comm comm_
Definition: tester.hpp:37
fei::SharedPtr< fei::SparseRowGraph > createGraph(bool blockEntryGraph, bool localRowGraph_includeSharedRows=false)
std::vector< int > rowNumbers
int addDOFs(int fieldID, int idType, int numIDs, const int *IDs)
#define MPI_Comm
Definition: fei_mpi.h:56
int getGlobalIndex(int idType, int ID, int fieldID, int fieldOffset, int whichComponentOfField, int &globalIndex)
void defineIDTypes(int numIDTypes, const int *idTypes)
test_Algebraic(MPI_Comm comm)
#define ERReturn(a)
int numProcs_
Definition: tester.hpp:38
int initConnectivity(int blockID, int connectivityID, const int *connectedIdentifiers)
void getGlobalIndexOffsets(std::vector< int > &globalOffsets) const
#define CHK_ERR(a)
int getNumDegreesOfFreedom(int idType, int ID)