LCOV - code coverage report
Current view: top level - tools - CheckInRange.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 31 40 77.5 %
Date: 2024-10-18 14:00:25 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-2023 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 "CheckInRange.h"
      23             : #include "Tools.h"
      24             : 
      25             : namespace PLMD {
      26             : 
      27          43 : bool CheckInRange::setBounds( const unsigned& n, const std::vector<std::string>& str_lower, const std::vector<std::string>& str_upper, std::string& errors ) {
      28          43 :   if( str_upper.size()!=n && str_upper.size()>0 ) { errors="wrong number of arguments for LESS_THAN_OR_EQUAL keyword"; return false; }
      29          43 :   if( str_lower.size()!=n && str_lower.size()>0 ) { errors="wrong number of arguments for GREATER_THAN_OR_EQUAL keyword"; return false; }
      30          43 :   if( str_upper.size()>0 && str_lower.size()>0 ) {
      31          14 :     lower.resize( str_lower.size() ); upper.resize( str_upper.size() );
      32          28 :     for(unsigned i=0; i<upper.size(); ++i) {
      33          14 :       if( str_lower[i]=="none" ) lower[i] = -std::numeric_limits<double>::max();
      34          14 :       else Tools::convert( str_lower[i], lower[i] );
      35          14 :       if( str_upper[i]=="none" ) upper[i] = std::numeric_limits<double>::max();
      36          14 :       else Tools::convert( str_upper[i], upper[i] );
      37             :     }
      38          29 :   } else if( str_upper.size()>0 ) {
      39           0 :     upper.resize( str_upper.size() );
      40           0 :     for(unsigned i=0; i<upper.size(); ++i) {
      41           0 :       if( str_upper[i]=="none" ) upper[i] = std::numeric_limits<double>::max();
      42           0 :       else Tools::convert( str_upper[i], upper[i] );
      43             :     }
      44          29 :   } else if( str_lower.size()>0 ) {
      45           3 :     lower.resize( str_lower.size() );
      46           6 :     for(unsigned i=0; i<lower.size(); ++i) {
      47           3 :       if( str_lower[i]=="none" ) lower[i] = -std::numeric_limits<double>::max();
      48           3 :       else Tools::convert( str_lower[i], lower[i] );
      49             :     }
      50             :   }
      51             :   return true;
      52             : }
      53             : 
      54          43 : bool CheckInRange::wereSet() const {
      55          43 :   return lower.size()>0 || upper.size()>0;
      56             : }
      57             : 
      58          17 : std::string CheckInRange::report( const std::vector<std::string>& a ) const {
      59          17 :   if( upper.size()>0 && lower.size()>0 ) {
      60          14 :     std::string str_l, str_u; Tools::convert( upper[0], str_u ); Tools::convert( lower[0], str_l );
      61          28 :     std::string out="only printing indices of atoms that have " + str_l + " <= " + a[0] + " <=" + str_u;
      62          14 :     for(unsigned i=1; i<upper.size(); ++i) {
      63           0 :       Tools::convert( upper[i], str_u ); Tools::convert( lower[i], str_l );
      64           0 :       out += " and " + str_l + " <= " + a[i] + " <=" + str_u;
      65             :     }
      66             :     return out;
      67             :   }
      68           3 :   if( upper.size()>0 ) {
      69           0 :     std::string str_u; Tools::convert( upper[0], str_u );
      70           0 :     std::string out="only printing indices of atoms that have " + a[0] + " <= " + str_u;
      71           0 :     for(unsigned i=1; i<upper.size(); ++i) { Tools::convert( upper[i], str_u ); out += " and " + a[i] + " <= " + str_u; }
      72             :     return out;
      73             :   }
      74           3 :   std::string str_l; Tools::convert( lower[0], str_l );
      75           6 :   std::string out="only printing indices of atoms that have " + str_l + " <= " + a[0];
      76           3 :   for(unsigned i=1; i<lower.size(); ++i) { Tools::convert( lower[i], str_l ); out += " and " + str_l + " <= " + a[i]; }
      77             :   return out;
      78             : }
      79             : 
      80      139130 : bool CheckInRange::check( const std::vector<double>& vals ) const {
      81      191478 :   for(unsigned j=0; j<vals.size(); ++j) {
      82       67788 :     if( upper.size()>0 && vals[j]>upper[j] ) return false;
      83       58176 :     if( lower.size()>0 && vals[j]<lower[j] ) return false;
      84             :   }
      85             :   return true;
      86             : }
      87             : 
      88             : }

Generated by: LCOV version 1.16