Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
e1056ad1
Unverified
Commit
e1056ad1
authored
Mar 22, 2019
by
peastman
Committed by
GitHub
Mar 22, 2019
Browse files
Merge pull request #2290 from peastman/atan2
Support atan2() in custom expressions
parents
6e3c2142
b24c1d1a
Changes
23
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
platforms/opencl/src/OpenCLExpressionUtilities.cpp
platforms/opencl/src/OpenCLExpressionUtilities.cpp
+4
-1
tests/TestCustomExternalForce.h
tests/TestCustomExternalForce.h
+17
-1
tests/TestParser.cpp
tests/TestParser.cpp
+2
-0
No files found.
platforms/opencl/src/OpenCLExpressionUtilities.cpp
View file @
e1056ad1
...
...
@@ -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) 2009-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -464,6 +464,9 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
case
Operation
::
ATAN
:
out
<<
"atan("
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
")"
;
break
;
case
Operation
::
ATAN2
:
out
<<
"atan2("
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
", "
<<
getTempName
(
node
.
getChildren
()[
1
],
temps
)
<<
")"
;
break
;
case
Operation
::
SINH
:
out
<<
"sinh("
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
")"
;
break
;
...
...
tests/TestCustomExternalForce.h
View file @
e1056ad1
...
...
@@ -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) 2008-201
5
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -216,6 +216,21 @@ void testIllegalVariable() {
ASSERT
(
threwException
);
}
void
testAtan2
()
{
System
system
;
system
.
addParticle
(
1.0
);
CustomExternalForce
*
force
=
new
CustomExternalForce
(
"atan2(x, y)"
);
force
->
addParticle
(
0
);
system
.
addForce
(
force
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
);
positions
[
0
]
=
Vec3
(
1.5
,
-
2.1
,
1.2
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Energy
);
ASSERT_EQUAL_TOL
(
atan2
(
positions
[
0
][
0
],
positions
[
0
][
1
]),
state
.
getPotentialEnergy
(),
1e-5
);
}
void
runPlatformTests
();
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -226,6 +241,7 @@ int main(int argc, char* argv[]) {
testPeriodic
();
testZeroPeriodicDistance
();
testIllegalVariable
();
testAtan2
();
runPlatformTests
();
}
catch
(
const
exception
&
e
)
{
...
...
tests/TestParser.cpp
View file @
e1056ad1
...
...
@@ -265,6 +265,7 @@ int main() {
verifyEvaluation
(
"ceil(x)"
,
-
2.1
,
3.0
,
-
2.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.3
,
2.0
,
1.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.0
,
2.0
,
2.0
);
verifyEvaluation
(
"atan2(x, y)"
,
3.0
,
1.5
,
std
::
atan
(
2.0
));
verifyInvalidExpression
(
"1..2"
);
verifyInvalidExpression
(
"1*(2+3"
);
verifyInvalidExpression
(
"5++4"
);
...
...
@@ -285,6 +286,7 @@ int main() {
verifyDerivative
(
"asin(x)"
,
"1/sqrt(1-x^2)"
);
verifyDerivative
(
"acos(x)"
,
"-1/sqrt(1-x^2)"
);
verifyDerivative
(
"atan(x)"
,
"1/(1+x^2)"
);
verifyDerivative
(
"atan2(2*x,y)"
,
"2*y/(4*x^2+y^2)"
);
verifyDerivative
(
"sinh(x)"
,
"cosh(x)"
);
verifyDerivative
(
"cosh(x)"
,
"sinh(x)"
);
verifyDerivative
(
"tanh(x)"
,
"1/(cosh(x)^2)"
);
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment