LCOV - code coverage report
Current view: top level - core - Colvar.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 67 67 100.0 %
Date: 2019-08-13 10:39:37 Functions: 8 9 88.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "Colvar.h"
      23             : #include "tools/OpenMP.h"
      24             : #include <vector>
      25             : #include <string>
      26             : 
      27             : using namespace std;
      28             : namespace PLMD {
      29             : 
      30        1420 : Colvar::Colvar(const ActionOptions&ao):
      31             :   Action(ao),
      32             :   ActionAtomistic(ao),
      33             :   ActionWithValue(ao),
      34        1420 :   isEnergy(false)
      35             : {
      36        1420 : }
      37             : 
      38        1389 : void Colvar::registerKeywords( Keywords& keys ) {
      39        1389 :   Action::registerKeywords( keys );
      40        1389 :   ActionWithValue::registerKeywords( keys );
      41        1389 :   ActionAtomistic::registerKeywords( keys );
      42        1389 :   keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances");
      43        1389 : }
      44             : 
      45        1547 : void Colvar::requestAtoms(const vector<AtomNumber> & a) {
      46        1547 :   plumed_massert(!isEnergy,"request atoms should not be called if this is energy");
      47             : // Tell actionAtomistic what atoms we are getting
      48        1547 :   ActionAtomistic::requestAtoms(a);
      49             : // Resize the derivatives of all atoms
      50        1546 :   for(int i=0; i<getNumberOfComponents(); ++i) getPntrToComponent(i)->resizeDerivatives(3*a.size()+9);
      51        1546 : }
      52             : 
      53       77211 : void Colvar::apply() {
      54       77211 :   vector<Vector>&   f(modifyForces());
      55       77211 :   Tensor&           v(modifyVirial());
      56       77211 :   const unsigned    nat=getNumberOfAtoms();
      57       77211 :   const unsigned    ncp=getNumberOfComponents();
      58       77211 :   const unsigned    fsz=f.size();
      59             : 
      60       77211 :   unsigned stride=1;
      61       77211 :   unsigned rank=0;
      62       77211 :   if(ncp>4*comm.Get_size()) {
      63         804 :     stride=comm.Get_size();
      64         804 :     rank=comm.Get_rank();
      65             :   }
      66             : 
      67       77211 :   unsigned nt=OpenMP::getNumThreads();
      68       77211 :   if(nt>ncp/(4*stride)) nt=1;
      69             : 
      70       77211 :   if(!isEnergy) {
      71      147515 :     #pragma omp parallel num_threads(nt)
      72             :     {
      73       74091 :       vector<Vector> omp_f(fsz);
      74       74082 :       Tensor         omp_v;
      75      148191 :       vector<double> forces(3*nat+9);
      76       74094 :       #pragma omp for
      77             :       for(unsigned i=rank; i<ncp; i+=stride) {
      78      120822 :         if(getPntrToComponent(i)->applyForce(forces)) {
      79      294568 :           for(unsigned j=0; j<nat; ++j) {
      80      246301 :             omp_f[j][0]+=forces[3*j+0];
      81      246301 :             omp_f[j][1]+=forces[3*j+1];
      82      246301 :             omp_f[j][2]+=forces[3*j+2];
      83             :           }
      84       48267 :           omp_v(0,0)+=forces[3*nat+0];
      85       48267 :           omp_v(0,1)+=forces[3*nat+1];
      86       48267 :           omp_v(0,2)+=forces[3*nat+2];
      87       48267 :           omp_v(1,0)+=forces[3*nat+3];
      88       48267 :           omp_v(1,1)+=forces[3*nat+4];
      89       48266 :           omp_v(1,2)+=forces[3*nat+5];
      90       48266 :           omp_v(2,0)+=forces[3*nat+6];
      91       48267 :           omp_v(2,1)+=forces[3*nat+7];
      92       48267 :           omp_v(2,2)+=forces[3*nat+8];
      93             :         }
      94             :       }
      95      148192 :       #pragma omp critical
      96             :       {
      97      719909 :         for(unsigned j=0; j<nat; ++j) f[j]+=omp_f[j];
      98       74096 :         v+=omp_v;
      99       74096 :       }
     100             :     }
     101             : 
     102       73424 :     if(ncp>4*comm.Get_size()) {
     103         804 :       if(fsz>0) comm.Sum(&f[0][0],3*fsz);
     104         804 :       comm.Sum(&v[0][0],9);
     105             :     }
     106             : 
     107        3787 :   } else if( isEnergy ) {
     108        3787 :     vector<double> forces(1);
     109        3787 :     if(getPntrToComponent(0)->applyForce(forces)) modifyForceOnEnergy()+=forces[0];
     110             :   }
     111       77211 : }
     112             : 
     113      141242 : void Colvar::setBoxDerivativesNoPbc(Value* v) {
     114      141242 :   Tensor virial;
     115      141242 :   unsigned nat=getNumberOfAtoms();
     116    46403156 :   for(unsigned i=0; i<nat; i++) virial-=Tensor(getPosition(i),
     117             :                                           Vector(v->getDerivative(3*i+0),
     118    15420638 :                                               v->getDerivative(3*i+1),
     119    30841276 :                                               v->getDerivative(3*i+2)));
     120      141242 :   setBoxDerivatives(v,virial);
     121      141242 : }
     122        4821 : }

Generated by: LCOV version 1.13