当前位置: 首页>>代码示例>>C++>>正文


C++ path::PotentialAction方法代码示例

本文整理汇总了C++中path::PotentialAction方法的典型用法代码示例。如果您正苦于以下问题:C++ path::PotentialAction方法的具体用法?C++ path::PotentialAction怎么用?C++ path::PotentialAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在path的用法示例。


在下文中一共展示了path::PotentialAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CenterOfMassMove

bool pimc::CenterOfMassMove(path p, int ptcl)
{
  //srand((unsigned)time(NULL));

  int NumTime=p.get_NumTime();
  double delta = 0.5;
  double shift = delta*(-1.0 + 2.0*((double) rand() / (RAND_MAX)));
  double oldbeads[NumTime];

  // Store the positions on the worldline
  for (int slice=0; slice<NumTime; slice++)
  {
    oldbeads[slice] = p.beads[slice][ptcl];
  }

  // Calculate the potential action
  double oldAction = 0.0;
  for (int slice=0; slice<NumTime; slice++)
    oldAction += p.PotentialAction(slice);

  // Displace the worldline
  for (int slice=0; slice<NumTime; slice++)
    p.beads[slice][ptcl] = oldbeads[slice] + shift;

  // Compute the new action
  double newAction = 0.0;
  for (int slice=0; slice<NumTime; slice++)
    newAction += p.PotentialAction(slice);

  // Accept the move, or reject and restore the bead positions
  if( ((double) rand() / (RAND_MAX)) < exp(-(newAction - oldAction)) )
    return true;
  else
  {
    for (int slice=0; slice<NumTime; slice++)
    {
      p.beads[slice][ptcl] = oldbeads[slice];
    }
    return false;
  }
}
开发者ID:henhans,项目名称:pimc,代码行数:41,代码来源:pimc.cpp

示例2: StagingMove

// There is bug inside stagingMove
bool pimc::StagingMove(path p, int ptcl)
{
  //srand((unsigned)time(NULL));

  // the length of the stage
  int m = 16;
  int NumTime=p.get_NumTime();
  double tau=p.get_tau();
  double lam=p.get_lam();
  double oldbeads[m-1];

  // Choose the start and end of the stage
  int alpha_start = (int) NumTime*((double) rand() / (RAND_MAX)) ; //np.random.randint(0,Path.numTimeSlices)
  //cout<< alpha_start<< endl;
  //int alpha_start = 15;
  int alpha_end = (alpha_start + m) % NumTime;

  // Record the positions of the beads to be updated and store the action
  for(int a=0; a<m-1; a++)
    oldbeads[a] = 0;

  double oldAction = 0.0;
  for (int a=1; a<m; a++)
  {
      int slice = (alpha_start + a) % NumTime;
      oldbeads[a-1] = p.beads[slice][ptcl];
      oldAction += p.PotentialAction(slice);
  }

  // Generate new positions and accumulate the new action
  double newAction = 0.0;

  for (int a=1; a<m; a++)
  {
    int slicem1;
    int slice = (alpha_start + a) % NumTime;
    if( (slice-1) > 0 )   
      slicem1 = (slice - 1) % NumTime;
    else if( (slice-1)==0)
      slicem1 = 0;
    else
      slicem1 = ((slice - 1) % NumTime) + NumTime;

    //cout << slicem1 <<endl;
    double tau1 = (m-a)*tau;
    //cout <<ptcl <<" " << slicem1 << " "<< slice <<endl;
    double avex = (tau1*p.beads[slicem1][ptcl] + tau*p.beads[alpha_end][ptcl]) / (tau + tau1);
    double sigma2 = 2.0*lam / ((1.0 / tau) + (1.0 / tau1));
    p.beads[slice][ptcl] = avex + sqrt(sigma2)*((double) rand() / (RAND_MAX));
    newAction += p.PotentialAction(slice);
  }   

  // Perform the Metropolis step, if we rejct, revert the worldline
    if( ((double) rand() / (RAND_MAX)) < exp(-(newAction - oldAction)) )
        return true;
    else
        for(int a=1; a<m; a++)
        {
            int slice = (alpha_start + a) % NumTime;
            p.beads[slice][ptcl] = oldbeads[a-1];
            return false;
        }
}
开发者ID:henhans,项目名称:pimc,代码行数:64,代码来源:pimc.cpp


注:本文中的path::PotentialAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。