From 374d19fdf372da7c0336a79f859a39c14382f69b Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Mon, 16 Sep 2024 16:55:26 +0100 Subject: [PATCH] Removed more code that was used for Stream stuff that is not usedd any longer --- src/adjmat/AdjacencyMatrixBase.cpp | 59 +++---- src/adjmat/AdjacencyMatrixBase.h | 33 ++-- src/adjmat/Neighbors.cpp | 2 +- src/adjmat/TorsionsMatrix.cpp | 10 +- src/colvar/MultiColvarTemplate.h | 21 +-- src/colvar/RMSDVector.cpp | 9 +- src/colvar/RMSDVector.h | 2 +- src/contour/FindContour.cpp | 2 +- src/contour/FindContourSurface.cpp | 4 +- src/contour/FindSphericalContour.cpp | 4 +- src/core/ActionWithMatrix.cpp | 20 +-- src/core/ActionWithMatrix.h | 29 +--- src/core/ActionWithVector.cpp | 162 ++---------------- src/core/ActionWithVector.h | 4 +- src/core/Value.cpp | 3 - src/core/Value.h | 9 +- src/crystdistrib/QuaternionProductMatrix.cpp | 8 +- src/dimred/ProjectPoints.cpp | 2 +- src/function/FunctionOfVector.h | 2 +- src/gridtools/FunctionOfGrid.h | 16 +- src/gridtools/InterpolateGrid.cpp | 16 +- src/gridtools/KDE.cpp | 15 +- src/matrixtools/MatrixTimesMatrix.cpp | 14 +- src/matrixtools/OuterProduct.cpp | 4 +- src/refdist/MatrixProductDiagonal.cpp | 21 ++- .../SecondaryStructureRMSD.cpp | 26 ++- src/symfunc/ThreeBodyGFunctions.cpp | 24 ++- src/valtools/VStack.cpp | 34 ++-- src/volumes/ActionVolume.cpp | 9 +- 29 files changed, 181 insertions(+), 383 deletions(-) diff --git a/src/adjmat/AdjacencyMatrixBase.cpp b/src/adjmat/AdjacencyMatrixBase.cpp index bdd82ab0f3..e658218742 100644 --- a/src/adjmat/AdjacencyMatrixBase.cpp +++ b/src/adjmat/AdjacencyMatrixBase.cpp @@ -262,21 +262,21 @@ void AdjacencyMatrixBase::setupForTask( const unsigned& current, std::vectorgetPositionInStream(); myvals.setValue( w_ind, weight ); - if( fabs(weight) & indices( myvals.getIndices() ); for(unsigned i=myvals.getSplitIndex(); igetPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat ); std::vector& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) ); @@ -286,42 +286,39 @@ void AdjacencyMatrixBase::performTask( const std::string& controller, const unsi // Calculate the components if we need them if( components ) { - unsigned x_index = getConstPntrToComponent(1)->getPositionInStream(); - unsigned y_index = getConstPntrToComponent(2)->getPositionInStream(); - unsigned z_index = getConstPntrToComponent(3)->getPositionInStream(); Vector atom = myvals.getAtomVector()[index2]; - myvals.setValue( x_index, atom[0] ); myvals.setValue( y_index, atom[1] ); myvals.setValue( z_index, atom[2] ); + myvals.setValue( 1, atom[0] ); myvals.setValue( 2, atom[1] ); myvals.setValue( 3, atom[2] ); if( !doNotCalculateDerivatives() ) { - myvals.addDerivative( x_index, 3*index1+0, -1 ); myvals.addDerivative( x_index, 3*index2+0, +1 ); - myvals.addDerivative( x_index, 3*index1+1, 0 ); myvals.addDerivative( x_index, 3*index2+1, 0 ); - myvals.addDerivative( x_index, 3*index1+2, 0 ); myvals.addDerivative( x_index, 3*index2+2, 0 ); - myvals.addDerivative( y_index, 3*index1+0, 0 ); myvals.addDerivative( y_index, 3*index2+0, 0 ); - myvals.addDerivative( y_index, 3*index1+1, -1 ); myvals.addDerivative( y_index, 3*index2+1, +1 ); - myvals.addDerivative( y_index, 3*index1+2, 0 ); myvals.addDerivative( y_index, 3*index2+2, 0 ); - myvals.addDerivative( z_index, 3*index1+0, 0 ); myvals.addDerivative( z_index, 3*index2+0, 0 ); - myvals.addDerivative( z_index, 3*index1+1, 0 ); myvals.addDerivative( z_index, 3*index2+1, 0 ); - myvals.addDerivative( z_index, 3*index1+2, -1 ); myvals.addDerivative( z_index, 3*index2+2, +1 ); + myvals.addDerivative( 1, 3*index1+0, -1 ); myvals.addDerivative( 1, 3*index2+0, +1 ); + myvals.addDerivative( 1, 3*index1+1, 0 ); myvals.addDerivative( 1, 3*index2+1, 0 ); + myvals.addDerivative( 1, 3*index1+2, 0 ); myvals.addDerivative( 1, 3*index2+2, 0 ); + myvals.addDerivative( 2, 3*index1+0, 0 ); myvals.addDerivative( 2, 3*index2+0, 0 ); + myvals.addDerivative( 2, 3*index1+1, -1 ); myvals.addDerivative( 2, 3*index2+1, +1 ); + myvals.addDerivative( 2, 3*index1+2, 0 ); myvals.addDerivative( 2, 3*index2+2, 0 ); + myvals.addDerivative( 3, 3*index1+0, 0 ); myvals.addDerivative( 3, 3*index2+0, 0 ); + myvals.addDerivative( 3, 3*index1+1, 0 ); myvals.addDerivative( 3, 3*index2+1, 0 ); + myvals.addDerivative( 3, 3*index1+2, -1 ); myvals.addDerivative( 3, 3*index2+2, +1 ); for(unsigned k=0; k<3; ++k) { // Update dynamic lists for central atom - myvals.updateIndex( x_index, 3*index1+k ); myvals.updateIndex( y_index, 3*index1+k ); myvals.updateIndex( z_index, 3*index1+k ); + myvals.updateIndex( 1, 3*index1+k ); myvals.updateIndex( 2, 3*index1+k ); myvals.updateIndex( 3, 3*index1+k ); // Update dynamic lists for bonded atom - myvals.updateIndex( x_index, 3*index2+k ); myvals.updateIndex( y_index, 3*index2+k ); myvals.updateIndex( z_index, 3*index2+k ); + myvals.updateIndex( 1, 3*index2+k ); myvals.updateIndex( 2, 3*index2+k ); myvals.updateIndex( 3, 3*index2+k ); } // Add derivatives of virial unsigned base = 3*getNumberOfAtoms(); // Virial for x - myvals.addDerivative( x_index, base+0, -atom[0] ); myvals.addDerivative( x_index, base+3, -atom[1] ); myvals.addDerivative( x_index, base+6, -atom[2] ); - myvals.addDerivative( x_index, base+1, 0 ); myvals.addDerivative( x_index, base+4, 0 ); myvals.addDerivative( x_index, base+7, 0 ); - myvals.addDerivative( x_index, base+2, 0 ); myvals.addDerivative( x_index, base+5, 0 ); myvals.addDerivative( x_index, base+8, 0 ); + myvals.addDerivative( 1, base+0, -atom[0] ); myvals.addDerivative( 1, base+3, -atom[1] ); myvals.addDerivative( 1, base+6, -atom[2] ); + myvals.addDerivative( 1, base+1, 0 ); myvals.addDerivative( 1, base+4, 0 ); myvals.addDerivative( 1, base+7, 0 ); + myvals.addDerivative( 1, base+2, 0 ); myvals.addDerivative( 1, base+5, 0 ); myvals.addDerivative( 1, base+8, 0 ); // Virial for y - myvals.addDerivative( y_index, base+0, 0 ); myvals.addDerivative( y_index, base+3, 0 ); myvals.addDerivative( y_index, base+6, 0 ); - myvals.addDerivative( y_index, base+1, -atom[0] ); myvals.addDerivative( y_index, base+4, -atom[1] ); myvals.addDerivative( y_index, base+7, -atom[2] ); - myvals.addDerivative( y_index, base+2, 0 ); myvals.addDerivative( y_index, base+5, 0 ); myvals.addDerivative( y_index, base+8, 0 ); + myvals.addDerivative( 2, base+0, 0 ); myvals.addDerivative( 2, base+3, 0 ); myvals.addDerivative( 2, base+6, 0 ); + myvals.addDerivative( 2, base+1, -atom[0] ); myvals.addDerivative( 2, base+4, -atom[1] ); myvals.addDerivative( 2, base+7, -atom[2] ); + myvals.addDerivative( 2, base+2, 0 ); myvals.addDerivative( 2, base+5, 0 ); myvals.addDerivative( 2, base+8, 0 ); // Virial for z - myvals.addDerivative( z_index, base+0, 0 ); myvals.addDerivative( z_index, base+3, 0 ); myvals.addDerivative( z_index, base+6, 0 ); - myvals.addDerivative( z_index, base+1, 0 ); myvals.addDerivative( z_index, base+4, 0 ); myvals.addDerivative( z_index, base+7, 0 ); - myvals.addDerivative( z_index, base+2, -atom[0] ); myvals.addDerivative( z_index, base+5, -atom[1] ); myvals.addDerivative( z_index, base+8, -atom[2] ); - for(unsigned k=0; k<9; ++k) { myvals.updateIndex( x_index, base+k ); myvals.updateIndex( y_index, base+k ); myvals.updateIndex( z_index, base+k ); } + myvals.addDerivative( 3, base+0, 0 ); myvals.addDerivative( 3, base+3, 0 ); myvals.addDerivative( 3, base+6, 0 ); + myvals.addDerivative( 3, base+1, 0 ); myvals.addDerivative( 3, base+4, 0 ); myvals.addDerivative( 3, base+7, 0 ); + myvals.addDerivative( 3, base+2, -atom[0] ); myvals.addDerivative( 3, base+5, -atom[1] ); myvals.addDerivative( 3, base+8, -atom[2] ); + for(unsigned k=0; k<9; ++k) { myvals.updateIndex( 1, base+k ); myvals.updateIndex( 2, base+k ); myvals.updateIndex( 3, base+k ); } for(unsigned k=1; k<4; ++k) { unsigned nmat = getConstPntrToComponent(k)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat ); std::vector& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) ); diff --git a/src/adjmat/AdjacencyMatrixBase.h b/src/adjmat/AdjacencyMatrixBase.h index e529688d8d..9f4aae2e1c 100644 --- a/src/adjmat/AdjacencyMatrixBase.h +++ b/src/adjmat/AdjacencyMatrixBase.h @@ -75,36 +75,33 @@ void AdjacencyMatrixBase::addAtomDerivatives( const unsigned& indno, const Vecto if( doNotCalculateDerivatives() ) return; plumed_dbg_assert( indno<2 ); unsigned index = myvals.getTaskIndex(); if( indno==1 ) index = myvals.getSecondTaskIndex(); - unsigned w_index = getConstPntrToComponent(0)->getPositionInStream(); - myvals.addDerivative( w_index, 3*index+0, der[0] ); - myvals.addDerivative( w_index, 3*index+1, der[1] ); - myvals.addDerivative( w_index, 3*index+2, der[2] ); + myvals.addDerivative( 0, 3*index+0, der[0] ); + myvals.addDerivative( 0, 3*index+1, der[1] ); + myvals.addDerivative( 0, 3*index+2, der[2] ); } inline void AdjacencyMatrixBase::addThirdAtomDerivatives( const unsigned& indno, const Vector& der, MultiValue& myvals ) const { if( doNotCalculateDerivatives() ) return; unsigned index = myvals.getIndices()[ indno + myvals.getSplitIndex() ]; - unsigned w_index = getConstPntrToComponent(0)->getPositionInStream(); - myvals.addDerivative( w_index, 3*index+0, der[0] ); - myvals.addDerivative( w_index, 3*index+1, der[1] ); - myvals.addDerivative( w_index, 3*index+2, der[2] ); + myvals.addDerivative( 0, 3*index+0, der[0] ); + myvals.addDerivative( 0, 3*index+1, der[1] ); + myvals.addDerivative( 0, 3*index+2, der[2] ); } inline void AdjacencyMatrixBase::addBoxDerivatives( const Tensor& vir, MultiValue& myvals ) const { if( doNotCalculateDerivatives() ) return; unsigned nbase = 3*getNumberOfAtoms(); - unsigned w_index = getConstPntrToComponent(0)->getPositionInStream(); - myvals.addDerivative( w_index, nbase+0, vir(0,0) ); - myvals.addDerivative( w_index, nbase+1, vir(0,1) ); - myvals.addDerivative( w_index, nbase+2, vir(0,2) ); - myvals.addDerivative( w_index, nbase+3, vir(1,0) ); - myvals.addDerivative( w_index, nbase+4, vir(1,1) ); - myvals.addDerivative( w_index, nbase+5, vir(1,2) ); - myvals.addDerivative( w_index, nbase+6, vir(2,0) ); - myvals.addDerivative( w_index, nbase+7, vir(2,1) ); - myvals.addDerivative( w_index, nbase+8, vir(2,2) ); + myvals.addDerivative( 0, nbase+0, vir(0,0) ); + myvals.addDerivative( 0, nbase+1, vir(0,1) ); + myvals.addDerivative( 0, nbase+2, vir(0,2) ); + myvals.addDerivative( 0, nbase+3, vir(1,0) ); + myvals.addDerivative( 0, nbase+4, vir(1,1) ); + myvals.addDerivative( 0, nbase+5, vir(1,2) ); + myvals.addDerivative( 0, nbase+6, vir(2,0) ); + myvals.addDerivative( 0, nbase+7, vir(2,1) ); + myvals.addDerivative( 0, nbase+8, vir(2,2) ); } inline diff --git a/src/adjmat/Neighbors.cpp b/src/adjmat/Neighbors.cpp index 58f4b4b978..709e1714d1 100644 --- a/src/adjmat/Neighbors.cpp +++ b/src/adjmat/Neighbors.cpp @@ -130,7 +130,7 @@ void Neighbors::setupForTask( const unsigned& task_index, std::vector& } void Neighbors::performTask( const std::string& controller, const unsigned& index1, const unsigned& index2, MultiValue& myvals ) const { - myvals.addValue( getConstPntrToComponent(0)->getPositionInStream(), 1.0 ); + myvals.addValue( 0, 1.0 ); } } diff --git a/src/adjmat/TorsionsMatrix.cpp b/src/adjmat/TorsionsMatrix.cpp index 26723db94c..563c6e7cfa 100644 --- a/src/adjmat/TorsionsMatrix.cpp +++ b/src/adjmat/TorsionsMatrix.cpp @@ -121,7 +121,7 @@ void TorsionsMatrix::setupForTask( const unsigned& task_index, std::vectorgetPositionInStream(), ind2=index2; + unsigned ind2=index2; if( index2>=getPntrToArgument(0)->getShape()[0] ) ind2 = index2 - getPntrToArgument(0)->getShape()[0]; Vector v1, v2, dv1, dv2, dconn; @@ -136,7 +136,7 @@ void TorsionsMatrix::performTask( const std::string& controller, const unsigned& } // Evaluate angle Torsion t; double angle = t.compute( v1, conn, v2, dv1, dconn, dv2 ); - myvals.addValue( ostrn, angle ); + myvals.addValue( 0, angle ); if( doNotCalculateDerivatives() ) return; @@ -148,12 +148,12 @@ void TorsionsMatrix::performTask( const std::string& controller, const unsigned& // And derivatives on positions unsigned narg_derivatives = getPntrToArgument(0)->getNumberOfValues() + getPntrToArgument(1)->getNumberOfValues(); for(unsigned i=0; i<3; ++i) { - myvals.addDerivative( ostrn, narg_derivatives + 3*index1+i, -dconn[i] ); myvals.addDerivative( ostrn, narg_derivatives + 3*index2+i, dconn[i] ); - myvals.updateIndex( ostrn, narg_derivatives + 3*index1+i ); myvals.updateIndex( ostrn, narg_derivatives + 3*index2+i ); + myvals.addDerivative( 0, narg_derivatives + 3*index1+i, -dconn[i] ); myvals.addDerivative( 0, narg_derivatives + 3*index2+i, dconn[i] ); + myvals.updateIndex( 0, narg_derivatives + 3*index1+i ); myvals.updateIndex( 0, narg_derivatives + 3*index2+i ); } //And virial Tensor vir( -extProduct( conn, dconn ) ); unsigned virbase = narg_derivatives + 3*getNumberOfAtoms(); - for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j ) { myvals.addDerivative( ostrn, virbase+3*i+j, vir(i,j) ); myvals.updateIndex( ostrn, virbase+3*i+j ); } + for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j ) { myvals.addDerivative( 0, virbase+3*i+j, vir(i,j) ); myvals.updateIndex( 0, virbase+3*i+j ); } } void TorsionsMatrix::runEndOfRowJobs( const unsigned& ival, const std::vector & indices, MultiValue& myvals ) const { diff --git a/src/colvar/MultiColvarTemplate.h b/src/colvar/MultiColvarTemplate.h index 3db20c9e2e..0811736aa4 100644 --- a/src/colvar/MultiColvarTemplate.h +++ b/src/colvar/MultiColvarTemplate.h @@ -166,7 +166,7 @@ void MultiColvarTemplate::performTask( const unsigned& task_index, MultiValue } // Calculate the CVs using the method in the Colvar T::calculateCV( mode, mass, charge, fpositions, values, derivs, virial, this ); - for(unsigned i=0; igetPositionInStream(), values[i] ); + for(unsigned i=0; i::performTask( const unsigned& task_index, MultiValue for(unsigned i=0; igetPositionInStream(); - myvals.addDerivative( jval, base + 0, derivs[j][i][0] ); - myvals.addDerivative( jval, base + 1, derivs[j][i][1] ); - myvals.addDerivative( jval, base + 2, derivs[j][i][2] ); + myvals.addDerivative( j, base + 0, derivs[j][i][0] ); + myvals.addDerivative( j, base + 1, derivs[j][i][1] ); + myvals.addDerivative( j, base + 2, derivs[j][i][2] ); } // Check for duplicated indices during update to avoid double counting bool newi=true; @@ -186,19 +185,17 @@ void MultiColvarTemplate::performTask( const unsigned& task_index, MultiValue } if( !newi ) continue; for(int j=0; jgetPositionInStream(); - myvals.updateIndex( jval, base ); - myvals.updateIndex( jval, base + 1 ); - myvals.updateIndex( jval, base + 2 ); + myvals.updateIndex( j, base ); + myvals.updateIndex( j, base + 1 ); + myvals.updateIndex( j, base + 2 ); } } unsigned nvir=3*getNumberOfAtoms(); for(int j=0; jgetPositionInStream(); for(unsigned i=0; i<3; ++i) { for(unsigned k=0; k<3; ++k) { - myvals.addDerivative( jval, nvir + 3*i + k, virial[j][i][k] ); - myvals.updateIndex( jval, nvir + 3*i + k ); + myvals.addDerivative( j, nvir + 3*i + k, virial[j][i][k] ); + myvals.updateIndex( j, nvir + 3*i + k ); } } } diff --git a/src/colvar/RMSDVector.cpp b/src/colvar/RMSDVector.cpp index edcc8f7c68..f304c90a3a 100644 --- a/src/colvar/RMSDVector.cpp +++ b/src/colvar/RMSDVector.cpp @@ -259,13 +259,12 @@ void RMSDVector::performTask( const unsigned& current, MultiValue& myvals ) cons for(unsigned j=0; j<3; ++j) pos[i][j] = getPntrToArgument(0)->get( j*natoms + i ); } double r = calculateRMSD( current, pos, der, direction ); - unsigned ostrn = getConstPntrToComponent(0)->getPositionInStream(); - myvals.setValue( ostrn, r ); + myvals.setValue( 0, r ); if( doNotCalculateDerivatives() ) return; for(unsigned i=0; i& forces ) const { - if( myval->getRank()==1 ) { ActionWithVector::gatherForcesOnStoredValue( myval, itask, myvals, forces ); return; } +void RMSDVector::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { + if( getConstPntrToComponent(ival)->getRank()==1 ) { ActionWithVector::gatherForcesOnStoredValue( ival, itask, myvals, forces ); return; } const std::vector& direction( myvals.getConstFirstAtomDerivativeVector()[1] ); unsigned natoms = direction.size(); for(unsigned i=0; i& buffer ) const override ; - void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; + void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; void setReferenceConfigurations(); void calculate() override ; bool checkForTaskForce( const unsigned& itask, const Value* myval ) const override ; diff --git a/src/contour/FindContour.cpp b/src/contour/FindContour.cpp index df0472b99d..0ab14ac7b1 100644 --- a/src/contour/FindContour.cpp +++ b/src/contour/FindContour.cpp @@ -184,7 +184,7 @@ void FindContour::performTask( const unsigned& current, MultiValue& myvals ) con // Now find the contour findContour( direction, point ); // And transfer to the store data vessel - for(unsigned i=0; igetRank(); ++i) myvals.setValue( getConstPntrToComponent(i)->getPositionInStream(), point[i] ); + for(unsigned i=0; igetRank(); ++i) myvals.setValue( i, point[i] ); } } diff --git a/src/contour/FindContourSurface.cpp b/src/contour/FindContourSurface.cpp index 1a1d1eb28c..756488c331 100644 --- a/src/contour/FindContourSurface.cpp +++ b/src/contour/FindContourSurface.cpp @@ -226,13 +226,13 @@ void FindContourSurface::performTask( const unsigned& current, MultiValue& myval std::string num; Tools::convert( getStep(), num ); error("On step " + num + " failed to find required grid point"); } - myvals.setValue( getConstPntrToComponent(0)->getPositionInStream(), minp ); + myvals.setValue( 0, minp ); } void FindContourSurface::gatherStoredValue( const unsigned& valindex, const unsigned& code, const MultiValue& myvals, const unsigned& bufstart, std::vector& buffer ) const { plumed_dbg_assert( valindex==0 ); unsigned istart = bufstart + (1+gridcoords.getDimension())*code; - unsigned valout = getConstPntrToComponent(0)->getPositionInStream(); buffer[istart] += myvals.get( valout ); + buffer[istart] += myvals.get( 0 ); } } diff --git a/src/contour/FindSphericalContour.cpp b/src/contour/FindSphericalContour.cpp index c4d731bae9..5479c365c3 100644 --- a/src/contour/FindSphericalContour.cpp +++ b/src/contour/FindSphericalContour.cpp @@ -186,7 +186,7 @@ void FindSphericalContour::performTask( const unsigned& current, MultiValue& myv if( val1*val2<0 ) { findContour( direction, contour_point ); double norm=0; for(unsigned j=0; j<3; ++j) norm += contour_point[j]*contour_point[j]; - myvals.setValue( getConstPntrToComponent(0)->getPositionInStream(), sqrt(norm) ); found=true; break; + myvals.setValue( 0, sqrt(norm) ); found=true; break; } for(unsigned j=0; j<3; ++j) contour_point[j] = tmp[j]; } @@ -196,7 +196,7 @@ void FindSphericalContour::performTask( const unsigned& current, MultiValue& myv void FindSphericalContour::gatherStoredValue( const unsigned& valindex, const unsigned& code, const MultiValue& myvals, const unsigned& bufstart, std::vector& buffer ) const { plumed_assert( valindex==0 ); unsigned istart = bufstart + (1+gridcoords.getDimension())*code; - unsigned valout = getConstPntrToComponent(0)->getPositionInStream(); buffer[istart] += myvals.get( valout ); + buffer[istart] += myvals.get( 0 ); } } diff --git a/src/core/ActionWithMatrix.cpp b/src/core/ActionWithMatrix.cpp index 6cd26945f0..a7521d0a2c 100644 --- a/src/core/ActionWithMatrix.cpp +++ b/src/core/ActionWithMatrix.cpp @@ -152,25 +152,25 @@ void ActionWithMatrix::runTask( const std::string& controller, const unsigned& c performTask( controller, current, colno, myvals ); bool hasval = !isAdjacencyMatrix(); for(int i=0; igetPositionInStream()) )>epsilon ) { hasval=true; break; } + if( std::fabs(myvals.get(i))>epsilon ) { hasval=true; break; } } if( hasval ) { - double checkval = myvals.get( getConstPntrToComponent(0)->getPositionInStream() ); + double checkval = myvals.get( 0 ); for(int i=0; igetNumberOfColumns(); if( myval->getRank()!=2 || myval->hasDerivatives() || !myval->valueIsStored() ) continue; 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; + double fforce; if( ncolsgetShape()[1] ) fforce = myval->getForce( myvals.getTaskIndex()*ncols + myval->matrix_bookeeping[current*(1+ncols)] ); else fforce = myval->getForce( myvals.getTaskIndex()*myval->getShape()[1] + col_stash_index ); - for(unsigned j=0; jgetPositionInStream() ); if( !isAdjacencyMatrix() ) checkval=finalval; + double finalval = myvals.get( i ); if( !isAdjacencyMatrix() ) checkval=finalval; if( std::fabs(checkval)>epsilon || (!isAdjacencyMatrix() && getNumberOfMasks()>0) ) { Value* myv = const_cast( myval ); if( ncolsgetShape()[1] ) { @@ -192,9 +192,9 @@ bool ActionWithMatrix::checkForTaskForce( const unsigned& itask, const Value* my return false; } -void ActionWithMatrix::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { - if( myval->getRank()==1 ) { ActionWithVector::gatherForcesOnStoredValue( myval, itask, myvals, forces ); return; } - unsigned matind = myval->getPositionInMatrixStash(); const std::vector& mat_indices( myvals.getMatrixRowDerivativeIndices( matind ) ); +void ActionWithMatrix::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { + if( getConstPntrToComponent(ival)->getRank()==1 ) { ActionWithVector::gatherForcesOnStoredValue( ival, itask, myvals, forces ); return; } + unsigned matind = getConstPntrToComponent(ival)->getPositionInMatrixStash(); const std::vector& mat_indices( myvals.getMatrixRowDerivativeIndices( matind ) ); for(unsigned i=0; igetRank()==2 && !myval->hasDerivatives() ) myvals.clearDerivatives( myval->getPositionInStream() ); + if( myval->getRank()==2 && !myval->hasDerivatives() ) myvals.clearDerivatives( i ); } } if( matrix_to_do_after ) matrix_to_do_after->clearMatrixElements( myvals ); diff --git a/src/core/ActionWithMatrix.h b/src/core/ActionWithMatrix.h index b5a870ba2c..3428393a43 100644 --- a/src/core/ActionWithMatrix.h +++ b/src/core/ActionWithMatrix.h @@ -85,7 +85,7 @@ class ActionWithMatrix : public ActionWithVector { /// Check if there are forces we need to account for on this task bool checkForTaskForce( const unsigned& itask, const Value* myval ) const override ; /// This gathers the force on a particular value - virtual void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const; + virtual void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const; }; inline @@ -95,47 +95,26 @@ bool ActionWithMatrix::matrixChainContinues() const { inline double ActionWithMatrix::getArgumentElement( const unsigned& ic, const unsigned& jelem, const MultiValue& myvals ) const { - if( !getPntrToArgument(ic)->valueHasBeenSet() ) return myvals.get( getPntrToArgument(ic)->getPositionInStream() ); return getPntrToArgument(ic)->get( jelem ); } inline double ActionWithMatrix::getElementOfMatrixArgument( const unsigned& imat, const unsigned& irow, const unsigned& jcol, const MultiValue& myvals ) const { plumed_dbg_assert( imatgetRank()==2 && !getPntrToArgument(imat)->hasDerivatives() ); - if( !getPntrToArgument(imat)->valueHasBeenSet() ) return myvals.get( getPntrToArgument(imat)->getPositionInStream() ); return getArgumentElement( imat, irow*getPntrToArgument(imat)->getShape()[1] + jcol, myvals ); } inline void ActionWithMatrix::addDerivativeOnVectorArgument( const bool& inchain, const unsigned& ival, const unsigned& jarg, const unsigned& jelem, const double& der, MultiValue& myvals ) const { plumed_dbg_massert( jarggetRank()<2, "failing in action " + getName() + " with label " + getLabel() ); - unsigned ostrn = getConstPntrToComponent(ival)->getPositionInStream(), vstart=arg_deriv_starts[jarg]; - if( !inchain ) { - myvals.addDerivative( ostrn, vstart + jelem, der ); myvals.updateIndex( ostrn, vstart + jelem ); - } else { - unsigned istrn = getPntrToArgument(jarg)->getPositionInStream(); - for(unsigned k=0; kgetRank()==2 && !getPntrToArgument(jarg)->hasDerivatives() ); - unsigned ostrn = getConstPntrToComponent(ival)->getPositionInStream(), vstart=arg_deriv_starts[jarg]; - if( !inchain ) { - unsigned dloc = vstart + irow*getPntrToArgument(jarg)->getNumberOfColumns() + jcol; - myvals.addDerivative( ostrn, dloc, der ); myvals.updateIndex( ostrn, dloc ); - } else { - unsigned istrn = getPntrToArgument(jarg)->getPositionInStream(); - for(unsigned k=0; kgetNumberOfColumns() + jcol; + myvals.addDerivative( ival, dloc, der ); myvals.updateIndex( ival, dloc ); } } diff --git a/src/core/ActionWithVector.cpp b/src/core/ActionWithVector.cpp index 2bdf064a1a..fdb6c0e51d 100644 --- a/src/core/ActionWithVector.cpp +++ b/src/core/ActionWithVector.cpp @@ -68,8 +68,7 @@ ActionWithVector::ActionWithVector(const ActionOptions&ao): action_to_do_after(NULL), never_reduce_tasks(false), reduce_tasks(false), - atomsWereRetrieved(false), - done_in_chain(false) + atomsWereRetrieved(false) { for(unsigned i=0; i( getPntrToArgument(i)->getPntrToAction() ); @@ -173,140 +172,6 @@ bool ActionWithVector::argumentDependsOn( const std::string& headstr, ActionWith } unsigned ActionWithVector::buildArgumentStore( const unsigned& argstart ) { - // Don't use chains for grids - for(unsigned i=argstart; iisConstant() ) continue; - ActionWithVector* av=dynamic_cast(getPntrToArgument(i)->getPntrToAction()); - if( !av || getPntrToArgument(i)->getRank()>0 && getPntrToArgument(i)->hasDerivatives() ) { done_in_chain=false; break; } - } - if( getenvChainForbidden()==Option::yes ) done_in_chain=false; - - if( done_in_chain ) { - std::vector alabels; std::vector f_actions; - for(unsigned i=argstart; igetPntrToAction())->getLabel(); - for(unsigned j=0; jisConstant() ) continue; - // Find the chain we need to add this to from the arguments - ActionWithVector* av=dynamic_cast(getPntrToArgument(i)->getPntrToAction()); plumed_assert( av ); - found=false; ActionWithVector* myact = av->getFirstActionInChain(); - if( getPntrToArgument(i)->getRank()==1 && getPntrToArgument(i)->storedata ) { - for(unsigned j=argstart; j( getPntrToArgument(j)->getPntrToAction() ); - if( !aarg || i==j ) continue; - for(unsigned k=0; kgetNumberOfArguments(); ++k) { - if( aarg->getPntrToArgument(k)==getPntrToArgument(i) ) { done_in_chain=false; return reallyBuildArgumentStore( argstart ); } - } - } - } - for(unsigned j=0; j0 ) { - if( f_actions[0]->checkForDependency(myact) ) getPntrToArgument(i)->buildDataStore(); - if( myact->checkForDependency(f_actions[0]) ) error("cannot deal with arguments in this order. Try swapping argument order"); - } - if( !getPntrToArgument(i)->storedata && getPntrToArgument(i)->getRank()>0 ) f_actions.push_back( myact ); - } - } - // Now make sure that everything we need is in the chain - if( f_actions.size()>0 ) { - // Check everything for later f_actions is done before f_actions[0] - for(unsigned i=1; i( f_actions[i] ); - if( !aarg || aarg->getNumberOfArguments()==0 ) continue; - for(unsigned j=0; jgetNumberOfArguments(); ++j) { - if( (aarg->getPntrToArgument(j))->isConstant() ) continue ; - bool found=false; std::string dep_argname = (aarg->getPntrToArgument(j))->getPntrToAction()->getLabel(); - for(const auto & pp : plumed.getActionSet()) { - Action* p(pp.get()); - // Check if this is the dependency - if( p->getLabel()==dep_argname ) { found=true; break; } - // Check if this is the first of the arguments that will appear in this chain - else if( p->getLabel()==f_actions[0]->getLabel() ) break; - } - if( !found ) { done_in_chain=false; break; } - } - // Stop trying to add things in the chain if we cannot - if( !done_in_chain ) return reallyBuildArgumentStore( argstart ); - } - std::vector empty(1); empty[0] = f_actions[0]->getLabel(); - for(unsigned i=1; iaddActionToChain( empty, f_actions[i] ); - } - // Now add this argument to the chain - bool added=false; - for(unsigned i=argstart; igetRank()>0 && !getPntrToArgument(i)->isConstant() ) { - ActionWithVector* av=dynamic_cast( getPntrToArgument(i)->getPntrToAction() ); - if( av && av->addActionToChain( alabels, this ) ) { added=true; break; } - } - } - plumed_massert(added, "could not add action " + getLabel() + " to chain of any of its arguments"); - // And get the number of derivatives - ActionWithVector* head=getFirstActionInChain(); - unsigned nder=0; arg_deriv_starts.resize( getNumberOfArguments() ); - for(unsigned i=0; i(getPntrToArgument(i)->getPntrToAction()); - if( actionInChain() && !getPntrToArgument(i)->ignoreStoredValue(head->getLabel()) ) { - arg_deriv_starts[i] = 0; head->getNumberOfStreamedDerivatives( arg_deriv_starts[i], getPntrToArgument(i) ); - } else if( iaction && iaction->isInSubChain(nder) ) { - arg_deriv_starts[i] = nder; - // Add the total number of derivatives that we have by this point in the chain to nder - if( iaction ) { nder=0; head->getNumberOfStreamedDerivatives( nder, getPntrToArgument(i) ); } - } else { - // Check if we have already found this action - int k=-1; - if( iaction ) { - ActionWithVector* ider_action=iaction->getActionWithDerivatives( iaction ); - for(unsigned j=0; j(getPntrToArgument(j)->getPntrToAction()); - if( jaction->getActionWithDerivatives(jaction)==ider_action || jaction->checkForDependency(ider_action) ) { k=j; break; } - } - if( k>=0 ) { arg_deriv_starts[i] = arg_deriv_starts[k]; continue; } - } - - if( i>0 ) { - // This is a fudge so that inputs like this work: - // c: CONTACT_MATRIX ATOMS=1-100 - // d: MATRIX_PRODUCT ARG=mat1,mat2 - // e: CUSTOM ARG=c,d - // f: MATRIX_PRODUCT ARG=mat3,mat4 - // g: CUSTOM ARG=c,f - // See symfunc rt-nbonds-q6 for an example - // In this example when we set arg_deriv_starts[1] for f in g nder=number of derivatives of c - // mder is equal to the number of derivatives by the time you get to f minus the number of derivatives for c - unsigned mder=0; - ActionWithVector* jaction=dynamic_cast(getPntrToArgument(i-1)->getPntrToAction()); - if( jaction->action_to_do_after && !(jaction->action_to_do_after)->getNumberOfStoredValues( getPntrToArgument(i-1), mder, i, getArguments() ) ) mder=0; - if( mder>0 ) nder = nder + mder; - } - - arg_deriv_starts[i] = nder; - // Add the total number of derivatives that we have by this point in the chain to nder - if( iaction ) { - nder=0; - if( (getPntrToArgument(i)->getPntrToAction())->getName().find("DIFFERENCE")!=std::string::npos ) { - ActionWithArguments* aarg=dynamic_cast( getPntrToArgument(i)->getPntrToAction() ); - plumed_assert( aarg && aarg->getNumberOfArguments()==2 ); - head->getNumberOfStreamedDerivatives( nder, aarg->getPntrToArgument(0) ); - nder += (aarg->getPntrToArgument(1))->getNumberOfValues(); - } else head->getNumberOfStreamedDerivatives( nder, getPntrToArgument(i) ); - } - } - } - nder=0; head->getNumberOfStreamedDerivatives( nder, NULL ); - return nder; - } return reallyBuildArgumentStore( argstart ); } @@ -677,7 +542,7 @@ void ActionWithVector::getNumberOfTasks( unsigned& ntasks ) { } void ActionWithVector::setupStreamedComponents( const std::string& headstr, unsigned& nquants, unsigned& nmat, unsigned& maxcol ) { - for(int i=0; istreampos=nquants; nquants++; } + for(int i=0; ihasDerivatives() || !myval->valueIsStored() ) continue; Value* myv = const_cast( myval ); if( getName()=="RMSD_VECTOR" && myv->getRank()==2 ) continue; - myv->set( current, myvals.get( myval->getPositionInStream() ) ); + myv->set( current, myvals.get( i ) ); } if( action_to_do_after ) action_to_do_after->runTask( current, myvals ); } @@ -742,12 +607,12 @@ void ActionWithVector::gatherAccumulators( const unsigned& taskCode, const Multi // This looks after storing of scalars that are summed from vectors/matrices if( getConstPntrToComponent(i)->getRank()==0 ) { plumed_dbg_massert( bufstartstreampos; buffer[bufstart] += myvals.get(sind); + buffer[bufstart] += myvals.get(i); if( getConstPntrToComponent(i)->hasDerivatives() ) { - for(unsigned k=0; k& force_tasks ) const if( action_to_do_after ) action_to_do_after->getForceTasks( force_tasks ); } -void ActionWithVector::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { - plumed_dbg_assert( myval->storedata ); +void ActionWithVector::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { + const Value* myval = getConstPntrToComponent(ival); plumed_dbg_assert( myval->storedata ); double fforce = myval->getForce(itask); - unsigned sspos = myval->getPositionInStream(); - for(unsigned j=0; jgetRank()>0 && myval->forcesWereAdded() ) gatherForcesOnStoredValue( myval, itask, myvals, forces ); + if( myval->getRank()>0 && myval->forcesWereAdded() ) gatherForcesOnStoredValue( k, itask, myvals, forces ); } } if( action_to_do_after ) action_to_do_after->gatherForces( itask, myvals, forces ); diff --git a/src/core/ActionWithVector.h b/src/core/ActionWithVector.h index ec12409140..4d972f608a 100644 --- a/src/core/ActionWithVector.h +++ b/src/core/ActionWithVector.h @@ -100,8 +100,6 @@ class ActionWithVector: protected: /// A vector that contains the start point for the argument derivatives std::vector arg_deriv_starts; -/// Assert if this action is part of a chain - bool done_in_chain; /// Turn off the flag that says this action has a masked input void ignoreMaskArguments(); /// This updates whether or not we are using all the task reduction stuff @@ -179,7 +177,7 @@ class ActionWithVector: /// Check if there is a force that needs to be accumulated on the ith task virtual bool checkForTaskForce( const unsigned& itask, const Value* myval ) const ; /// Gather the forces on a particular value - virtual void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const ; + virtual void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const ; /// This is to transfer data from the buffer to the final value void finishComputations( const std::vector& buf ); /// Apply the forces on this data diff --git a/src/core/Value.cpp b/src/core/Value.cpp index d91692c80c..b3539269e4 100644 --- a/src/core/Value.cpp +++ b/src/core/Value.cpp @@ -40,7 +40,6 @@ Value::Value(): shape(std::vector()), hasDeriv(true), bufstart(0), - streampos(0), matpos(0), ngrid_der(0), ncols(0), @@ -64,7 +63,6 @@ Value::Value(const std::string& name): shape(std::vector()), hasDeriv(true), bufstart(0), - streampos(0), ngrid_der(0), matpos(0), ncols(0), @@ -88,7 +86,6 @@ Value::Value(ActionWithValue* av, const std::string& name, const bool withderiv, storedata(false), hasDeriv(withderiv), bufstart(0), - streampos(0), ngrid_der(0), matpos(0), ncols(0), diff --git a/src/core/Value.h b/src/core/Value.h index dfbe885a4a..59ac360ed5 100644 --- a/src/core/Value.h +++ b/src/core/Value.h @@ -87,7 +87,7 @@ class Value { /// Does this quanity have derivatives bool hasDeriv; /// Variables for storing data - unsigned bufstart, streampos, matpos, ngrid_der, ncols; + unsigned bufstart, matpos, ngrid_der, ncols; /// If we are storing a matrix is it symmetric? bool symmetric; /// This is a bookeeping array that holds the non-zero elements of the "sparse" matrix @@ -213,8 +213,6 @@ class Value { void setDerivativeIsZeroWhenValueIsZero(); /// Return a bool that tells us if the derivative is zero when the value is zero bool isDerivativeZeroWhenValueIsZero() const ; -/// - unsigned getPositionInStream() const ; /// This stuff handles where to look for the start of the row that contains the row of the matrix void setPositionInMatrixStash( const unsigned& p ); unsigned getPositionInMatrixStash() const ; @@ -434,11 +432,6 @@ bool Value::isDerivativeZeroWhenValueIsZero() const { return derivativeIsZeroWhenValueIsZero; } -inline -unsigned Value::getPositionInStream() const { - return streampos; -} - inline unsigned Value::getPositionInMatrixStash() const { return matpos; diff --git a/src/crystdistrib/QuaternionProductMatrix.cpp b/src/crystdistrib/QuaternionProductMatrix.cpp index e0b5b1c217..de87a7368b 100644 --- a/src/crystdistrib/QuaternionProductMatrix.cpp +++ b/src/crystdistrib/QuaternionProductMatrix.cpp @@ -128,7 +128,7 @@ void QuaternionProductMatrix::performTask( const std::string& controller, const //real part of q1*q2 for(unsigned i=0; i<4; ++i) { if( i>0 ) {pref=-1; pref2=-1;} - myvals.addValue( getConstPntrToComponent(0)->getPositionInStream(), pref*quat1[i]*quat2[i] ); + myvals.addValue( 0, pref*quat1[i]*quat2[i] ); if( doNotCalculateDerivatives() ) continue ; if (i>0) conj=-1; addDerivativeOnVectorArgument( false, 0, i, index1, conj*pref*quat2[i], myvals ); @@ -143,7 +143,7 @@ void QuaternionProductMatrix::performTask( const std::string& controller, const else pref=1; if(i==2) pref2=-1; else pref2=1; - myvals.addValue( getConstPntrToComponent(1)->getPositionInStream(), pref*quat1[i]*quat2[(5-i)%4]); + myvals.addValue( 1, pref*quat1[i]*quat2[(5-i)%4]); if( doNotCalculateDerivatives() ) continue ; if (i>0) conj=-1; addDerivativeOnVectorArgument( false, 1, i, index1, conj*pref*quat2[(5-i)%4], myvals ); @@ -159,7 +159,7 @@ void QuaternionProductMatrix::performTask( const std::string& controller, const else pref=1; if (i==3) pref2=-1; else pref2=1; - myvals.addValue( getConstPntrToComponent(2)->getPositionInStream(), pref*quat1[i]*quat2[(i+2)%4]); + myvals.addValue( 2, pref*quat1[i]*quat2[(i+2)%4]); if( doNotCalculateDerivatives() ) continue ; if (i>0) conj=-1; addDerivativeOnVectorArgument( false, 2, i, index1, conj*pref*quat2[(i+2)%4], myvals ); @@ -175,7 +175,7 @@ void QuaternionProductMatrix::performTask( const std::string& controller, const else pref=1; if(i==1) pref2=-1; else pref2=1; - myvals.addValue( getConstPntrToComponent(3)->getPositionInStream(), pref*quat1[i]*quat2[(3-i)]); + myvals.addValue( 3, pref*quat1[i]*quat2[(3-i)]); if( doNotCalculateDerivatives() ) continue ; if (i>0) conj=-1; addDerivativeOnVectorArgument( false, 3, i, index1, conj*pref*quat2[3-i], myvals ); diff --git a/src/dimred/ProjectPoints.cpp b/src/dimred/ProjectPoints.cpp index 1b6bb2de57..e9f4a39562 100644 --- a/src/dimred/ProjectPoints.cpp +++ b/src/dimred/ProjectPoints.cpp @@ -169,7 +169,7 @@ void ProjectPoints::getProjection( const unsigned& current, std::vector& void ProjectPoints::performTask( const unsigned& current, MultiValue& myvals ) const { std::vector point( dimout ); getProjection( current, point ); - for(unsigned j=0; jgetPositionInStream(), point[j] ); + for(unsigned j=0; j::FunctionOfVector(const ActionOptions&ao): myfunc.read( this ); // Create the task list if( myfunc.doWithTasks() ) { - doAtEnd=false; if( shape[0]>0 ) done_in_chain=true; + doAtEnd=false; } else { plumed_assert( getNumberOfArguments()==1 ); getPntrToArgument(0)->buildDataStore(); } // Get the names of the components std::vector components( keywords.getOutputComponents() ); diff --git a/src/gridtools/FunctionOfGrid.h b/src/gridtools/FunctionOfGrid.h index aec8cae75d..0b956030c5 100644 --- a/src/gridtools/FunctionOfGrid.h +++ b/src/gridtools/FunctionOfGrid.h @@ -163,23 +163,22 @@ void FunctionOfGrid::performTask( const unsigned& current, MultiValue& myvals std::vector vals(1); Matrix derivatives( 1, getNumberOfArguments()-argstart ); myfunc.calc( this, args, vals, derivatives ); unsigned np = myvals.getTaskIndex(); // And set the values and derivatives - unsigned ostrn = getConstPntrToComponent(0)->getPositionInStream(); - myvals.addValue( ostrn, vals[0] ); + myvals.addValue( 0, vals[0] ); if( !myfunc.zeroRank() ) { // Add the derivatives for a grid for(unsigned j=argstart; jgetRank()+j-argstart, derivatives(0,j-argstart) ); + myvals.addDerivative( 0, getConstPntrToComponent(0)->getRank()+j-argstart, derivatives(0,j-argstart) ); // And now we calculate the derivatives of the value that is stored on the grid correctly so that we can interpolate functions if( getPntrToArgument(j)->getRank()!=0 ) { - for(unsigned k=0; kgetRank(); ++k) myvals.addDerivative( ostrn, k, derivatives(0,j-argstart)*getPntrToArgument(j)->getGridDerivative( np, k ) ); + for(unsigned k=0; kgetRank(); ++k) myvals.addDerivative( 0, k, derivatives(0,j-argstart)*getPntrToArgument(j)->getGridDerivative( np, k ) ); } } unsigned nderivatives = getConstPntrToComponent(0)->getNumberOfGridDerivatives(); - for(unsigned j=0; j::gatherStoredValue( const unsigned& valindex, const unsig if( getConstPntrToComponent(0)->getRank()>0 && getConstPntrToComponent(0)->hasDerivatives() ) { plumed_dbg_assert( getNumberOfComponents()==1 && valindex==0 ); unsigned nder = getConstPntrToComponent(0)->getNumberOfGridDerivatives(); - unsigned ostr = getConstPntrToComponent(0)->getPositionInStream(); - unsigned kp = bufstart + code*(1+nder); buffer[kp] += myvals.get( ostr ); - for(unsigned i=0; i& buffer ) const ; - void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; + void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; }; PLUMED_REGISTER_ACTION(InterpolateGrid,"INTERPOLATE_GRID") @@ -161,19 +161,19 @@ std::vector InterpolateGrid::getGridCoordinateNames() const { void InterpolateGrid::performTask( const unsigned& current, MultiValue& myvals ) const { std::vector pos( output_grid.getDimension() ); output_grid.getGridPointCoordinates( current, pos ); std::vector val(1); Matrix der( 1, output_grid.getDimension() ); input_grid.calc( this, pos, val, der ); - unsigned ostrn = getConstPntrToComponent(0)->getPositionInStream(); myvals.setValue( ostrn, val[0] ); - for(unsigned i=0; i& buffer ) const { - plumed_dbg_assert( valindex==0 ); unsigned ostrn = getConstPntrToComponent(0)->getPositionInStream(); - unsigned istart = bufstart + (1+output_grid.getDimension())*code; buffer[istart] += myvals.get( ostrn ); - for(unsigned i=0; i& forces ) const { - std::vector pos(output_grid.getDimension()); double ff = myval->getForce(itask); +void InterpolateGrid::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { + std::vector pos(output_grid.getDimension()); double ff = getConstPntrToComponent(ival)->getForce(itask); output_grid.getGridPointCoordinates( itask, pos ); input_grid.applyForce( this, pos, ff, forces ); } diff --git a/src/gridtools/KDE.cpp b/src/gridtools/KDE.cpp index b127fdfd7e..92c4c33cc7 100644 --- a/src/gridtools/KDE.cpp +++ b/src/gridtools/KDE.cpp @@ -89,7 +89,7 @@ class KDE : public ActionWithGrid { const unsigned& bufstart, std::vector& buffer ) const override ; bool checkForTaskForce( const unsigned& itask, const Value* myval ) const override ; void updateForceTasksFromValue( const Value* myval, std::vector& force_tasks ) const override ; - void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; + void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; }; PLUMED_REGISTER_ACTION(KDE,"KDE") @@ -395,7 +395,6 @@ int KDE::checkTaskStatus( const unsigned& taskno, int& flag ) const { void KDE::performTask( const unsigned& current, MultiValue& myvals ) const { if( numberOfKernels==1 ) { double newval; std::vector args( gridobject.getDimension() ), der( gridobject.getDimension() ); - unsigned valout = getConstPntrToComponent(0)->getPositionInStream(); gridobject.getGridPointCoordinates( current, args ); if( getName()=="KDE" ) { if( kerneltype=="DISCRETE" ) { @@ -422,8 +421,8 @@ void KDE::performTask( const unsigned& current, MultiValue& myvals ) const { newval = hh*von_misses_norm*exp( von_misses_concentration*dot ); for(unsigned i=0; igetPositionInStream(); buffer[istart] += myvals.get( valout ); - for(unsigned i=0; i args( gridobject.getDimension() ); double height; retrieveArgumentsAndHeight( myvals, args, height ); @@ -551,7 +550,7 @@ bool KDE::checkForTaskForce( const unsigned& itask, const Value* myval ) const { return checkTaskIsActive( itask ); } -void KDE::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { +void KDE::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { if( numberOfKernels==1 ) { plumed_error(); return; @@ -586,7 +585,7 @@ void KDE::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, for(unsigned i=0; igetForce( neighbors[i] ); double newval = height*von_misses_norm*exp( von_misses_concentration*dot ); + double fforce = getConstPntrToComponent(ival)->getForce( neighbors[i] ); double newval = height*von_misses_norm*exp( von_misses_concentration*dot ); if( hasheight && getPntrToArgument(args.size())->getRank()==0 ) forces[ hforce_start ] += newval*fforce / height; else if( hasheight ) forces[ hforce_start + getPntrToArgument(args.size())->getIndexInStore(itask) ] += newval*fforce / height; unsigned n=0; for(unsigned j=0; jgetIndexInStore(itask)] += von_misses_concentration*newval*gpoint[j]*fforce; n += getPntrToArgument(j)->getNumberOfStoredValues(); } diff --git a/src/matrixtools/MatrixTimesMatrix.cpp b/src/matrixtools/MatrixTimesMatrix.cpp index fcce406492..7916dd868c 100644 --- a/src/matrixtools/MatrixTimesMatrix.cpp +++ b/src/matrixtools/MatrixTimesMatrix.cpp @@ -149,7 +149,7 @@ void MatrixTimesMatrix::setupForTask( const unsigned& task_index, std::vectorgetPositionInStream(), ind2=index2; + unsigned ind2=index2; if( index2>=getPntrToArgument(0)->getShape()[0] ) ind2 = index2 - getPntrToArgument(0)->getShape()[0]; Value* myarg = getPntrToArgument(0); @@ -179,18 +179,18 @@ void MatrixTimesMatrix::performTask( const std::string& controller, const unsign } else matval+= val1*val2; if( !squared || doNotCalculateDerivatives() ) continue ; - myvals.addDerivative( ostrn, index1*ncols + i, val2 ); myvals.updateIndex( ostrn, index1*ncols + i ); - myvals.addDerivative( ostrn, base + kind*ncols2 + colno[i], val1 ); myvals.updateIndex( ostrn, base + kind*ncols2 + colno[i] ); + myvals.addDerivative( 0, index1*ncols + i, val2 ); myvals.updateIndex( 0, index1*ncols + i ); + myvals.addDerivative( 0, base + kind*ncols2 + colno[i], val1 ); myvals.updateIndex( 0, base + kind*ncols2 + colno[i] ); } // And add this part of the product if( !squared ) matval = sqrt(matval); - myvals.addValue( ostrn, matval ); + myvals.addValue( 0, matval ); if( squared || doNotCalculateDerivatives() ) return; for(unsigned i=0; igetRowIndex( index1, i ); if( colno[i]<0 ) continue; - myvals.addDerivative( ostrn, index1*ncols + i, dvec1[i]/(2*matval) ); myvals.updateIndex( ostrn, index1*ncols + i ); - myvals.addDerivative( ostrn, base + i*ncols2 + colno[i], dvec2[i]/(2*matval) ); myvals.updateIndex( ostrn, base + i*ncols2 + colno[i] ); + myvals.addDerivative( 0, index1*ncols + i, dvec1[i]/(2*matval) ); myvals.updateIndex( 0, index1*ncols + i ); + myvals.addDerivative( 0, base + i*ncols2 + colno[i], dvec2[i]/(2*matval) ); myvals.updateIndex( 0, base + i*ncols2 + colno[i] ); } } else { for(unsigned i=0; igetPositionInStream(), ind2=index2; + unsigned ind2=index2; if( index2>=getPntrToArgument(0)->getShape()[0] ) ind2 = index2 - getPntrToArgument(0)->getShape()[0]; if( diagzero && index1==ind2 ) return; @@ -156,7 +156,7 @@ void OuterProduct::performTask( const std::string& controller, const unsigned& i fval=args[0]; if( args[1]>args[0] ) { fval=args[1]; jarg=1; kelem=ind2; jstore=stored_vector2; } } else { fval=function.evaluate( args ); } - myvals.addValue( ostrn, fval ); + myvals.addValue( 0, fval ); if( doNotCalculateDerivatives() ) return ; if( domin || domax ) { diff --git a/src/refdist/MatrixProductDiagonal.cpp b/src/refdist/MatrixProductDiagonal.cpp index e52e535d9c..3c6ff8f0e9 100644 --- a/src/refdist/MatrixProductDiagonal.cpp +++ b/src/refdist/MatrixProductDiagonal.cpp @@ -87,20 +87,19 @@ unsigned MatrixProductDiagonal::getNumberOfDerivatives() { } void MatrixProductDiagonal::performTask( const unsigned& task_index, MultiValue& myvals ) const { - unsigned ostrn = getConstPntrToComponent(0)->getPositionInStream(); Value* arg1 = getPntrToArgument(0); Value* arg2 = getPntrToArgument(1); if( arg1->getRank()==1 ) { double val1 = arg1->get( task_index ); double val2 = arg2->get( task_index ); - myvals.addValue( ostrn, val1*val2 ); + myvals.addValue( 0, val1*val2 ); if( doNotCalculateDerivatives() ) return; - myvals.addDerivative( ostrn, task_index, val2 ); - myvals.updateIndex( ostrn, task_index ); + myvals.addDerivative( 0, task_index, val2 ); + myvals.updateIndex( 0, task_index ); unsigned nvals = getPntrToArgument(0)->getNumberOfValues(); - myvals.addDerivative( ostrn, nvals + task_index, val1 ); - myvals.updateIndex( ostrn, nvals + task_index ); + myvals.addDerivative( 0, nvals + task_index, val1 ); + myvals.updateIndex( 0, nvals + task_index ); } else { unsigned nmult = arg1->getRowLength(task_index); unsigned nrowsA = getPntrToArgument(0)->getShape()[1]; @@ -116,13 +115,13 @@ void MatrixProductDiagonal::performTask( const unsigned& task_index, MultiValue& if( doNotCalculateDerivatives() ) continue; - myvals.addDerivative( ostrn, task_index*nrowsA + kind, val2 ); - myvals.updateIndex( ostrn, task_index*nrowsA + kind ); - myvals.addDerivative( ostrn, nvals1 + kind*nrowsB + task_index, val1 ); - myvals.updateIndex( ostrn, nvals1 + kind*nrowsB + task_index ); + myvals.addDerivative( 0, task_index*nrowsA + kind, val2 ); + myvals.updateIndex( 0, task_index*nrowsA + kind ); + myvals.addDerivative( 0, nvals1 + kind*nrowsB + task_index, val1 ); + myvals.updateIndex( 0, nvals1 + kind*nrowsB + task_index ); } // And add this part of the product - myvals.addValue( ostrn, matval ); + myvals.addValue( 0, matval ); } } diff --git a/src/secondarystructure/SecondaryStructureRMSD.cpp b/src/secondarystructure/SecondaryStructureRMSD.cpp index f92e7b594c..dc2124a3d4 100644 --- a/src/secondarystructure/SecondaryStructureRMSD.cpp +++ b/src/secondarystructure/SecondaryStructureRMSD.cpp @@ -235,22 +235,21 @@ void SecondaryStructureRMSD::performTask( const unsigned& current, MultiValue& m } const double inpairs = 1./static_cast(drmsd_targets[i].size()); - unsigned ostrn = getConstPntrToComponent(i)->getPositionInStream(); - drmsd = sqrt(inpairs*drmsd); myvals.setValue( ostrn, drmsd ); + drmsd = sqrt(inpairs*drmsd); myvals.setValue( i, drmsd ); if( !doNotCalculateDerivatives() ) { double scalef = inpairs / drmsd; for(unsigned j=0; jgetPositionInStream(); - myvals.setValue( ostrn, nr ); + myvals.setValue( i, nr ); if( !doNotCalculateDerivatives() ) { Tensor vir; vir.zero(); for(unsigned j=0; jgetPositionInStream(); - double nonweight = functions[n].evaluate( values ); myvals.addValue( ostrn, nonweight*weightij ); + double nonweight = functions[n].evaluate( values ); myvals.addValue( n, nonweight*weightij ); if( doNotCalculateDerivatives() ) continue; for(unsigned m=0; mgetPositionInStream(); - myvals.updateIndex( ostrn, ipos ); myvals.updateIndex( ostrn, matsize+ipos ); - myvals.updateIndex( ostrn, 2*matsize+ipos ); myvals.updateIndex( ostrn, 3*matsize+ipos ); + myvals.updateIndex( n, ipos ); myvals.updateIndex( n, matsize+ipos ); + myvals.updateIndex( n, 2*matsize+ipos ); myvals.updateIndex( n, 3*matsize+ipos ); } } } diff --git a/src/valtools/VStack.cpp b/src/valtools/VStack.cpp index 7d155cd263..17f632c4ce 100644 --- a/src/valtools/VStack.cpp +++ b/src/valtools/VStack.cpp @@ -58,7 +58,7 @@ class VStack : public ActionWithMatrix { /// void getMatrixColumnTitles( std::vector& argnames ) const override ; /// - void gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; + void gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const override ; }; PLUMED_REGISTER_ACTION(VStack,"VSTACK") @@ -95,15 +95,15 @@ VStack::VStack(const ActionOptions& ao): // And store this value getPntrToComponent(0)->buildDataStore(); getPntrToComponent(0)->reshapeMatrixStore( shape[1] ); // Setup everything so we can build the store - done_in_chain=true; ActionWithVector* av=dynamic_cast( getPntrToArgument(0)->getPntrToAction() ); + ActionWithVector* av=dynamic_cast( getPntrToArgument(0)->getPntrToAction() ); if( av ) { const ActionWithVector* head0 = av->getFirstActionInChain(); for(unsigned i=0; i( getPntrToArgument(i)->getPntrToAction() ); if( !avv ) continue; - if( head0!=avv->getFirstActionInChain() ) { done_in_chain=false; break; } + if( head0!=avv->getFirstActionInChain() ) { break; } } - } else done_in_chain=false; + } unsigned nder = buildArgumentStore(0); // This checks which values have been stored stored.resize( getNumberOfArguments() ); std::string headstr=getFirstActionInChain()->getLabel(); @@ -139,14 +139,14 @@ int VStack::checkTaskIsActive( const unsigned& itask ) const { void VStack::performTask( const std::string& controller, const unsigned& index1, const unsigned& index2, MultiValue& myvals ) const { unsigned ind2 = index2; if( index2>=getConstPntrToComponent(0)->getShape()[0] ) ind2 = index2 - getConstPntrToComponent(0)->getShape()[0]; - myvals.addValue( getConstPntrToComponent(0)->getPositionInStream(), getArgumentElement( ind2, index1, myvals ) ); + myvals.addValue( 0, getArgumentElement( ind2, index1, myvals ) ); if( doNotCalculateDerivatives() ) return; addDerivativeOnVectorArgument( stored[ind2], 0, ind2, index1, 1.0, myvals ); } -void VStack::gatherForcesOnStoredValue( const Value* myval, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { - unsigned matind = myval->getPositionInMatrixStash(); +void VStack::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector& forces ) const { + unsigned matind = getConstPntrToComponent(ival)->getPositionInMatrixStash(); for(unsigned i=0; i unsigned nmat = getConstPntrToComponent(0)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat ); std::vector& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) ); plumed_assert( nmat_indgetPositionInStream(); - for(unsigned k=0; kgetShape()[0]; - for(unsigned i=0; igetShape()[0]; + for(unsigned i=0; igetPositionInStream(); - outvals.setValue( ostrn, weight ); + outvals.setValue( 0, weight ); if( doNotCalculateDerivatives() ) return; // Atom position - for(unsigned i=0; i<3; ++i ) { outvals.addDerivative( ostrn, 3*curr+i, wdf[i] ); outvals.updateIndex( ostrn, 3*curr+i ); } + for(unsigned i=0; i<3; ++i ) { outvals.addDerivative( 0, 3*curr+i, wdf[i] ); outvals.updateIndex( 0, 3*curr+i ); } // Add derivatives with respect to reference positions unsigned vbase = 3*(getNumberOfAtoms()-nref); for(unsigned i=0; i