VectorXd Robot::prediction(VectorXd X){ VectorXd Xs(3); VectorXf noise = VectorXf::Random(3); Xs(0)=X(0)+10*noise(0); Xs(1)=X(1)+10*noise(1); Xs(2)=X(2)+10*noise(2); return Xs; }
void DfHpqX::getHpq(TlDenseSymmetricMatrix_Lapack* pHpq, TlDenseSymmetricMatrix_Lapack* pHpq2) { const int numOfAOs = this->m_nNumOfAOs; // make coordinates const Fl_Geometry flGeom((*this->pPdfParam_)["coordinates"]); const int numOfAtoms = flGeom.getNumOfAtoms(); const int numOfDummyAtoms = flGeom.getNumOfDummyAtoms(); const int numOfRealAtoms = numOfAtoms - numOfDummyAtoms; std::vector<TlAtom> Cs(numOfRealAtoms); std::vector<TlAtom> Xs(numOfDummyAtoms); std::size_t realAtomIndex = 0; std::size_t dummyAtomIndex = 0; for (int i = 0; i < numOfAtoms; ++i) { const std::string atomName = flGeom.getAtomSymbol(i); const TlPosition p = flGeom.getCoordinate(i); const double charge = flGeom.getCharge(i); const TlAtom atom(atomName, p, charge); if (atomName == "X") { Xs[dummyAtomIndex] = atom; ++dummyAtomIndex; } else { Cs[realAtomIndex] = atom; ++realAtomIndex; } } assert(realAtomIndex == Cs.size()); assert(dummyAtomIndex == Xs.size()); pHpq->resize(numOfAOs); pHpq2->resize(numOfAOs); this->createEngines(); DfTaskCtrl* pTaskCtrl = this->getDfTaskCtrlObject(); std::vector<DfTaskCtrl::Task2> taskList; bool hasTask = pTaskCtrl->getQueue2(this->orbitalInfo_, true, this->grainSize_, &taskList, true); while (hasTask == true) { this->getHpq_part(this->orbitalInfo_, taskList, Cs, Xs, pHpq, pHpq2); hasTask = pTaskCtrl->getQueue2(this->orbitalInfo_, true, this->grainSize_, &taskList); } if (this->chargeExtrapolateNumber_ > 0) { *pHpq2 /= static_cast<double>(this->chargeExtrapolateNumber_); } this->finalize(pHpq, pHpq2); delete pTaskCtrl; pTaskCtrl = NULL; this->destroyEngines(); }
int Ifpack_ShyLU::JustTryIt() { // Dummy function, To show the error in AztecOO, This works //cout << "Entering JustTryIt" << endl; AztecOO *solver; solver = slu_data_.innersolver; //cout << solver_ << endl; Epetra_Map BsMap(-1, slu_data_.Snr, slu_data_.SRowElems, 0, A_->Comm()); Epetra_MultiVector Xs(BsMap, 1); Epetra_MultiVector Bs(BsMap, 1); Xs.PutScalar(0.0); solver->SetLHS(&Xs); solver->SetRHS(&Bs); solver->Iterate(30, 1e-10); return 0; }
real BppSolver::columnGeneration(BinPackingProblem& bpp) { while (true) // repeat until no column can be added { try { real masterObjValue = 0.0; // solve LP master bool found = BPSolver.solve(); if (found) { // master lp lower bound value masterObjValue = BPSolver.getObjValue(); BPmodel.setDualValues(BPSolver); // set pricer obj coeficient to dual master values pricerModel.setObjLinearCoefs(BPmodel.getDualsValues()); } else { // master not feasible. return IloInfinity; } #ifdef EXPORT_MODELS pricerSolver.exportModel("pricer.lp"); #endif found = pricerSolver.solve(); if (found) { // get pricer objectif value Z* real pricerValue = pricerSolver.getObjValue(); if (pricerValue - 1.0 >= EPS) // then add new column { auto& Z = pricerModel.getPrimalValues(); #ifdef DBG_OUTPUT for (int i = 0; i < nbItems; i++) std::cout << Z[i] << " "; std::cout << std::endl; #endif // get the set S* such that Zi == 1 IntBin _S; for (std::size_t i = 0; i < bpp.getNbItems(); i++) { if (Z[i] >= 1 - EPS) _S.addItem(i, bpp.getItemWeights()[i]); } // make _S maximal makeBinMaximal(bpp, _S); // add new bin variable to master BPmodel.addColumn(_S); #ifdef EXPORT_MODELS BPSolver.exportModel("model.lp"); #endif } else // no column to add. { #ifdef DBG_OUTPUT std::cout << masterObjValue << std::endl; IloNumArray Xs(env); BPSolver.getValues(BPVars, Xs); for (size_t i = 0; i < BPVars.getSize(); i++) std::cout << Xs[i] << ", "; std::cout << std::endl; Xs.end(); #endif #ifdef EXPORT_MODEL BPSolver.exportModel("model.lp"); pricerSolver.exportModel("pricer.lp"); #endif // !EXPORT_MODEL BPmodel.setPrimalValues(BPSolver); return masterObjValue; } } else // pricer solution not found { } } catch (IloException& e) { std::cout << "IloException rised : " << e << std::endl; } // TODO exception handling catch (...) // other errors { } }// END WHILE }
void parcel::setRelaxationTimes ( label celli, scalar& tauMomentum, scalarField& tauEvaporation, scalar& tauHeatTransfer, scalarField& tauBoiling, const spray& sDB, const scalar rho, const vector& Up, const scalar temperature, const scalar pressure, const scalarField& Yfg, const scalarField& m0, const scalar dt ) { const liquidMixture& fuels = sDB.fuels(); scalar mCell = rho*sDB.mesh().V()[cell()]; scalarField mfg(Yfg*mCell); label Ns = sDB.composition().Y().size(); label Nf = fuels.components().size(); // Tf is based on the 1/3 rule scalar Tf = T() + (temperature - T())/3.0; // calculate mixture properties scalar W = 0.0; scalar kMixture = 0.0; scalar cpMixture = 0.0; scalar muf = 0.0; for(label i=0; i<Ns; i++) { scalar Y = sDB.composition().Y()[i][celli]; W += Y/sDB.gasProperties()[i].W(); // Using mass-fractions to average... kMixture += Y*sDB.gasProperties()[i].kappa(Tf); cpMixture += Y*sDB.gasProperties()[i].Cp(Tf); muf += Y*sDB.gasProperties()[i].mu(Tf); } W = 1.0/W; scalarField Xf(Nf, 0.0); scalarField Yf(Nf, 0.0); scalarField psat(Nf, 0.0); scalarField msat(Nf, 0.0); for(label i=0; i<Nf; i++) { label j = sDB.liquidToGasIndex()[i]; scalar Y = sDB.composition().Y()[j][celli]; scalar Wi = sDB.gasProperties()[j].W(); Yf[i] = Y; Xf[i] = Y*W/Wi; psat[i] = fuels.properties()[i].pv(pressure, temperature); msat[i] = min(1.0, psat[i]/pressure)*Wi/W; } scalar nuf = muf/rho; scalar liquidDensity = fuels.rho(pressure, T(), X()); scalar liquidcL = fuels.cp(pressure, T(), X()); scalar heatOfVapour = fuels.hl(pressure, T(), X()); // calculate the partial rho of the fuel vapour // alternative is to use the mass fraction // however, if rhoFuelVap is small (zero) // d(mass)/dt = 0 => no evaporation... hmmm... is that good? NO! // Assume equilibrium at drop-surface => pressure @ surface // = vapour pressure to calculate fuel-vapour density @ surface scalar pressureAtSurface = fuels.pv(pressure, T(), X()); scalar rhoFuelVap = pressureAtSurface*fuels.W(X())/(specie::RR*Tf); scalarField Xs(sDB.fuels().Xs(pressure, temperature, T(), Xf, X())); scalarField Ys(Nf, 0.0); scalar Wliq = 0.0; for(label i=0; i<Nf; i++) { label j = sDB.liquidToGasIndex()[i]; scalar Wi = sDB.gasProperties()[j].W(); Wliq += Xs[i]*Wi; } for(label i=0; i<Nf; i++) { label j = sDB.liquidToGasIndex()[i]; scalar Wi = sDB.gasProperties()[j].W(); Ys[i] = Xs[i]*Wi/Wliq; } scalar Reynolds = Re(Up, nuf); scalar Prandtl = Pr(cpMixture, muf, kMixture); // calculate the characteritic times if(liquidCore_> 0.5) { // no drag for parcels in the liquid core.. tauMomentum = GREAT; } else { tauMomentum = sDB.drag().relaxationTime ( Urel(Up), d(), rho, liquidDensity, nuf, dev() ); } // store the relaxationTime since it is needed in some breakup models. tMom_ = tauMomentum; tauHeatTransfer = sDB.heatTransfer().relaxationTime ( liquidDensity, d(), liquidcL, kMixture, Reynolds, Prandtl ); // evaporation-properties are evaluated at averaged temperature // set the boiling conditions true if pressure @ surface is 99.9% // of the pressure // this is mainly to put a limit on the evaporation time, // since tauEvaporation is very very small close to the boiling point. for(label i=0; i<Nf; i++) { scalar Td = min(T(), 0.999*fuels.properties()[i].Tc()); bool boiling = fuels.properties()[i].pv(pressure, Td) >= 0.999*pressure; scalar Di = fuels.properties()[i].D(pressure, Td); scalar Schmidt = Sc(nuf, Di); scalar partialPressure = Xf[i]*pressure; // saturated vapour if(partialPressure > psat[i]) { tauEvaporation[i] = GREAT; } // not saturated vapour else { if (!boiling) { // for saturation evaporation, only use 99.99% for numerical robustness scalar dm = max(SMALL, 0.9999*msat[i] - mfg[i]); tauEvaporation[i] = sDB.evaporation().relaxationTime ( d(), fuels.properties()[i].rho(pressure, Td), rhoFuelVap, Di, Reynolds, Schmidt, Xs[i], Xf[i], m0[i], dm, dt ); } else { scalar Nusselt = sDB.heatTransfer().Nu(Reynolds, Prandtl); // calculating the boiling temperature of the liquid at ambient pressure scalar tBoilingSurface = Td; label Niter = 0; scalar deltaT = 10.0; scalar dp0 = fuels.properties()[i].pv(pressure, tBoilingSurface) - pressure; while ((Niter < 200) && (mag(deltaT) > 1.0e-3)) { Niter++; scalar pBoil = fuels.properties()[i].pv(pressure, tBoilingSurface); scalar dp = pBoil - pressure; if ( (dp > 0.0) && (dp0 > 0.0) ) { tBoilingSurface -= deltaT; } else { if ( (dp < 0.0) && (dp0 < 0.0) ) { tBoilingSurface += deltaT; } else { deltaT *= 0.5; if ( (dp > 0.0) && (dp0 < 0.0) ) { tBoilingSurface -= deltaT; } else { tBoilingSurface += deltaT; } } } dp0 = dp; } scalar vapourSurfaceEnthalpy = 0.0; scalar vapourFarEnthalpy = 0.0; for(label k = 0; k < sDB.gasProperties().size(); k++) { vapourSurfaceEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(tBoilingSurface); vapourFarEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(temperature); } scalar kLiquid = fuels.properties()[i].K(pressure, 0.5*(tBoilingSurface+T())); tauBoiling[i] = sDB.evaporation().boilingTime ( fuels.properties()[i].rho(pressure, Td), fuels.properties()[i].cp(pressure, Td), heatOfVapour, kMixture, Nusselt, temperature - T(), d(), liquidCore(), sDB.runTime().value() - ct(), Td, tBoilingSurface, vapourSurfaceEnthalpy, vapourFarEnthalpy, cpMixture, temperature, kLiquid ); } } } }
void PSSinthesis::Sinthesis(double s) { hops[Qcolumn-1] = round(hopa*(pow(2,(s/12)))); //Some declaration int L; L = N; for (int i=0; i< Qcolumn-1; i++) L = L + hops[i]; double r; int n1; int n2; double n3; //Some inicialization ysaida2 = &ysaida[L-N]; // We can divide the code in two here Phi = PhiPrevious + (hops[Qcolumn-1])*omega_true_sobre_fs[0] ; for (int i=0; i<(N/2 + 1); i++) Xs(i) = ExponencialComplexa(Phi(i)); Xs = Xa_abs[0] % Xs; PhiPrevious = Phi; for (int i=0; i<(N/2 + 1); i++) { fXs[i][0] = real(Xs(i)); fXs[i][1] = imag(Xs(i)); } /*Synthesis*/ if (p2) fftwf_execute(p2); double norm = N*sqrt( N/(2.0*hops[Qcolumn-1]) ); for (int i=0; i<N; i++) q[i] = q[i]*w[0](i)/norm; if (first == true) { first = false; fill_n(ysaida,L-N,0); for (int i=L-N; i<L; i++) ysaida[i] = q[i-(L-N)]; } else { for (int i=L-N; i<L; i++) ysaida[i] = ysaida[i] + q[i-(L-N)]; } //Linear interpolation r = hops[Qcolumn-1]/(1.0*hopa); for (int n=0; n < hopa; n++) { n3 = n*r+1; n1 = floor(n3); n2 = ceil(n3); yshift[n] = ysaida2[n1] + (ysaida2[n2]-ysaida2[n1])*(n3 - n1); } //Shift ysaida hops[0] left for (int i=0; i<L-hops[0]; i++) ysaida[i] = ysaida[i+hops[0]]; for (int i=L-hops[0]; i<L; i++) ysaida[i] = 0; }
void PitchDetection::FindNote() { for (int i=0; i<N; i++) { frames[N+i] = 0; } if (p) fftwf_execute(p); for (int i=0; i<(N + 1); i++) { Xa(i) = cx_float(fXa[i][0], fXa[i][1]); } Xs = Xa % conj(Xa); for (int i=0; i<(N + 1); i++) { fXs[i][0] = real(Xs(i)); fXs[i][1] = imag(Xs(i)); } if (p2) fftwf_execute(p2); for (int i=0; i<N; i++) { R(i) = q[i]/(2*N); } NORM.zeros(); NORM(0) = 2*R(0); for (int i=1; i<N; i++) { NORM(i) = NORM(i-1) - pow(frames[i-1],2)- pow(frames[N-i],2); } for (int i=0; i<N; i++) { F(i) = 1 -0.05*i/(N-1); } AUTO = ( 2*F % R )/NORM; int flag = 0; for (int i=0; (i<N)&&(flag==0); i++) { if( AUTO(i) > 0 ) { AUTO(i) = 0; } else { flag = 1; } } uword max_index; double fidelity = AUTO.max(max_index); if ((fidelity > 0.95) && (fidelity < 1) && ((int)max_index < N-1)) { double a = AUTO(max_index-1); double b = AUTO(max_index); double c = AUTO(max_index+1); double real_index = max_index + 0.5*(a-c)/(a-2*b+c); f = fs/real_index; int nota = (int)round( (12/log(2))*log(f/16.351597831287414) ); oitava = floor(nota/12.0); note = nota % 12; //cout << "nota = " << note[0] << " oitava = " << oitava[0] << " fidelity = " << fidelity << "\n"; } }
int shylu_dist_solve<Epetra_CrsMatrix,Epetra_MultiVector>( shylu_symbolic<Epetra_CrsMatrix,Epetra_MultiVector> *ssym, shylu_data<Epetra_CrsMatrix,Epetra_MultiVector> *data, shylu_config<Epetra_CrsMatrix,Epetra_MultiVector> *config, const Epetra_MultiVector& X, Epetra_MultiVector& Y ) { int err; AztecOO *solver = 0; assert(X.Map().SameAs(Y.Map())); //assert(X.Map().SameAs(A_->RowMap())); const Epetra_MultiVector *newX; newX = &X; //rd_->redistribute(X, newX); int nvectors = newX->NumVectors(); // May have to use importer/exporter Epetra_Map BsMap(-1, data->Snr, data->SRowElems, 0, X.Comm()); Epetra_Map BdMap(-1, data->Dnr, data->DRowElems, 0, X.Comm()); Epetra_MultiVector Bs(BsMap, nvectors); Epetra_Import BsImporter(BsMap, newX->Map()); assert(BsImporter.SourceMap().SameAs(newX->Map())); assert((newX->Map()).SameAs(BsImporter.SourceMap())); Bs.Import(*newX, BsImporter, Insert); Epetra_MultiVector Xs(BsMap, nvectors); Epetra_SerialComm LComm; // Use Serial Comm for the local vectors. Epetra_Map LocalBdMap(-1, data->Dnr, data->DRowElems, 0, LComm); Epetra_MultiVector localrhs(LocalBdMap, nvectors); Epetra_MultiVector locallhs(LocalBdMap, nvectors); Epetra_MultiVector Z(BdMap, nvectors); Epetra_MultiVector Bd(BdMap, nvectors); Epetra_Import BdImporter(BdMap, newX->Map()); assert(BdImporter.SourceMap().SameAs(newX->Map())); assert((newX->Map()).SameAs(BdImporter.SourceMap())); Bd.Import(*newX, BdImporter, Insert); int lda; double *values; err = Bd.ExtractView(&values, &lda); assert (err == 0); int nrows = ssym->C->RowMap().NumMyElements(); // copy to local vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = localrhs.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } // TODO : Do we need to reset the lhs and rhs here ? if (config->amesosForDiagonal) { ssym->LP->SetRHS(&localrhs); ssym->LP->SetLHS(&locallhs); ssym->Solver->Solve(); } else { ssym->ifSolver->ApplyInverse(localrhs, locallhs); } err = locallhs.ExtractView(&values, &lda); assert (err == 0); // copy to distributed vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = Z.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } Epetra_MultiVector temp1(BsMap, nvectors); ssym->R->Multiply(false, Z, temp1); Bs.Update(-1.0, temp1, 1.0); Xs.PutScalar(0.0); Epetra_LinearProblem Problem(data->Sbar.get(), &Xs, &Bs); if (config->schurSolver == "Amesos") { Amesos_BaseSolver *solver2 = data->dsolver; data->LP2->SetLHS(&Xs); data->LP2->SetRHS(&Bs); //cout << "Calling solve *****************************" << endl; solver2->Solve(); //cout << "Out of solve *****************************" << endl; } else { if (config->libName == "Belos") { solver = data->innersolver; solver->SetLHS(&Xs); solver->SetRHS(&Bs); } else { // See the comment above on why we are not able to reuse the solver // when outer solve is AztecOO as well. solver = new AztecOO(); //solver.SetPrecOperator(precop_); solver->SetAztecOption(AZ_solver, AZ_gmres); // Do not use AZ_none solver->SetAztecOption(AZ_precond, AZ_dom_decomp); //solver->SetAztecOption(AZ_precond, AZ_none); //solver->SetAztecOption(AZ_precond, AZ_Jacobi); ////solver->SetAztecOption(AZ_precond, AZ_Neumann); //solver->SetAztecOption(AZ_overlap, 3); //solver->SetAztecOption(AZ_subdomain_solve, AZ_ilu); //solver->SetAztecOption(AZ_output, AZ_all); //solver->SetAztecOption(AZ_diagnostics, AZ_all); solver->SetProblem(Problem); } // What should be a good inner_tolerance :-) ? solver->Iterate(config->inner_maxiters, config->inner_tolerance); } Epetra_MultiVector temp(BdMap, nvectors); ssym->C->Multiply(false, Xs, temp); temp.Update(1.0, Bd, -1.0); //Epetra_SerialComm LComm; // Use Serial Comm for the local vectors. //Epetra_Map LocalBdMap(-1, data->Dnr, data->DRowElems, 0, LComm); //Epetra_MultiVector localrhs(LocalBdMap, nvectors); //Epetra_MultiVector locallhs(LocalBdMap, nvectors); //int lda; //double *values; err = temp.ExtractView(&values, &lda); assert (err == 0); //int nrows = data->Cptr->RowMap().NumMyElements(); // copy to local vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = localrhs.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } if (config->amesosForDiagonal) { ssym->LP->SetRHS(&localrhs); ssym->LP->SetLHS(&locallhs); ssym->Solver->Solve(); } else { ssym->ifSolver->ApplyInverse(localrhs, locallhs); } err = locallhs.ExtractView(&values, &lda); assert (err == 0); // copy to distributed vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = temp.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } // For checking faults //if (NumApplyInverse_ == 5) temp.ReplaceMyValue(0, 0, 0.0); Epetra_Export XdExporter(BdMap, Y.Map()); Y.Export(temp, XdExporter, Insert); Epetra_Export XsExporter(BsMap, Y.Map()); Y.Export(Xs, XsExporter, Insert); if (config->libName == "Belos" || config->schurSolver == "Amesos") { // clean up } else { delete solver; } return 0; }//end shylu_dist_solve <epetra,epetra>