10 #include <fei_macros.hpp>
12 #include <test_utils/test_VectorSpace.hpp>
14 #include <snl_fei_Factory.hpp>
15 #include <fei_ParameterSet.hpp>
16 #include <fei_LibraryWrapper.hpp>
20 #define fei_file "test_VectorSpace.cpp"
21 #include <fei_ErrMacros.hpp>
23 test_VectorSpace::test_VectorSpace(MPI_Comm comm)
28 test_VectorSpace::~test_VectorSpace()
32 int test_VectorSpace::runtests()
42 int test_VectorSpace::test0()
46 std::vector<int> fieldIDs(numProcs_);
48 std::vector<int> fieldSizes(numProcs_, fieldSize);
50 for(i=0; i<numProcs_; ++i) fieldIDs[i] = i;
54 vspace.defineIDTypes(1, &idType);
55 vspace.defineFields(fieldIDs.size(), &fieldIDs[0], &fieldSizes[0]);
57 CHK_ERR( vspace.addDOFs(idType, 1, &ID) );
59 for(i=0; i<numProcs_; ++i) {
60 if (i == localProc_)
continue;
62 int numSharingProcsPerID = 1;
65 CHK_ERR( vspace.initSharedIDs(1, idType, &ID,
66 &numSharingProcsPerID, &sharingProc) );
69 CHK_ERR( vspace.addDOFs(fieldIDs[localProc_], idType,
72 CHK_ERR( vspace.initComplete() );
74 std::vector<int> globalIndexOffsets;
76 vspace.getGlobalIndexOffsets(globalIndexOffsets);
81 int test_VectorSpace::test1()
88 std::vector<int>& fieldIDs = testdata->fieldIDs;
89 std::vector<int>& idTypes = testdata->idTypes;
90 std::vector<int>& ids = testdata->ids;
98 test_VectorSpace::create_VectorSpace(comm_,
99 testdata, localProc_, numProcs_,
109 std::vector<int> globalOffsets;
111 vectorSpace.getGlobalIndexOffsets(globalOffsets);
113 if (localProc_ > 0) {
114 if (globalOffsets[localProc_] != (localProc_+1)*2*numDOFsPerID) {
119 if (globalOffsets[localProc_+1] != (localProc_+2)*2*numDOFsPerID) {
123 std::vector<int> globalBlkOffsets;
124 vectorSpace.getGlobalBlkIndexOffsets(globalBlkOffsets);
125 if (localProc_ > 0) {
126 if (globalBlkOffsets[localProc_] != (localProc_+1)*2) {
131 if (globalBlkOffsets[localProc_+1] != (localProc_+2)*2) {
135 int len = ids.size();
137 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[0], fieldIDs[0],
138 0, 0, globalIndex) );
140 int correctIndex = globalOffsets[localProc_];
141 int correctBlkIndex = globalBlkOffsets[localProc_];
142 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
143 if (localProc_ != 0) correctBlkIndex -= 2;
145 if (globalIndex != correctIndex) {
149 int globalBlkIndex = 0;
150 CHK_ERR( vectorSpace.getGlobalBlkIndex(idTypes[0], ids[0], globalBlkIndex) );
151 if (globalBlkIndex != correctBlkIndex) {
153 << globalBlkIndex <<
", correctBlkIndex: " << correctBlkIndex << FEI_ENDL;
157 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[1], fieldIDs[0],
158 0, 0, globalIndex) );
160 correctIndex = globalOffsets[localProc_] + 4;
161 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
163 if (globalIndex != correctIndex) {
167 CHK_ERR( vectorSpace.getGlobalBlkIndex(idTypes[0], ids[1], globalBlkIndex) );
168 correctBlkIndex = globalBlkOffsets[localProc_]+1;
169 if (localProc_ != 0) correctBlkIndex -= 2;
171 if (globalBlkIndex != correctBlkIndex) {
173 << globalBlkIndex <<
", correctBlkIndex: " << correctBlkIndex << FEI_ENDL;
177 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[len-1], fieldIDs[0],
178 0, 0, globalIndex) );
179 correctIndex = globalOffsets[localProc_] + 12;
180 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
182 if (globalIndex != correctIndex) {
186 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[0], fieldIDs[1],
187 0, 0, globalIndex) );
188 correctIndex = globalOffsets[localProc_] + 1;
189 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
191 if (globalIndex != correctIndex) {
195 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[1], fieldIDs[1],
196 0, 0, globalIndex) );
197 correctIndex = globalOffsets[localProc_] + 5;
198 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
200 if (globalIndex != correctIndex) {
204 CHK_ERR( vectorSpace.getGlobalIndex(idTypes[0], ids[len-1], fieldIDs[1],
205 0, 0, globalIndex) );
206 correctIndex = globalOffsets[localProc_] + 13;
207 if (localProc_ != 0) correctIndex -= 2*numDOFsPerID;
209 if (globalIndex != correctIndex) {
213 std::vector<int> globalIndices(ids.size()*numDOFsPerID);
215 CHK_ERR( vectorSpace.getGlobalIndices(ids.size(),
217 idTypes[0], fieldIDs[0],
218 &globalIndices[0] ));
220 std::vector<int> idFieldIDs(ids.size(), fieldIDs[1]);
221 std::vector<int> idIDTypes(ids.size(), idTypes[0]);
223 CHK_ERR( vectorSpace.getGlobalIndices(ids.size(),
225 idTypes[0], fieldIDs[0],
226 &globalIndices[0] ));
228 CHK_ERR( vectorSpace.getGlobalBlkIndices(ids.size(),
231 &globalIndices[0] ));
233 CHK_ERR( vectorSpace.getGlobalIndices(ids.size(),
237 &globalIndices[0]) );
239 unsigned numFields = vectorSpace.getNumFields();
240 if (numFields != fieldIDs.size()) {
244 std::vector<int> testgetfields;
245 vectorSpace.getFields(testgetfields);
246 if (testgetfields.size() != numFields) {
250 if (fieldIDs != testgetfields) {
259 int test_VectorSpace::test2()
262 bool run_this_test =
false;
263 assert( (run_this_test =
true) ==
true);
264 if (!run_this_test)
return(0);
273 std::vector<int>& idTypes = testdata->idTypes;
274 std::vector<int>& ids = testdata->ids;
280 test_VectorSpace::create_VectorSpace(comm_,
281 testdata, localProc_,
287 if (localProc_ < numProcs_-1) {
288 int numSharingProcsPerID = 1;
289 int sharingProc = localProc_+1;
291 CHK_ERR( vectorSpacePtr->
initSharedIDs(1, idTypes[0], &ids[0],
292 &numSharingProcsPerID,
305 if (numProcs_ > 1)
if (err == 0)
return(-1);
311 int test_VectorSpace::test3()
319 test_VectorSpace::create_VectorSpace(comm_,
320 testdata, localProc_, numProcs_,
326 factory->createVectorSpace(comm_,
"U3copy");
340 std::vector<int> globalOffsets;
341 std::vector<int> globalOffsetsCopy;
347 for(
size_t i=0; i<globalOffsets.size(); ++i) {
348 if (globalOffsets[i] != globalOffsetsCopy[i]) {
357 if (globalOffsetsCopy[numProcs_] != globalOffsets[numProcs_]) {
366 int test_VectorSpace::test4()
372 test_VectorSpace::create_VectorSpace(MPI_Comm comm)
376 MPI_Comm_rank(comm, &localProc);
377 MPI_Comm_size(comm, &numProcs);
380 testData test_data(localProc, numProcs);
384 test_VectorSpace::create_VectorSpace(comm, &test_data, localProc, numProcs,
385 false,
false, (
const char*)0, factory);
388 FEI_COUT <<
"ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL;
389 throw std::runtime_error(
"test_Vector::vector_test1: ERROR, failed to create valid fei::VectorSpace.");
396 test_VectorSpace::create_VectorSpace(MPI_Comm comm,
400 bool defineBothFields,
401 bool initSolnBothFields,
404 bool turnOnDebugOutput)
417 if (factory.
get() == NULL) {
426 std::vector<int>& fieldIDs = testdata->fieldIDs;
427 std::vector<int>& fieldSizes = testdata->fieldSizes;
428 std::vector<int>& idTypes = testdata->idTypes;
429 std::vector<int>& ids = testdata->ids;
430 std::vector<int>& sharedIDs = testdata->sharedIDs;
431 std::vector<int>& numSharingProcsPerID = testdata->numSharingProcsPerID;
432 std::vector<int>& sharingProcs = testdata->sharingProcs;
436 paramset.
add(param1);
437 if (turnOnDebugOutput) {
439 paramset.
add(param2);
444 int numFields = defineBothFields ? 2 : 1;
452 vectorSpace.
addDOFs(fieldIDs[0],
457 if (initSolnBothFields) {
458 vectorSpace.
addDOFs(fieldIDs[1],
466 sharedIDs.size() ? &sharedIDs[0] : 0,
467 numSharingProcsPerID.size() ? &numSharingProcsPerID[0] : 0,
468 sharingProcs.size() ? &sharingProcs[0] : 0
int initSharedIDs(int numShared, int idType, const int *sharedIDs, const int *numSharingProcsPerID, const int *sharingProcs)
void defineFields(int numFields, const int *fieldIDs, const int *fieldSizes, const int *fieldTypes=NULL)
int addDOFs(int fieldID, int idType, int numIDs, const int *IDs)
void setParameters(const fei::ParameterSet ¶mset)
virtual fei::SharedPtr< VectorSpace > createVectorSpace(MPI_Comm, const char *name)
int addVectorSpace(fei::VectorSpace *inputSpace)
void add(const Param ¶m, bool maintain_unique_keys=true)
void defineIDTypes(int numIDTypes, const int *idTypes)
std::ostream & console_out()
void getGlobalIndexOffsets(std::vector< int > &globalOffsets) const
int localProc(MPI_Comm comm)
int numProcs(MPI_Comm comm)