LCOV - code coverage report
Current view: top level - core - ActionToGetData.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 47 83.0 %
Date: 2026-03-30 11:13:23 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-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 "ActionToGetData.h"
      23             : #include "ActionRegister.h"
      24             : #include "PlumedMain.h"
      25             : 
      26             : //+PLUMEDOC ANALYSIS GET
      27             : /*
      28             : Get data from PLUMED for another code
      29             : 
      30             : \par Examples
      31             : 
      32             : */
      33             : //+ENDPLUMEDOC
      34             : 
      35             : namespace PLMD {
      36             : 
      37             : PLUMED_REGISTER_ACTION(ActionToGetData,"GET")
      38             : 
      39         119 : void ActionToGetData::registerKeywords(Keywords& keys) {
      40         119 :   Action::registerKeywords(keys);
      41         119 :   ActionPilot::registerKeywords(keys);
      42         119 :   ActionWithArguments::registerKeywords(keys);
      43         238 :   keys.add("compulsory","STRIDE","1","the frequency with which the quantities of interest should be stored");
      44         238 :   keys.add("compulsory","TYPE","value","what do you want to collect for the value can be derivative/force");
      45         119 :   keys.use("ARG");
      46         119 :   keys.setValueDescription("a copy of the data in the value specified by the ARG keyword");
      47         119 : }
      48             : 
      49         115 : ActionToGetData::ActionToGetData(const ActionOptions&ao):
      50             :   Action(ao),
      51             :   ActionPilot(ao),
      52             :   ActionWithArguments(ao),
      53         115 :   mydata(DataPassingObject::create(plumed.getRealPrecision())) {
      54             :   std::string type;
      55         230 :   parse("TYPE",type);
      56         115 :   if( type=="value" ) {
      57         115 :     gtype=val;
      58           0 :   } else if( type=="derivatives" ) {
      59           0 :     gtype=deriv;
      60           0 :   } else if( type=="forces" ) {
      61           0 :     gtype=force;
      62             :   } else {
      63           0 :     plumed_merror("cannot get " + type + " for value TYPE should be value/derivative/force");
      64             :   }
      65             : 
      66         115 :   if( gtype!=val ) {
      67           0 :     error("not implemented functionality to pass derviatives or forces to python.  Email gareth.tribello@gmail.com if you want this.");
      68             :   }
      69             : 
      70         115 :   if( getNumberOfArguments()!=1 ) {
      71           0 :     error("python interface works best when you ask for one argument at a time");
      72             :   }
      73         115 :   if( getPntrToArgument(0)->getNumberOfValues()==0 ) {
      74           0 :     error("cannot get data as shape of value " + getPntrToArgument(0)->getName() + " has not been set");
      75             :   }
      76         115 :   getPntrToArgument(0)->buildDataStore();
      77         115 :   data.resize( getPntrToArgument(0)->getNumberOfValues() );
      78         115 : }
      79             : 
      80         115 : void ActionToGetData::get_rank( const TypesafePtr & dims ) {
      81         115 :   if( getPntrToArgument(0)->getRank()==0 ) {
      82          98 :     dims.set(long(1));
      83          98 :     return;
      84             :   }
      85          17 :   dims.set(long(getPntrToArgument(0)->getRank()));
      86             : }
      87             : 
      88          51 : void ActionToGetData::get_shape( const TypesafePtr & dims ) {
      89          51 :   if( getPntrToArgument(0)->getRank()==0 ) {
      90          34 :     dims.set(long(1));
      91          34 :     return;
      92             :   }
      93          17 :   auto dims_=dims.get<long*>( { getPntrToArgument(0)->getRank() } );
      94          37 :   for(unsigned j=0; j<getPntrToArgument(0)->getRank(); ++j) {
      95          20 :     dims_[j] = getPntrToArgument(0)->getShape()[j];
      96             :   }
      97             : }
      98             : 
      99         115 : void ActionToGetData::set_memory( const TypesafePtr & val ) {
     100         115 :   mydata->setValuePointer(val,getPntrToArgument(0)->getShape(),false);
     101         115 : }
     102             : 
     103       12447 : void ActionToGetData::calculate() {
     104       12447 :   plumed_assert( gtype==val );
     105       12447 :   mydata->setData( getPntrToArgument(0) );
     106       12447 : }
     107             : 
     108             : }

Generated by: LCOV version 1.16