void VDPositionControlW32::RecalcThumbRect(VDPosition pos, bool update) { RECT rOld(mThumbRect); mThumbRect.left = FrameToPixel(pos) - mThumbWidth; mThumbRect.right = mThumbRect.left + 2*mThumbWidth; mThumbRect.top = mTrackArea.top; mThumbRect.bottom = mTrackArea.bottom; if (update && mhwnd && memcmp(&mThumbRect, &rOld, sizeof(RECT))) { InvalidateRect(mhwnd, &rOld, TRUE); InvalidateRect(mhwnd, &mThumbRect, TRUE); } }
void SolverMCBF::runCycle() { // loop over Monte Carlo cycles for (int cycle = 0; cycle < nCycles+nThermalize; cycle++) { // New position to test for (int i = 0; i < nParticles; i++) { for (int j = 0; j < nDimensions; j++) { rNew(i,j) = rOld(i,j) + stepLength*(ran2(&idum) - 0.5); } wf->updatePositionAndCurrentParticle(rNew, i); ratio = wf->getRatio(); // squared in Wavefunction // Check for step acceptance (if yes, update position, if no, reset position) if (ran2(&idum) <= ratio) { rOld.row(i) = rNew.row(i); wf->acceptMove(); if (cycle > nThermalize) nAccepted++; } else { rNew.row(i) = rOld.row(i); wf->rejectMove(); } } if (cycle >= nThermalize) { deltaE = localEnergy->evaluate(rNew, wf); if (blocking) logger->log(deltaE); energySum += deltaE; energySquaredSum += deltaE*deltaE; if (minimizing) { tempVariationalGradient = wf->variationalDerivatives(); variationalGradientSum += tempVariationalGradient; variationalGradientESum += tempVariationalGradient*deltaE; } } } }
//************************************************************ void MCIS::MetropolisAlgoIS(){ observables->initializeObservables(nCycles); qForceOld = zeros<mat>(nParticles, nDimensions); qForceNew = zeros<mat>(nParticles, nDimensions); acceptedSteps=0; rOld = randn(nParticles,nDimensions)*sqrt(timeStep); //std=sqrt(2*D*dt), D=0.5 rNew = rOld; trialWavefunction->initializeWavefunction(rOld); qForceOld = getQuantumForce(rOld); // loop over Monte Carlo cycles for(int cycle = 0; cycle < nCycles+thermalization; cycle++) { // New position to test for(int i = 0; i < nParticles; i++) { for(int j = 0; j < nDimensions; j++) { rNew(i,j) = rOld(i,j) + randn()*sqrt(timeStep)+qForceOld(i,j)*timeStep*D; } trialWavefunction->activeParticle(rNew,i); trialWavefunction->updateWavefunction(); qForceNew=getQuantumForce(rNew); //compute green's function ratio GreensFunction=0; for (int k = 0; k < nParticles; k++){ for(int l=0; l<nDimensions; l++){ GreensFunction+=(qForceOld(k,l)+qForceNew(k,l))* (D*timeStep*0.5*(qForceOld(k,l)-qForceNew(k,l))-rNew(k,l)+rOld(k,l)); } } GreensFunction= exp(0.5*GreensFunction); R =trialWavefunction->getRatio(); R*=R*GreensFunction; if(ran2(&idum) <= R) { trialWavefunction->acceptMove(); rOld.row(i) = rNew.row(i); qForceOld=qForceNew; if(cycle > thermalization){ acceptedSteps++; } } else { trialWavefunction->rejectMove(); rNew.row(i) = rOld.row(i); qForceNew=qForceOld; } } // update energies if(cycle > thermalization){ observables->currentConfiguration(rNew); observables->calculateObservables(); } } acceptedSteps /= ((nCycles-1)*nParticles); }
double VMCSolver::runMonteCarloIntegration() { nAccepted=0; nRejected=0; rOld = zeros<mat>(nParticles, nDimensions); rNew = zeros<mat>(nParticles, nDimensions); double energySum = 0; double energySquaredSum = 0; double deltaE; // initialise trial positions for(int i = 0; i < nParticles; i++) { for(int j = 0; j < nDimensions; j++) { rOld(i,j)=sqrt(h)*this->gaussianDeviate(&idum); } } initialize(); // loop over Monte Carlo cycles int my_start=0; int my_end=local_nCycles; double r12 = 0; thermalize(); for(int cycle = my_start; cycle < my_end; cycle++) { // if(cycle%(my_end/100)==0) // cout << "Currently in cycle "<< cycle<<endl; if(cycle%nrOfCyclesEachOutput==0 && createOutput && cycle >0){ datalogger.flushData(); } // New position to test for(int i = 0; i < nParticles; i++) { this->currentparticle=i; wf.setCurrentParticle(i); this->cycle(i); } //collect data deltaE = wf.localEnergyCF(rNew); if(createOutput){ datalogger.addData(deltaE); } energySum += deltaE; energySquaredSum += deltaE*deltaE; } if(createOutput){ datalogger.flushFinalData(); } double energy = energySum/(local_nCycles); double energySquared = energySquaredSum/(local_nCycles); double totalenergy=0; double totalenergySquared=0; int totalaccepted=0, totalrejected=0; //1 processor receives all information //MPI_Reduce(&energy, &totalenergy, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); //all processors receive all information MPI_Allreduce(&energy, &totalenergy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); totalenergy/=numprocs; MPI_Allreduce(&nAccepted, &totalaccepted, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&nRejected, &totalrejected, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&energySquared, &totalenergySquared, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); totalenergySquared/=numprocs; acceptRatio=double(totalaccepted)/(totalrejected+totalaccepted); double variance = totalenergySquared-pow(totalenergy,2); cout << "Energy: " << totalenergy << " Energy (squared sum): " << totalenergySquared << endl; cout << "Variance: "<< variance<<endl; cout << "Total acceptratio: " <<acceptRatio << endl; return totalenergy; }