int test_MatrixGraph_test6(MPI_Comm comm, int numProcs, int localProc, const std::string& path) { testData* testdata = new testData(localProc, numProcs); std::vector<int>& ids = testdata->ids; fei::SharedPtr<LibraryWrapper> wrapper; fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm, wrapper)); fei::SharedPtr<fei::VectorSpace> vectorSpacePtr = test_VectorSpace::create_VectorSpace(comm, testdata, localProc, numProcs, false, //defineBothFields false, //initSolnBothFields "U_MatGrph", factory); fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr = test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs, false, false, "U_MatGrph", vectorSpacePtr, factory, path); CHK_ERR( matrixGraphPtr->initComplete() ); fei::SharedPtr<fei::MatrixGraph> matrixGraph2Ptr = test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs, false, false, "U_MatGrph2", vectorSpacePtr, factory, path); CHK_ERR( matrixGraph2Ptr->initComplete() ); bool equivalent = false; CHK_ERR( matrixGraphPtr->compareStructure(*matrixGraph2Ptr, equivalent) ); if (!equivalent) { ERReturn(-1); } fei::SharedPtr<fei::MatrixGraph> matrixGraph3Ptr = test_MatrixGraph::create_MatrixGraph(testdata, localProc, numProcs, false, false, "U_MatGrph3", vectorSpacePtr, factory, path); if (localProc == 0) { std::vector<int>& fieldIDs = testdata->fieldIDs; std::vector<int>& idTypes = testdata->idTypes; int offsetOfSlave = 0; int offsetIntoSlaveField = 0; std::vector<double> weights(2, 1.0); double rhsValue = 0.0; std::vector<int> cr_idTypes(2, idTypes[0]); std::vector<int> cr_fieldIDs(2, fieldIDs[0]); CHK_ERR( matrixGraph3Ptr->initSlaveConstraint(2, &cr_idTypes[0], &ids[2], &cr_fieldIDs[0], offsetOfSlave, offsetIntoSlaveField, &weights[0], rhsValue) ); } CHK_ERR( matrixGraph3Ptr->initComplete() ); CHK_ERR( matrixGraphPtr->compareStructure(*matrixGraph3Ptr, equivalent) ); if (equivalent) { ERReturn(-1); } delete testdata; return(0); }
int test_Matrix::serialtest3() { testData* testdata = new testData(localProc_, numProcs_); std::vector<int>& fieldIDs = testdata->fieldIDs; std::vector<int>& fieldSizes = testdata->fieldSizes; std::vector<int>& idTypes = testdata->idTypes; std::vector<int>& ids = testdata->ids; fei::SharedPtr<fei::VectorSpace> vspc(new fei::VectorSpace(comm_, "sU_Mat3")); vspc->defineFields(fieldIDs.size(), &fieldIDs[0], &fieldSizes[0]); vspc->defineIDTypes(idTypes.size(), &idTypes[0]); fei::SharedPtr<fei::MatrixGraph> matgraph(new fei::MatrixGraph_Impl2(vspc, vspc, "sU_Mat3")); int numIDs = ids.size(); int fieldID = fieldIDs[0]; int idType = idTypes[0]; int patternID = matgraph->definePattern(numIDs, idType, fieldID); CHK_ERR( matgraph->initConnectivityBlock(0, 1, patternID) ); CHK_ERR( matgraph->initConnectivity(0, 0, &ids[0]) ); //set up a slave constraint that defines id 2, field 0 to be equal to //id 1, field 0. int offsetOfSlave = 1; int offsetIntoSlaveField = 0; std::vector<double> weights(2); weights[0] = 1.0; weights[1] = -1.0; double rhsValue = 0.0; std::vector<int> cr_idtypes(2, idTypes[0]); std::vector<int> cr_fieldIDs(2, fieldIDs[0]); CHK_ERR( matgraph->initSlaveConstraint(2, //numIDs &cr_idtypes[0], &ids[1], &cr_fieldIDs[0], offsetOfSlave, offsetIntoSlaveField, &weights[0], rhsValue) ); CHK_ERR( matgraph->initComplete() ); fei::SharedPtr<fei::FillableMat> ssmat(new fei::FillableMat); int localsize = matgraph->getRowSpace()->getNumIndices_Owned(); localsize -= 1;//subtract the slave fei::Matrix* matrix = new fei::Matrix_Impl<fei::FillableMat>(ssmat, matgraph, localsize); if (matrix == NULL) { ERReturn(-1); } std::vector<int> indices(numIDs); CHK_ERR( matgraph->getConnectivityIndices(0, 0, numIDs, &indices[0], numIDs) ); std::vector<double> data1(numIDs*numIDs); std::vector<double*> data2d(numIDs); int i; for(i=0; i<numIDs; ++i) { data2d[i] = &(data1[i*numIDs]); } for(i=0; i<numIDs*numIDs; ++i) { data1[i] = 1.0*i; } CHK_ERR( matrix->sumIn(numIDs, &indices[0], numIDs, &indices[0], &data2d[0], 0) ); CHK_ERR( matrix->sumIn(0, 0, &data2d[0], 0) ); delete matrix; delete testdata; return(0); }
int test_MatrixGraph::test5() { testData* testdata = new testData(localProc_, numProcs_); std::vector<int>& fieldIDs = testdata->fieldIDs; std::vector<int>& idTypes = testdata->idTypes; std::vector<int>& ids = testdata->ids; fei::SharedPtr<LibraryWrapper> wrapper; fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm_, wrapper)); fei::SharedPtr<fei::VectorSpace> vectorSpacePtr = test_VectorSpace::create_VectorSpace(comm_, testdata, localProc_, numProcs_, true, //defineBothFields true, //initSolnBothFields "U_MatGrph5", factory,true); fei::SharedPtr<fei::MatrixGraph> matrixGraphPtr = create_MatrixGraph(testdata, localProc_, numProcs_, true, false, "U_MatGrph5", vectorSpacePtr, factory, path_, true); if (localProc_ == 0) { int offsetOfSlave = 0; int offsetIntoSlaveField = 0; std::vector<double> weights(6, 0.0); weights[3] = 1.0; double rhsValue = 0.0; std::vector<int> cr_idTypes(2, idTypes[0]); std::vector<int> cr_fieldIDs(2, fieldIDs[1]); CHK_ERR( matrixGraphPtr->initSlaveConstraint(2, &cr_idTypes[0], &ids[2], &cr_fieldIDs[0], offsetOfSlave, offsetIntoSlaveField, &weights[0], rhsValue) ); weights[3] = 0.0; weights[4] = 1.0; offsetIntoSlaveField = 1; CHK_ERR( matrixGraphPtr->initSlaveConstraint(2, &cr_idTypes[0], &ids[2], &cr_fieldIDs[0], offsetOfSlave, offsetIntoSlaveField, &weights[0], rhsValue) ); } CHK_ERR( matrixGraphPtr->initComplete() ); fei::SharedPtr<fei::VectorSpace> reducedSolnSpacePtr = matrixGraphPtr->getRowSpace(); std::vector<int> globalIndexOffsets; reducedSolnSpacePtr->getGlobalIndexOffsets(globalIndexOffsets); int numRows_unreduced = globalIndexOffsets[localProc_+1] - globalIndexOffsets[localProc_]; fei::SharedPtr<fei::SparseRowGraph> localgraph = matrixGraphPtr->createGraph(false); std::vector<int>& rowOffsets = localgraph->rowOffsets; int numReducedRows = rowOffsets.size()-1; if (localProc_ == 0) { if (numReducedRows != numRows_unreduced-2) ERReturn(-1); } else { if (numReducedRows != numRows_unreduced) ERReturn(-1); } delete testdata; return(0); }