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


C++ MultiValue::addDerivative方法代码示例

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


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

示例1: retrieveDerivatives

void StoreDataVessel::retrieveDerivatives( const unsigned& myelem, const bool& normed, MultiValue& myvals ){
  plumed_dbg_assert( myvals.getNumberOfValues()==vecsize && myvals.getNumberOfDerivatives()==getAction()->getNumberOfDerivatives() );

  myvals.clearAll();
  if( getAction()->lowmem ){
      recalculateStoredQuantity( myelem, myvals );
      if( normed ) getAction()->normalizeVectorDerivatives( myvals );
  } else {
      unsigned jelem = getAction()->getPositionInCurrentTaskList( myelem );
      // Retrieve the derivatives for elements 0 and 1 - weight and norm
      for(unsigned icomp=0;icomp<vecsize;++icomp){
          unsigned ibuf = jelem * ( vecsize*nspace ) + icomp*nspace + 1;
          unsigned kder = getNumberOfStoredValues() + jelem * ( nspace - 1 );
          for(unsigned j=0;j<active_der[jelem];++j){
              myvals.addDerivative( icomp, active_der[kder], local_buffer[ibuf] );
              kder++; ibuf++;
          }
      }
      if( normed ) getAction()->normalizeVectorDerivatives( myvals );
      // Now ensure appropriate parts of list are activated
      myvals.emptyActiveMembers();
      unsigned kder = getNumberOfStoredValues() + jelem * ( nspace - 1 );
      for(unsigned j=0;j<active_der[jelem];++j){ myvals.putIndexInActiveArray( active_der[kder] ); kder++; }
      myvals.sortActiveList();
  } 
}
开发者ID:edoardob90,项目名称:plumed2,代码行数:26,代码来源:StoreDataVessel.cpp

示例2: completeTask

void MultiColvarFilter::completeTask( const unsigned& curr, MultiValue& invals, MultiValue& outvals ) const {
  invals.copyValues( outvals );
  if( derivativesAreRequired() ) invals.copyDerivatives( outvals );
 
  // Retrive the value of the multicolvar and apply filter
  double val=invals.get(1), df, weight=applyFilter( val, df );

  // Now propegate derivatives
  if( !getPntrToMultiColvar()->weightHasDerivatives ){
     outvals.setValue( 0, weight );
     if( derivativesAreRequired() ){
         for(unsigned i=0;i<invals.getNumberActive();++i){
             unsigned jder=invals.getActiveIndex(i);
             outvals.addDerivative( 0, jder, df*invals.getDerivative(1, jder ) );
         }
     }
  } else {
     double ww=outvals.get(0); outvals.setValue( 0, ww*weight );
     if( derivativesAreRequired() ){
         for(unsigned i=0;i<outvals.getNumberActive();++i){
             unsigned ider=outvals.getActiveIndex(i);
             outvals.setDerivative( 0, ider, weight*outvals.getDerivative(1,ider) + ww*df*outvals.getDerivative(0,ider) );
         }
     }
  }
}
开发者ID:yongwangCPH,项目名称:plumed2,代码行数:26,代码来源:MultiColvarFilter.cpp

示例3: performTask

void DFSClusterDiameter::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const { 
  unsigned iatom=current/getNumberOfNodes(), jatom = current - iatom*getNumberOfNodes();
  Vector distance=getSeparation( getPosition(iatom), getPosition(jatom) );
  double dd = distance.modulo(), inv = 1.0/dd ; myvals.setValue( 1, dd ); 
  if( !doNotCalculateDerivatives() ){
      myvals.addDerivative( 1, 3*iatom + 0, -inv*distance[0] );
      myvals.addDerivative( 1, 3*iatom + 1, -inv*distance[1] );
      myvals.addDerivative( 1, 3*iatom + 2, -inv*distance[2] );
      myvals.addDerivative( 1, 3*jatom + 0, +inv*distance[0] );
      myvals.addDerivative( 1, 3*jatom + 1, +inv*distance[1] );
      myvals.addDerivative( 1, 3*jatom + 2, +inv*distance[2] );
      Tensor vir = -inv*Tensor(distance,distance);
      unsigned vbase = myvals.getNumberOfDerivatives() - 9;
      for(unsigned i=0;i<3;++i){
          for(unsigned j=0;j<3;++j) myvals.addDerivative( 1, vbase+3*i+j, vir(i,j) );
      }
  }
}
开发者ID:yongwangCPH,项目名称:plumed2,代码行数:18,代码来源:DFSClusterRadius.cpp

