Example #1
0
int main(int argc, char *argv[])
{
  parseCommandLineOptions(argc, argv);
  initializeRandomNumberGeneratorTo(rng_seed);
  initializeOutput();
  setInitialConditions();
  if (graphicsModeEnabled()) initializeDisplay();
  
  perturbation_length=fixed_perturbation_length;

  for(monte_carlo_steps=start_mcs; monte_carlo_steps<=end_mcs; monte_carlo_steps++)
  {
    updatePairList();
    generateOutput();
    attempted_moves = 0;
    accepted_moves = 0;

    for (monte_carlo_step_counter=0; monte_carlo_step_counter<number_of_molecules; monte_carlo_step_counter++) 
    {
      double boltzmann_factor;
      double the_exponential;
  
      delta_energy = 0;
      attemptMove();
      attempted_moves++;

      if (delta_energy < 0) 
      {
        change_flag = 1;
        accepted_moves++;
        continue; /* move accepted */
      }

      // the following uses reduced temperature
      the_exponential = 0.0 - delta_energy/temperature;
     /* evaluate exponential, unless it's arbitrarily small */
      if (the_exponential > -25)
      {
        boltzmann_factor = exp(the_exponential);
        if (boltzmann_factor > rnd())
        {
          change_flag = 1;
          accepted_moves++;
          continue; /* move accepted */
        }
      }

      // revert move
      x[particle_number] -= dx;
      y[particle_number] -= dy;
      z[particle_number] -= dz;
    }

    if (monte_carlo_steps < relaxation_allowance) 
    {
      acceptance_ratio = (0.0 + accepted_moves)/(0.0 + attempted_moves);
      if (acceptance_ratio < target_acceptance_ratio) perturbation_length *= .9;
      else if (perturbation_length*perturbation_length*perturbation_length*16 < box_x*box_y*box_z) perturbation_length *=1.1;
    }
    else perturbation_length = fixed_perturbation_length;
    if (graphicsModeEnabled() && changeFlagIsSet()) drawGraphicalRepresentation();
  } 

  finalizeOutput();
  return 0;
} /* end main */
Example #2
0
bool MD_PZone::zoneAnimate(void)
{
	if (_fsmState == END)
		return(true);

	// work through things that stop us running this at all
	if (((_fsmState == PAUSE) && (millis() - _lastRunTime < _pauseTime)) ||
		(millis() - _lastRunTime < _tickTime) ||
		(_suspend))
			return(false);

	// save the time now, before we run the animation, so that the animation is part of the
	// delay between animations giving more accurate frame timing.
	_lastRunTime = millis();

	// any text to display?
	if (_pText != NULL)
	{
		switch (_fsmState)
		{
			case END:		// do nothing in this state
				PRINT_STATE("ANIMATE");
				break;

			case INITIALISE:
				PRINT_STATE("ANIMATE");

				setInitialConditions();
				zoneClear();
				_moveIn = true;
			// fall through to process the effect, first call will be with INITIALISE

			default: // All state except END are handled by the special effect functions
			switch (_moveIn ? _effectIn : _effectOut)
			{
				case PRINT:				effectPrint(_moveIn);			break;
				case SLICE:				effectSlice(_moveIn);			break;
				case WIPE:				effectWipe(false, _moveIn);		break;
				case WIPE_CURSOR:		effectWipe(true, _moveIn);		break;
				case OPENING:			effectOpen(false, _moveIn);		break;
				case OPENING_CURSOR:	effectOpen(true, _moveIn);		break;
				case CLOSING:			effectClose(false, _moveIn);	break;
				case CLOSING_CURSOR:	effectClose(true, _moveIn);		break;
				case BLINDS:			effectBlinds(_moveIn);			break;
				case DISSOLVE:			effectDissolve(_moveIn);		break;
				case SCAN_HORIZ:		effectHScan(_moveIn);			break;
				case SCAN_VERT:			effectVScan(_moveIn);			break;
				case GROW_UP:			effectGrow(true, _moveIn);		break;
				case GROW_DOWN:			effectGrow(false, _moveIn);		break;
				case SCROLL_UP:			effectVScroll(true, _moveIn);	break;
				case SCROLL_DOWN:		effectVScroll(false, _moveIn);	break;
				case SCROLL_LEFT:		effectHScroll(true, _moveIn);	break;
				case SCROLL_RIGHT:		effectHScroll(false, _moveIn);	break;
				case SCROLL_UP_LEFT:	effectDiag(true, true, _moveIn);	break;
				case SCROLL_UP_RIGHT:	effectDiag(true, false, _moveIn);	break;
				case SCROLL_DOWN_LEFT:	effectDiag(false, true, _moveIn);	break;
				case SCROLL_DOWN_RIGHT:	effectDiag(false, false, _moveIn);	break;
				default:
				_fsmState = END;
			}

			// one way toggle for input to output, reset on initialize
			_moveIn = _moveIn && !(_fsmState == PAUSE);
			break;
		}
	}

	TIME_PROFILE("\nAnimation time ");
	TIME_PROFILE(": Cycle time ");

	return(_fsmState == END);
}