Пример #1
0
void 
OPViscosityCollisionalE::stream(const double& edt)
{
  //Move the time forward
  //currentdt += edt;
  
  //Now test if we've gone over the step time
  if (currentdt + edt >= dt)
    {
      newG (delG);

      currentdt += edt - dt;

      //Now calculate the start of the new delG
      for (size_t iDim = 0; iDim < NDIM; ++iDim)
	for (size_t jDim = 0; jDim < NDIM; ++jDim)
	  delG[iDim][jDim] = 0.0;
      
      while (currentdt >= dt)
	{
	  currentdt -= dt;

	  newG(delG);
	}
    }
  else
      currentdt += edt;
}
Пример #2
0
  void 
  OPThermalDiffusionE::stream(const double edt)
  {      
    //Now test if we've gone over the step time
    if (currentdt + edt >= dt)
      {
	delG += constDelG * (dt - currentdt);
	delGsp1 += (constDelGsp1 - massFracSp1 * sysMom) * (dt - currentdt);
	newG();
	currentdt += edt - dt;
      
	while (currentdt >= dt)
	  {
	    delG = constDelG * dt;
	    delGsp1 = (constDelGsp1 - massFracSp1 * sysMom) * dt;
	    currentdt -= dt;
	    newG();
	  }

	//Now calculate the start of the new delG
	delG = constDelG * currentdt;
	delGsp1 = (constDelGsp1 - massFracSp1 * sysMom) * currentdt;
      }
    else
      {
	currentdt += edt;
	delG += constDelG * edt;
	delGsp1 += (constDelGsp1 - massFracSp1 * sysMom) * edt;
      }
  }
Пример #3
0
  void 
  OPThermalConductivityE::stream(const double& edt)
  {
    //Now test if we've gone over the step time
    if (currentdt + edt >= dt)
      {
	delG += constDelG * (dt - currentdt);
	newG();
	currentdt += edt - dt;

	while (currentdt >= dt)
	  {
	    delG = constDelG * dt;
	    currentdt -= dt;
	    newG();
	  }

	//Now calculate the start of the new delG
	delG = constDelG * currentdt;
      }
    else
      {
	currentdt += edt;
	delG += constDelG * edt;
      }
  }
Пример #4
0
Form::Form(QWidget *parent) : game(NULL), // подключение формы
    QWidget(parent),
    ui(new Ui::Form)
{
    ui -> setupUi(this);

    layout = new QVBoxLayout(this);
    settingsLayout = new QHBoxLayout;

    QPushButton* newgame = new QPushButton();
    QPushButton* exitgame = new QPushButton();

    QPixmap newG(":/sprite/new.png");
    QPixmap exG(":/sprite/exit.png");
    QIcon newGIcon(newG);
    QIcon exGIcon(exG);
    newgame  -> setIcon(newGIcon);
    exitgame -> setIcon(exGIcon);
    newgame  -> setIconSize(QSize(304,70)); // загрузка картинки "Новая игра"
    exitgame -> setIconSize(QSize(290,70)); // загрузка картинки "Выход"

    connect(newgame,  SIGNAL(clicked()), this, SLOT(newGame())); // Если нажата кнопка, то новая игра
    connect(exitgame, SIGNAL(clicked()), this, SLOT(exitGame())); // Если нажата кнопка, то выход

    settingsLayout -> addWidget(newgame);
    settingsLayout -> addWidget(exitgame);

    layout -> setContentsMargins(2, 2, 2, 2);
    layout -> addLayout(settingsLayout);
    newGame();

    setLayout(layout);
}
Пример #5
0
  void 
  OPViscosityE::stream(const double& edt)
  {
    //Move the time forward
    //currentdt += edt;
  
    //Now test if we've gone over the step time
    if (currentdt + edt >= dt)
      {
	for (size_t iDim = 0; iDim < NDIM; ++iDim)
	  for (size_t jDim = 0; jDim < NDIM; ++jDim)
	    delG[iDim][jDim] += constDelG[iDim][jDim] * (dt - currentdt);

	newG (delG);

	currentdt += edt - dt;
      
	while (currentdt >= dt)
	  {
	    for (size_t iDim = 0; iDim < NDIM; ++iDim)
	      for (size_t jDim = 0; jDim < NDIM; ++jDim)
		delG[iDim][jDim] = constDelG[iDim][jDim] * dt;

	    currentdt -= dt;

	    newG(delG);
	  }

	//Now calculate the start of the new delG
	for (size_t iDim = 0; iDim < NDIM; ++iDim)
	  for (size_t jDim = 0; jDim < NDIM; ++jDim)
	    delG[iDim][jDim] = constDelG[iDim][jDim] * currentdt;

      }
    else
      {
	currentdt += edt;

	for (size_t iDim = 0; iDim < NDIM; ++iDim)
	  for (size_t jDim = 0; jDim < NDIM; ++jDim)
	    delG[iDim][jDim] += constDelG[iDim][jDim] * edt;
      }
  }