示例4: addConnectionDerivatives

void ActionWithInputMatrix::addConnectionDerivatives( const unsigned& i, const unsigned& j, MultiValue& myvals, MultiValue& myvout ) const {
  if( !mymatrix->matrixElementIsActive( i, j ) ) return;
  unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
  // Get derivatives and add
  mymatrix->retrieveDerivatives( myelem, false, myvals );
  for(unsigned jd=0; jd<myvals.getNumberActive(); ++jd) {
    unsigned ider=myvals.getActiveIndex(jd);
    myvout.addDerivative( 1, ider, myvals.getDerivative( 1, ider ) );
  }
}
开发者ID:JFDama,项目名称:plumed2,代码行数:10,代码来源:ActionWithInputMatrix.cpp

示例5: transformBridgedDerivatives

void ManyRestraintsBase::transformBridgedDerivatives( const unsigned& current, MultiValue& invals, MultiValue& outvals ) const {
    outvals.setValue( 0, invals.get(0) );

    // Get the potential
    double dval=0, val=calcPotential( invals.get(1), dval );

    outvals.setValue( 1, val );
    for(unsigned i=0; i<invals.getNumberActive(); ++i) {
        unsigned jder=invals.getActiveIndex(i);
        outvals.addDerivative( 1, jder, dval*invals.getDerivative( 1, jder ) );
    }

    // Now update the outvals derivatives lists
    outvals.emptyActiveMembers();
    for(unsigned j=0; j<invals.getNumberActive(); ++j) outvals.updateIndex( invals.getActiveIndex(j) );
    outvals.completeUpdate();
    return;
}
开发者ID:edoardob90,项目名称:plumed2,代码行数:18,代码来源:ManyRestraintsBase.cpp

示例6: compute

