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_ContourFindingObject_h 23 : #define __PLUMED_contour_ContourFindingObject_h 24 : 25 : #include "function/FunctionSetup.h" 26 : #include "tools/RootFindingBase.h" 27 : 28 : namespace PLMD { 29 : namespace contour { 30 : 31 : template <class T> 32 0 : class ContourFindingObject { 33 : public: 34 : /// This is the object that does the root finding 35 : RootFindingBase<ContourFindingObject<T>> mymin; 36 : /// This holds the input grid 37 : // gridtools::EvaluateGridFunction 38 : T function; 39 : /// Where you would like to find the contour 40 : double contour; 41 : /// Get rid of constructor in future 42 8 : explicit ContourFindingObject() : mymin(this), contour(0.0) {} 43 : /// Register keywords 44 : static void registerKeywords( Keywords& keys ); 45 : /// Get the contour value -- this will become static in future 46 : double getDifferenceFromContour( const std::vector<double>& x, std::vector<double>& der ) const ; 47 : /// Read in the contour object 48 : static void read( ContourFindingObject& func, ActionWithArguments* action, function::FunctionOptions& options ); 49 : /// Find the contour 50 : static void findContour( const ContourFindingObject& myobj, const std::vector<double>& direction, std::vector<double>& point ); 51 : }; 52 : 53 : template <class T> 54 11 : void ContourFindingObject<T>::registerKeywords( Keywords& keys ) { 55 11 : keys.add("compulsory","CONTOUR","the value we would like to draw the contour at in the space"); 56 11 : T::registerKeywords(keys); 57 11 : keys.remove("ZERO_OUTSIDE_GRID_RANGE"); 58 11 : } 59 : 60 : template <class T> 61 4 : void ContourFindingObject<T>::read( ContourFindingObject& func, ActionWithArguments* action, function::FunctionOptions& options ) { 62 4 : action->parse("CONTOUR",func.contour); 63 4 : T::read( func.function, action, options ); 64 4 : } 65 : 66 : template <class T> 67 1896 : void ContourFindingObject<T>::findContour( const ContourFindingObject& myobj, const std::vector<double>& direction, std::vector<double>& point ) { 68 1896 : myobj.mymin.linesearch( direction, point, &ContourFindingObject<T>::getDifferenceFromContour ); 69 1896 : } 70 : 71 : template <class T> 72 13485 : double ContourFindingObject<T>::getDifferenceFromContour( const std::vector<double>& x, std::vector<double>& der ) const { 73 13485 : std::vector<double> vals(1); 74 : auto funcout = function::FunctionOutput::create( 1, 75 : vals.data(), 76 : x.size(), 77 : der.data() ); 78 13485 : T::calc( function, 79 : false, 80 : View<const double>(x.data(),x.size()), 81 : funcout ); 82 13485 : return vals[0] - contour; 83 : } 84 : 85 : } 86 : } 87 : #endif