LCOV - code coverage report
Current view: top level - contour - DumpContour.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 36 100.0 %
Date: 2024-10-18 13:59:31 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "core/ActionWithArguments.h"
      23             : #include "core/ActionPilot.h"
      24             : #include "core/ActionRegister.h"
      25             : #include "tools/OFile.h"
      26             : #include "core/PlumedMain.h"
      27             : #include "FindContour.h"
      28             : 
      29             : namespace PLMD {
      30             : namespace contour {
      31             : 
      32             : //+PLUMEDOC GRIDANALYSIS DUMPCONTOUR
      33             : /*
      34             : Print the contour
      35             : 
      36             : \par Examples
      37             : 
      38             : */
      39             : //+ENDPLUMEDOC
      40             : 
      41             : class DumpContour :
      42             :   public ActionWithArguments,
      43             :   public ActionPilot {
      44             : private:
      45             :   std::string fmt, filename;
      46             : public:
      47             :   static void registerKeywords( Keywords& keys );
      48             :   explicit DumpContour(const ActionOptions&ao);
      49           2 :   ~DumpContour() {}
      50           2 :   void calculate() override {}
      51           2 :   void apply() override {}
      52             :   void update() override ;
      53             : };
      54             : 
      55             : PLUMED_REGISTER_ACTION(DumpContour,"DUMPCONTOUR")
      56             : 
      57           3 : void DumpContour::registerKeywords( Keywords& keys ) {
      58           3 :   Action::registerKeywords( keys );
      59           3 :   ActionPilot::registerKeywords( keys );
      60           3 :   ActionWithArguments::registerKeywords( keys );
      61           6 :   keys.addInputKeyword("compulsory","ARG","vector","the labels of the values that should be output to the file");
      62           6 :   keys.add("compulsory","STRIDE","1","the frequency with which the grid should be output to the file.");
      63           6 :   keys.add("compulsory","FILE","density","the file on which to write the grid.");
      64           6 :   keys.add("optional","FMT","the format that should be used to output real numbers");
      65           3 : }
      66             : 
      67           1 : DumpContour::DumpContour(const ActionOptions&ao):
      68             :   Action(ao),
      69             :   ActionWithArguments(ao),
      70             :   ActionPilot(ao),
      71           1 :   fmt("%f")
      72             : {
      73           1 :   if( getNumberOfArguments()!=1 ) error("should only be one argument");
      74           1 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      75           1 :   if( !fc ) error("can only use this action to print data from FIND_CONTOUR actions");
      76             : 
      77           2 :   parse("FILE",filename);
      78           1 :   if(filename.length()==0) error("name out output file was not specified");
      79             : 
      80           1 :   log.printf("  outputting contour with label %s to file named %s",getPntrToArgument(0)->getName().c_str(), filename.c_str() );
      81           2 :   parse("FMT",fmt); log.printf(" with format %s \n", fmt.c_str() ); fmt = " " + fmt;
      82           1 : }
      83             : 
      84           2 : void DumpContour::update() {
      85           2 :   OFile ofile; ofile.link(*this);
      86           2 :   ofile.setBackupString("analysis");
      87           2 :   ofile.open( filename );
      88             : 
      89           2 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      90           2 :   unsigned maxp = fc->active_cells.size(), ncomp = fc->getNumberOfComponents();
      91       32930 :   unsigned ntasks = 0; for(unsigned i=0; i<maxp; ++i) ntasks += fc->active_cells[i];
      92             : 
      93           2 :   ofile.printf("%d\n", ntasks ); ofile.printf("Points found on isocontour\n");
      94       32930 :   for(unsigned i=0; i<maxp; ++i) {
      95       32928 :     if( fc->active_cells[i]==0 ) continue ;
      96        1108 :     const char* defname="X"; const char* name=defname; ofile.printf("%s", name);
      97        4432 :     for(unsigned j=0; j<ncomp; ++j ) ofile.printf((" " + fmt).c_str(), (fc->copyOutput(j))->get(i)  );
      98        1108 :     ofile.printf("\n");
      99             :   }
     100           2 : }
     101             : 
     102             : 
     103             : }
     104             : }

Generated by: LCOV version 1.16