src/ffs/ffs_trial.c
int ffs_trial_init(ffs_trial_arg_t * trial, ffs_state_t * sinit,
		   ranlcg_t * rantraj, int nlocaltraj, int itraj,
		   int * status) {

  ffs_t * ffs = NULL;
  MPI_Comm comm;

  int n, ncross;
  int iovershot;
  int icrossed;
  int mpi_errnol = 0;
  double t0, t1, t_elapsed;
  double lambda_a, lambda_b;
  double lambda, lambda_old;
  double random;

  int not_started;
  int init_independent;
  int init_nstepmax;
  double init_prob_accept;
  double teq;

  dbg_return_if(trial == NULL, -1);
  dbg_return_if(sinit == NULL, -1);
  dbg_return_if(rantraj == NULL, -1);
  dbg_return_if(status == NULL, -1);

  ffs_init_independent(trial->init, &init_independent);
  ffs_init_nstepmax(trial->init, &init_nstepmax);
  ffs_init_prob_accept(trial->init, &init_prob_accept);
  ffs_init_teq(trial->init, &teq);

  ffs_param_lambda_a(trial->param, &lambda_a);
  ffs_param_lambda_b(trial->param, &lambda_b);

  dbg_err_if( proxy_ffs(trial->proxy, &ffs) );
  ffs_comm(ffs, &comm);

  mpi_errnol = proxy_lambda(trial->proxy);
  mpi_err_if_any(mpi_errnol, comm);

  ffs_lambda(ffs, &lambda_old);

  /* Equilibrate */

  if (itraj == 1 || init_independent) {
    dbg_err_if( ffs_trial_initial_state(trial, sinit, rantraj) );
  }

  proxy_lambda(trial->proxy);
  ffs_lambda(ffs, &lambda_old);

  t_elapsed = 0.0;
  not_started = 1;
  proxy_info(trial->proxy, FFS_INFO_TIME_PUT);
  ffs_time(ffs, &t0);

  for (n = 0; n < init_nstepmax; n++) {

    proxy_execute(trial->proxy, SIM_EXECUTE_RUN);
    proxy_lambda(trial->proxy);
    ffs_lambda(ffs, &lambda);
    ffs_time(ffs, &t1);

    /* Overshot to state B? Come back to initial state. */

    iovershot = (lambda >= lambda_b);
    MPI_Bcast(&iovershot, 1, MPI_INT, 0, comm);

    if (iovershot) {

      if (not_started == 0) {
        t_elapsed += (t1 - t0); /* Time spent between A and B is counted */
      }

      dbg_err_if( ffs_trial_initial_state(trial, sinit, rantraj) );

      ffs_time(ffs, &t0);
      proxy_lambda(trial->proxy);
      ffs_lambda(ffs, &lambda_old);
      lambda = lambda_old;
      not_started = 1;
    }

    /* Do we have a forward crossing of first interface? */
    /* At this point only root has lambda, so broadcast the result. */

    icrossed = (lambda_old < lambda_a) && (lambda >= lambda_a);
    MPI_Bcast(&icrossed, 1, MPI_INT, 0, comm);

    if (icrossed && t1 >= teq) {

      if (not_started) {
	not_started = 0;
	t0 = t1;
      }
      else {

	ffs_result_aflux_ncross_add(trial->flux);
	ffs_result_aflux_ncross_local(trial->flux, &ncross);

	ffs_time(ffs, &t1);
	t_elapsed += (t1 - t0);
	t0 = t1;

	/* Accept (i.e., break) if... */

	ranlcg_reep(rantraj, &random);
	if (random < init_prob_accept) break;
      }
    }

    lambda_old = lambda;
  }

  *status = FFS_TRIAL_SUCCEEDED;
  if (n >= init_nstepmax) *status = FFS_TRIAL_TIMED_OUT;

  dbg_err_if( ffs_result_aflux_status_set(trial->flux, nlocaltraj, *status) );
  dbg_err_if( ffs_result_aflux_time_set(trial->flux, nlocaltraj, t_elapsed) );

  return 0;

 err:

  mpilog(trial->log, "Problem in generation of initial state\n");

  return -1;
}
/*****************************************************************************
 *
 *  ffs_trial_init
 *
 *  Generate an initial configuration at lambda_a
 *
 *****************************************************************************/
