Commit e04a18fc authored by Giacomo Fiorin's avatar Giacomo Fiorin
Browse files

Upgrade Lepton library to version 2019-06-02

parent 8f431b0f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ settings in Makefile.common should work.
Note: some Colvars functions use the Lepton mathematical expression parser,
which is here included (no additional steps required).  For more details, see:
  https://simtk.org/projects/lepton
Starting from 2019-06-02, Lepton requires C++11.  Please see:
  https://colvars.github.io/README-c++11.html
  https://lammps.sandia.gov/doc/Build_settings.html#cxx11


## Documentation
+6 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2013-2016 Stanford University and the Authors.      *
 * Portions copyright (c) 2013-2019 Stanford University and the Authors.      *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
@@ -99,10 +99,11 @@ private:
    mutable std::vector<double> workspace;
    mutable std::vector<double> argValues;
    std::map<std::string, double> dummyVariables;
    void* jitCode;
    double (*jitCode)();
#ifdef LEPTON_USE_JIT
    void generateJitCode();
    void generateSingleArgCall(asmjit::X86Compiler& c, asmjit::X86XmmVar& dest, asmjit::X86XmmVar& arg, double (*function)(double));
    void generateSingleArgCall(asmjit::X86Compiler& c, asmjit::X86Xmm& dest, asmjit::X86Xmm& arg, double (*function)(double));
    void generateTwoArgCall(asmjit::X86Compiler& c, asmjit::X86Xmm& dest, asmjit::X86Xmm& arg1, asmjit::X86Xmm& arg2, double (*function)(double, double));
    std::vector<double> constants;
    asmjit::JitRuntime runtime;
#endif
+32 −0
Original line number Diff line number Diff line
@@ -72,6 +72,38 @@ public:
    virtual CustomFunction* clone() const = 0;
};

/**
 * This class is an implementation of CustomFunction that does no computation.  It just returns
 * 0 for the value and derivatives.  This is useful when using the parser to analyze expressions
 * rather than to evaluate them.  You can just create PlaceholderFunctions to represent any custom
 * functions that may appear in expressions.
 */

class LEPTON_EXPORT PlaceholderFunction : public CustomFunction {
public:
    /**
     * Create a Placeholder function.
     *
     * @param numArgs    the number of arguments the function expects
     */
    PlaceholderFunction(int numArgs) : numArgs(numArgs) {
    }
    int getNumArguments() const {
        return numArgs;
    }
    double evaluate(const double* arguments) const {
        return 0.0;
    }
    double evaluateDerivative(const double* arguments, const int* derivOrder) const {
        return 0.0;
    }
    CustomFunction* clone() const {
        return new PlaceholderFunction(numArgs);
    };
private:
    int numArgs;
};

} // namespace Lepton

#endif /*LEPTON_CUSTOM_FUNCTION_H_*/
+9 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Portions copyright (c) 2009-2018 Stanford University and the Authors.      *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
@@ -65,6 +65,14 @@ public:
     * Get an Operation in this program.
     */
    const Operation& getOperation(int index) const;
    /**
     * Change an Operation in this program.
     *
     * The Operation must have been allocated on the heap with the "new" operator.
     * The ExpressionProgram assumes ownership of it and will delete it when it
     * is no longer needed.
     */
    void setOperation(int index, Operation* operation);
    /**
     * Get the size of the stack needed to execute this program.  This is the largest number of elements present
     * on the stack at any point during evaluation.
+31 −3
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2009-2015 Stanford University and the Authors.      *
 * Portions copyright (c) 2009-2019 Stanford University and the Authors.      *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
@@ -63,7 +63,7 @@ public:
     * can be used when processing or analyzing parsed expressions.
     */
    enum Id {CONSTANT, VARIABLE, CUSTOM, ADD, SUBTRACT, MULTIPLY, DIVIDE, POWER, NEGATE, SQRT, EXP, LOG,
             SIN, COS, SEC, CSC, TAN, COT, ASIN, ACOS, ATAN, SINH, COSH, TANH, ERF, ERFC, STEP, DELTA, SQUARE, CUBE, RECIPROCAL,
             SIN, COS, SEC, CSC, TAN, COT, ASIN, ACOS, ATAN, ATAN2, SINH, COSH, TANH, ERF, ERFC, STEP, DELTA, SQUARE, CUBE, RECIPROCAL,
             ADD_CONSTANT, MULTIPLY_CONSTANT, POWER_CONSTANT, MIN, MAX, ABS, FLOOR, CEIL, SELECT};
    /**
     * Get the name of this Operation.
@@ -137,6 +137,7 @@ public:
    class Asin;
    class Acos;
    class Atan;
    class Atan2;
    class Sinh;
    class Cosh;
    class Tanh;
@@ -226,6 +227,11 @@ class LEPTON_EXPORT Operation::Custom : public Operation {
public:
    Custom(const std::string& name, CustomFunction* function) : name(name), function(function), isDerivative(false), derivOrder(function->getNumArguments(), 0) {
    }
    Custom(const std::string& name, CustomFunction* function, const std::vector<int>& derivOrder) : name(name), function(function), isDerivative(false), derivOrder(derivOrder) {
        for (int order : derivOrder)
            if (order != 0)
                isDerivative = true;
    }
    Custom(const Custom& base, int derivIndex) : name(base.name), function(base.function->clone()), isDerivative(true), derivOrder(base.derivOrder) {
        derivOrder[derivIndex]++;
    }
@@ -684,6 +690,28 @@ public:
    ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
};

class LEPTON_EXPORT Operation::Atan2 : public Operation {
public:
    Atan2() {
    }
    std::string getName() const {
        return "atan2";
    }
    Id getId() const {
        return ATAN2;
    }
    int getNumArguments() const {
        return 2;
    }
    Operation* clone() const {
        return new Atan2();
    }
    double evaluate(double* args, const std::map<std::string, double>& variables) const {
        return std::atan2(args[0], args[1]);
    }
    ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
};

class LEPTON_EXPORT Operation::Sinh : public Operation {
public:
    Sinh() {
Loading