Skip to content

Commit

Permalink
Small fixes that correct the calculation forces when there is a funct…
Browse files Browse the repository at this point in the history
…ion of a matrix in the apply loop
  • Loading branch information
Gareth Aneurin Tribello committed Aug 15, 2024
1 parent 6492e55 commit 05389b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/core/ActionWithMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ void ActionWithMatrix::runTask( const std::string& controller, const unsigned& c
unsigned matindex = myval->getPositionInMatrixStash(), col_stash_index = colno;
if( colno>=myval->getShape()[0] ) col_stash_index = colno - myval->getShape()[0];
if( myval->forcesWereAdded() ) {
unsigned sind = myval->getPositionInStream();
double fforce = myval->getForce( myvals.getTaskIndex()*ncols + myval->matrix_bookeeping[current*(1+ncols)] );
if( ncols>=myval->getShape()[1] ) fforce = myval->getForce( myvals.getTaskIndex()*myval->getShape()[1] + col_stash_index );
unsigned sind = myval->getPositionInStream(); double fforce;
if( ncols<myval->getShape()[1] ) fforce = myval->getForce( myvals.getTaskIndex()*ncols + myval->matrix_bookeeping[current*(1+ncols)] );

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'unsigned int' before it is converted to 'size_type'.
else fforce = myval->getForce( myvals.getTaskIndex()*myval->getShape()[1] + col_stash_index );
for(unsigned j=0; j<myvals.getNumberActive(sind); ++j) {
unsigned kindex = myvals.getActiveIndex(sind,j); myvals.addMatrixForce( matindex, kindex, fforce*myvals.getDerivative(sind,kindex ) );
}
Expand Down
12 changes: 6 additions & 6 deletions src/function/FunctionOfMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ unsigned FunctionOfMatrix<T>::getNumberOfColumns() const {
template <class T>
void FunctionOfMatrix<T>::setupForTask( const unsigned& task_index, std::vector<unsigned>& indices, MultiValue& myvals ) const {
for(unsigned i=0; i<getNumberOfArguments(); ++i) plumed_assert( getPntrToArgument(i)->getRank()==2 );
unsigned start_n = getPntrToArgument(0)->getShape()[0], size_v = getPntrToArgument(0)->getShape()[1];
unsigned start_n = getPntrToArgument(0)->getShape()[0], size_v = getPntrToArgument(0)->getRowLength(task_index);
if( indices.size()!=size_v+1 ) indices.resize( size_v+1 );
for(unsigned i=0; i<size_v; ++i) indices[i+1] = start_n + i;
for(unsigned i=0; i<size_v; ++i) indices[i+1] = start_n + getPntrToArgument(0)->getRowIndex(task_index, i);
myvals.setSplitIndex( size_v + 1 );
}

Expand Down Expand Up @@ -337,7 +337,7 @@ void FunctionOfMatrix<T>::performTask( const std::string& controller, const unsi
if( getPntrToArgument(j)->getRank()==2 ) {
for(int i=0; i<getNumberOfComponents(); ++i) {
unsigned ostrn=getConstPntrToComponent(i)->getPositionInStream();
unsigned myind = base + getPntrToArgument(j)->getShape()[1]*index1 + ind2;
unsigned myind = base + getPntrToArgument(j)->getNumberOfColumns()*index1 + ind2;
myvals.addDerivative( ostrn, myind, derivatives(i,j) );
myvals.updateIndex( ostrn, myind );
}
Expand All @@ -348,7 +348,7 @@ void FunctionOfMatrix<T>::performTask( const std::string& controller, const unsi
myvals.updateIndex( ostrn, base );
}
}
base += getPntrToArgument(j)->getNumberOfValues();
base += getPntrToArgument(j)->getNumberOfStoredValues();
}
}
}
Expand Down Expand Up @@ -413,9 +413,9 @@ void FunctionOfMatrix<T>::runEndOfRowJobs( const unsigned& ind, const std::vecto
if( mat_indices.size()<nderivatives ) mat_indices.resize( nderivatives ); unsigned matderbase = 0;
for(unsigned i=argstart; i<getNumberOfArguments(); ++i) {
if( getPntrToArgument(i)->getRank()==0 ) continue ;
unsigned ss = getPntrToArgument(i)->getShape()[1]; unsigned tbase = matderbase + ss*myvals.getTaskIndex();
unsigned ss = getPntrToArgument(i)->getNumberOfColumns(); unsigned tbase = matderbase + ss*myvals.getTaskIndex();
for(unsigned k=0; k<ss; ++k) mat_indices[ntot_mat + k] = tbase + k;
ntot_mat += ss; matderbase += getPntrToArgument(i)->getNumberOfValues();
ntot_mat += ss; matderbase += getPntrToArgument(i)->getNumberOfStoredValues();
}
myvals.setNumberOfMatrixRowDerivatives( nmat, ntot_mat );
}
Expand Down

1 comment on commit 05389b7

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.