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