Пример #6
0
  void 
  OPVACF::eventUpdate(const System&, const NEventData& PDat, const double& edt) 
  { 
    //Move the time forward
    currentdt += edt;
  
    //Now test if we've gone over the step time
    while (currentdt >= dt)
      {
	currentdt -= dt;
	newG(PDat);
      }
  }
Пример #7
0
  void 
  OPVACF::eventUpdate(const LocalEvent& iEvent, const NEventData& PDat) 
  {
    //Move the time forward
    currentdt += iEvent.getdt();
  
    //Now test if we've gone over the step time
    while (currentdt >= dt)
      {
	currentdt -= dt;
	newG(PDat);
      }
  }
  void 
  OPThermalConductivitySpeciesSpeciesE::stream(const double& edt)
  {
    size_t Nsp(Sim->dynamics.getSpecies().size());
  
    //Now test if we've gone over the step time
    if (currentdt + edt >= dt)
      {      
	for (size_t spec(0); spec < Nsp; ++spec)
	  delG[spec] += constDelG[spec] * (dt - currentdt);
      
	newG();
      
	currentdt += edt - dt;
      
	while (currentdt >= dt)
	  {
	    for (size_t spec(0); spec < Nsp; ++spec)
	      delG[spec] = constDelG[spec] * dt;
	  
	    currentdt -= dt;
	    newG();
	  }
      
	//Now calculate the start of the new delG
	for (size_t spec(0); spec < Nsp; ++spec)
	  delG[spec] = constDelG[spec] * currentdt;
      }
    else
      {
	currentdt += edt;

	for (size_t spec(0); spec < Nsp; ++spec)
	  delG[spec] += constDelG[spec] * edt;
      }
  }
