Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2015-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 "ActionWithInputGrid.h"
23 : #include "core/PlumedMain.h"
24 : #include "core/ActionSet.h"
25 :
26 : namespace PLMD {
27 : namespace gridtools {
28 :
29 23 : void ActionWithInputGrid::registerKeywords( Keywords& keys ) {
30 23 : ActionWithGrid::registerKeywords( keys );
31 92 : keys.add("compulsory","GRID","the action that creates the input grid you would like to use");
32 92 : keys.add("optional","COMPONENT","if your input is a vector field use this to specifiy the component of the input vector field for which you wish to use");
33 23 : }
34 :
35 16 : ActionWithInputGrid::ActionWithInputGrid(const ActionOptions&ao):
36 : Action(ao),
37 : ActionWithGrid(ao),
38 16 : ingrid(NULL)
39 : {
40 32 : std::string mlab; parse("GRID",mlab);
41 32 : vesselbase::ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<vesselbase::ActionWithVessel*>(mlab);
42 16 : if(!mves) error("action labelled " + mlab + " does not exist or does not have vessels");
43 16 : addDependency(mves);
44 :
45 16 : for(unsigned i=0; i<mves->getNumberOfVessels(); ++i) {
46 16 : ingrid=dynamic_cast<GridVessel*>( mves->getPntrToVessel(i) );
47 16 : if( ingrid ) break;
48 : }
49 16 : if( !ingrid ) error("input action does not calculate a grid");
50 :
51 16 : if( ingrid->getNumberOfComponents()==1 ) {
52 16 : mycomp=0;
53 : } else {
54 0 : int tcomp=-1; parse("COMPONENT",tcomp);
55 0 : if( tcomp<0 ) error("component of vector field was not specified - use COMPONENT keyword");
56 0 : mycomp=tcomp;
57 : }
58 32 : log.printf(" using %uth component of grid calculated by action %s \n",mycomp,mves->getLabel().c_str() );
59 16 : }
60 :
61 18 : void ActionWithInputGrid::clearAverage() {
62 53 : if( mygrid->getType()=="flat" ) mygrid->setBounds( ingrid->getMin(), ingrid->getMax(), mygrid->getNbin(), mygrid->getGridSpacing() );
63 18 : ActionWithAveraging::clearAverage();
64 18 : }
65 :
66 58 : void ActionWithInputGrid::prepareForAveraging() {
67 58 : if( checkAllActive() ) {
68 149525 : for(unsigned i=0; i<ingrid->getNumberOfPoints(); ++i) {
69 49803 : if( ingrid->inactive(i) ) error("if FIND_CONTOUR is used with BUFFER option then other actions cannot be performed with grid");
70 : }
71 : }
72 58 : }
73 :
74 21 : void ActionWithInputGrid::performOperations( const bool& from_update ) {
75 21 : prepareForAveraging(); runAllTasks();
76 21 : }
77 :
78 : }
79 4839 : }
80 :
|