void ExternalLanguage::receivedStdout( K3Process *, char * buffer, int buflen ) { QStringList lines = QStringList::split( '\n', QString::fromLocal8Bit( buffer, buflen ), false ); QStringList::iterator end = lines.end(); for ( QStringList::iterator it = lines.begin(); it != end; ++it ) { if ( isError( *it ) ) { outputError( *it ); outputtedError( *it ); } else if ( isWarning( *it ) ) { outputWarning( *it ); outputtedWarning( *it ); } else { outputMessage( *it ); outputtedMessage( *it ); } } }
double NLEQInterface::solve(const vector<double>& yin) { if (yin.size() == 0) { return 0; } // Set up a dummy Jacobian, actual Jacobian is computed // by NLEQ using finite differences // double* Jacobian = new double[1]; ierr = 0; IWK[31 - 1] = maxIterations; // Max iterations // Set up default scaling factors for (int i = 0; i < n; i++) { XScal[i] = 1.0; } for (int i = 0; i < nOpts; i++) { iopt[i] = 0; } iopt[31 - 1] = 3; // Set for Highly nonlinear problem // Initialise all array elements to 0.0 for (int i = 0; i < LIWK; i++) { IWK[i] = 0; } IWK[31 - 1] = maxIterations; // Max iterations for (int i = 0; i < LWRK; i++) { RWK[i] = 0.0; } RWK[22 - 1] = 1E-20; // Minimal allowed damping factor // For some reason NLEQ modifies the tolerance value, use a local copy instead double tmpTol = relativeTolerance; // set up the thread local variables, only this thread // access them. if (*threadModel) { throw(Exception("thread local storage model is set, this should never occur here.")); } *threadModel = model; vector<double> stateVector(n); model->getStateVector(&stateVector[0]); NLEQ1( &n, &ModelFunction, NULL, &stateVector[0], XScal, &tmpTol, iopt, &ierr, &LIWK, IWK, &LWRK, RWK); // done, clear it. *threadModel = 0; if (ierr == 2) // retry { for (int i = 0; i < nOpts; i++) { iopt[i] = 0; } iopt[31 - 1] = 3; // Set for Highly nonlinear problem iopt[0] = 1; // Try again but tell NLEQ not to reinitialize tmpTol = relativeTolerance; } if(ierr > 0 ) { if (isWarning(ierr)) { Log(Logger::LOG_WARNING) << ErrorForStatus(ierr); } else { string err = ErrorForStatus(ierr); Log(Logger::LOG_ERROR)<<"Error :"<<err; throw NLEQException(err); } } return computeSumsOfSquares(); }