Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-2018 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 "GridPrintingBase.h"
23 : #include "core/PlumedMain.h"
24 : #include "core/ActionSet.h"
25 : #include "vesselbase/ActionWithVessel.h"
26 :
27 : namespace PLMD {
28 : namespace gridtools {
29 :
30 41 : void GridPrintingBase::registerKeywords( Keywords& keys ) {
31 41 : Action::registerKeywords( keys ); ActionPilot::registerKeywords( keys );
32 41 : keys.add("compulsory","GRID","the action that creates the grid you would like to output");
33 : keys.add("compulsory","STRIDE","0","the frequency with which the grid should be output to the file. The default "
34 41 : "value of 0 ensures that the grid is only output at the end of the trajectory");
35 41 : keys.add("compulsory","FILE","density","the file on which to write the grid.");
36 41 : keys.add("optional","FMT","the format that should be used to output real numbers");
37 41 : }
38 :
39 39 : GridPrintingBase::GridPrintingBase(const ActionOptions&ao):
40 : Action(ao),
41 : ActionPilot(ao),
42 39 : fmt("%f")
43 : {
44 39 : std::string mlab; parse("GRID",mlab);
45 39 : vesselbase::ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<vesselbase::ActionWithVessel*>(mlab);
46 39 : if(!mves) error("action labelled " + mlab + " does not exist or does not have vessels");
47 39 : addDependency(mves);
48 :
49 39 : for(unsigned i=0; i<mves->getNumberOfVessels(); ++i) {
50 39 : ingrid=dynamic_cast<GridVessel*>( mves->getPntrToVessel(i) );
51 39 : if( ingrid ) break;
52 : }
53 39 : if( !ingrid ) error("input action does not calculate a grid");
54 :
55 39 : parse("FMT",fmt); parse("FILE",filename);
56 39 : if(filename.length()==0) error("name out output file was not specified");
57 39 : log.printf(" outputting grid calculated by action %s to file named %s with format %s \n",mves->getLabel().c_str(),filename.c_str(), fmt.c_str() );
58 39 : }
59 :
60 62 : void GridPrintingBase::update() {
61 124 : if( getStep()==0 || getStride()==0 ) return ;
62 :
63 39 : OFile ofile; ofile.link(*this);
64 39 : ofile.setBackupString("analysis");
65 39 : ofile.open( filename ); printGrid( ofile ); ofile.close();
66 : }
67 :
68 39 : void GridPrintingBase::runFinalJobs() {
69 78 : if( getStride()>0 ) return;
70 :
71 16 : OFile ofile; ofile.link(*this);
72 16 : ofile.open( filename ); printGrid( ofile ); ofile.close();
73 : }
74 :
75 : }
76 2523 : }
|