Skip to content

Commit 7e0f435

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
Gareth Aneurin Tribello
authored and
Gareth Aneurin Tribello
committed
Optimised adding of forces in AdjacencyMatrixBase by using the fact that we already worked out that some of the elements of the matrix are zero and that the forces on these elements are zero
1 parent 2115528 commit 7e0f435

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/adjmat/AdjacencyMatrixBase.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,15 @@ void AdjacencyMatrixBase::setupForTask( const unsigned& current, std::vector<uns
267267
if( indices.size()!=(1+ablocks.size()+threeblocks.size()) ) indices.resize( 1+ablocks.size()+threeblocks.size() );
268268

269269
// Now get the positions
270-
unsigned natoms=retrieveNeighbours( current, indices );
270+
unsigned natoms; const Value* myval = getConstPntrToComponent(0);
271+
if( myval->forcesWereAdded() ) {
272+
natoms = 0; indices[natoms] = current; natoms++;
273+
unsigned nelements = myval->getRowLength(current), startr = current*myval->getNumberOfColumns();
274+
for(unsigned j=0; j<nelements; ++j ) {
275+
unsigned jind = myval->getRowIndex( current, j );
276+
if( ablocks[jind]!=indices[0] && fabs( myval->getForce( startr + j ) )>epsilon ) { indices[natoms] = ablocks[jind]; natoms++; }
277+
}
278+
} else natoms=retrieveNeighbours( current, indices );
271279
unsigned ntwo_atoms=natoms; myvals.setSplitIndex( ntwo_atoms );
272280

273281
// Now retrieve everything for the third atoms

src/valtools/VStack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void VStack::performTask( const std::string& controller, const unsigned& index1,
140140
}
141141

142142
void VStack::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector<double>& forces ) const {
143-
unsigned matind = myval->getPositionInMatrixStash(); const std::vector<unsigned>& mat_indices( myvals.getMatrixRowDerivativeIndices( matind ) );
143+
unsigned matind = myval->getPositionInMatrixStash();
144144
for(unsigned i=0; i<forces.size(); ++i) forces[i] += myvals.getStashedMatrixForce( matind, i );
145145
}
146146

0 commit comments

Comments
 (0)