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
039bb3fb
Commit
039bb3fb
authored
May 08, 2013
by
Peter Eastman
Browse files
Very minor code simplification
parent
70ff98db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
86 deletions
+82
-86
platforms/cuda/src/kernels/coulombLennardJones.cu
platforms/cuda/src/kernels/coulombLennardJones.cu
+41
-43
platforms/opencl/src/kernels/coulombLennardJones.cl
platforms/opencl/src/kernels/coulombLennardJones.cl
+41
-43
No files found.
platforms/cuda/src/kernels/coulombLennardJones.cu
View file @
039bb3fb
#if USE_EWALD
#if USE_EWALD
bool
needCorrection
=
hasExclusions
&&
isExcluded
&&
atom1
!=
atom2
&&
atom1
<
NUM_ATOMS
&&
atom2
<
NUM_ATOMS
;
bool
needCorrection
=
hasExclusions
&&
isExcluded
&&
atom1
!=
atom2
&&
atom1
<
NUM_ATOMS
&&
atom2
<
NUM_ATOMS
;
if
(
!
isExcluded
||
needCorrection
)
{
if
((
!
isExcluded
&&
r2
<
CUTOFF_SQUARED
)
||
needCorrection
)
{
if
(
r2
<
CUTOFF_SQUARED
||
needCorrection
)
{
const
real
alphaR
=
EWALD_ALPHA
*
r
;
const
real
alphaR
=
EWALD_ALPHA
*
r
;
const
real
expAlphaRSqr
=
EXP
(
-
alphaR
*
alphaR
);
const
real
expAlphaRSqr
=
EXP
(
-
alphaR
*
alphaR
);
const
real
prefactor
=
138.935456
f
*
posq1
.
w
*
posq2
.
w
*
invR
;
const
real
prefactor
=
138.935456
f
*
posq1
.
w
*
posq2
.
w
*
invR
;
#ifdef USE_DOUBLE_PRECISION
#ifdef USE_DOUBLE_PRECISION
const
real
erfcAlphaR
=
erfc
(
alphaR
);
const
real
erfcAlphaR
=
erfc
(
alphaR
);
#else
#else
// This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as
// 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
// the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum
// error of 3e-7.
// error of 3e-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
;
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
;
t
*=
t
;
t
*=
t
;
t
*=
t
;
const
real
erfcAlphaR
=
RECIP
(
t
*
t
);
const
real
erfcAlphaR
=
RECIP
(
t
*
t
);
#endif
#endif
real
tempForce
=
0.0
f
;
real
tempForce
=
0.0
f
;
if
(
needCorrection
)
{
if
(
needCorrection
)
{
// Subtract off the part of this interaction that was included in the reciprocal space contribution.
// Subtract off the part of this interaction that was included in the reciprocal space contribution.
tempForce
=
-
prefactor
*
((
1.0
f
-
erfcAlphaR
)
-
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempForce
=
-
prefactor
*
((
1.0
f
-
erfcAlphaR
)
-
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempEnergy
+=
-
prefactor
*
(
1.0
f
-
erfcAlphaR
);
tempEnergy
+=
-
prefactor
*
(
1.0
f
-
erfcAlphaR
);
}
}
else
{
else
{
#if HAS_LENNARD_JONES
#if HAS_LENNARD_JONES
real
sig
=
sigmaEpsilon1
.
x
+
sigmaEpsilon2
.
x
;
real
sig
=
sigmaEpsilon1
.
x
+
sigmaEpsilon2
.
x
;
real
sig2
=
invR
*
sig
;
real
sig2
=
invR
*
sig
;
sig2
*=
sig2
;
sig2
*=
sig2
;
real
sig6
=
sig2
*
sig2
*
sig2
;
real
sig6
=
sig2
*
sig2
*
sig2
;
real
epssig6
=
sig6
*
(
sigmaEpsilon1
.
y
*
sigmaEpsilon2
.
y
);
real
epssig6
=
sig6
*
(
sigmaEpsilon1
.
y
*
sigmaEpsilon2
.
y
);
tempForce
=
epssig6
*
(
12.0
f
*
sig6
-
6.0
f
);
tempForce
=
epssig6
*
(
12.0
f
*
sig6
-
6.0
f
);
real
ljEnergy
=
epssig6
*
(
sig6
-
1.0
f
);
real
ljEnergy
=
epssig6
*
(
sig6
-
1.0
f
);
#if USE_LJ_SWITCH
#if USE_LJ_SWITCH
if
(
r
>
LJ_SWITCH_CUTOFF
)
{
if
(
r
>
LJ_SWITCH_CUTOFF
)
{
real
x
=
r
-
LJ_SWITCH_CUTOFF
;
real
x
=
r
-
LJ_SWITCH_CUTOFF
;
real
switchValue
=
1
+
x
*
x
*
x
*
(
LJ_SWITCH_C3
+
x
*
(
LJ_SWITCH_C4
+
x
*
LJ_SWITCH_C5
));
real
switchValue
=
1
+
x
*
x
*
x
*
(
LJ_SWITCH_C3
+
x
*
(
LJ_SWITCH_C4
+
x
*
LJ_SWITCH_C5
));
real
switchDeriv
=
x
*
x
*
(
3
*
LJ_SWITCH_C3
+
x
*
(
4
*
LJ_SWITCH_C4
+
x
*
5
*
LJ_SWITCH_C5
));
real
switchDeriv
=
x
*
x
*
(
3
*
LJ_SWITCH_C3
+
x
*
(
4
*
LJ_SWITCH_C4
+
x
*
5
*
LJ_SWITCH_C5
));
tempForce
=
tempForce
*
switchValue
-
ljEnergy
*
switchDeriv
*
r
;
tempForce
=
tempForce
*
switchValue
-
ljEnergy
*
switchDeriv
*
r
;
ljEnergy
*=
switchValue
;
ljEnergy
*=
switchValue
;
}
}
#endif
#endif
tempForce
+=
prefactor
*
(
erfcAlphaR
+
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempForce
+=
prefactor
*
(
erfcAlphaR
+
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempEnergy
+=
ljEnergy
+
prefactor
*
erfcAlphaR
;
tempEnergy
+=
ljEnergy
+
prefactor
*
erfcAlphaR
;
#else
#else
tempForce
=
prefactor
*
(
erfcAlphaR
+
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempForce
=
prefactor
*
(
erfcAlphaR
+
alphaR
*
expAlphaRSqr
*
TWO_OVER_SQRT_PI
);
tempEnergy
+=
prefactor
*
erfcAlphaR
;
tempEnergy
+=
prefactor
*
erfcAlphaR
;
#endif
#endif
}
dEdR
+=
tempForce
*
invR
*
invR
;
}
}
dEdR
+=
tempForce
*
invR
*
invR
;
}
}
#else
#else
{
{
...
...
platforms/opencl/src/kernels/coulombLennardJones.cl
View file @
039bb3fb
#
if
USE_EWALD
#
if
USE_EWALD
bool
needCorrection
=
hasExclusions
&&
isExcluded
&&
atom1
!=
atom2
&&
atom1
<
NUM_ATOMS
&&
atom2
<
NUM_ATOMS
;
bool
needCorrection
=
hasExclusions
&&
isExcluded
&&
atom1
!=
atom2
&&
atom1
<
NUM_ATOMS
&&
atom2
<
NUM_ATOMS
;
if
(
!isExcluded
|
| needCorrection) {
if
((
!isExcluded
&&
r2
<
CUTOFF_SQUARED
)
||
needCorrection
)
{
if (r2 < CUTOFF_SQUARED |
|
needCorrection
)
{
const
real
alphaR
=
EWALD_ALPHA*r
;
const
real
alphaR
=
EWALD_ALPHA*r
;
const
real
expAlphaRSqr
=
EXP
(
-alphaR*alphaR
)
;
const
real
expAlphaRSqr
=
EXP
(
-alphaR*alphaR
)
;
const
real
prefactor
=
138.935456f*posq1.w*posq2.w*invR
;
const
real
prefactor
=
138.935456f*posq1.w*posq2.w*invR
;
#
ifdef
USE_DOUBLE_PRECISION
#
ifdef
USE_DOUBLE_PRECISION
const
real
erfcAlphaR
=
erfc
(
alphaR
)
;
const
real
erfcAlphaR
=
erfc
(
alphaR
)
;
#
else
#
else
//
This
approximation
for
erfc
is
from
Abramowitz
and
Stegun
(
1964
)
p.
299.
They
cite
the
following
as
//
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
//
the
original
source:
C.
Hastings,
Jr.,
Approximations
for
Digital
Computers
(
1955
)
.
It
has
a
maximum
//
error
of
3e-7.
//
error
of
3e-7.
real
t
=
1.0f+
(
0.0705230784f+
(
0.0422820123f+
(
0.0092705272f+
(
0.0001520143f+
(
0.0002765672f+0.0000430638f*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
)
*alphaR
;
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
;
t
*=
t
;
t
*=
t
;
t
*=
t
;
const
real
erfcAlphaR
=
RECIP
(
t*t
)
;
const
real
erfcAlphaR
=
RECIP
(
t*t
)
;
#
endif
#
endif
real
tempForce
=
0
;
real
tempForce
=
0
;
if
(
needCorrection
)
{
if
(
needCorrection
)
{
//
Subtract
off
the
part
of
this
interaction
that
was
included
in
the
reciprocal
space
contribution.
//
Subtract
off
the
part
of
this
interaction
that
was
included
in
the
reciprocal
space
contribution.
tempForce
=
-prefactor*
((
1.0f-erfcAlphaR
)
-alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempForce
=
-prefactor*
((
1.0f-erfcAlphaR
)
-alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempEnergy
+=
-prefactor*
(
1.0f-erfcAlphaR
)
;
tempEnergy
+=
-prefactor*
(
1.0f-erfcAlphaR
)
;
}
}
else
{
else
{
#
if
HAS_LENNARD_JONES
#
if
HAS_LENNARD_JONES
real
sig
=
sigmaEpsilon1.x
+
sigmaEpsilon2.x
;
real
sig
=
sigmaEpsilon1.x
+
sigmaEpsilon2.x
;
real
sig2
=
invR*sig
;
real
sig2
=
invR*sig
;
sig2
*=
sig2
;
sig2
*=
sig2
;
real
sig6
=
sig2*sig2*sig2
;
real
sig6
=
sig2*sig2*sig2
;
real
epssig6
=
sig6*
(
sigmaEpsilon1.y*sigmaEpsilon2.y
)
;
real
epssig6
=
sig6*
(
sigmaEpsilon1.y*sigmaEpsilon2.y
)
;
tempForce
=
epssig6*
(
12.0f*sig6
-
6.0f
)
;
tempForce
=
epssig6*
(
12.0f*sig6
-
6.0f
)
;
real
ljEnergy
=
epssig6*
(
sig6
-
1.0f
)
;
real
ljEnergy
=
epssig6*
(
sig6
-
1.0f
)
;
#
if
USE_LJ_SWITCH
#
if
USE_LJ_SWITCH
if
(
r
>
LJ_SWITCH_CUTOFF
)
{
if
(
r
>
LJ_SWITCH_CUTOFF
)
{
real
x
=
r-LJ_SWITCH_CUTOFF
;
real
x
=
r-LJ_SWITCH_CUTOFF
;
real
switchValue
=
1+x*x*x*
(
LJ_SWITCH_C3+x*
(
LJ_SWITCH_C4+x*LJ_SWITCH_C5
))
;
real
switchValue
=
1+x*x*x*
(
LJ_SWITCH_C3+x*
(
LJ_SWITCH_C4+x*LJ_SWITCH_C5
))
;
real
switchDeriv
=
x*x*
(
3*LJ_SWITCH_C3+x*
(
4*LJ_SWITCH_C4+x*5*LJ_SWITCH_C5
))
;
real
switchDeriv
=
x*x*
(
3*LJ_SWITCH_C3+x*
(
4*LJ_SWITCH_C4+x*5*LJ_SWITCH_C5
))
;
tempForce
=
tempForce*switchValue
-
ljEnergy*switchDeriv*r
;
tempForce
=
tempForce*switchValue
-
ljEnergy*switchDeriv*r
;
ljEnergy
*=
switchValue
;
ljEnergy
*=
switchValue
;
}
}
#
endif
#
endif
tempForce
+=
prefactor*
(
erfcAlphaR+alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempForce
+=
prefactor*
(
erfcAlphaR+alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempEnergy
+=
ljEnergy
+
prefactor*erfcAlphaR
;
tempEnergy
+=
ljEnergy
+
prefactor*erfcAlphaR
;
#
else
#
else
tempForce
=
prefactor*
(
erfcAlphaR+alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempForce
=
prefactor*
(
erfcAlphaR+alphaR*expAlphaRSqr*TWO_OVER_SQRT_PI
)
;
tempEnergy
+=
prefactor*erfcAlphaR
;
tempEnergy
+=
prefactor*erfcAlphaR
;
#
endif
#
endif
}
dEdR
+=
tempForce*invR*invR
;
}
}
dEdR
+=
tempForce*invR*invR
;
}
}
#
else
#
else
{
{
...
...
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