"platforms/cpu/src/CpuConstantPotentialForceAvx2.cpp" did not exist on "b1a2221493b2563ec2d3351adc1e39c7b67a0cb6"
Unverified Commit 75c1fcb6 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2476 from peastman/functions

Optimized processing of expressions with tabulated functions
parents 97b972e9 5eb439d8
......@@ -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) 2014-2016 Stanford University and the Authors. *
* Portions copyright (c) 2014-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -35,6 +35,7 @@
#include "openmm/TabulatedFunction.h"
#include "openmm/internal/windowsExport.h"
#include "lepton/CustomFunction.h"
#include <memory>
#include <vector>
namespace OpenMM {
......@@ -146,6 +147,22 @@ private:
std::vector<double> values;
};
/**
* This is a lightweight wrapper around an immutable CustomFunction. It makes
* cloning very inexpensive since nothing needs to be copied except a single
* pointer.
*/
class OPENMM_EXPORT SharedFunctionWrapper : public Lepton::CustomFunction {
public:
SharedFunctionWrapper(std::shared_ptr<const CustomFunction> pointer);
int getNumArguments() const;
double evaluate(const double* arguments) const;
double evaluateDerivative(const double* arguments, const int* derivOrder) const;
CustomFunction* clone() const;
private:
std::shared_ptr<const CustomFunction> pointer;
};
} // namespace OpenMM
#endif /*OPENMM_REFERENCETABULATEDFUNCTION_H_*/
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014-2016 Stanford University and the Authors. *
* Portions copyright (c) 2014-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -56,19 +56,22 @@ using namespace std;
using Lepton::CustomFunction;
extern "C" OPENMM_EXPORT CustomFunction* createReferenceTabulatedFunction(const TabulatedFunction& function) {
CustomFunction* fn;
if (dynamic_cast<const Continuous1DFunction*>(&function) != NULL)
return new ReferenceContinuous1DFunction(dynamic_cast<const Continuous1DFunction&>(function));
if (dynamic_cast<const Continuous2DFunction*>(&function) != NULL)
return new ReferenceContinuous2DFunction(dynamic_cast<const Continuous2DFunction&>(function));
if (dynamic_cast<const Continuous3DFunction*>(&function) != NULL)
return new ReferenceContinuous3DFunction(dynamic_cast<const Continuous3DFunction&>(function));
if (dynamic_cast<const Discrete1DFunction*>(&function) != NULL)
return new ReferenceDiscrete1DFunction(dynamic_cast<const Discrete1DFunction&>(function));
if (dynamic_cast<const Discrete2DFunction*>(&function) != NULL)
return new ReferenceDiscrete2DFunction(dynamic_cast<const Discrete2DFunction&>(function));
if (dynamic_cast<const Discrete3DFunction*>(&function) != NULL)
return new ReferenceDiscrete3DFunction(dynamic_cast<const Discrete3DFunction&>(function));
throw OpenMMException("createReferenceTabulatedFunction: Unknown function type");
fn = new ReferenceContinuous1DFunction(dynamic_cast<const Continuous1DFunction&>(function));
else if (dynamic_cast<const Continuous2DFunction*>(&function) != NULL)
fn = new ReferenceContinuous2DFunction(dynamic_cast<const Continuous2DFunction&>(function));
else if (dynamic_cast<const Continuous3DFunction*>(&function) != NULL)
fn = new ReferenceContinuous3DFunction(dynamic_cast<const Continuous3DFunction&>(function));
else if (dynamic_cast<const Discrete1DFunction*>(&function) != NULL)
fn = new ReferenceDiscrete1DFunction(dynamic_cast<const Discrete1DFunction&>(function));
else if (dynamic_cast<const Discrete2DFunction*>(&function) != NULL)
fn = new ReferenceDiscrete2DFunction(dynamic_cast<const Discrete2DFunction&>(function));
else if (dynamic_cast<const Discrete3DFunction*>(&function) != NULL)
fn = new ReferenceDiscrete3DFunction(dynamic_cast<const Discrete3DFunction&>(function));
else
throw OpenMMException("createReferenceTabulatedFunction: Unknown function type");
return new SharedFunctionWrapper(shared_ptr<const CustomFunction>(fn));
}
ReferenceContinuous1DFunction::ReferenceContinuous1DFunction(const Continuous1DFunction& function) : function(function) {
......@@ -298,3 +301,22 @@ double ReferenceDiscrete3DFunction::evaluateDerivative(const double* arguments,
CustomFunction* ReferenceDiscrete3DFunction::clone() const {
return new ReferenceDiscrete3DFunction(function);
}
SharedFunctionWrapper::SharedFunctionWrapper(shared_ptr<const CustomFunction> pointer) : pointer(pointer) {
}
int SharedFunctionWrapper::getNumArguments() const {
return pointer->getNumArguments();
}
double SharedFunctionWrapper::evaluate(const double* arguments) const {
return pointer->evaluate(arguments);
}
double SharedFunctionWrapper::evaluateDerivative(const double* arguments, const int* derivOrder) const {
return pointer->evaluateDerivative(arguments, derivOrder);
}
CustomFunction* SharedFunctionWrapper::clone() const {
return new SharedFunctionWrapper(pointer);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment