void View::dropEvent(QDropEvent* ev) { // From Q3 support: // "Sets the drop to happen at the given point. You do not normally need to use this // as it will be set internally before your widget receives the drop event." // But we need to remap it here... //ev->setPoint(mapDev(ev->pos())); QDropEvent nev(mapDev(ev->pos()), ev->possibleActions(), ev->mimeData(), ev->mouseButtons(), ev->keyboardModifiers(), ev->type()); //viewDropEvent(ev); viewDropEvent(&nev); }
QVector<double> MainWindow::nevyazka(QVector<double> A, QVector<double> B, QVector<double> X) { int n = B.size(); QVector<double> nev(B.size()); double s = 0; for(int i=0;i<n;i++) { s=0; for(int j=0;j<n;j++) { s= s+A[i*n+j] * X[j]; } nev[i]=s-B[i]; } return nev; }
double MainWindow::nevyazkaSumm(QVector<double> A, QVector<double> B, QVector<double> X) { int n = B.size(); QVector<double> nev(B.size()); double s = 0; for(int i=0;i<n;i++) { s=0; for(int j=0;j<n;j++) { s= s+A[i*n+j] * X[j]; } nev[i]=s-B[i]; } double nevyazkaSumm; for(int i=0;i <nev.size();i++) { nevyazkaSumm+=nev[i]*nev[i]; } return sqrt(nevyazkaSumm); }
NOX::Abstract::Group::ReturnType LOCA::Epetra::Group::computeComplex(double frequency) { std::string callingFunction = "LOCA::Epetra::Group::computeComplex()"; // We must have the time-dependent interface if (userInterfaceTime == Teuchos::null) return NOX::Abstract::Group::BadDependency; #ifdef HAVE_NOX_EPETRAEXT if (isValidComplex) return NOX::Abstract::Group::Ok; NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok; NOX::Abstract::Group::ReturnType status; // Get Jacobian matrix Teuchos::RCP<Epetra_RowMatrix> jac = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(sharedLinearSystem.getObject(this)->getJacobianOperator()); // Create complex matrix if (complexMatrix == Teuchos::null) { std::vector< std::vector<int> >rowStencil(2); std::vector<int> rowIndex; rowStencil[0].push_back(0); rowStencil[0].push_back(1); rowStencil[1].push_back(-1); rowStencil[1].push_back(0); rowIndex.push_back(0); rowIndex.push_back(1); complexMatrix = Teuchos::rcp(new EpetraExt::BlockCrsMatrix(*jac, rowStencil, rowIndex, jac->Comm())); // Construct global solution vector, the overlap vector, and importer between them complexVec = Teuchos::rcp(new EpetraExt::BlockVector(jac->RowMatrixRowMap(), complexMatrix->RowMap())); } // Get mass matrix M Teuchos::RCP<Epetra_RowMatrix> mass = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(shiftedSharedLinearSystem->getObject(this)->getJacobianOperator()); // Compute w*M status = computeShiftedMatrix(0.0, frequency); finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus, callingFunction); // Load w*M in complex matrix complexMatrix->LoadBlock(*mass, 1, 0); // Compute -w*M status = computeShiftedMatrix(0.0, -frequency); finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus, callingFunction); // Load -w*M in complex matrix complexMatrix->LoadBlock(*mass, 0, 1); // Compute J status = computeJacobian(); finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus, callingFunction); // Load J in complex matrix complexMatrix->LoadBlock(*jac, 0, 0); complexMatrix->LoadBlock(*jac, 1, 1); // Create linear system if (complexSharedLinearSystem == Teuchos::null) { NOX::Epetra::Vector nev(complexVec, NOX::Epetra::Vector::CreateView); Teuchos::RCP<Teuchos::ParameterList> lsParams = globalData->parsedParams->getSublist("Linear Solver"); // Create the Linear System Teuchos::RCP<NOX::Epetra::Interface::Required> iReq; Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac; Teuchos::RCP<NOX::Epetra::LinearSystem> complexLinSys = Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, *lsParams, iReq, iJac, complexMatrix, nev)); complexLinSys->setJacobianOperatorForSolve(complexMatrix); complexSharedLinearSystem = Teuchos::rcp(new NOX::SharedObject<NOX::Epetra::LinearSystem, LOCA::Epetra::Group>(complexLinSys)); } if (finalStatus == NOX::Abstract::Group::Ok) isValidComplex = true; return finalStatus; #else globalData->locaErrorCheck->throwError(callingFunction, "Must have EpetraExt support for Hopf tracking. Configure trilinos with --enable-epetraext"); return NOX::Abstract::Group::BadDependency; #endif }
NOX::Abstract::Group::ReturnType LOCA::Epetra::Group::applyComplexTransposeInverseMultiVector( Teuchos::ParameterList& lsParams, const NOX::Abstract::MultiVector& input_real, const NOX::Abstract::MultiVector& input_imag, NOX::Abstract::MultiVector& result_real, NOX::Abstract::MultiVector& result_imag) const { std::string callingFunction = "LOCA::Epetra::Group::applyComplexTransposeInverseMultiVector()"; // We must have the time-dependent interface if (userInterfaceTime == Teuchos::null) return NOX::Abstract::Group::BadDependency; #ifdef HAVE_NOX_EPETRAEXT if (complexSharedLinearSystem == Teuchos::null) { NOX::Epetra::Vector nev(complexVec, NOX::Epetra::Vector::CreateView); // Create the Linear System Teuchos::RCP<NOX::Epetra::Interface::Required> iReq; Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac; Teuchos::RCP<NOX::Epetra::LinearSystem> complexLinSys = Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams, iReq, iJac, complexMatrix, nev)); complexLinSys->setJacobianOperatorForSolve(complexMatrix); complexSharedLinearSystem = Teuchos::rcp(new NOX::SharedObject<NOX::Epetra::LinearSystem, LOCA::Epetra::Group>(complexLinSys)); } Teuchos::RCP<NOX::Epetra::LinearSystem> complexLinSys = Teuchos::rcp_const_cast<NOX::Epetra::LinearSystem>(complexSharedLinearSystem->getObject()); // Instantiate transpose solver LOCA::Epetra::TransposeLinearSystem::Factory tls_factory(globalData); if (tls_strategy == Teuchos::null) tls_strategy = tls_factory.create(Teuchos::rcp(&lsParams, false), complexLinSys); // Compute complex transpose tls_strategy->createJacobianTranspose(); // Now compute preconditioner tls_strategy->createTransposePreconditioner(xVector, lsParams); // Solve each complex system EpetraExt::BlockVector complex_input(*complexVec); EpetraExt::BlockVector complex_result(*complexVec); NOX::Epetra::Vector nev_input(Teuchos::rcp(&complex_input,false), NOX::Epetra::Vector::CreateView); NOX::Epetra::Vector nev_result(Teuchos::rcp(&complex_result,false), NOX::Epetra::Vector::CreateView); const NOX::Epetra::Vector* epetra_input_real; const NOX::Epetra::Vector* epetra_input_imag; NOX::Epetra::Vector* epetra_result_real; NOX::Epetra::Vector* epetra_result_imag; bool status; bool finalStatus = true; for (int i=0; i<input_real.numVectors(); i++) { epetra_input_real = dynamic_cast<const NOX::Epetra::Vector*>(&input_real[i]); epetra_input_imag = dynamic_cast<const NOX::Epetra::Vector*>(&input_imag[i]); epetra_result_real = dynamic_cast<NOX::Epetra::Vector*>(&result_real[i]); epetra_result_imag = dynamic_cast<NOX::Epetra::Vector*>(&result_imag[i]); complex_input.LoadBlockValues(epetra_input_real->getEpetraVector(), 0); complex_input.LoadBlockValues(epetra_input_imag->getEpetraVector(), 1); complex_result.PutScalar(0.0); status = tls_strategy->applyJacobianTransposeInverse(lsParams, nev_input, nev_result); complex_result.ExtractBlockValues(epetra_result_real->getEpetraVector(),0); complex_result.ExtractBlockValues(epetra_result_imag->getEpetraVector(),1); finalStatus = finalStatus && status; } // Set original operators in linear system complexMatrix->SetUseTranspose(false); complexLinSys->setJacobianOperatorForSolve(complexMatrix); complexLinSys->destroyPreconditioner(); if (finalStatus) return NOX::Abstract::Group::Ok; else return NOX::Abstract::Group::NotConverged; #else globalData->locaErrorCheck->throwError(callingFunction, "Must have EpetraExt support for Hopf tracking. Configure trilinos with --enable-epetraext"); return NOX::Abstract::Group::BadDependency; #endif }
int main(int argc, char *argv[]){ int mode=0; int n = 1; int t = 3; int max = 10; double *A; double *b; double t1; FILE* input; int ret = 0; opterr = 0; while ((ret = getopt( argc, argv, "f::g:N:t:")) != -1) { switch (ret) { case 'N': if (optarg == NULL) return -1; max = atoi(optarg); printf("максимальный выходной размер: %d\n", max); break; case 't': if (optarg == NULL) return -1; t = atoi(optarg); break; case 'f': mode = 1; if (optarg != NULL){ printf ("ввод из файла %s\n", optarg); if ((input = fopen (optarg, "r")) == NULL) { perror ("невозможно открыть файл\n"); return -1; } } else { printf ("ввод из файла input.txt\n"); if ((input = fopen ("input.txt", "r")) == NULL) { perror ("невозможно открыть файл\n"); return -1; } } break; case 'g': if (mode == 1) break; if (optarg == NULL) return -1; printf("ввод из функции\n"); mode = 2; n = atoi(optarg); printf("матрица размера: %d\n", n); break; case '?': printf("неизвестная опция -%c\n", optopt); printf("поддерживаемые опции:\n"); printf("f - ввод матрицы из файла, являющегося аргументом, или, если аргумента нет, ввод матрицы из файла input.txt;\n"); printf("g - ввод матрицы из функции. Аргумент функции (обязателен) является размером матрицы;\n"); printf("t - количество нитей;\n"); printf("N - максимальный выходной размер.\n"); return -1; } } printf("Используется %d нитей.\n", t); if (mode == 1){ if(fscanf (input, "%d", &n) == 0){ printf ("не получилось сосканировать размер матрицы из файла\n"); return -1; } A = new double [n*(n+1)]; if (A == NULL){ printf("не удалось выделить память под матрицу А\n"); return -1; } if (file_input(input, n, A) != 0){ return -1; } fclose(input); } else if (mode == 2){ A = new double [n*(n+1)]; if (func_input(A, n) != 0){ return -1; } } else { printf("Требуется запустить программу с какими-либо параметрами\n"); printf("Поддерживаемые параметры запуска:\n"); printf("f - ввод матрицы из файла, являющегося аргументом, или, если аргумента нет, ввод матрицы из файла input.txt;\n"); printf("g - ввод матрицы из функции. Аргумент функции (обязателен) является размером матрицы;\n"); printf("t - количество нитей;\n"); printf("N - опция, аргумент которой (обязателен) задает максимальный выходной размер.\n"); return -1; } pthread_t *threads = new pthread_t [t]; //инициализируем нити, выделяем под них память if (threads == NULL){ printf("не удалось выделить память под массив нитей\n"); return -1; } b = new double [n]; if (b == NULL){ printf("не удалось выделить память под вектор b\n"); return -1; } for (int z=0;z<n;z++){ b[z] = -A[z*(n+1)+n]; } int MAX_OUTPUT_SIZE = 10; PrintMatrix(n, A, b, MAX_OUTPUT_SIZE); delete []b; printf("\n"); FILE *out; out = fopen("output.txt", "wr"); if(out == NULL){ printf("не могу открыть выходной файл\n"); return -1; } double *x = new double [n]; //сюда пишем решение if (x == NULL){ printf("не удалось выделить память под вектор x\n"); return -1; } double *E = new double [(n+1)*(n+1)]; //здесь будут храниться базисы if (E == NULL){ printf("не удалось выделить память под матрицу Е\n"); return -1; } solve *args = new solve [t]; //массив структур для нитей if (args == NULL){ printf("не удалось выделить память под аргументы нитей\n"); return -1; } double *v = new double [n+1]; //сюда запоминается вектор для master if (v == NULL){ printf("не удалось выделить память под вектор v\n"); return -1; } printf("\nрешение системы...\n"); t1 = get_full_time(); //get_full_time для счета астрономического времени Solve(n,A,x,t,threads,E,args,v); t1 = get_full_time() - t1; Nevyaska * arg = new Nevyaska [t]; if (args == NULL){ printf("не удалось выделить память под структуру значений для невязки\n"); return -1; } printf("\n"); file_output(out,n,max,x); printf("время решения системы = %f\n", t1); printf("\nподсчет невязки...\n"); printf("невязка = %e\n", nev(n,A,x,t,threads,arg)); if (mode == 2){ printf("норма погрешности = %e\n", error_rate(n,x)); } delete []A; delete []x; delete []E; delete []v; delete []args; delete []threads; delete []arg; fclose(out); return 0; }