Commit b53c6593 authored by Peter Eastman's avatar Peter Eastman
Browse files

Documentation for vector functions

parent 4c28df55
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2011-2017 Stanford University and the Authors. * * Portions copyright (c) 2011-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -194,7 +194,7 @@ namespace OpenMM { ...@@ -194,7 +194,7 @@ namespace OpenMM {
* *
* <tt><pre> * <tt><pre>
* integrator.beginIfBlock("uniform < acceptanceProbability"); * integrator.beginIfBlock("uniform < acceptanceProbability");
* integrator.computePerDof("x", "xnew"); * integrator.addComputePerDof("x", "xnew");
* integrator.endBlock(); * integrator.endBlock();
* </pre></tt> * </pre></tt>
* *
...@@ -203,6 +203,21 @@ namespace OpenMM { ...@@ -203,6 +203,21 @@ namespace OpenMM {
* following comparison operators: =, <. >, !=, <=, >=. Blocks may be nested * following comparison operators: =, <. >, !=, <=, >=. Blocks may be nested
* inside each other. * inside each other.
* *
* "Per-DOF" computations can also be thought of as per-particle computations
* that operate on three component vectors. For example, "x+dt*v" means to take
* the particle's velocity (a vector), multiply it by the step size, and add the
* position (also a vector). The result is a new vector that can be stored into
* a per-DOF variable with addComputePerDof(), or it can be summed over all
* components of all particles with addComputeSum(). Because the calculation is
* done on vectors, you can use functions that operate explicitly on vectors
* rather than just computing each component independently. For example, the
* following line uses a cross product to compute the angular momentum of each
* particle and stores it into a per-DOF variable.
*
* <tt><pre>
* integrator.addComputePerDof("angularMomentum", "m*cross(x, v)");
* </pre></tt>
*
* Another feature of CustomIntegrator is that it can use derivatives of the * Another feature of CustomIntegrator is that it can use derivatives of the
* potential energy with respect to context parameters. These derivatives are * potential energy with respect to context parameters. These derivatives are
* typically computed by custom forces, and are only computed if a Force object * typically computed by custom forces, and are only computed if a Force object
...@@ -243,6 +258,18 @@ namespace OpenMM { ...@@ -243,6 +258,18 @@ namespace OpenMM {
* are defined in radians, and log is the natural logarithm. step(x) = 0 if x is less than 0, 1 otherwise. delta(x) = 1 if x is 0, 0 otherwise. * are defined in radians, and log is the natural logarithm. step(x) = 0 if x is less than 0, 1 otherwise. delta(x) = 1 if x is 0, 0 otherwise.
* select(x,y,z) = z if x = 0, y otherwise. An expression may also involve intermediate quantities that are defined following the main expression, using ";" as a separator. * select(x,y,z) = z if x = 0, y otherwise. An expression may also involve intermediate quantities that are defined following the main expression, using ";" as a separator.
* *
* Expressions used in ComputePerDof and ComputeSum steps can also use the following
* functions that operate on vectors: cross(a, b) is the cross product of two
* vectors; dot(a, b) is the dot product of two vectors; _x(a), _y(a), and _z(a)
* extract a single component from a vector; and vector(a, b, c) creates a new
* vector with the x component of the first argument, the y component of the
* second argument, and the z component of the third argument. Remember that every
* quantity appearing in a vector expression is a vector. Functions that appear
* to return a scalar really return a vector whose components are all the same.
* For example, _z(a) returns the vector (a.z, a.z, a.z). Likewise, wherever a
* constant appears in the expression, it really means a vector whose components
* all have the same value.
*
* In addition, you can call addTabulatedFunction() to define a new function based on tabulated values. You specify the function by * In addition, you can call addTabulatedFunction() to define a new function based on tabulated values. You specify the function by
* creating a TabulatedFunction object. That function can then appear in expressions. * creating a TabulatedFunction object. That function can then appear in expressions.
*/ */
......
...@@ -86,7 +86,10 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express ...@@ -86,7 +86,10 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
throw OpenMMException("Unknown variable in expression: "+node.getOperation().getName()); throw OpenMMException("Unknown variable in expression: "+node.getOperation().getName());
case Operation::CUSTOM: case Operation::CUSTOM:
{ {
if (isVecType)
out << "make_" << tempType << "(0);\n"; out << "make_" << tempType << "(0);\n";
else
out << "0;\n";
temps.push_back(make_pair(node, name)); temps.push_back(make_pair(node, name));
hasRecordedNode = true; hasRecordedNode = true;
......
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