EvolveCloudFunctionObject<CloudType>::EvolveCloudFunctionObject
(
    const word& name,
    const Time& t,
    const dictionary& dict
)
:
    functionObject(
        name
    ),
    dict_(dict),
    regionName_(
        dict_.found("region")
        ? dict_.lookup("region")
        : polyMesh::defaultRegion
    ),
    obr_(t.lookupObject<objectRegistry>(regionName_)),
    cloudName_(
        dict.lookup("cloudName")
    ),
    g_("dummy",dimless,vector::zero)
{
    if(dict_.found("g")) {
        dimensionedVector newG(dict_.lookup("g"));
        g_.dimensions().reset(newG.dimensions());
        g_=newG;
    } else {
        const Time &runTime=t;
        //        const fvMesh &mesh=dynamicCast<const fvMesh &>(obr_);
        const fvMesh &mesh=dynamic_cast<const fvMesh &>(obr_);

        #include "readGravitationalAcceleration.H"
        g_.dimensions().reset(g.dimensions());
        g_=g;
    }
}
Пример #10
0
bool VMCcuda::run() {
    if (UseDrift == "yes")
        return runWithDrift();

    resetRun();
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    IndexType updatePeriod= (QMCDriverMode[QMC_UPDATE_MODE])
                            ? Period4CheckProperties
                            : (nBlocks+1)*nSteps;

    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();

    vector<RealType>  LocalEnergy(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw);
    vector<GradType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    double Esum;

    // First do warmup steps
    for (int step=0; step<myWarmupSteps; step++) {
        for(int iat=0; iat<nat; ++iat)  {
            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(delpos,Random);
            for(int iw=0; iw<nw; ++iw) {
                PosType G = W[iw]->Grad[iat];
                newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw];
                ratios[iw] = 1.0;
            }
            W.proposeMove_GPU(newpos, iat);

            Psi.ratio(W,iat,ratios,newG, newL);

            accepted.clear();
            vector<bool> acc(nw, false);
            for(int iw=0; iw<nw; ++iw) {
                if(ratios[iw]*ratios[iw] > Random()) {
                    accepted.push_back(W[iw]);
                    nAccept++;
                    W[iw]->R[iat] = newpos[iw];
                    acc[iw] = true;
                }
                else
                    nReject++;
            }
            W.acceptMove_GPU(acc);
            if (accepted.size())
                Psi.update(accepted,iat);
        }
    }

    do {
        IndexType step = 0;
        nAccept = nReject = 0;
        Esum = 0.0;
        Estimators->startBlock(nSteps);
        do
        {
            ++step;
            ++CurrentStep;
            for (int isub=0; isub<nSubSteps; isub++) {
                for(int iat=0; iat<nat; ++iat)  {
                    //create a 3N-Dimensional Gaussian with variance=1
                    makeGaussRandomWithEngine(delpos,Random);
                    for(int iw=0; iw<nw; ++iw) {
                        PosType G = W[iw]->Grad[iat];
                        newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw];
                        ratios[iw] = 1.0;
                    }
                    W.proposeMove_GPU(newpos, iat);

                    Psi.ratio(W,iat,ratios,newG, newL);

                    accepted.clear();
                    vector<bool> acc(nw, false);
                    for(int iw=0; iw<nw; ++iw) {
                        if(ratios[iw]*ratios[iw] > Random()) {
                            accepted.push_back(W[iw]);
                            nAccept++;
                            W[iw]->R[iat] = newpos[iw];
                            acc[iw] = true;
                        }
                        else
                            nReject++;
                    }
                    W.acceptMove_GPU(acc);
                    if (accepted.size())
                        Psi.update(accepted,iat);
                }
            }
            Psi.gradLapl(W, grad, lapl);
            H.evaluate (W, LocalEnergy);
            if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0)
                W.saveEnsemble();
            Estimators->accumulate(W);
        } while(step<nSteps);
        Psi.recompute(W);

        // vector<RealType> logPsi(W.WalkerList.size(), 0.0);
        // Psi.evaluateLog(W, logPsi);

        double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
        Estimators->stopBlock(accept_ratio);

        nAcceptTot += nAccept;
        nRejectTot += nReject;
        ++block;
        recordBlock(block);
    } while(block<nBlocks);

    //Mover->stopRun();

    //finalize a qmc section
    return finalize(block);
}
Пример #11
0
bool VMCcuda::runWithDrift()
{
    resetRun();
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();

    vector<RealType>  LocalEnergy(nw), oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);

    // First, do warmup steps
    for (int step=0; step<myWarmupSteps; step++) {
        for(int iat=0; iat<nat; iat++) {
            Psi.getGradient (W, iat, oldG);

            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(delpos,Random);
            for(int iw=0; iw<nw; iw++) {
                oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                newpos[iw]=W[iw]->R[iat] + dr[iw];
                ratios[iw] = 1.0;
            }
            W.proposeMove_GPU(newpos, iat);

            Psi.ratio(W,iat,ratios,newG, newL);

            accepted.clear();
            vector<bool> acc(nw, false);
            for(int iw=0; iw<nw; ++iw) {
                PosType drOld =
                    newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                PosType drNew  =
                    (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];

                RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                RealType x = logGb - logGf;
                RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                if(Random() < prob) {
                    accepted.push_back(W[iw]);
                    nAccept++;
                    W[iw]->R[iat] = newpos[iw];
                    acc[iw] = true;
                }
                else
                    nReject++;
            }
            W.acceptMove_GPU(acc);
            if (accepted.size())
                Psi.update(accepted,iat);
        }
    }

    // Now do data collection steps
    do {
        IndexType step = 0;
        nAccept = nReject = 0;
        Estimators->startBlock(nSteps);
        do {
            step++;
            CurrentStep++;
            for (int isub=0; isub<nSubSteps; isub++) {
                for(int iat=0; iat<nat; iat++) {
                    Psi.getGradient (W, iat, oldG);

                    //create a 3N-Dimensional Gaussian with variance=1
                    makeGaussRandomWithEngine(delpos,Random);
                    for(int iw=0; iw<nw; iw++) {
                        oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                        dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                        newpos[iw]=W[iw]->R[iat] + dr[iw];
                        ratios[iw] = 1.0;
                    }
                    W.proposeMove_GPU(newpos, iat);

                    Psi.ratio(W,iat,ratios,newG, newL);

                    accepted.clear();
                    vector<bool> acc(nw, false);
                    for(int iw=0; iw<nw; ++iw) {
                        PosType drOld =
                            newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                        // if (dot(drOld, drOld) > 25.0)
                        //   cerr << "Large drift encountered!  Old drift = " << drOld << endl;
                        RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                        newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                        PosType drNew  =
                            (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
                        // if (dot(drNew, drNew) > 25.0)
                        //   cerr << "Large drift encountered!  Drift = " << drNew << endl;
                        RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                        RealType x = logGb - logGf;
                        RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                        if(Random() < prob) {
                            accepted.push_back(W[iw]);
                            nAccept++;
                            W[iw]->R[iat] = newpos[iw];
                            acc[iw] = true;
                        }
                        else
                            nReject++;
                    }
                    W.acceptMove_GPU(acc);
                    if (accepted.size())
                        Psi.update(accepted,iat);
                }
                // cerr << "Rank = " << myComm->rank() <<
                //   "  CurrentStep = " << CurrentStep << "  isub = " << isub << endl;
            }
            Psi.gradLapl(W, grad, lapl);
            H.evaluate (W, LocalEnergy);
            if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0)
                W.saveEnsemble();
            Estimators->accumulate(W);
        } while(step<nSteps);
        Psi.recompute(W);

        double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
        Estimators->stopBlock(accept_ratio);

        nAcceptTot += nAccept;
        nRejectTot += nReject;
        ++block;
        recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    if (!myComm->rank())
        gpu::cuda_memory_manager.report();
    return finalize(block);
}
Пример #12
0
  bool DMCcuda::run() 
  { 
    bool NLmove = NonLocalMove == "yes";
    bool scaleweight = ScaleWeight == "yes";
    if (NLmove) 
      app_log() << "  Using Casula nonlocal moves in DMCcuda.\n";
    if (scaleweight)
      app_log() << "  Scaling weight per Umrigar/Nightengale.\n";
      
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<ValueType> V2(nw), V2bar(nw);
    vector<vector<NonLocalData> > Txy(nw);

    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	ResizeTimer.start();
	LocalEnergy.resize(nw);       oldScale.resize(nw);
	newScale.resize(nw);          delpos.resize(nw);
	dr.resize(nw);                newpos.resize(nw);
	ratios.resize(nw);            rplus.resize(nw);
	rminus.resize(nw);            oldG.resize(nw);
	newG.resize(nw);              oldL.resize(nw);
	newL.resize(nw);              accepted.resize(nw);
	lapl.resize(nw, nat);         grad.resize(nw, nat);
	R2prop.resize(nw,0.0);        R2acc.resize(nw,0.0);
	V2.resize(nw,0.0);            V2bar.resize(nw,0.0);

	W.updateLists_GPU();
	ResizeTimer.stop();

	if (NLmove) {
	  Txy.resize(nw);
	  for (int iw=0; iw<nw; iw++) {
	    Txy[iw].clear();
	    Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  }
	}

	for (int iw=0; iw<nw; iw++)
	  W[iw]->Age++;
	
	DriftDiffuseTimer.start();
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);

          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	      V2bar[iw] +=  newScale[iw] *  newScale[iw] * dot(newG[iw],newG[iw]);
	    }
	    else {
	      nReject++;
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(oldG[iw],oldG[iw]);
	      V2bar[iw] +=  oldScale[iw] *  oldScale[iw] * dot(oldG[iw],oldG[iw]);
	    }	      
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	DriftDiffuseTimer.stop();
	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	HTimer.start();
	if (NLmove)	  H.evaluate (W, LocalEnergy, Txy);
	else    	  H.evaluate (W, LocalEnergy);
	HTimer.stop();
