Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : * -------------------------------------------------------------------------- * 3 : * Lepton * 4 : * -------------------------------------------------------------------------- * 5 : * This is part of the Lepton expression parser originating from * 6 : * Simbios, the NIH National Center for Physics-Based Simulation of * 7 : * Biological Structures at Stanford, funded under the NIH Roadmap for * 8 : * Medical Research, grant U54 GM072970. See https://simtk.org. * 9 : * * 10 : * Portions copyright (c) 2013-2016 Stanford University and the Authors. * 11 : * Authors: Peter Eastman * 12 : * Contributors: * 13 : * * 14 : * Permission is hereby granted, free of charge, to any person obtaining a * 15 : * copy of this software and associated documentation files (the "Software"), * 16 : * to deal in the Software without restriction, including without limitation * 17 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 18 : * and/or sell copies of the Software, and to permit persons to whom the * 19 : * Software is furnished to do so, subject to the following conditions: * 20 : * * 21 : * The above copyright notice and this permission notice shall be included in * 22 : * all copies or substantial portions of the Software. * 23 : * * 24 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 25 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 26 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 27 : * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 28 : * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 29 : * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 30 : * USE OR OTHER DEALINGS IN THE SOFTWARE. * 31 : * -------------------------------------------------------------------------- * 32 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 33 : #ifndef __PLUMED_lepton_CustomFunction_h 34 : #define __PLUMED_lepton_CustomFunction_h 35 : 36 : /* -------------------------------------------------------------------------- * 37 : * lepton * 38 : * -------------------------------------------------------------------------- * 39 : * This is part of the lepton expression parser originating from * 40 : * Simbios, the NIH National Center for Physics-Based Simulation of * 41 : * Biological Structures at Stanford, funded under the NIH Roadmap for * 42 : * Medical Research, grant U54 GM072970. See https://simtk.org. * 43 : * * 44 : * Portions copyright (c) 2009 Stanford University and the Authors. * 45 : * Authors: Peter Eastman * 46 : * Contributors: * 47 : * * 48 : * Permission is hereby granted, free of charge, to any person obtaining a * 49 : * copy of this software and associated documentation files (the "Software"), * 50 : * to deal in the Software without restriction, including without limitation * 51 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 52 : * and/or sell copies of the Software, and to permit persons to whom the * 53 : * Software is furnished to do so, subject to the following conditions: * 54 : * * 55 : * The above copyright notice and this permission notice shall be included in * 56 : * all copies or substantial portions of the Software. * 57 : * * 58 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 59 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 60 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 61 : * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 62 : * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 63 : * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 64 : * USE OR OTHER DEALINGS IN THE SOFTWARE. * 65 : * -------------------------------------------------------------------------- */ 66 : 67 : #include "windowsIncludes.h" 68 : 69 : namespace PLMD { 70 : namespace lepton { 71 : 72 : /** 73 : * This class is the interface for defining your own function that may be included in expressions. 74 : * To use it, create a concrete subclass that implements all of the virtual methods for each new function 75 : * you want to define. Then when you call Parser::parse() to parse an expression, pass a map of 76 : * function names to CustomFunction objects. 77 : */ 78 : 79 : class LEPTON_EXPORT CustomFunction { 80 : public: 81 0 : virtual ~CustomFunction() { 82 0 : } 83 : /** 84 : * Get the number of arguments this function expects. 85 : */ 86 : virtual int getNumArguments() const = 0; 87 : /** 88 : * Evaluate the function. 89 : * 90 : * @param arguments the array of argument values 91 : */ 92 : virtual double evaluate(const double* arguments) const = 0; 93 : /** 94 : * Evaluate a derivative of the function. 95 : * 96 : * @param arguments the array of argument values 97 : * @param derivOrder an array specifying the number of times the function has been differentiated 98 : * with respect to each of its arguments. For example, the array {0, 2} indicates 99 : * a second derivative with respect to the second argument. 100 : */ 101 : virtual double evaluateDerivative(const double* arguments, const int* derivOrder) const = 0; 102 : /** 103 : * Create a new duplicate of this object on the heap using the "new" operator. 104 : */ 105 : virtual CustomFunction* clone() const = 0; 106 : }; 107 : 108 : } // namespace lepton 109 : } // namespace PLMD 110 : 111 : #endif /*LEPTON_CUSTOM_FUNCTION_H_*/