LCOV - code coverage report
Current view: top level - contour - ContourFindingBase.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 6 6 100.0 %
Date: 2024-10-18 14:00:25 Functions: 1 1 100.0 %

          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             : #ifndef __PLUMED_contour_ContourFindingBase_h
      23             : #define __PLUMED_contour_ContourFindingBase_h
      24             : 
      25             : #include "tools/RootFindingBase.h"
      26             : #include "gridtools/ActionWithGrid.h"
      27             : #include "gridtools/EvaluateGridFunction.h"
      28             : 
      29             : namespace PLMD {
      30             : namespace contour {
      31             : 
      32             : class ContourFindingBase : public gridtools::ActionWithGrid {
      33             : private:
      34             : /// This is the object that does the root finding
      35             :   RootFindingBase<ContourFindingBase> mymin;
      36             : /// This holds the input grid
      37             :   gridtools::EvaluateGridFunction function;
      38             : protected:
      39             : /// Where you would like to find the contour
      40             :   double contour;
      41             : /// Find a contour along line specified by direction
      42             :   void findContour( const std::vector<double>& direction, std::vector<double>& point ) const ;
      43             : /// Get the input grid object for the grid that we are finding the contour in
      44             :   const gridtools::GridCoordinatesObject& getInputGridObject() const ;
      45             : public:
      46             :   static void registerKeywords( Keywords& keys );
      47             :   explicit ContourFindingBase(const ActionOptions&ao);
      48             :   void setupOnFirstStep( const bool incalc ) override;
      49             :   virtual void setupValuesOnFirstStep() = 0;
      50             : /// Get the contour value
      51             :   double getDifferenceFromContour( const std::vector<double>& x, std::vector<double>& der ) const ;
      52             : };
      53             : 
      54             : inline
      55             : void ContourFindingBase::findContour( const std::vector<double>& direction, std::vector<double>& point ) const {
      56        1896 :   mymin.linesearch( direction, point, &ContourFindingBase::getDifferenceFromContour );
      57        1896 : }
      58             : 
      59             : inline
      60       13479 : double ContourFindingBase::getDifferenceFromContour( const std::vector<double>& x, std::vector<double>& der ) const {
      61       13479 :   std::vector<double> vals(1); Matrix<double> deriva( 1, x.size() ); function.calc( this, x, vals, deriva );
      62       53916 :   for(unsigned i=0; i<der.size(); ++i) der[i] = deriva(0,i);
      63       26958 :   return vals[0] - contour;
      64             : }
      65             : 
      66             : inline
      67             : const gridtools::GridCoordinatesObject& ContourFindingBase::getInputGridObject() const {
      68             :   return function.getGridObject();
      69             : }
      70             : 
      71             : }
      72             : }
      73             : #endif

Generated by: LCOV version 1.16