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
4b5b08af
Commit
4b5b08af
authored
Sep 11, 2014
by
peastman
Browse files
Switched to a slightly faster (and more accurate) approximation for erfc()
parent
d7620eff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
13 deletions
+7
-13
platforms/cuda/src/kernels/coulombLennardJones.cu
platforms/cuda/src/kernels/coulombLennardJones.cu
+4
-7
platforms/opencl/src/kernels/coulombLennardJones.cl
platforms/opencl/src/kernels/coulombLennardJones.cl
+3
-6
No files found.
platforms/cuda/src/kernels/coulombLennardJones.cu
View file @
4b5b08af
...
...
@@ -10,19 +10,16 @@ if ((!isExcluded && r2 < CUTOFF_SQUARED) || needCorrection) {
#else
// This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as
// the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum
// error of
3
e-7.
// error of
1.5
e-7.
real
t
=
1.0
f
+
(
0.0705230784
f
+
(
0.0422820123
f
+
(
0.0092705272
f
+
(
0.0001520143
f
+
(
0.0002765672
f
+
0.0000430638
f
*
alphaR
)
*
alphaR
)
*
alphaR
)
*
alphaR
)
*
alphaR
)
*
alphaR
;
t
*=
t
;
t
*=
t
;
t
*=
t
;
const
real
erfcAlphaR
=
RECIP
(
t
*
t
);
const
real
t
=
RECIP
(
1.0
f
+
0.3275911
f
*
alphaR
);
const
real
erfcAlphaR
=
(
0.254829592
f
+
(
-
0.284496736
f
+
(
1.421413741
f
+
(
-
1.453152027
f
+
1.061405429
f
*
t
)
*
t
)
*
t
)
*
t
)
*
t
*
expAlphaRSqr
;
#endif
real
tempForce
=
0.0
f
;
if
(
needCorrection
)
{
// Subtract off the part of this interaction that was included in the reciprocal space contribution.
if
(
1
-
erfcAlphaR
>
1e-6
)
{
if
(
1
.0
f
-
erfcAlphaR
>
1e-6
f
)
{
real
erfAlphaR
=
ERF
(
alphaR
);
// Our erfc approximation is not accurate enough when r is very small, which happens with Drude particles.
tempForce
=
-
prefactor
*
(
erfAlphaR
-
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempEnergy
+=
-
prefactor
*
erfAlphaR
;
...
...
platforms/opencl/src/kernels/coulombLennardJones.cl
View file @
4b5b08af
...
...
@@ -10,13 +10,10 @@ if ((!isExcluded && r2 < CUTOFF_SQUARED) || needCorrection) {
#
else
//
This
approximation
for
erfc
is
from
Abramowitz
and
Stegun
(
1964
)
p.
299.
They
cite
the
following
as
//
the
original
source:
C.
Hastings,
Jr.,
Approximations
for
Digital
Computers
(
1955
)
.
It
has
a
maximum
//
error
of
3
e-7.
//
error
of
1.5
e-7.
real
t
=
1.0f+
(
0.0705230784f+
(
0.0422820123f+
(
0.0092705272f+
(
0.0001520143f+
(
0.0002765672f+0.0000430638f*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
;
t
*=
t
;
t
*=
t
;
t
*=
t
;
const
real
erfcAlphaR
=
RECIP
(
t*t
)
;
const
real
t
=
RECIP
(
1.0f+0.3275911f*alphaR
)
;
const
real
erfcAlphaR
=
(
0.254829592f+
(
-0.284496736f+
(
1.421413741f+
(
-1.453152027f+1.061405429f*t
)
*t
)
*t
)
*t
)
*t*
expAlphaRSqr
;
#
endif
real
tempForce
=
0
;
if
(
needCorrection
)
{
...
...
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