void Histogram::compute( const unsigned& current, MultiValue& myvals ) const {
  if( mvectors ) {
    std::vector<double> cvals( myvessels[0]->getNumberOfQuantities() );
    stashes[0]->retrieveSequentialValue( current, true, cvals );
    for(unsigned i=2; i<myvessels[0]->getNumberOfQuantities(); ++i) myvals.setValue( i-1, cvals[i] );
    myvals.setValue( 0, cvals[0] ); myvals.setValue( myvessels[0]->getNumberOfQuantities() - 1, ww );
    if( in_apply ) {
      MultiValue& tmpval = stashes[0]->getTemporyMultiValue(0);
      if( tmpval.getNumberOfValues()!=myvessels[0]->getNumberOfQuantities() ||
          tmpval.getNumberOfDerivatives()!=myvessels[0]->getNumberOfDerivatives() )
        tmpval.resize( myvessels[0]->getNumberOfQuantities(), myvessels[0]->getNumberOfDerivatives() );
      stashes[0]->retrieveDerivatives( stashes[0]->getTrueIndex(current), true, tmpval );
      for(unsigned j=0; j<tmpval.getNumberActive(); ++j) {
        unsigned jder=tmpval.getActiveIndex(j); myvals.addDerivative( 0, jder, tmpval.getDerivative(0, jder) );
        for(unsigned i=2; i<myvessels[0]->getNumberOfQuantities(); ++i) myvals.addDerivative( i-1, jder, tmpval.getDerivative(i, jder) );
      }
      myvals.updateDynamicList();
    }
  } else if( myvessels.size()>0 ) {
    std::vector<double> cvals( myvessels[0]->getNumberOfQuantities() );
    stashes[0]->retrieveSequentialValue( current, false, cvals );
    unsigned derbase; double totweight=cvals[0], tnorm = cvals[0]; myvals.setValue( 1, cvals[1] );
    // Get the derivatives as well if we are in apply
    if( in_apply ) {
      // This bit gets the total weight
      double weight0 = cvals[0];  // Store the current weight
      for(unsigned j=1; j<myvessels.size(); ++j) {
        stashes[j]->retrieveSequentialValue( current, false, cvals ); totweight *= cvals[0];
      }
      // And this bit the derivatives
      MultiValue& tmpval = stashes[0]->getTemporyMultiValue(0);
      if( tmpval.getNumberOfValues()!=myvessels[0]->getNumberOfQuantities() ||
          tmpval.getNumberOfDerivatives()!=myvessels[0]->getNumberOfDerivatives() )
        tmpval.resize( myvessels[0]->getNumberOfQuantities(), myvessels[0]->getNumberOfDerivatives() );
      stashes[0]->retrieveDerivatives( stashes[0]->getTrueIndex(current), false, tmpval );
      for(unsigned j=0; j<tmpval.getNumberActive(); ++j) {
        unsigned jder=tmpval.getActiveIndex(j);
        myvals.addDerivative( 1, jder, tmpval.getDerivative(1,jder) );
        myvals.addDerivative( 0, jder, (totweight/weight0)*tmpval.getDerivative(0,jder) );
      }
      derbase = myvessels[0]->getNumberOfDerivatives();
    }
    for(unsigned i=1; i<myvessels.size(); ++i) {
      if( cvals.size()!=myvessels[i]->getNumberOfQuantities() ) cvals.resize( myvessels[i]->getNumberOfQuantities() );
      stashes[i]->retrieveSequentialValue( current, false, cvals );
      tnorm *= cvals[0]; myvals.setValue( 1+i, cvals[1] );
      // Get the derivatives as well if we are in apply
      if( in_apply ) {
        MultiValue& tmpval = stashes[0]->getTemporyMultiValue(0);
        if( tmpval.getNumberOfValues()!=myvessels[0]->getNumberOfQuantities() ||
            tmpval.getNumberOfDerivatives()!=myvessels[0]->getNumberOfDerivatives() )
          tmpval.resize( myvessels[0]->getNumberOfQuantities(), myvessels[0]->getNumberOfDerivatives() );
        stashes[i]->retrieveDerivatives( stashes[i]->getTrueIndex(current), false, tmpval );
        for(unsigned j=0; j<tmpval.getNumberActive(); ++j) {
          unsigned jder=tmpval.getActiveIndex(j);
          myvals.addDerivative( 1+i, derbase+jder, tmpval.getDerivative(1,jder) );
          myvals.addDerivative( 0, derbase+jder, (totweight/cvals[0])*tmpval.getDerivative(0,jder) );
        }
        derbase += myvessels[i]->getNumberOfDerivatives();
      }
    }
    myvals.setValue( 0, tnorm ); myvals.setValue( 1+myvessels.size(), ww );
    if( in_apply ) myvals.updateDynamicList();
  } else {
    plumed_assert( !in_apply );
    std::vector<Value*> vv( myhist->getVectorOfValues() );
    std::vector<double> val( getNumberOfArguments() ), der( getNumberOfArguments() );
    // Retrieve the location of the grid point at which we are evaluating the kernel
    mygrid->getGridPointCoordinates( current, val );
    if( kernel ) {
      for(unsigned i=0; i<getNumberOfArguments(); ++i) vv[i]->set( val[i] );
      // Evaluate the histogram at the relevant grid point and set the values
      double vvh = kernel->evaluate( vv, der,true); myvals.setValue( 1, vvh );
    } else {
      plumed_merror("normalisation of vectors does not work with arguments and spherical grids");
      // Evalulate dot product
      double dot=0; for(unsigned j=0; j<getNumberOfArguments(); ++j) { dot+=val[j]*getArgument(j); der[j]=val[j]; }
      // Von misses distribution for concentration parameter
      double newval = (myhist->von_misses_norm)*exp( (myhist->von_misses_concentration)*dot ); myvals.setValue( 1, newval );
      // And final derivatives
      for(unsigned j=0; j<getNumberOfArguments(); ++j) der[j] *= (myhist->von_misses_concentration)*newval;
    }
    // Set the derivatives and delete the vector of values
    for(unsigned i=0; i<getNumberOfArguments(); ++i) { myvals.setDerivative( 1, i, der[i] ); delete vv[i]; }
  }
}
开发者ID:JFDama,项目名称:plumed2,代码行数:86,代码来源:Histogram.cpp

