本文整理汇总了C++中MultiValue::getActiveIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiValue::getActiveIndex方法的具体用法?C++ MultiValue::getActiveIndex怎么用?C++ MultiValue::getActiveIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiValue
的用法示例。
在下文中一共展示了MultiValue::getActiveIndex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: storeDerivatives
void StoreDataVessel::storeDerivatives( const unsigned& myelem, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const {
plumed_dbg_assert( vecsize>0 && getAction()->derivativesAreRequired() && myelem<getAction()->getFullNumberOfTasks() );
unsigned jelem = getAction()->getPositionInCurrentTaskList( myelem );
if( getAction()->getFullNumberOfTasks()==getNumberOfStoredValues() ){
der_list[jelem]=myvals.getNumberActive();
unsigned kder = getNumberOfStoredValues() + jelem * ( nspace - 1 );
for(unsigned j=0;j<myvals.getNumberActive();++j){ der_list[kder] = myvals.getActiveIndex(j); kder++; }
} else {
// This ensures that active indices are gathered correctly if
// we have multiple tasks contributing to a stored quantity
unsigned kder = getNumberOfStoredValues() + jelem * ( nspace - 1 );
for(unsigned j=0;j<myvals.getNumberActive();++j){
bool found=false; unsigned jder = myvals.getActiveIndex(j);
for(unsigned k=0;k<der_list[jelem];++k){
if( der_list[kder+k]==jder ){ found=true; break; }
}
if(!found){ der_list[kder+der_list[jelem]]=jder; der_list[jelem]++; }
}
}
// Store the values of the components and the derivatives
for(unsigned icomp=0;icomp<vecsize;++icomp){
unsigned ibuf = bufstart + jelem * ( vecsize*nspace ) + icomp*nspace + 1;
for(unsigned j=0;j<myvals.getNumberActive();++j){
unsigned jder=myvals.getActiveIndex(j);
buffer[ibuf] += myvals.getDerivative( icomp, jder ); ibuf++;
}
}
}
示例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) );
}
}
}
}
示例3: copyScaledDerivatives
void ReferenceValuePack::copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals ){
plumed_dbg_assert( tvals.getNumberOfDerivatives()==myvals.getNumberOfDerivatives() );
for(unsigned i=0;i<tvals.getNumberActive();++i){
unsigned ider=tvals.getActiveIndex(i);
myvals.addDerivative( oind, ider, scalef*tvals.getDerivative( from, ider ) );
}
}
示例4: 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;
}
示例5: 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 ) );
}
}
示例6: normalizeVectorDerivatives
void VectorMultiColvar::normalizeVectorDerivatives( MultiValue& myvals ) const {
double v = myvals.get(1), weight = 1.0 / v, wdf = 1.0 / ( v*v*v );
for(unsigned j=0;j<myvals.getNumberActive();++j){
double comp2=0.0; unsigned jder=myvals.getActiveIndex(j);
for(unsigned jcomp=2;jcomp<myvals.getNumberOfValues();++jcomp) comp2 += myvals.get(jcomp)*myvals.getDerivative( jcomp, jder );
for(unsigned jcomp=2;jcomp<myvals.getNumberOfValues();++jcomp){
myvals.setDerivative( jcomp, jder, weight*myvals.getDerivative( jcomp, jder ) - wdf*comp2*myvals.get(jcomp) );
}
}
}
示例7: calculate
void HistogramOnGrid::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const {
if( addOneKernelAtATime ) {
plumed_dbg_assert( myvals.getNumberOfValues()==2 && !wasforced );
std::vector<double> der( dimension );
for(unsigned i=0; i<dimension; ++i) der[i]=myvals.getDerivative( 1, i );
accumulate( getAction()->getPositionInCurrentTaskList(current), myvals.get(0), myvals.get(1), der, buffer );
} else {
plumed_dbg_assert( myvals.getNumberOfValues()==dimension+2 );
std::vector<double> point( dimension );
double weight=myvals.get(0)*myvals.get( 1+dimension );
for(unsigned i=0; i<dimension; ++i) point[i]=myvals.get( 1+i );
// Get the kernel
unsigned num_neigh;
std::vector<unsigned> neighbors;
std::vector<double> der( dimension );
KernelFunctions* kernel=getKernelAndNeighbors( point, num_neigh, neighbors );
// If no kernel normalize the vector so von misses distribution is calculated correctly
if( !kernel ) {
double norm=0;
for(unsigned j=0; j<dimension; ++j) norm += point[j]*point[j];
norm=sqrt( norm );
for(unsigned j=0; j<dimension; ++j) point[j] = point[j] / norm;
}
if( !kernel && getType()=="flat" ) {
plumed_dbg_assert( num_neigh==1 );
accumulate( neighbors[0], weight, 1.0, der, buffer );
} else {
double totwforce=0.0;
std::vector<double> intforce( 2*dimension, 0.0 );
std::vector<Value*> vv( getVectorOfValues() );
double newval;
std::vector<double> xx( dimension );
for(unsigned i=0; i<num_neigh; ++i) {
unsigned ineigh=neighbors[i];
if( inactive( ineigh ) ) continue ;
getGridPointCoordinates( ineigh, xx );
for(unsigned j=0; j<dimension; ++j) vv[j]->set(xx[j]);
if( kernel ) {
newval = kernel->evaluate( vv, der, true );
} else {
// Evalulate dot product
double dot=0;
for(unsigned j=0; j<dimension; ++j) {
dot+=xx[j]*point[j];
der[j]=xx[j];
}
// Von misses distribution for concentration parameter
newval = von_misses_norm*exp( von_misses_concentration*dot );
// And final derivatives
for(unsigned j=0; j<dimension; ++j) der[j] *= von_misses_concentration*newval;
}
accumulate( ineigh, weight, newval, der, buffer );
if( wasForced() ) {
accumulateForce( ineigh, weight, der, intforce );
totwforce += myvals.get( 1+dimension )*newval*forces[ineigh];
}
}
if( wasForced() ) {
unsigned nder = getAction()->getNumberOfDerivatives();
unsigned gridbuf = getNumberOfBufferPoints()*getNumberOfQuantities();
for(unsigned j=0; j<dimension; ++j) {
for(unsigned k=0; k<myvals.getNumberActive(); ++k) {
// Minus sign here as we are taking derivative with respect to position of center of kernel NOT derivative wrt to
// grid point
unsigned kder=myvals.getActiveIndex(k);
buffer[ bufstart + gridbuf + kder ] -= intforce[j]*myvals.getDerivative( j+1, kder );
}
}
// Accumulate the sum of all the weights
buffer[ bufstart + gridbuf + nder ] += myvals.get(0);
// Add the derivatives of the weights into the force -- this is separate loop as weights of all parts are considered together
for(unsigned k=0; k<myvals.getNumberActive(); ++k) {
unsigned kder=myvals.getActiveIndex(k);
buffer[ bufstart + gridbuf + kder ] += totwforce*myvals.getDerivative( 0, kder );
buffer[ bufstart + gridbuf + nder + 1 + kder ] += myvals.getDerivative( 0, kder );
}
}
delete kernel;
for(unsigned i=0; i<dimension; ++i) delete vv[i];
}
}
}