fei::SharedPtr<fei::Matrix> test_Matrix::create_matrix(fei::SharedPtr<fei::Factory> factory) { testData test_data(localProc_, numProcs_); fei::SharedPtr<fei::VectorSpace> vspace = test_VectorSpace::create_VectorSpace(comm_, &test_data, localProc_, numProcs_, false, false, (const char*)0, factory); int err = vspace->initComplete(); if (err != 0) { FEI_COUT << "ERROR, failed to create valid fei::VectorSpace." << FEI_ENDL; throw std::runtime_error("test_Vector::vector_test1: ERROR, failed to create valid fei::VectorSpace."); } fei::SharedPtr<fei::MatrixGraph> mgraph = factory->createMatrixGraph(vspace, vspace, NULL); std::vector<int>& fieldIDs = test_data.fieldIDs; std::vector<int>& idTypes = test_data.idTypes; std::vector<int>& ids = test_data.ids; int numIDs = ids.size(); int fieldID = fieldIDs[0]; int idType = idTypes[0]; int patternID = mgraph->definePattern(numIDs, idType, fieldID); mgraph->initConnectivityBlock(0, 1, patternID); mgraph->initConnectivity(0, 0, &ids[0]); mgraph->initComplete(); fei::SharedPtr<fei::Matrix> matrix = factory->createMatrix(mgraph); return(matrix); }
fei::SharedPtr<fei::MatrixGraph> test_MatrixGraph::create_MatrixGraph(testData* testdata, int localProc, int numProcs, bool bothFields, bool nonSymmetric, const char* name, fei::SharedPtr<fei::VectorSpace> vectorSpacePtr, fei::SharedPtr<fei::Factory> factory, const std::string& path, bool turnOnDebugOutput) { // //This function creates a MatrixGraph object, and initializes it as follows: // //setRowSpace(vectorSpacePtr) // //definePattern patternID=0, numIDs=4, idType=testdata->idTypes[0] // fieldID=testdata->fieldIDs[0] if !bothFields, else // fieldIDs=testdata->fieldIDs // //initConnectivityBlock blockID=0, numConnectivityLists=1 // //initConnectivity blockID, 0, testdata->ids // //If nonSymmetric==true, then also do the following: // definePattern patternID=1, numIDs=1, idType=testdata->idTypes[0] // fieldID=testdata->fieldIDs[0] if !bothFields, else // fieldIDs=testdata->fieldIDs // definePattern patternID=2, numIDs=4, idType=testdata->idTypes[0] // fieldID=testdata->fieldIDs[0] if !bothFields, else // fieldIDs=testdata->fieldIDs // //initConnectivityBlock blockID=1, patterns 1 and 2 // //initConnectivity blockID, 0, testdata->ids // fei::SharedPtr<fei::MatrixGraph> mgptr; if (factory.get() == NULL) { fei::SharedPtr<fei::MatrixGraph> tmp(new fei::MatrixGraph_Impl2(vectorSpacePtr, vectorSpacePtr, name)); mgptr = tmp; } else { mgptr = factory->createMatrixGraph(vectorSpacePtr, vectorSpacePtr, name); } fei::ParameterSet paramset; fei::Param param1("name", name); paramset.add(param1); if (turnOnDebugOutput) { if (path.empty()) { fei::Param param2("debugOutput", "."); paramset.add(param2); } else { fei::Param param2("debugOutput", path.c_str()); paramset.add(param2); } } fei::MatrixGraph* matrixGraphPtr = mgptr.get(); matrixGraphPtr->setParameters(paramset); matrixGraphPtr->setRowSpace(vectorSpacePtr); int patternID = 0; int numIDs = 4; int idType = testdata->idTypes[0]; int fieldID = testdata->fieldIDs[0]; if (bothFields) { std::vector<int> numFieldsPerID(numIDs, 2); std::vector<int> fieldIDsArray(numIDs*2); for(int i=0; i<numIDs; ++i) { fieldIDsArray[i*2] = testdata->fieldIDs[0]; fieldIDsArray[i*2+1] = testdata->fieldIDs[1]; } patternID = matrixGraphPtr->definePattern(numIDs, idType, &numFieldsPerID[0], &fieldIDsArray[0]); } else { patternID = matrixGraphPtr->definePattern(numIDs, idType, fieldID); } int blockID = 0; int numConnectivityLists = 1; matrixGraphPtr->initConnectivityBlock(blockID, numConnectivityLists, patternID); matrixGraphPtr->initConnectivity(blockID, 0, &(testdata->ids[0])); if (!nonSymmetric) { return(mgptr); } int patternID1 = 1, patternID2 = 2; int numRowIDs = 1, numColIDs = 4; if (bothFields) { std::vector<int> numFieldsPerID(numIDs, 2); std::vector<int> fieldIDsArray(numIDs*2); for(int i=0; i<numIDs; ++i) { fieldIDsArray[i*2] = testdata->fieldIDs[0]; fieldIDsArray[i*2+1] = testdata->fieldIDs[1]; } patternID1 = matrixGraphPtr->definePattern(numRowIDs, idType, &numFieldsPerID[0], &fieldIDsArray[0]); patternID2 = matrixGraphPtr->definePattern(numColIDs, idType, &numFieldsPerID[0], &fieldIDsArray[0]); } else { patternID1 = matrixGraphPtr->definePattern(numRowIDs, idType, fieldID); patternID2 = matrixGraphPtr->definePattern(numColIDs, idType, fieldID); } blockID = 1; matrixGraphPtr->initConnectivityBlock(blockID, numConnectivityLists, patternID1, patternID2); matrixGraphPtr->initConnectivity(blockID, 0, &(testdata->ids[0]), &(testdata->ids[0])); return(mgptr); }