LCOV - code coverage report
Current view: top level - contour - DumpContour.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 35 35 100.0 %
Date: 2024-10-18 14:00:25 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 ); keys.use("ARG");
      61           6 :   keys.add("compulsory","STRIDE","1","the frequency with which the grid should be output to the file.");
      62           6 :   keys.add("compulsory","FILE","density","the file on which to write the grid.");
      63           6 :   keys.add("optional","FMT","the format that should be used to output real numbers");
      64           3 : }
      65             : 
      66           1 : DumpContour::DumpContour(const ActionOptions&ao):
      67             :   Action(ao),
      68             :   ActionWithArguments(ao),
      69             :   ActionPilot(ao),
      70           1 :   fmt("%f")
      71             : {
      72           1 :   if( getNumberOfArguments()!=1 ) error("should only be one argument");
      73           1 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      74           1 :   if( !fc ) error("can only use this action to print data from FIND_CONTOUR actions");
      75             : 
      76           2 :   parse("FILE",filename);
      77           1 :   if(filename.length()==0) error("name out output file was not specified");
      78             : 
      79           1 :   log.printf("  outputting contour with label %s to file named %s",getPntrToArgument(0)->getName().c_str(), filename.c_str() );
      80           2 :   parse("FMT",fmt); log.printf(" with format %s \n", fmt.c_str() ); fmt = " " + fmt;
      81           1 : }
      82             : 
      83           2 : void DumpContour::update() {
      84           2 :   OFile ofile; ofile.link(*this);
      85           2 :   ofile.setBackupString("analysis");
      86           2 :   ofile.open( filename );
      87             : 
      88           2 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      89           2 :   unsigned maxp = fc->active_cells.size(), ncomp = fc->getNumberOfComponents();
      90       32930 :   unsigned ntasks = 0; for(unsigned i=0; i<maxp; ++i) ntasks += fc->active_cells[i];
      91             : 
      92           2 :   ofile.printf("%d\n", ntasks ); ofile.printf("Points found on isocontour\n");
      93       32930 :   for(unsigned i=0; i<maxp; ++i) {
      94       32928 :     if( fc->active_cells[i]==0 ) continue ;
      95        1108 :     const char* defname="X"; const char* name=defname; ofile.printf("%s", name);
      96        4432 :     for(unsigned j=0; j<ncomp; ++j ) ofile.printf((" " + fmt).c_str(), (fc->copyOutput(j))->get(i)  );
      97        1108 :     ofile.printf("\n");
      98             :   }
      99           2 : }
     100             : 
     101             : 
     102             : }
     103             : }

Generated by: LCOV version 1.16