LCOV - code coverage report
Current view: top level - core - ActionToGetData.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 32 90.6 %
Date: 2024-10-18 14:00:25 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         117 : void ActionToGetData::registerKeywords(Keywords& keys) {
      40         117 :   Action::registerKeywords(keys); ActionPilot::registerKeywords(keys); ActionWithArguments::registerKeywords(keys);
      41         234 :   keys.add("compulsory","STRIDE","1","the frequency with which the quantities of interest should be stored");
      42         234 :   keys.add("compulsory","TYPE","value","what do you want to collect for the value can be derivative/force");
      43         117 :   keys.use("ARG");
      44         117 :   keys.setValueDescription("a copy of the data in the value specified by the ARG keyword");
      45         117 : }
      46             : 
      47         115 : ActionToGetData::ActionToGetData(const ActionOptions&ao):
      48             :   Action(ao),
      49             :   ActionPilot(ao),
      50             :   ActionWithArguments(ao),
      51         115 :   mydata(DataPassingObject::create(plumed.getRealPrecision()))
      52             : {
      53         230 :   std::string type; parse("TYPE",type);
      54         115 :   if( type=="value" ) gtype=val;
      55           0 :   else if( type=="derivatives" ) gtype=deriv;
      56           0 :   else if( type=="forces" ) gtype=force;
      57           0 :   else plumed_merror("cannot get " + type + " for value TYPE should be value/derivative/force");
      58             : 
      59         115 :   if( gtype!=val ) error("not implemented functionality to pass derviatives or forces to python.  Email gareth.tribello@gmail.com if you want this.");
      60             : 
      61         115 :   if( getNumberOfArguments()!=1 ) error("python interface works best when you ask for one argument at a time");
      62         115 :   if( getPntrToArgument(0)->getNumberOfValues()==0 ) error("cannot get data as shape of value " + getPntrToArgument(0)->getName() + " has not been set");
      63         115 :   getPntrToArgument(0)->buildDataStore(); data.resize( getPntrToArgument(0)->getNumberOfValues() );
      64         115 : }
      65             : 
      66         115 : void ActionToGetData::get_rank( const TypesafePtr & dims ) {
      67         115 :   if( getPntrToArgument(0)->getRank()==0 ) { dims.set(long(1)); return; }
      68          17 :   dims.set(long(getPntrToArgument(0)->getRank()));
      69             : }
      70             : 
      71          51 : void ActionToGetData::get_shape( const TypesafePtr & dims ) {
      72          51 :   if( getPntrToArgument(0)->getRank()==0 ) { dims.set(long(1)); return; }
      73          17 :   auto dims_=dims.get<long*>( { getPntrToArgument(0)->getRank() } );
      74          37 :   for(unsigned j=0; j<getPntrToArgument(0)->getRank(); ++j) dims_[j] = getPntrToArgument(0)->getShape()[j];
      75             : }
      76             : 
      77         115 : void ActionToGetData::set_memory( const TypesafePtr & val ) {
      78         115 :   mydata->setValuePointer(val,getPntrToArgument(0)->getShape(),false);
      79         115 : }
      80             : 
      81       12447 : void ActionToGetData::calculate() {
      82       12447 :   plumed_assert( gtype==val ); mydata->setData( getPntrToArgument(0) );
      83       12447 : }
      84             : 
      85             : }

Generated by: LCOV version 1.16