LCOV - code coverage report
Current view: top level - contour - DumpContour.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 43 46 93.5 %
Date: 2025-04-08 21:11:17 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           3 :   keys.add("compulsory","STRIDE","1","the frequency with which the grid should be output to the file.");
      63           3 :   keys.add("compulsory","FILE","density","the file on which to write the grid.");
      64           3 :   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           1 :   if( getNumberOfArguments()!=1 ) {
      73           0 :     error("should only be one argument");
      74             :   }
      75           1 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      76           1 :   if( !fc ) {
      77           0 :     error("can only use this action to print data from FIND_CONTOUR actions");
      78             :   }
      79             : 
      80           2 :   parse("FILE",filename);
      81           1 :   if(filename.length()==0) {
      82           0 :     error("name out output file was not specified");
      83             :   }
      84             : 
      85           1 :   log.printf("  outputting contour with label %s to file named %s",getPntrToArgument(0)->getName().c_str(), filename.c_str() );
      86           1 :   parse("FMT",fmt);
      87           1 :   log.printf(" with format %s \n", fmt.c_str() );
      88           1 :   fmt = " " + fmt;
      89           1 : }
      90             : 
      91           2 : void DumpContour::update() {
      92           2 :   OFile ofile;
      93           2 :   ofile.link(*this);
      94           2 :   ofile.setBackupString("analysis");
      95           2 :   ofile.open( filename );
      96             : 
      97           2 :   FindContour* fc=dynamic_cast<FindContour*>( getPntrToArgument(0)->getPntrToAction() );
      98           2 :   unsigned maxp = fc->active_cells.size(), ncomp = fc->getNumberOfComponents();
      99             :   unsigned ntasks = 0;
     100       32930 :   for(unsigned i=0; i<maxp; ++i) {
     101       32928 :     ntasks += fc->active_cells[i];
     102             :   }
     103             : 
     104           2 :   ofile.printf("%d\n", ntasks );
     105           2 :   ofile.printf("Points found on isocontour\n");
     106       32930 :   for(unsigned i=0; i<maxp; ++i) {
     107       32928 :     if( fc->active_cells[i]==0 ) {
     108       31820 :       continue ;
     109             :     }
     110             :     const char* defname="X";
     111             :     const char* name=defname;
     112        1108 :     ofile.printf("%s", name);
     113        4432 :     for(unsigned j=0; j<ncomp; ++j ) {
     114        6648 :       ofile.printf((" " + fmt).c_str(), (fc->copyOutput(j))->get(i)  );
     115             :     }
     116        1108 :     ofile.printf("\n");
     117             :   }
     118           2 : }
     119             : 
     120             : 
     121             : }
     122             : }

Generated by: LCOV version 1.16