// 	for (int iw=0; iw<nw; iw++) {
// 	  branchEngine->clampEnergy(LocalEnergy[iw]);
// 	  W[iw]->getPropertyBase()[LOCALENERGY] = LocalEnergy[iw];
// 	}
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	if (NLmove) {
	  // Now, attempt nonlocal move
	  accepted.clear();
	  vector<int> iatList;
	  vector<PosType> accPos;
	  for (int iw=0; iw<nw; iw++) {
	    /// HACK HACK HACK
// 	    if (LocalEnergy[iw] < -2300.0) {
// 	      cerr << "Walker " << iw << " has energy " 
// 		   << LocalEnergy[iw] << endl;;
// 	      double maxWeight = 0.0;
// 	      int elMax = -1;
// 	      PosType posMax;
// 	      for (int j=1; j<Txy[iw].size(); j++)
// 		if (std::fabs(Txy[iw][j].Weight) > std::fabs(maxWeight)) {
// 		  maxWeight = Txy[iw][j].Weight;
// 		  elMax = Txy[iw][j].PID;
// 		  posMax = W[iw]->R[elMax] + Txy[iw][j].Delta;
// 		}
// 	      cerr << "Maximum weight is " << maxWeight << " for electron " 
// 		   << elMax << " at position " << posMax << endl;
// 	      PosType unit = W.Lattice.toUnit(posMax);
// 	      unit[0] -= round(unit[0]);
// 	      unit[1] -= round(unit[1]);
// 	      unit[2] -= round(unit[2]);
// 	      cerr << "Reduced position = " << unit << endl;
// 	    }

	    int ibar = NLop.selectMove(Random(), Txy[iw]);
		    
	    if (ibar) {
	      accepted.push_back(W[iw]);
	      int iat = Txy[iw][ibar].PID;
	      iatList.push_back(iat);
	      accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	    }
	  }
	  if (accepted.size()) {
	    Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	    Psi.update(accepted,iatList);
	    for (int i=0; i<accepted.size(); i++)
	      accepted[i]->R[iatList[i]] = accPos[i];
	    W.NLMove_GPU (accepted, accPos, iatList);
	    // HACK HACK HACK
	    // Recompute the kinetic energy
	    // Psi.gradLapl(W, grad, lapl);
	    // H.evaluate (W, LocalEnergy);
	    //W.copyWalkersToGPU();
	  }
	}

	// Now branch
	BranchTimer.start();
	for (int iw=0; iw<nw; iw++) {
	  RealType v2=0.0, v2bar=0.0;
	  for(int iat=0; iat<nat; iat++) {
	    v2 += dot(W.G[iat],W.G[iat]);
	    RealType newscale = getDriftScale(m_tauovermass,newG[iw]);
	    v2 += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	    v2bar +=  newscale * newscale * dot(newG[iw],newG[iw]);
	  }
	  //RealType scNew = std::sqrt(V2bar[iw] / V2[iw]);
	  RealType scNew = std::sqrt(v2bar/v2);
	  RealType scOld = (CurrentStep == 1) ? scNew : W[iw]->getPropertyBase()[DRIFTSCALE];

	  W[iw]->getPropertyBase()[DRIFTSCALE] = scNew;
	  // fprintf (stderr, "iw = %d  scNew = %1.8f  scOld = %1.8f\n", iw, scNew, scOld);
	  RealType tauRatio = R2acc[iw] / R2prop[iw];
	  if (tauRatio < 0.5) 
	    cerr << "  tauRatio = " << tauRatio << endl;
	  RealType taueff = m_tauovermass * tauRatio;
	  if (scaleweight) 
	    W[iw]->Weight *= branchEngine->branchWeightTau
	      (LocalEnergy[iw], LocalEnergyOld[iw], scNew, scOld, taueff);
	  else
	    W[iw]->Weight *= branchEngine->branchWeight
	      (LocalEnergy[iw], LocalEnergyOld[iw]);

	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	  
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
	BranchTimer.stop();
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Пример #13
0
  bool DMCcuda::runWithNonlocal() 
  { 
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<vector<NonLocalData> > Txy(nw);
    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	LocalEnergy.resize(nw);    	oldScale.resize(nw);
	newScale.resize(nw);    	delpos.resize(nw);
	dr.resize(nw);                  newpos.resize(nw);
	ratios.resize(nw);	        rplus.resize(nw);
	rminus.resize(nw);              oldG.resize(nw);
	newG.resize(nw);                oldL.resize(nw);
	newL.resize(nw);                accepted.resize(nw);
	lapl.resize(nw, nat);           grad.resize(nw, nat);
	R2prop.resize(nw,0.0);          R2acc.resize(nw,0.0);

	W.updateLists_GPU();

	Txy.resize(nw);
	for (int iw=0; iw<nw; iw++) {
	  Txy[iw].clear();
	  Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  W[iw]->Age++;
	}
	
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);
	  
          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	    }
	    else 
	      nReject++;
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	for (int iw=0; iw < nw; iw++) 
	  if (W[iw]->Age)
	    cerr << "Encountered stuck walker with iw=" << iw << endl;

	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	H.evaluate (W, LocalEnergy, Txy);
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	// Now, attempt nonlocal move
	accepted.clear();
	vector<int> iatList;
	vector<PosType> accPos;
	for (int iw=0; iw<nw; iw++) {
	  int ibar = NLop.selectMove(Random(), Txy[iw]);
	  // cerr << "Txy[iw].size() = " << Txy[iw].size() << endl;
	  if (ibar) {
	    accepted.push_back(W[iw]);
	    int iat = Txy[iw][ibar].PID;
	    iatList.push_back(iat);
	    accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	  }
	}
	if (accepted.size()) {
	  //   W.proposeMove_GPU(newpos, iatList);
	  Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	  Psi.update(accepted,iatList);
	  for (int i=0; i<accepted.size(); i++)
	    accepted[i]->R[iatList[i]] = accPos[i];
	  W.copyWalkersToGPU();
	}

	// Now branch
	for (int iw=0; iw<nw; iw++) {
	  W[iw]->Weight *= branchEngine->branchWeight(LocalEnergy[iw], LocalEnergyOld[iw]);
	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Пример #14
0
void Island::Step(const TimeStep &timeStep)
{
	ContactSolver contactSolver(*this);

	// update velocity
	for (auto &body : mRigidBodies)
	{
		switch (body.mType)
		{
		case RigidBody::DYNAMIC:
			float dtscale = body.mParent->cphy->dtScale;

			// apply gravity
			if (body.mHasGravity)
			{
				Vector3 newG( mGravity + body.mGravityFactor);
				body.mLinearVelocity += newG * timeStep.dt;
			}
				
			// integrate velocity
			body.mLinearVelocity +=
				body.mMassData.inverseMass * (body.mLinearImpulseAccumulator + body.mForceAccumulator * timeStep.dt  * dtscale);
			body.mAngularVelocity +=
				body.mGlobalInverseInertiaTensor * (body.mAngularImpulseAccumulator + body.mTorqueAccumulator * timeStep.dt  * dtscale);
			body.mForceAccumulator.ZeroOut();
			body.mTorqueAccumulator.ZeroOut();
			body.mLinearImpulseAccumulator.ZeroOut();
			body.mAngularImpulseAccumulator.ZeroOut();
			body.mLinearVelocity *= mLinearDamp;
			body.mAngularVelocity *= mAngularDamp;
			break;
		}
	}

	// warm start
	if (timeStep.params.warmStart)
		contactSolver.WarmStartVelocityConstraints(timeStep);

	// initialize constraints
	for (auto &joint : mJoints)
		joint.InitializeVelocityConstraints(timeStep);
	contactSolver.InitializeVelocityConstraints(timeStep);

	// solve constraints
	for (unsigned char i = 0; i < timeStep.velocityIterations; ++i)
	{
		for (auto &joint : mJoints)
			joint.SolveVelocityConstraints(timeStep);
		contactSolver.SolveVelocityConstraints(timeStep);
	}

	// cache velocity constraint results
	if (timeStep.params.warmStart)
		contactSolver.CacheVelocityConstraintResults(timeStep);

	// integrate position
	for (auto &body : mRigidBodies)
	{
		// integrate
		body.IntegratePosition(timeStep);

		// update
		body.UpdateOrientation();
		body.UpdatePositionFromGlobalCentroid();
	}

	// solve position constraints, NOPE
	for (unsigned char i = 0; i < timeStep.positionIterations; ++i)
	{
		for (auto &joint : mJoints)
			joint.SolvePositionConstraints(timeStep);
		contactSolver.SolvePositionConstraints(timeStep);
	}

	// update proxies
	for (auto &body : mRigidBodies)
		body.UpdateProxies();
}