10 #include <fei_macros.hpp>
12 #include <test_utils/test_MatrixGraph.hpp>
14 #include <test_utils/test_VectorSpace.hpp>
16 #include <snl_fei_Factory.hpp>
17 #include <fei_Pattern.hpp>
18 #include <fei_MatrixGraph_Impl2.hpp>
19 #include <fei_SparseRowGraph.hpp>
20 #include <fei_LibraryWrapper.hpp>
23 #define fei_file "test_MatrixGraph.cpp"
24 #include <fei_ErrMacros.hpp>
26 test_MatrixGraph::test_MatrixGraph(MPI_Comm comm)
31 test_MatrixGraph::~test_MatrixGraph()
35 int test_MatrixGraph_test6(MPI_Comm comm,
int numProcs,
int localProc,
36 const std::string& path)
39 std::vector<int>& ids = testdata->ids;
45 test_VectorSpace::create_VectorSpace(comm,
46 testdata, localProc, numProcs,
49 "U_MatGrph", factory);
52 test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
53 false,
false,
"U_MatGrph",
54 vectorSpacePtr, factory, path);
59 test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
60 false,
false,
"U_MatGrph2",
61 vectorSpacePtr, factory, path);
63 CHK_ERR( matrixGraph2Ptr->initComplete() );
65 bool equivalent =
false;
73 test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs,
74 false,
false,
"U_MatGrph3",
75 vectorSpacePtr, factory, path);
78 std::vector<int>& fieldIDs = testdata->fieldIDs;
79 std::vector<int>& idTypes = testdata->idTypes;
80 int offsetOfSlave = 0;
81 int offsetIntoSlaveField = 0;
82 std::vector<double> weights(2, 1.0);
83 double rhsValue = 0.0;
84 std::vector<int> cr_idTypes(2, idTypes[0]);
85 std::vector<int> cr_fieldIDs(2, fieldIDs[0]);
110 void test_MatrixGraph_test7(MPI_Comm comm,
int numProcs,
int localProc)
115 int rowfield = 0, rowfieldsize = 1;
116 int colfield = 1, colfieldsize = 3;
117 rowspace->defineFields(1, &rowfield, &rowfieldsize);
118 colspace->defineFields(1, &colfield, &colfieldsize);
122 int pID = mgraph.definePattern(4, 0, colfield);
126 FEI_COUT <<
"getNumIndices: " << pattern->
getNumIndices()<<
", colfieldsize: " << colfieldsize<<FEI_ENDL;
127 FEI_OSTRINGSTREAM osstr;
128 osstr <<
"test_MatrixGraph_test7, line "<<__LINE__<<FEI_ENDL;
129 throw std::runtime_error(osstr.str());
133 void test_MatrixGraph_test8(MPI_Comm comm,
int numProcs,
int localProc)
135 FEI_COUT <<
"testing matrix-graph with 'diagonal' connectivity block...";
142 int rowfield = 0, rowfieldsize = 1;
145 rowspace->defineIDTypes(1, &idType);
150 int patternID = mgraph.definePattern(numIDs, idType, rowfield);
154 FEI_OSTRINGSTREAM osstr;
155 osstr <<
"test_MatrixGraph_test8, line "<<__LINE__<<FEI_ENDL;
156 throw std::runtime_error(osstr.str());
160 int numConnLists = 1;
161 bool diagonal =
true;
162 mgraph.initConnectivityBlock(blockID, numConnLists, patternID, diagonal);
164 std::vector<int> ids(numIDs);
165 for(
int i=0; i<numIDs; ++i) {
169 mgraph.initConnectivity(blockID, 0, &ids[0]);
171 mgraph.initComplete();
174 mgraph.createGraph(
false);
177 FEI_OSTRINGSTREAM osstr;
178 osstr <<
"test_MatrixGraph_test8, line "<<__LINE__<<FEI_ENDL;
179 throw std::runtime_error(osstr.str());
183 catch(std::runtime_error& exc) {
184 FEI_OSTRINGSTREAM osstr;
185 osstr <<
"test_MatrixGraph_test8, caught exception: " << exc.what();
186 throw std::runtime_error(osstr.str());
189 FEI_COUT <<
"ok" << FEI_ENDL;
192 int test_MatrixGraph::runtests()
195 CHK_ERR( serialtest1() );
204 CHK_ERR( test_MatrixGraph_test6(comm_, numProcs_, localProc_, path_) );
206 test_MatrixGraph_test7(comm_, numProcs_, localProc_);
207 test_MatrixGraph_test8(comm_, numProcs_, localProc_);
212 int test_MatrixGraph::serialtest1()
215 std::vector<int> idTypes(numIDs, 1);
217 std::vector<int> numFieldsPerID(numIDs, 1);
218 std::vector<int> fieldIDs(numIDs, 0);
219 std::vector<int> fieldSizes(numIDs, 1);
222 &numFieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);
226 if (pType != fei::Pattern::SIMPLE) {
233 int test_MatrixGraph::test1()
236 std::vector<int>& ids = testdata->ids;
242 test_VectorSpace::create_VectorSpace(comm_,
243 testdata, localProc_, numProcs_,
246 "U_MatGrph", factory);
251 create_MatrixGraph(testdata, localProc_, numProcs_,
252 false,
false,
"U_MatGrph", vectorSpacePtr, factory, path_);
258 std::vector<int> globalIndexOffsets;
262 int numRowLengths = globalIndexOffsets[localProc_+1] -
263 globalIndexOffsets[localProc_];
270 std::vector<int>& rowOffsets = localgraph->
rowOffsets;
271 numLocalRows = rowOffsets.size()-1;
273 if (numLocalRows != numRowLengths) ERReturn(-1);
275 int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
276 correctNumLocalRows *= dofPerID;
278 if (numLocalRows != correctNumLocalRows) {
284 int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
285 if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID;
287 if (numNonzeros != correctNumNonzeros) {
294 for(
int i=0; i<numLocalRows; ++i) {
295 int globalRow = globalIndexOffsets[localProc_]+i;
296 int globalEndRow = globalIndexOffsets[numProcs_]-1;
298 int correctRowLength = 4*dofPerID;
299 if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
300 correctRowLength += 2*dofPerID;
303 if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
305 <<
", correctRowLength: " << correctRowLength <<
", "
306 <<
"rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
310 for(
int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
311 if (nonzeros[offset++] != ids[0]+j) {
322 int test_MatrixGraph::test2()
327 int init_nonsymmetric_block(
testData* testdata,
331 testdata->fieldIDs[0]);
333 testdata->fieldIDs[1]);
339 &(testdata->ids[0])) );
343 int test_MatrixGraph::test3()
346 std::vector<int>& ids = testdata->ids;
352 test_VectorSpace::create_VectorSpace(comm_,
353 testdata, localProc_, numProcs_,
356 "U_MatGrph3", factory);
361 create_MatrixGraph(testdata, localProc_, numProcs_,
363 "U_MatGrph3", vectorSpacePtr,
368 CHK_ERR( init_nonsymmetric_block(testdata, matrixGraphPtr.
get()) );
372 std::vector<int> globalIndexOffsets;
376 int numRowLengths = globalIndexOffsets[localProc_+1] -
377 globalIndexOffsets[localProc_];
384 int numGrphLocalRows = localgraph->
rowNumbers.size();
386 std::vector<int>& rowOffsets = localgraph->
rowOffsets;
387 numLocalRows = rowOffsets.size()-1;
389 int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
390 correctNumLocalRows *= dofPerID;
392 if (numLocalRows != correctNumLocalRows) {
396 if (numLocalRows != numRowLengths) ERReturn(-1);
397 if (numLocalRows != numGrphLocalRows) ERReturn(-1);
401 int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
402 if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
404 if (numNonzeros != correctNumNonzeros) {
410 std::vector<int> rowindices;
412 for(
int i=0; i<numLocalRows; ++i) {
413 int globalRow = globalIndexOffsets[localProc_]+i;
414 int globalEndRow = globalIndexOffsets[numProcs_]-1;
416 int correctRowLength = 4*dofPerID;
417 if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
418 correctRowLength += 2*dofPerID;
421 if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
423 <<
", correctRowLength: " << correctRowLength <<
", "
424 <<
"rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
428 for(
int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
429 if (nonzeros[offset++] != ids[0]*dofPerID+j) {
440 int test_MatrixGraph::test4()
443 std::vector<int>& ids = testdata->ids;
449 test_VectorSpace::create_VectorSpace(comm_,
450 testdata, localProc_, numProcs_,
453 "U_MatGrph4", factory);
458 create_MatrixGraph(testdata, localProc_, numProcs_,
460 "U_MatGrph4", vectorSpacePtr, factory, path_);
466 std::vector<int> globalIndexOffsets;
470 int numRowLengths = globalIndexOffsets[localProc_+1] -
471 globalIndexOffsets[localProc_];
478 std::vector<int>& rowOffsets = localgraph->
rowOffsets;
479 numLocalRows = rowOffsets.size()-1;
481 int correctNumLocalRows = localProc_==0 ? ids.size() : ids.size()-2;
482 correctNumLocalRows *= dofPerID;
484 if (numLocalRows != correctNumLocalRows) {
488 if (numLocalRows != numRowLengths) ERReturn(-1);
492 int correctNumNonzeros = numLocalRows*ids.size()*dofPerID;
493 if (localProc_ < numProcs_-1) correctNumNonzeros += 4*dofPerID*dofPerID;
495 if (numNonzeros != correctNumNonzeros) {
502 for(
int i=0; i<numLocalRows; ++i) {
503 int globalRow = globalIndexOffsets[localProc_]+i;
504 int globalEndRow = globalIndexOffsets[numProcs_]-1;
506 int correctRowLength = 4*dofPerID;
507 if (globalRow > 2*dofPerID-1 && globalRow < globalEndRow-(2*dofPerID-1)) {
508 correctRowLength += 2*dofPerID;
511 if (rowOffsets[i+1]-rowOffsets[i] != correctRowLength) {
513 <<
", correctRowLength: " << correctRowLength <<
", "
514 <<
"rowOffsets[i+1]-rowOffsets[i]: " << rowOffsets[i+1]-rowOffsets[i] << FEI_ENDL;
518 for(
int j=0; j<rowOffsets[i+1]-rowOffsets[i]; ++j) {
519 if (nonzeros[offset++] != ids[0]*dofPerID+j) {
530 int test_MatrixGraph::test5()
533 std::vector<int>& fieldIDs = testdata->fieldIDs;
534 std::vector<int>& idTypes = testdata->idTypes;
535 std::vector<int>& ids = testdata->ids;
541 test_VectorSpace::create_VectorSpace(comm_,
542 testdata, localProc_, numProcs_,
549 create_MatrixGraph(testdata, localProc_, numProcs_,
550 true,
false,
"U_MatGrph5", vectorSpacePtr,
551 factory, path_,
true);
553 if (localProc_ == 0) {
554 int offsetOfSlave = 0;
555 int offsetIntoSlaveField = 0;
556 std::vector<double> weights(6, 0.0);
558 double rhsValue = 0.0;
559 std::vector<int> cr_idTypes(2, idTypes[0]);
560 std::vector<int> cr_fieldIDs(2, fieldIDs[1]);
567 offsetIntoSlaveField,
573 offsetIntoSlaveField = 1;
579 offsetIntoSlaveField,
589 std::vector<int> globalIndexOffsets;
593 int numRows_unreduced = globalIndexOffsets[localProc_+1] -
594 globalIndexOffsets[localProc_];
599 std::vector<int>& rowOffsets = localgraph->
rowOffsets;
600 int numReducedRows = rowOffsets.size()-1;
602 if (localProc_ == 0) {
603 if (numReducedRows != numRows_unreduced-2) ERReturn(-1);
606 if (numReducedRows != numRows_unreduced) ERReturn(-1);
615 int localProc,
int numProcs,
616 bool bothFields,
bool nonSymmetric,
620 const std::string& path,
621 bool turnOnDebugOutput)
649 if (factory.
get() == NULL) {
651 vectorSpacePtr, name));
660 paramset.
add(param1);
661 if (turnOnDebugOutput) {
664 paramset.
add(param2);
667 fei::Param param2(
"debugOutput", path.c_str());
668 paramset.
add(param2);
680 int idType = testdata->idTypes[0];
681 int fieldID = testdata->fieldIDs[0];
684 std::vector<int> numFieldsPerID(numIDs, 2);
685 std::vector<int> fieldIDsArray(numIDs*2);
686 for(
int i=0; i<numIDs; ++i) {
687 fieldIDsArray[i*2] = testdata->fieldIDs[0];
688 fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
696 patternID = matrixGraphPtr->
definePattern(numIDs, idType, fieldID);
700 int numConnectivityLists = 1;
703 numConnectivityLists,
712 int patternID1 = 1, patternID2 = 2;
713 int numRowIDs = 1, numColIDs = 4;
716 std::vector<int> numFieldsPerID(numIDs, 2);
717 std::vector<int> fieldIDsArray(numIDs*2);
718 for(
int i=0; i<numIDs; ++i) {
719 fieldIDsArray[i*2] = testdata->fieldIDs[0];
720 fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
723 patternID1 = matrixGraphPtr->
definePattern(numRowIDs, idType,
726 patternID2 = matrixGraphPtr->
definePattern(numColIDs, idType,
740 numConnectivityLists,
741 patternID1, patternID2);
745 &(testdata->ids[0]));
virtual void setParameters(const fei::ParameterSet ¶ms)=0
int getNumIndices() const
virtual int initSlaveConstraint(int numIDs, const int *idTypes, const int *IDs, const int *fieldIDs, int offsetOfSlave, int offsetIntoSlaveField, const double *weights, double rhsValue)=0
std::vector< int > rowNumbers
void defineFields(int numFields, const int *fieldIDs, const int *fieldSizes, const int *fieldTypes=NULL)
virtual void setRowSpace(fei::SharedPtr< fei::VectorSpace > rowSpace)=0
virtual fei::SharedPtr< fei::SparseRowGraph > createGraph(bool blockEntryGraph, bool localRowGraph_includeSharedRows=false)=0
std::vector< int > packedColumnIndices
std::vector< int > rowOffsets
virtual fei::SharedPtr< fei::VectorSpace > getRowSpace()=0
virtual int initConnectivity(int blockID, int connectivityID, const int *connectedIdentifiers)=0
virtual int initComplete()=0
void add(const Param ¶m, bool maintain_unique_keys=true)
PatternType getPatternType() const
std::ostream & console_out()
void getGlobalIndexOffsets(std::vector< int > &globalOffsets) const
virtual int compareStructure(const fei::MatrixGraph &matrixGraph, bool &equivalent) const =0
virtual int definePattern(int numIDs, int idType)=0
virtual fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > columnSpace, const char *name)=0
virtual int initConnectivityBlock(int blockID, int numConnectivityLists, int patternID, bool diagonal=false)=0