LCOV - code coverage report
Current view: top level - reference - MultiReferenceBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 47 47 100.0 %
Date: 2020-11-18 11:20:57 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2019 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #include "MultiReferenceBase.h"
      23             : #include "tools/Communicator.h"
      24             : #include "MetricRegister.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28          15 : MultiReferenceBase::MultiReferenceBase( const std::string& type, const bool& checksoff ):
      29             :   wasSet(false),
      30          15 :   skipchecks(checksoff),
      31          30 :   mtype(type)
      32             : {
      33          15 :   if(checksoff) plumed_assert( mtype.length()==0 );
      34          15 : }
      35             : 
      36          30 : MultiReferenceBase::~MultiReferenceBase() {
      37        1614 :   for(unsigned i=0; i<frames.size(); ++i) delete frames[i];
      38          15 : }
      39             : 
      40           2 : void MultiReferenceBase::clearFrames() {
      41         304 :   for(unsigned i=0; i<frames.size(); ++i) delete frames[i];
      42           2 :   frames.resize(0);
      43           2 :   clearRestOfData();
      44           2 : }
      45             : 
      46         428 : void MultiReferenceBase::readFrame( PDB& mypdb ) {
      47         428 :   wasSet=true;
      48             :   // If skipchecks are enabled metric types must be specified in the input file
      49         428 :   ReferenceConfiguration* mymsd=metricRegister().create<ReferenceConfiguration>( mtype, mypdb );
      50             :   // Save everything
      51         428 :   frames.push_back( mymsd );
      52             :   // Do reading in derived class
      53         428 :   readRestOfFrame();
      54             :   // Check readin was succesfull
      55         428 :   mymsd->checkRead();
      56         428 : }
      57             : 
      58          14 : void MultiReferenceBase::getAtomAndArgumentRequirements( std::vector<AtomNumber>& atoms, std::vector<std::string>& args ) {
      59          28 :   plumed_assert( atoms.size()==0 && args.size()==0 );
      60        1312 :   for(unsigned i=0; i<frames.size(); ++i) {
      61         428 :     frames[i]->getAtomRequests( atoms );
      62         428 :     frames[i]->getArgumentRequests( args );
      63             :   }
      64          14 : }
      65             : 
      66             : // void MultiReferenceBase::setNumberOfAtomsAndArguments( const unsigned& natoms, const unsigned& nargs ){
      67             : //   for(unsigned i=0;i<frames.size();++i){
      68             : //       frames[i]->setNumberOfAtoms( natoms );
      69             : //       frames[i]->setNumberOfArguments( nargs );
      70             : //   }
      71             : // }
      72             : 
      73         200 : void MultiReferenceBase::copyFrame( ReferenceConfiguration* frameToCopy ) {
      74             :   // Create a reference configuration of the appropriate type
      75         400 :   ReferenceConfiguration* mymsd=metricRegister().create<ReferenceConfiguration>( frameToCopy->getName() );
      76             :   // Copy names of arguments and and indexes
      77         200 :   mymsd->setNamesAndAtomNumbers( frameToCopy->getAbsoluteIndexes(), frameToCopy->getArgumentNames() );
      78             :   // Copy reference positions, reference arguments and reference metric
      79         200 :   mymsd->setReferenceConfig( frameToCopy->getReferencePositions(), frameToCopy->getReferenceArguments(), frameToCopy->getReferenceMetric() );
      80             :   // Copy weight
      81         200 :   mymsd->setWeight( frameToCopy->getWeight() );
      82             :   // Easy bit - copy the frame
      83         200 :   frames.push_back( mymsd );
      84             :   // This resizes the low dim array
      85         200 :   resizeRestOfFrame();
      86         200 : }
      87             : 
      88          10 : void MultiReferenceBase::setWeights( const std::vector<double>& weights ) {
      89          10 :   plumed_assert( weights.size()==frames.size() );
      90        1684 :   for(unsigned i=0; i<weights.size(); ++i) frames[i]->setWeight( weights[i] );
      91          10 : }
      92             : 
      93             : 
      94           2 : void MultiReferenceBase::calculateAllDistances( const Pbc& pbc, const std::vector<Value*> & vals, Communicator& comm, Matrix<double>& distances, const bool& squared ) {
      95             :   distances=0.0;
      96           2 :   unsigned k=0, size=comm.Get_size(), rank=comm.Get_rank();
      97         598 :   for(unsigned i=1; i<frames.size(); ++i) {
      98       19998 :     for(unsigned j=0; j<i; ++j) {
      99        9900 :       if( (k++)%size!=rank ) continue;
     100       49500 :       distances(i,j) = distances(j,i) = distance( pbc, vals, frames[i], frames[j], squared );
     101             :     }
     102             :   }
     103           2 :   comm.Sum( distances );
     104           2 : }
     105             : 
     106        4839 : }

Generated by: LCOV version 1.13