Exemple #1
0
PRBool nsDisplayClip::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
                                         nsRegion* aVisibleRegion) {
  nsRegion clipped;
  clipped.And(*aVisibleRegion, mClip);
  nsRegion rNew(clipped);
  PRBool anyVisible = nsDisplayWrapList::OptimizeVisibility(aBuilder, &rNew);
  nsRegion subtracted;
  subtracted.Sub(clipped, rNew);
  aVisibleRegion->SimpleSubtract(subtracted);
  return anyVisible;
}
Exemple #2
0
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;
            }
        }
    }
}
Exemple #3
0
//************************************************************
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);
}
/**
* This method will get called on idle. This method should be responsible with doing the work that the application needs to do 
* (i.e. run simulations, and so on).
*/
void ControllerEditor::processTask(){
	double simulationTime = 0;
	double maxRunningTime = 0.98/Globals::desiredFrameRate;
	Vector3d backupInput;
	bool once = false;

	//if we still have time during this frame, or if we need to finish the physics step, do this until the simulation time reaches the desired value
	while (simulationTime/maxRunningTime < Globals::animationTimeToRealTimeRatio){
		simulationTime += SimGlobals::dt;

		double phi = conF->getController()->getPhase();
		lastFSMState = conF->getController()->getFSMState();
		double signChange = (conF->getController()->getStance() == RIGHT_STANCE)?-1:1;
		Globals::targetPosePhase = phi;
		Tcl_UpdateLinkedVar( Globals::tclInterpreter, "targetPosePhase" );

//		tprintf("d = %2.4lf, v = %2.4lf\n", conF->con->d.x, conF->con->v.x);

		avgSpeed += conF->getCharacter()->getHeading().getComplexConjugate().rotate(conF->getCharacter()->getRoot()->getCMVelocity()).z;
		timesVelSampled++;

		if (conF) {
			if( phi < dTrajX.getMaxPosition() ) {
				dTrajX.clear();
				dTrajZ.clear();
				vTrajX.clear();
				vTrajZ.clear();
			}
			Vector3d d = conF->getController()->d;
			Vector3d v = conF->getController()->v;
			dTrajX.addKnot( phi, d.x * signChange);
			dTrajZ.addKnot( phi, d.z  );
			vTrajX.addKnot( phi, v.x * signChange );
			vTrajZ.addKnot( phi, v.z  );					

			bool newStep = conF->advanceInTime(SimGlobals::dt);
			//int sign = -1;
			double maxChange = 0.2;
			char * s = "out\\reducedCharacterState.rs";
			if (!once)
			{
				backupInput = conF->getCharacter()->getRoot()->getCMVelocity();
				once = true;
			}
			if (newStep) {
				avgSpeed /= timesVelSampled;
				Vector3d v = conF->getLastStepTaken();
				tprintf("step: %lf %lf %lf (phi = %lf, speed = %lf)\n", v.x, v.y, v.z, phi, avgSpeed);
				//Globals::animationRunning = false;

				//conF->getCharacter()->setHeading(.2);
				RigidBody* bBall = InteractiveWorld::getBall();
				if (bBall != NULL)
				{
				double q1 = bBall->getCMPosition().getZ();
				double q2 = bBall->getCMPosition().getX();
				double m1 = conF->getCharacter()->getRoot()->getCMPosition().getZ();
				double m2 = conF->getCharacter()->getRoot()->getCMPosition().getX();

				double q = (q2 - m2)/(q1 - m1);
				double curr = SimGlobals::desiredHeading;
				double diff = ( q - diff);
				double dist = sqrt(pow((q2 - m2), 2) + pow((q1 - m1), 2));
				if (dist < .4)
				{
					//s = "out\\reducedCharacterState1.rs";
					tprintf("state changed once");

					//Vector3d input=conF->getCharacter()->getRoot()->getCMVelocity() * 1.2;

					//conF->getCharacter()->getRoot()->setCMVelocity(input);

					//Vector3d d = conF->getController()->d;
					//Vector3d v = conF->getController()->v;
					//dTrajX.addKnot(phi, d.x * signChange);
					//dTrajZ.addKnot(phi, d.z*2);
					//vTrajX.addKnot(phi, v.x * signChange);
					//vTrajZ.addKnot(phi, v.z*2);

					//Character* bip = conF->getCharacter();
					//SimBiController* con = new SimBiController(bip);
					//char * fline = "../data/characters/fJog.rbs";
					//FILE *f = fopen(fline, "r");
					//SimBiConState* tempState;
					
					
					//con->loadFromFile(line);

					
				}
				else
				{
					Vector3d input = backupInput;

					conF->getCharacter()->getRoot()->setCMVelocity(input);
					//s = "out\\reducedCharacterState.rs";
				}
				/*if (q > 0)
				{
					if (abs(diff) > .2)
					{
						conF->getCharacter()->setHeading(curr + maxChange);
						//conF->getCharacter()->setHeading(q/3);
						SimGlobals::desiredHeading = (curr + maxChange);
					}
					else
					{
						conF->getCharacter()->setHeading(q / 2);
						//conF->getCharacter()->setHeading(q/3);
						SimGlobals::desiredHeading = (q / 2);
					}

				}
				else
				{
					if (abs(diff) > .2)
					{
						conF->getCharacter()->setHeading(curr - maxChange);
						//conF->getCharacter()->setHeading(q/3);
						SimGlobals::desiredHeading = (curr - maxChange);
					}
					else
					{*/
				q = atan(q);
				
						conF->getCharacter()->setHeading(q );
						//conF->getCharacter()->setHeading(q/3);
						SimGlobals::desiredHeading = (q);
					/*}


				}*/
				tprintf("step: %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",dist ,curr, q, q1, q2, m1, m2, bBall->getOrientation().getV().getX(),bBall->getOrientation().getV().getZ());
				}
				
				avgSpeed = 0;
				timesVelSampled = 0;

				stepTaken();

				//get the reversed new state...
				DynamicArray<double> newState;
				if (conF->getController()->getStance() == RIGHT_STANCE)
					conF->getCharacter()->getReverseStanceState(&newState);
				else
					conF->getCharacter()->getState(&newState);

				ReducedCharacterState rNew(&newState);

				conF->getCharacter()->saveReducedStateToFile(s, newState);
			}

//			if (conF->getController()->isBodyInContactWithTheGround()){
//				tprintf("Lost control of the biped...\n");
//				Globals::animationRunning = false;
//				break;
//			}
//		break;
		}
	}
}