bool ProjectBase::addOMCase(QString filePath) { // do not reload if already loaded if(!casesFiles().contains(QFileInfo(filePath))) { OMCase* newCase = Load::newOMCase(filePath,this); if(!newCase) return false; Problem* problem = dynamic_cast<Problem*>(newCase); if(problem) addProblem(problem); else { Result* result = dynamic_cast<Result*>(newCase); if(result) addResult(result); } return true; } else { InfoSender::instance()->sendWarning(QString("OMCase already loaded. Won't be loaded a second time. [")+filePath+QString("]")); return false; } }
void Driver::addDependence( const QString & fileName, const Dependence & dep ) { QFileInfo fileInfo( dep.first ); QString fn = fileInfo.absFilePath(); if ( !depresolv ){ findOrInsertDependenceList( fileName ).insert( fn, dep ); return; } QString file = findIncludeFile( dep ); findOrInsertDependenceList( fileName ).insert( file, dep ); if ( m_parsedUnits.find(file) != m_parsedUnits.end() ) return; if ( !QFile::exists( file ) ) { Problem p( "Couldn't find include file " + dep.first, lexer ? lexer->currentLine() : -1, lexer ? lexer->currentColumn() : -1 ); addProblem( fileName, p ); return; } QString cfn = m_currentFileName; Lexer *l = lexer; parseFile( file ); m_currentFileName = cfn; lexer = l; }
Problem* ProjectBase::restoreProblemFromResult(Result* result) { Problem* restoredPb = result->problem()->clone(); restoredPb->setName(restoredPb->name().replace(" result","")); HighTools::checkUniqueProblemName(this,restoredPb,_problems); addProblem(restoredPb); return restoredPb; }
int mathGame::problemGenerator(){ int randomProblem = 0, correctAnswer = 0, answer = 0; randomProblem = rand() % 4 + 1; switch (randomProblem) { case 1: correctAnswer = minusProblem(); cin >> answer; if (answer == correctAnswer) { cout << "Correct!" << endl; addPoint(); } else cout << "Incorrect!" << endl; break; case 2: correctAnswer = addProblem(); cin >> answer; if (answer == correctAnswer) { cout << "Correct!" << endl; addPoint(); } else cout << "Incorrect!" << endl; break; case 3: correctAnswer = multiplyProblem(); cin >> answer; if (answer == correctAnswer) { cout << "Correct!" << endl; addPoint(); } else cout << "Incorrect!" << endl; break; case 4: correctAnswer = divideProblem(); cin >> answer; if (answer == correctAnswer) { cout << "Correct!" << endl; addPoint(); } else cout << "Incorrect!" << endl; break; default: cout << "error 111: number out of range" << endl; break; } return answer; }
/* * The equalities are eliminated. * *0=(Me_1 Me_2)(Re Ri)' + Qe *Vi=(Mi_1 Mi_2)(Re Ri)' + Qi * *Re=-Me_1^{-1}(Me_2Ri+Qe) * *Vi=(Mi_2-Mi_1 Me_1^{-1} Me_2)Ri+Qi-Mi1 Me_1^{-1} Qe * */ void GMPReducedSolve(GenericMechanicalProblem* pInProblem, double *reaction , double *velocity, int * info, SolverOptions* options, NumericsOptions* numerics_options) { SparseBlockStructuredMatrix* m = pInProblem->M->matrix1; int nbRow = m->blocksize0[m->blocknumber0 - 1]; int nbCol = m->blocksize1[m->blocknumber1 - 1]; double *Me = (double *) malloc(nbRow * nbCol * sizeof(double)); double *Qe = (double *) malloc(nbRow * sizeof(double)); double *Mi = (double *) malloc(nbRow * nbCol * sizeof(double)); double *Qi = (double *) malloc(nbRow * sizeof(double)); int Me_size; int Mi_size; buildReducedGMP(pInProblem, Me, Mi, Qe, Qi, &Me_size, &Mi_size); if ((Me_size == 0 || Mi_size == 0)) { genericMechanicalProblem_GS(pInProblem, reaction, velocity, info, options, numerics_options); free(Me); free(Qe); free(Mi); free(Qi); return; } double * pseduInvMe1 = (double *)malloc(Me_size * Me_size * sizeof(double)); memcpy(pseduInvMe1, Me, Me_size * Me_size * sizeof(double)); pinv(pseduInvMe1, Me_size, Me_size, 1e-16); double *Mi2 = Mi + Mi_size * Me_size; double *Mi1 = Mi; double *Me2 = Me + Me_size * Me_size; #ifdef GMP_DEBUG_GMPREDUCED_SOLVE double *Me1 = Me; FILE * titi = fopen("buildReducedGMP_output.txt", "w"); printf("GMPReducedsolve\n"); printDenseMatrice("Me1", titi, Me1, Me_size, Me_size); printDenseMatrice("Me2", titi, Me2, Me_size, Mi_size); printDenseMatrice("Mi1", titi, Mi1, Mi_size, Me_size); printDenseMatrice("Mi2", titi, Mi2, Mi_size, Mi_size); printDenseMatrice("Qe", titi, Qe, Me_size, 1); printDenseMatrice("Qi", titi, Qi, Mi_size, 1); printDenseMatrice("Me1inv", titi, pseduInvMe1, Me_size, Me_size); #endif double * reducedProb = (double *)malloc(Mi_size * Mi_size * sizeof(double)); memcpy(reducedProb, Mi2, Mi_size * Mi_size * sizeof(double)); double * Mi1pseduInvMe1 = (double *)malloc(Mi_size * Me_size * sizeof(double)); cblas_dgemm(CblasColMajor,CblasNoTrans, CblasNoTrans, Mi_size, Me_size, Me_size, -1.0, Mi1, Mi_size, pseduInvMe1, Me_size, 0.0, Mi1pseduInvMe1, Mi_size); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE printDenseMatrice("minusMi1pseduInvMe1", titi, Mi1pseduInvMe1, Mi_size, Me_size); fprintf(titi, "_minusMi1pseduInvMe1=-Mi1*Me1inv;\n"); #endif cblas_dgemv(CblasColMajor,CblasNoTrans, Mi_size, Me_size, 1.0, Mi1pseduInvMe1, Mi_size, Qe, 1, 1.0, Qi, 1); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE printDenseMatrice("newQi", titi, Qi, Mi_size, 1); fprintf(titi, "_newQi=Qi+_minusMi1pseduInvMe1*Qe;\n"); #endif cblas_dgemm(CblasColMajor,CblasNoTrans, CblasNoTrans, Mi_size, Mi_size, Me_size, 1.0, Mi1pseduInvMe1, Mi_size, Me2, Me_size, 1.0, reducedProb, Mi_size); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE printDenseMatrice("W", titi, reducedProb, Mi_size, Mi_size); fprintf(titi, "_W=Mi2+_minusMi1pseduInvMe1*Me2;\n"); #endif listNumericsProblem * curProblem = 0; GenericMechanicalProblem * _pnumerics_GMP = buildEmptyGenericMechanicalProblem(); curProblem = pInProblem->firstListElem; while (curProblem) { switch (curProblem->type) { case SICONOS_NUMERICS_PROBLEM_EQUALITY: { break; } case SICONOS_NUMERICS_PROBLEM_LCP: { addProblem(_pnumerics_GMP, curProblem->type, curProblem->size); break; } case SICONOS_NUMERICS_PROBLEM_FC3D: { FrictionContactProblem* pFC3D = (FrictionContactProblem*)addProblem(_pnumerics_GMP, curProblem->type, curProblem->size); *(pFC3D->mu) = *(((FrictionContactProblem*)curProblem->problem)->mu); break; } default: printf("GMPReduced buildReducedGMP: problemType unknown: %d . \n", curProblem->type); } curProblem = curProblem->nextProblem; } NumericsMatrix numM; numM.storageType = 0; numM.matrix0 = reducedProb; numM.matrix1 = 0; numM.size0 = Mi_size; numM.size1 = Mi_size; _pnumerics_GMP->M = &numM; _pnumerics_GMP->q = Qi; double *Rreduced = (double *) malloc(Mi_size * sizeof(double)); double *Vreduced = (double *) malloc(Mi_size * sizeof(double)); genericMechanicalProblem_GS(_pnumerics_GMP, Rreduced, Vreduced, info, options, numerics_options); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE if (*info) { printf("\nGMPREduced failed!\n"); } else { printf("\nGMPREduced succed!\n"); printDenseMatrice("Ri", titi, Rreduced, Mi_size, 1); printDenseMatrice("Vi", titi, Vreduced, Mi_size, 1); } #endif if (!*info) { /*Re computation*/ double * Re = (double*)malloc(Me_size * sizeof(double)); double * Rbuf = (double*)malloc(Me_size * sizeof(double)); memcpy(Rbuf, Qe, Me_size * sizeof(double)); cblas_dgemv(CblasColMajor,CblasNoTrans, Me_size, Mi_size, 1.0, Me2, Me_size, Rreduced, 1, 1.0, Rbuf, 1); cblas_dgemv(CblasColMajor,CblasNoTrans, Me_size, Me_size, -1.0, pseduInvMe1, Me_size, Rbuf, 1, 0.0, Re, 1); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE fprintf(titi, "_Re=-Me1inv*(Me2*Ri+Qe);\n"); printDenseMatrice("Re", titi, Re, Me_size, 1); #endif GMPReducedSolToSol(pInProblem, reaction, velocity, Re, Rreduced, Vreduced); double err; int tolViolate = GenericMechanical_compute_error(pInProblem, reaction, velocity, options->dparam[0], options, &err); if (tolViolate) { printf("GMPReduced, warnning, reduced problem solved, but error of intial probleme violated tol = %e, err= %e\n", options->dparam[0], err); } free(Re); free(Rbuf); } #ifdef GMP_DEBUG_GMPREDUCED_SOLVE fclose(titi); #endif free(Rreduced); free(Vreduced); freeGenericMechanicalProblem(_pnumerics_GMP, NUMERICS_GMP_FREE_GMP); free(Me); free(Mi); free(Qe); free(Qi); free(pseduInvMe1); free(reducedProb); free(Mi1pseduInvMe1); // GenericMechanicalProblem GMPOutProblem; // SparseBlockStructuredMatrix mOut; }
/* * The equalities are assamblate in one block. * *0=(Me_1 Me_2)(Re Ri)' + Qe *Vi=(Mi_1 Mi_2)(Re Ri)' + Qi * *and GS. */ void GMPReducedEqualitySolve(GenericMechanicalProblem* pInProblem, double *reaction , double *velocity, int * info, SolverOptions* options, NumericsOptions* numerics_options) { SparseBlockStructuredMatrix* m = pInProblem->M->matrix1; int nbRow = m->blocksize0[m->blocknumber0 - 1]; int nbCol = m->blocksize1[m->blocknumber1 - 1]; int Me_size; int Mi_size; double * reducedProb = (double *)malloc(nbRow * nbCol * sizeof(double)); double * Qreduced = (double *)malloc(nbRow * sizeof(double)); double *Rreduced = (double *) calloc(nbCol, sizeof(double)); double *Vreduced = (double *) calloc(nbRow, sizeof(double)); _GMPReducedEquality(pInProblem, reducedProb, Qreduced, &Me_size, &Mi_size); if (Me_size == 0) { genericMechanicalProblem_GS(pInProblem, reaction, velocity, info, options, numerics_options); free(reducedProb); free(Qreduced); free(Rreduced); free(Vreduced); return; } listNumericsProblem * curProblem = 0; GenericMechanicalProblem * _pnumerics_GMP = buildEmptyGenericMechanicalProblem(); curProblem = pInProblem->firstListElem; if (Me_size) addProblem(_pnumerics_GMP, SICONOS_NUMERICS_PROBLEM_EQUALITY, Me_size); unsigned int curPos = 0; unsigned int curPosEq = 0; unsigned int curPosInq = Me_size; while (curProblem) { unsigned int curSize = curProblem->size; switch (curProblem->type) { case SICONOS_NUMERICS_PROBLEM_EQUALITY: { memcpy(Vreduced + curPosEq, velocity + curPos, curSize * sizeof(double)); memcpy(Rreduced + curPosEq, reaction + curPos, curSize * sizeof(double)); curPosEq += curSize; curPos += curSize; break; } case SICONOS_NUMERICS_PROBLEM_LCP: { memcpy(Vreduced + curPosInq, velocity + curPos, curSize * sizeof(double)); memcpy(Rreduced + curPosInq, reaction + curPos, curSize * sizeof(double)); curPosInq += curSize; curPos += curSize; addProblem(_pnumerics_GMP, curProblem->type, curProblem->size); break; } case SICONOS_NUMERICS_PROBLEM_FC3D: { memcpy(Vreduced + curPosInq, velocity + curPos, curSize * sizeof(double)); memcpy(Rreduced + curPosInq, reaction + curPos, curSize * sizeof(double)); curPosInq += curSize; curPos += curSize; FrictionContactProblem* pFC3D = (FrictionContactProblem*)addProblem(_pnumerics_GMP, curProblem->type, curProblem->size); *(pFC3D->mu) = *(((FrictionContactProblem*)curProblem->problem)->mu); break; } default: printf("GMPReduced buildReducedGMP: problemType unknown: %d . \n", curProblem->type); } curProblem = curProblem->nextProblem; } #ifdef GMP_DEBUG_GMPREDUCED_SOLVE // printDenseMatrice("newPrb",titi,reducedProb,nbRow,nbCol); // printDenseMatrice("newQ",titi,Qreduced,nbRow,1); #endif NumericsMatrix numM; numM.storageType = 0; numM.matrix0 = reducedProb; numM.matrix1 = 0; numM.size0 = nbRow; numM.size1 = nbCol; _pnumerics_GMP->M = &numM; _pnumerics_GMP->q = Qreduced; genericMechanicalProblem_GS(_pnumerics_GMP, Rreduced, Vreduced, info, options, numerics_options); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE if (*info) { printf("\nGMPREduced2 failed!\n"); } else { printf("\nGMPREduced2 succed!\n"); // printDenseMatrice("R",titi,Rreduced,nbRow,1); // printDenseMatrice("V",titi,Vreduced,nbRow,1); } #endif if (!*info) { GMPReducedSolToSol(pInProblem, reaction, velocity, Rreduced, Rreduced + Me_size, Vreduced + Me_size); #ifdef GMP_DEBUG_GMPREDUCED_SOLVE // printDenseMatrice("R2",titi,reaction,nbRow,1); // printDenseMatrice("V2",titi,velocity,nbRow,1); #endif double err; int tolViolate = GenericMechanical_compute_error(pInProblem, reaction, velocity, options->dparam[0], options, &err); if (tolViolate) { printf("GMPReduced2, warnning, reduced problem solved, but error of intial probleme violated tol = %e, err= %e\n", options->dparam[0], err); } } #ifdef GMP_DEBUG_GMPREDUCED_SOLVE // fclose(titi); #endif free(Rreduced); free(Vreduced); freeGenericMechanicalProblem(_pnumerics_GMP, NUMERICS_GMP_FREE_GMP); free(Qreduced); free(reducedProb); }
void Driver::addDependence( const QString & fileName, const Dependence & dep ) { // this can happen if the parser was invoked on a snippet of text and not a file if ( fileName.isEmpty() || !m_currentParsedFile ) return; //@todo prevent cyclic dependency-loops QFileInfo fileInfo( dep.first ); QString fn = fileInfo.absFilePath(); if ( !depresolv ) { findOrInsertDependenceList( fileName ).insert( fn, dep ); m_currentParsedFile->addIncludeFile( dep.first, 0, dep.second == Dep_Local ); return ; } QString file = findIncludeFile( dep ); findOrInsertDependenceList( fileName ).insert( file, dep ); m_currentParsedFile->addIncludeFile( file, 0, dep.second == Dep_Local ); if ( !QFile::exists( file ) ) { Problem p( i18n( "Could not find include file %1" ).arg( dep.first ), lexer ? lexer->currentLine() : -1, lexer ? lexer->currentColumn() : -1, Problem::Level_Warning ); addProblem( fileName, p ); return ; } if( m_currentLexerCache ) m_currentLexerCache->addIncludeFile( file, QDateTime() ); ///The time will be overwritten in CachedLexedFile::merge(...) /**What should be done: * 1. Lex the file to get all the macros etc. * 2. TODO: Check what previously set macros the file was affected by, and compare those macros to any previously parsed instances of this file. * 2.1 If there is a parse-instance of the file where all macros that played a role had the same values, we do not need to reparse this file. * 2.2 If there is no such fitting instance, the file needs to be parsed and put to the code-model. * * It'll be necessary to have multiple versions of one file in the code-model. */ IntIncreaser i( m_dependenceDepth ); if( m_dependenceDepth > m_maxDependenceDepth ) { //kdDebug( 9007 ) << "maximum dependence-depth of " << m_maxDependenceDepth << " was reached, " << fileName << " will not be processed" << endl; return; } CachedLexedFilePointer lexedFileP = m_lexerCache.lexedFile( HashedString( file ) ); if( lexedFileP ) { CachedLexedFile& lexedFile( *lexedFileP ); m_currentLexerCache->merge( lexedFile ); //The ParseHelper will will copy the include-files into the result later for( MacroSet::Macros::const_iterator it = lexedFile.definedMacros().macros().begin(); it != lexedFile.definedMacros().macros().end(); ++it ) { addMacro( (*it) ); } ///@todo fill usingMacro(...) return; } ParseHelper h( file, true, this, false, m_currentMasterFileName ); /*if ( m_parsedUnits.find(file) != m_parsedUnits.end() ) return;*/ if( shouldParseIncludedFile( m_currentParsedFile ) ) ///Until the ParseHelper is destroyed, m_currentParsedFile will stay the included file h.parse(); }