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
34ddae96
Commit
34ddae96
authored
Dec 11, 2014
by
peastman
Browse files
ReferenceNeighborList correctly handles triclinic boxes
parent
4b6f53e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
32 deletions
+65
-32
platforms/reference/src/SimTKReference/ReferenceNeighborList.cpp
...ms/reference/src/SimTKReference/ReferenceNeighborList.cpp
+26
-12
platforms/reference/tests/TestReferenceNeighborList.cpp
platforms/reference/tests/TestReferenceNeighborList.cpp
+39
-20
No files found.
platforms/reference/src/SimTKReference/ReferenceNeighborList.cpp
View file @
34ddae96
...
@@ -147,19 +147,33 @@ public:
...
@@ -147,19 +147,33 @@ public:
int
dIndexY
=
int
(
maxDistance
/
voxelSizeY
)
+
1
;
int
dIndexY
=
int
(
maxDistance
/
voxelSizeY
)
+
1
;
int
dIndexZ
=
int
(
maxDistance
/
voxelSizeZ
)
+
1
;
int
dIndexZ
=
int
(
maxDistance
/
voxelSizeZ
)
+
1
;
VoxelIndex
centerVoxelIndex
=
getVoxelIndex
(
locationI
);
VoxelIndex
centerVoxelIndex
=
getVoxelIndex
(
locationI
);
int
lastx
=
centerVoxelIndex
.
x
+
dIndexX
;
int
minz
=
centerVoxelIndex
.
z
-
dIndexZ
;
int
lasty
=
centerVoxelIndex
.
y
+
dIndexY
;
int
maxz
=
centerVoxelIndex
.
z
+
dIndexZ
;
int
lastz
=
centerVoxelIndex
.
z
+
dIndexZ
;
if
(
usePeriodic
)
maxz
=
min
(
maxz
,
minz
+
nz
-
1
);
for
(
int
z
=
minz
;
z
<=
maxz
;
++
z
)
{
int
boxz
=
(
int
)
floor
((
float
)
z
/
nz
);
int
miny
=
centerVoxelIndex
.
y
-
dIndexY
;
int
maxy
=
centerVoxelIndex
.
y
+
dIndexY
;
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
lastx
=
min
(
lastx
,
centerVoxelIndex
.
x
-
dIndexX
+
nx
-
1
);
int
yoffset
=
(
int
)
ceil
(
boxz
*
periodicBoxVectors
[
2
][
1
]
/
voxelSizeY
);
lasty
=
min
(
lasty
,
centerVoxelIndex
.
y
-
dIndexY
+
ny
-
1
);
miny
-=
yoffset
;
lastz
=
min
(
lastz
,
centerVoxelIndex
.
z
-
dIndexZ
+
nz
-
1
);
maxy
-=
yoffset
-
1
;
maxy
=
min
(
maxy
,
miny
+
ny
-
1
);
}
}
for
(
int
x
=
centerVoxelIndex
.
x
-
dIndexX
;
x
<=
lastx
;
++
x
)
for
(
int
y
=
miny
;
y
<=
maxy
;
++
y
)
{
for
(
int
y
=
centerVoxelIndex
.
y
-
dIndexY
;
y
<=
lasty
;
++
y
)
{
{
for
(
int
z
=
centerVoxelIndex
.
z
-
dIndexZ
;
z
<=
lastz
;
++
z
)
int
boxy
=
(
int
)
floor
((
float
)
y
/
ny
);
int
minx
=
centerVoxelIndex
.
x
-
dIndexX
;
int
maxx
=
centerVoxelIndex
.
x
+
dIndexX
;
if
(
usePeriodic
)
{
int
xoffset
=
(
int
)
ceil
((
boxy
*
periodicBoxVectors
[
1
][
0
]
+
boxz
*
periodicBoxVectors
[
2
][
0
])
/
voxelSizeX
);
minx
-=
xoffset
;
maxx
-=
xoffset
-
1
;
maxx
=
min
(
maxx
,
minx
+
nx
-
1
);
}
for
(
int
x
=
minx
;
x
<=
maxx
;
++
x
)
{
{
VoxelIndex
voxelIndex
(
x
,
y
,
z
);
VoxelIndex
voxelIndex
(
x
,
y
,
z
);
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
...
...
platforms/reference/tests/TestReferenceNeighborList.cpp
View file @
34ddae96
...
@@ -62,29 +62,24 @@ void testNeighborList()
...
@@ -62,29 +62,24 @@ void testNeighborList()
assert
(
neighborList
.
size
()
==
0
);
assert
(
neighborList
.
size
()
==
0
);
}
}
double
periodicDifference
(
double
val1
,
double
val2
,
double
period
)
{
double
distance2
(
RealVec
&
pos1
,
RealVec
&
pos2
,
const
RealVec
*
periodicBoxVectors
)
{
double
diff
=
val1
-
val2
;
RealVec
diff
=
pos1
-
pos2
;
double
base
=
floor
(
diff
/
period
+
0.5
)
*
period
;
diff
-=
periodicBoxVectors
[
2
]
*
floor
(
diff
[
2
]
/
periodicBoxVectors
[
2
][
2
]
+
0.5
);
return
diff
-
base
;
diff
-=
periodicBoxVectors
[
1
]
*
floor
(
diff
[
1
]
/
periodicBoxVectors
[
1
][
1
]
+
0.5
);
diff
-=
periodicBoxVectors
[
0
]
*
floor
(
diff
[
0
]
/
periodicBoxVectors
[
0
][
0
]
+
0.5
);
return
diff
.
dot
(
diff
);
}
}
double
distance2
(
RealVec
&
pos1
,
RealVec
&
pos2
,
const
RealVec
&
periodicBoxSize
)
{
void
verifyNeighborList
(
NeighborList
&
list
,
int
numParticles
,
vector
<
RealVec
>&
positions
,
const
RealVec
*
periodicBoxVectors
,
double
cutoff
)
{
double
dx
=
periodicDifference
(
pos1
[
0
],
pos2
[
0
],
periodicBoxSize
[
0
]);
double
dy
=
periodicDifference
(
pos1
[
1
],
pos2
[
1
],
periodicBoxSize
[
1
]);
double
dz
=
periodicDifference
(
pos1
[
2
],
pos2
[
2
],
periodicBoxSize
[
2
]);
return
dx
*
dx
+
dy
*
dy
+
dz
*
dz
;
}
void
verifyNeighborList
(
NeighborList
&
list
,
int
numParticles
,
vector
<
RealVec
>&
positions
,
const
RealVec
&
periodicBoxSize
,
double
cutoff
)
{
for
(
int
i
=
0
;
i
<
(
int
)
list
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
list
.
size
();
i
++
)
{
int
particle1
=
list
[
i
].
first
;
int
particle1
=
list
[
i
].
first
;
int
particle2
=
list
[
i
].
second
;
int
particle2
=
list
[
i
].
second
;
ASSERT
(
distance2
(
positions
[
particle1
],
positions
[
particle2
],
periodicBox
Size
)
<=
cutoff
*
cutoff
);
ASSERT
(
distance2
(
positions
[
particle1
],
positions
[
particle2
],
periodicBox
Vectors
)
<=
cutoff
*
cutoff
);
}
}
int
count
=
0
;
int
count
=
0
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
j
=
i
+
1
;
j
<
numParticles
;
j
++
)
for
(
int
j
=
i
+
1
;
j
<
numParticles
;
j
++
)
if
(
distance2
(
positions
[
i
],
positions
[
j
],
periodicBox
Size
)
<=
cutoff
*
cutoff
)
if
(
distance2
(
positions
[
i
],
positions
[
j
],
periodicBox
Vectors
)
<=
cutoff
*
cutoff
)
count
++
;
count
++
;
ASSERT_EQUAL
(
count
,
list
.
size
());
ASSERT_EQUAL
(
count
,
list
.
size
());
}
}
...
@@ -92,7 +87,6 @@ void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& p
...
@@ -92,7 +87,6 @@ void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& p
void
testPeriodic
()
{
void
testPeriodic
()
{
const
int
numParticles
=
100
;
const
int
numParticles
=
100
;
const
double
cutoff
=
3.0
;
const
double
cutoff
=
3.0
;
const
RealVec
periodicBoxSize
(
20.0
,
15.0
,
22.0
);
RealVec
periodicBoxVectors
[
3
];
RealVec
periodicBoxVectors
[
3
];
periodicBoxVectors
[
0
]
=
RealVec
(
20
,
0
,
0
);
periodicBoxVectors
[
0
]
=
RealVec
(
20
,
0
,
0
);
periodicBoxVectors
[
1
]
=
RealVec
(
0
,
15
,
0
);
periodicBoxVectors
[
1
]
=
RealVec
(
0
,
15
,
0
);
...
@@ -102,16 +96,40 @@ void testPeriodic() {
...
@@ -102,16 +96,40 @@ void testPeriodic() {
init_gen_rand
(
0
,
sfmt
);
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
particleList
[
i
][
0
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxSize
[
0
]
*
3
);
particleList
[
i
][
0
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
0
][
0
]
*
3
);
particleList
[
i
][
1
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxSize
[
1
]
*
3
);
particleList
[
i
][
1
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
1
][
1
]
*
3
);
particleList
[
i
][
2
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxSize
[
2
]
*
3
);
particleList
[
i
][
2
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
2
][
2
]
*
3
);
}
vector
<
set
<
int
>
>
exclusions
(
numParticles
);
NeighborList
neighborList
;
computeNeighborListNaive
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBoxVectors
,
cutoff
);
computeNeighborListVoxelHash
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBoxVectors
,
cutoff
);
}
void
testTriclinic
()
{
const
int
numParticles
=
1000
;
const
double
cutoff
=
3.0
;
RealVec
periodicBoxVectors
[
3
];
periodicBoxVectors
[
0
]
=
RealVec
(
20
,
0
,
0
);
periodicBoxVectors
[
1
]
=
RealVec
(
5
,
15
,
0
);
periodicBoxVectors
[
2
]
=
RealVec
(
-
3
,
-
7
,
22
);
vector
<
RealVec
>
particleList
(
numParticles
);
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
particleList
[
i
][
0
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
0
][
0
]
*
3
);
particleList
[
i
][
1
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
1
][
1
]
*
3
);
particleList
[
i
][
2
]
=
(
RealOpenMM
)
(
genrand_real2
(
sfmt
)
*
periodicBoxVectors
[
2
][
2
]
*
3
);
}
}
vector
<
set
<
int
>
>
exclusions
(
numParticles
);
vector
<
set
<
int
>
>
exclusions
(
numParticles
);
NeighborList
neighborList
;
NeighborList
neighborList
;
computeNeighborListNaive
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
computeNeighborListNaive
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBox
Size
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBox
Vectors
,
cutoff
);
computeNeighborListVoxelHash
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
computeNeighborListVoxelHash
(
neighborList
,
numParticles
,
particleList
,
exclusions
,
periodicBoxVectors
,
true
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBox
Size
,
cutoff
);
verifyNeighborList
(
neighborList
,
numParticles
,
particleList
,
periodicBox
Vectors
,
cutoff
);
}
}
int
main
()
int
main
()
...
@@ -119,6 +137,7 @@ int main()
...
@@ -119,6 +137,7 @@ int main()
try
{
try
{
testNeighborList
();
testNeighborList
();
testPeriodic
();
testPeriodic
();
testTriclinic
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
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