ffs_trial_init
Generate an initial configuration at lambda_a
ffs_trial_init Generate an initial configuration at lambda_a
int ffs_trial_init(ffs_trial_arg_t * trial, ffs_state_t * sinit,
		   ranlcg_t * rantraj, int nlocaltraj, int itraj,
		   int * status) {
  ffs_t * ffs = NULL;
  MPI_Comm comm;
  int n, ncross;
  int iovershot;
  int icrossed;
  int mpi_errnol = 0;
  double t0, t1, t_elapsed;
  double lambda_a, lambda_b;
  double lambda, lambda_old;
  double random;
  int not_started;
  int init_independent;
  int init_nstepmax;
  double init_prob_accept;
  double teq;
  dbg_return_if(trial == NULL, -1);
  dbg_return_if(sinit == NULL, -1);
  dbg_return_if(rantraj == NULL, -1);
  dbg_return_if(status == NULL, -1);
  ffs_init_independent(trial->init, &init_independent);
  ffs_init_nstepmax(trial->init, &init_nstepmax);
  ffs_init_prob_accept(trial->init, &init_prob_accept);
  ffs_init_teq(trial->init, &teq);
  ffs_param_lambda_a(trial->param, &lambda_a);
  ffs_param_lambda_b(trial->param, &lambda_b);
  dbg_err_if( proxy_ffs(trial->proxy, &ffs) );
  ffs_comm(ffs, &comm);
  mpi_errnol = proxy_lambda(trial->proxy);
  mpi_err_if_any(mpi_errnol, comm);
  ffs_lambda(ffs, &lambda_old);
  if (itraj == 1 || init_independent) {
    dbg_err_if( ffs_trial_initial_state(trial, sinit, rantraj) );
  }
  proxy_lambda(trial->proxy);
  ffs_lambda(ffs, &lambda_old);
  t_elapsed = 0.0;
  not_started = 1;
  proxy_info(trial->proxy, FFS_INFO_TIME_PUT);
  ffs_time(ffs, &t0);
  for (n = 0; n < init_nstepmax; n++) {
    proxy_execute(trial->proxy, SIM_EXECUTE_RUN);
    proxy_lambda(trial->proxy);
    ffs_lambda(ffs, &lambda);
    ffs_time(ffs, &t1);
    iovershot = (lambda >= lambda_b);
    MPI_Bcast(&iovershot, 1, MPI_INT, 0, comm);
    if (iovershot) {
      if (not_started == 0) {
        t_elapsed += (t1 - t0); 
      }
      dbg_err_if( ffs_trial_initial_state(trial, sinit, rantraj) );
      ffs_time(ffs, &t0);
      proxy_lambda(trial->proxy);
      ffs_lambda(ffs, &lambda_old);
      lambda = lambda_old;
      not_started = 1;
    }
    icrossed = (lambda_old < lambda_a) && (lambda >= lambda_a);
    MPI_Bcast(&icrossed, 1, MPI_INT, 0, comm);
    if (icrossed && t1 >= teq) {
      if (not_started) {
	not_started = 0;
	t0 = t1;
      }
      else {
	ffs_result_aflux_ncross_add(trial->flux);
	ffs_result_aflux_ncross_local(trial->flux, &ncross);
	ffs_time(ffs, &t1);
	t_elapsed += (t1 - t0);
	t0 = t1;
	ranlcg_reep(rantraj, &random);
	if (random < init_prob_accept) break;
      }
    }
    lambda_old = lambda;
  }
  *status = FFS_TRIAL_SUCCEEDED;
  if (n >= init_nstepmax) *status = FFS_TRIAL_TIMED_OUT;
  dbg_err_if( ffs_result_aflux_status_set(trial->flux, nlocaltraj, *status) );
  dbg_err_if( ffs_result_aflux_time_set(trial->flux, nlocaltraj, t_elapsed) );
  return 0;
 err:
  mpilog(trial->log, "Problem in generation of initial state\n");
  return -1;
}
int ffs_trial_init ( ffs_trial_arg_t * trial , ffs_state_t * sinit , ranlcg_t * rantraj , int nlocaltraj , int itraj , int * status ) { ffs_t * ffs = NULL ; MPI_Comm comm ; int n , ncross ; int iovershot ; int icrossed ; int mpi_errnol = 0 ; double t0 , t1 , t_elapsed ; double lambda_a , lambda_b ; double lambda , lambda_old ; double random ; int not_started ; int init_independent ; int init_nstepmax ; double init_prob_accept ; double teq ; dbg_return_if ( trial == NULL , -1 ) ; dbg_return_if ( sinit == NULL , -1 ) ; dbg_return_if ( rantraj == NULL , -1 ) ; dbg_return_if ( status == NULL , -1 ) ; ffs_init_independent ( trial -> init , & init_independent ) ; ffs_init_nstepmax ( trial -> init , & init_nstepmax ) ; ffs_init_prob_accept ( trial -> init , & init_prob_accept ) ; ffs_init_teq ( trial -> init , & teq ) ; ffs_param_lambda_a ( trial -> param , & lambda_a ) ; ffs_param_lambda_b ( trial -> param , & lambda_b ) ; dbg_err_if ( proxy_ffs ( trial -> proxy , & ffs ) ) ; ffs_comm ( ffs , & comm ) ; mpi_errnol = proxy_lambda ( trial -> proxy ) ; mpi_err_if_any ( mpi_errnol , comm ) ; ffs_lambda ( ffs , & lambda_old ) ; if ( itraj == 1 || init_independent ) { dbg_err_if ( ffs_trial_initial_state ( trial , sinit , rantraj ) ) ; } proxy_lambda ( trial -> proxy ) ; ffs_lambda ( ffs , & lambda_old ) ; t_elapsed = 0.0 ; not_started = 1 ; proxy_info ( trial -> proxy , FFS_INFO_TIME_PUT ) ; ffs_time ( ffs , & t0 ) ; for ( n = 0 ; n < init_nstepmax ; n ++ ) { proxy_execute ( trial -> proxy , SIM_EXECUTE_RUN ) ; proxy_lambda ( trial -> proxy ) ; ffs_lambda ( ffs , & lambda ) ; ffs_time ( ffs , & t1 ) ; iovershot = ( lambda >= lambda_b ) ; MPI_Bcast ( & iovershot , 1 , MPI_INT , 0 , comm ) ; if ( iovershot ) { if ( not_started == 0 ) { t_elapsed += ( t1 - t0 ) ; } dbg_err_if ( ffs_trial_initial_state ( trial , sinit , rantraj ) ) ; ffs_time ( ffs , & t0 ) ; proxy_lambda ( trial -> proxy ) ; ffs_lambda ( ffs , & lambda_old ) ; lambda = lambda_old ; not_started = 1 ; } icrossed = ( lambda_old < lambda_a ) && ( lambda >= lambda_a ) ; MPI_Bcast ( & icrossed , 1 , MPI_INT , 0 , comm ) ; if ( icrossed && t1 >= teq ) { if ( not_started ) { not_started = 0 ; t0 = t1 ; } else { ffs_result_aflux_ncross_add ( trial -> flux ) ; ffs_result_aflux_ncross_local ( trial -> flux , & ncross ) ; ffs_time ( ffs , & t1 ) ; t_elapsed += ( t1 - t0 ) ; t0 = t1 ; ranlcg_reep ( rantraj , & random ) ; if ( random < init_prob_accept ) break ; } } lambda_old = lambda ; } * status = FFS_TRIAL_SUCCEEDED ; if ( n >= init_nstepmax ) * status = FFS_TRIAL_TIMED_OUT ; dbg_err_if ( ffs_result_aflux_status_set ( trial -> flux , nlocaltraj , * status ) ) ; dbg_err_if ( ffs_result_aflux_time_set ( trial -> flux , nlocaltraj , t_elapsed ) ) ; return 0 ; err : mpilog ( trial -> log , " \n " ) ; return -1 ; }
ffs_trial_init
  Generate an initial configuration at lambda_a
ffs_trial_init Generate an initial configuration at lambda_a
/* Equilibrate */ /* Overshot to state B? Come back to initial state. */ /* Time spent between A and B is counted */ /* Do we have a forward crossing of first interface? */ /* At this point only root has lambda, so broadcast the result. */ /* Accept (i.e., break) if... */