示例7: setNumberInVolume

void VolumeGradientBase::setNumberInVolume( const unsigned& ivol, const unsigned& curr, const double& weight,
    const Vector& wdf, const Tensor& virial, const std::vector<Vector>& refders,
    MultiValue& outvals ) const {
  MultiColvarBase* mcolv=getPntrToMultiColvar();
  if( !mcolv->weightHasDerivatives ) {
    outvals.setValue(ivol, weight );
    if( derivativesAreRequired() ) {
      CatomPack catom; mcolv->getCentralAtomPack( 0, curr, catom );
      for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
        unsigned jatom=3*catom.getIndex(i);
        outvals.addDerivative( ivol, jatom+0, catom.getDerivative(i,0,wdf) );
        outvals.addDerivative( ivol, jatom+1, catom.getDerivative(i,1,wdf) );
        outvals.addDerivative( ivol, jatom+2, catom.getDerivative(i,2,wdf) );
      }
      unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
      for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, virial(i,j) );
      for(unsigned i=0; i<refders.size(); ++i) {
        unsigned iatom=nmder+3*i;

        outvals.addDerivative( ivol, iatom+0, refders[i][0] );
        outvals.addDerivative( ivol, iatom+1, refders[i][1] );
        outvals.addDerivative( ivol, iatom+2, refders[i][2] );
      }
    }
  } else if(ivol==0) {
    double ww=outvals.get(0); outvals.setValue(ivol,ww*weight);
    if( derivativesAreRequired() ) {
      plumed_merror("This needs testing");
      CatomPack catom; mcolv->getCentralAtomPack( 0, curr, catom );
      for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
        unsigned jatom=3*catom.getIndex(i);
        outvals.addDerivative( ivol, jatom+0, weight*outvals.getDerivative(ivol,jatom+0) + ww*catom.getDerivative(i,0,wdf) );
        outvals.addDerivative( ivol, jatom+1, weight*outvals.getDerivative(ivol,jatom+1) + ww*catom.getDerivative(i,1,wdf) );
        outvals.addDerivative( ivol, jatom+2, weight*outvals.getDerivative(ivol,jatom+2) + ww*catom.getDerivative(i,2,wdf) );
      }
      unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
      for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, ww*virial(i,j) );
      for(unsigned i=0; i<refders.size(); ++i) {
        unsigned iatom=nmder+3*i;
        outvals.addDerivative( ivol, iatom+0, ww*refders[i][0] );
        outvals.addDerivative( ivol, iatom+1, ww*refders[i][1] );
        outvals.addDerivative( ivol, iatom+2, ww*refders[i][2] );
      }
    }
  } else {
    double ww=outvals.get(0); outvals.setValue(ivol,ww*weight);
    if( derivativesAreRequired() ) {
      plumed_merror("This needs testing");
      CatomPack catom; mcolv->getCentralAtomPack( 0, curr, catom );
      for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
        unsigned jatom=3*catom.getIndex(i);
        outvals.addDerivative( ivol, jatom+0, ww*catom.getDerivative(i,0,wdf) );
        outvals.addDerivative( ivol, jatom+1, ww*catom.getDerivative(i,1,wdf) );
        outvals.addDerivative( ivol, jatom+2, ww*catom.getDerivative(i,2,wdf) );
      }
      unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
      for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, ww*virial(i,j) );
      for(unsigned i=0; i<refders.size(); ++i) {
        unsigned iatom=nmder+3*i;
        outvals.addDerivative( ivol, iatom+0, ww*refders[i][0] );
        outvals.addDerivative( ivol, iatom+1, ww*refders[i][1] );
        outvals.addDerivative( ivol, iatom+2, ww*refders[i][2] );
      }
    }
  }
}
开发者ID:GiovanniBussi,项目名称:test-travis-ci,代码行数:66,代码来源:VolumeGradientBase.cpp


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