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
4193a416
Commit
4193a416
authored
Dec 16, 2014
by
peastman
Browse files
CpuNeighborList correctly handles triclinic boxes
parent
34ddae96
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
111 deletions
+179
-111
platforms/cpu/include/CpuNeighborList.h
platforms/cpu/include/CpuNeighborList.h
+5
-2
platforms/cpu/src/CpuNeighborList.cpp
platforms/cpu/src/CpuNeighborList.cpp
+142
-87
platforms/cpu/src/CpuNonbondedForce.cpp
platforms/cpu/src/CpuNonbondedForce.cpp
+3
-3
platforms/cpu/tests/TestCpuNeighborList.cpp
platforms/cpu/tests/TestCpuNeighborList.cpp
+23
-13
platforms/reference/src/SimTKReference/ReferenceNeighborList.cpp
...ms/reference/src/SimTKReference/ReferenceNeighborList.cpp
+6
-6
No files found.
platforms/cpu/include/CpuNeighborList.h
View file @
4193a416
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
#include "AlignedArray.h"
#include "AlignedArray.h"
#include "RealVec.h"
#include "windowsExportCpu.h"
#include "windowsExportCpu.h"
#include "openmm/internal/ThreadPool.h"
#include "openmm/internal/ThreadPool.h"
#include <set>
#include <set>
...
@@ -40,12 +41,14 @@
...
@@ -40,12 +41,14 @@
#include <vector>
#include <vector>
namespace
OpenMM
{
namespace
OpenMM
{
class
OPENMM_EXPORT_CPU
CpuNeighborList
{
class
OPENMM_EXPORT_CPU
CpuNeighborList
{
public:
public:
class
ThreadTask
;
class
ThreadTask
;
class
Voxels
;
class
Voxels
;
CpuNeighborList
(
int
blockSize
);
CpuNeighborList
(
int
blockSize
);
void
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
std
::
vector
<
std
::
set
<
int
>
>&
exclusions
,
const
RealVec
*
periodicBoxVectors
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
);
void
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
std
::
vector
<
std
::
set
<
int
>
>&
exclusions
,
void
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
std
::
vector
<
std
::
set
<
int
>
>&
exclusions
,
const
float
*
periodicBoxSize
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
);
const
float
*
periodicBoxSize
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
);
int
getNumBlocks
()
const
;
int
getNumBlocks
()
const
;
...
@@ -68,7 +71,7 @@ private:
...
@@ -68,7 +71,7 @@ private:
Voxels
*
voxels
;
Voxels
*
voxels
;
const
std
::
vector
<
std
::
set
<
int
>
>*
exclusions
;
const
std
::
vector
<
std
::
set
<
int
>
>*
exclusions
;
const
float
*
atomLocations
;
const
float
*
atomLocations
;
const
float
*
periodicBox
Size
;
RealVec
periodicBox
Vectors
[
3
]
;
int
numAtoms
;
int
numAtoms
;
bool
usePeriodic
;
bool
usePeriodic
;
float
maxDistance
;
float
maxDistance
;
...
...
platforms/cpu/src/CpuNeighborList.cpp
View file @
4193a416
...
@@ -45,12 +45,12 @@ namespace OpenMM {
...
@@ -45,12 +45,12 @@ namespace OpenMM {
class
VoxelIndex
class
VoxelIndex
{
{
public:
public:
VoxelIndex
()
:
x
(
0
),
y
(
0
)
{
VoxelIndex
()
:
y
(
0
),
z
(
0
)
{
}
}
VoxelIndex
(
int
x
,
int
y
)
:
x
(
x
),
y
(
y
)
{
VoxelIndex
(
int
y
,
int
z
)
:
y
(
y
),
z
(
z
)
{
}
}
int
x
;
int
y
;
int
y
;
int
z
;
};
};
/**
/**
...
@@ -59,26 +59,35 @@ public:
...
@@ -59,26 +59,35 @@ public:
*/
*/
class
CpuNeighborList
::
Voxels
{
class
CpuNeighborList
::
Voxels
{
public:
public:
Voxels
(
int
blockSize
,
float
vsx
,
float
vsy
,
float
minx
,
float
maxx
,
float
miny
,
float
maxy
,
const
float
*
periodicBoxSize
,
bool
usePeriodic
)
:
Voxels
(
int
blockSize
,
float
vsy
,
float
vsz
,
float
miny
,
float
maxy
,
float
minz
,
float
maxz
,
const
RealVec
*
periodicBoxVectors
,
bool
usePeriodic
)
:
blockSize
(
blockSize
),
voxelSizeX
(
vsx
),
voxelSizeY
(
vsy
),
minx
(
minx
),
maxx
(
maxx
),
miny
(
miny
),
maxy
(
maxy
),
periodicBoxSize
(
periodicBoxSize
),
usePeriodic
(
usePeriodic
)
{
blockSize
(
blockSize
),
voxelSizeY
(
vsy
),
voxelSizeZ
(
vsz
),
miny
(
miny
),
maxy
(
maxy
),
minz
(
minz
),
maxz
(
maxz
),
periodicBoxVectors
(
periodicBoxVectors
),
usePeriodic
(
usePeriodic
)
{
periodicBoxSize
[
0
]
=
(
float
)
periodicBoxVectors
[
0
][
0
];
periodicBoxSize
[
1
]
=
(
float
)
periodicBoxVectors
[
1
][
1
];
periodicBoxSize
[
2
]
=
(
float
)
periodicBoxVectors
[
2
][
2
];
recipBoxSize
[
0
]
=
(
float
)
(
1
/
periodicBoxVectors
[
0
][
0
]);
recipBoxSize
[
1
]
=
(
float
)
(
1
/
periodicBoxVectors
[
1
][
1
]);
recipBoxSize
[
2
]
=
(
float
)
(
1
/
periodicBoxVectors
[
2
][
2
]);
triclinic
=
(
periodicBoxVectors
[
0
][
1
]
!=
0.0
||
periodicBoxVectors
[
0
][
2
]
!=
0.0
||
periodicBoxVectors
[
1
][
0
]
!=
0.0
||
periodicBoxVectors
[
1
][
2
]
!=
0.0
||
periodicBoxVectors
[
2
][
0
]
!=
0.0
||
periodicBoxVectors
[
2
][
1
]
!=
0.0
);
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
n
x
=
(
int
)
floorf
(
periodicBox
Size
[
0
]
/
voxelSize
X
+
0.5
f
);
n
y
=
(
int
)
floorf
(
periodicBox
Vectors
[
1
][
1
]
/
voxelSize
Y
+
0.5
f
);
n
y
=
(
int
)
floorf
(
periodicBox
Size
[
1
]
/
voxelSize
Y
+
0.5
f
);
n
z
=
(
int
)
floorf
(
periodicBox
Vectors
[
2
][
2
]
/
voxelSize
Z
+
0.5
f
);
voxelSize
X
=
periodicBox
Size
[
0
]
/
n
x
;
voxelSize
Y
=
periodicBox
Vectors
[
1
][
1
]
/
n
y
;
voxelSize
Y
=
periodicBox
Size
[
1
]
/
n
y
;
voxelSize
Z
=
periodicBox
Vectors
[
2
][
2
]
/
n
z
;
}
}
else
{
else
{
nx
=
max
(
1
,
(
int
)
floorf
((
maxx
-
minx
)
/
voxelSizeX
+
0.5
f
));
ny
=
max
(
1
,
(
int
)
floorf
((
maxy
-
miny
)
/
voxelSizeY
+
0.5
f
));
ny
=
max
(
1
,
(
int
)
floorf
((
maxy
-
miny
)
/
voxelSizeY
+
0.5
f
));
if
(
maxx
>
minx
)
nz
=
max
(
1
,
(
int
)
floorf
((
maxz
-
minz
)
/
voxelSizeZ
+
0.5
f
));
voxelSizeX
=
(
maxx
-
minx
)
/
nx
;
if
(
maxy
>
miny
)
if
(
maxy
>
miny
)
voxelSizeY
=
(
maxy
-
miny
)
/
ny
;
voxelSizeY
=
(
maxy
-
miny
)
/
ny
;
if
(
maxz
>
minz
)
voxelSizeZ
=
(
maxz
-
minz
)
/
nz
;
}
}
bins
.
resize
(
n
x
);
bins
.
resize
(
n
y
);
for
(
int
i
=
0
;
i
<
n
x
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n
y
;
i
++
)
{
bins
[
i
].
resize
(
n
y
);
bins
[
i
].
resize
(
n
z
);
for
(
int
j
=
0
;
j
<
n
y
;
j
++
)
for
(
int
j
=
0
;
j
<
n
z
;
j
++
)
bins
[
i
][
j
].
resize
(
0
);
bins
[
i
][
j
].
resize
(
0
);
}
}
}
}
...
@@ -88,28 +97,28 @@ public:
...
@@ -88,28 +97,28 @@ public:
*/
*/
void
insert
(
const
int
&
atom
,
const
float
*
location
)
{
void
insert
(
const
int
&
atom
,
const
float
*
location
)
{
VoxelIndex
voxelIndex
=
getVoxelIndex
(
location
);
VoxelIndex
voxelIndex
=
getVoxelIndex
(
location
);
bins
[
voxelIndex
.
x
][
voxelIndex
.
y
].
push_back
(
make_pair
(
location
[
2
],
atom
));
bins
[
voxelIndex
.
y
][
voxelIndex
.
z
].
push_back
(
make_pair
(
location
[
0
],
atom
));
}
}
/**
/**
* Sort the particles in each voxel by
z
coordinate.
* Sort the particles in each voxel by
x
coordinate.
*/
*/
void
sortItems
()
{
void
sortItems
()
{
for
(
int
i
=
0
;
i
<
n
x
;
i
++
)
for
(
int
i
=
0
;
i
<
n
y
;
i
++
)
for
(
int
j
=
0
;
j
<
n
y
;
j
++
)
for
(
int
j
=
0
;
j
<
n
z
;
j
++
)
sort
(
bins
[
i
][
j
].
begin
(),
bins
[
i
][
j
].
end
());
sort
(
bins
[
i
][
j
].
begin
(),
bins
[
i
][
j
].
end
());
}
}
/**
/**
* Find the index of the first particle in voxel (
x,y
) whose
z
coordinate in >= the specified value.
* Find the index of the first particle in voxel (
y,z
) whose
x
coordinate in >= the specified value.
*/
*/
int
findLowerBound
(
int
x
,
int
y
,
double
z
)
const
{
int
findLowerBound
(
int
y
,
int
z
,
double
x
)
const
{
const
vector
<
pair
<
float
,
int
>
>&
bin
=
bins
[
x
][
y
];
const
vector
<
pair
<
float
,
int
>
>&
bin
=
bins
[
y
][
z
];
int
lower
=
0
;
int
lower
=
0
;
int
upper
=
bin
.
size
();
int
upper
=
bin
.
size
();
while
(
lower
<
upper
)
{
while
(
lower
<
upper
)
{
int
middle
=
(
lower
+
upper
)
/
2
;
int
middle
=
(
lower
+
upper
)
/
2
;
if
(
bin
[
middle
].
first
<
z
)
if
(
bin
[
middle
].
first
<
x
)
lower
=
middle
+
1
;
lower
=
middle
+
1
;
else
else
upper
=
middle
;
upper
=
middle
;
...
@@ -118,15 +127,15 @@ public:
...
@@ -118,15 +127,15 @@ public:
}
}
/**
/**
* Find the index of the first particle in voxel (
x,y
) whose
z
coordinate in greater than the specified value.
* Find the index of the first particle in voxel (
y,z
) whose
x
coordinate in greater than the specified value.
*/
*/
int
findUpperBound
(
int
x
,
int
y
,
double
z
)
const
{
int
findUpperBound
(
int
y
,
int
z
,
double
x
)
const
{
const
vector
<
pair
<
float
,
int
>
>&
bin
=
bins
[
x
][
y
];
const
vector
<
pair
<
float
,
int
>
>&
bin
=
bins
[
y
][
z
];
int
lower
=
0
;
int
lower
=
0
;
int
upper
=
bin
.
size
();
int
upper
=
bin
.
size
();
while
(
lower
<
upper
)
{
while
(
lower
<
upper
)
{
int
middle
=
(
lower
+
upper
)
/
2
;
int
middle
=
(
lower
+
upper
)
/
2
;
if
(
bin
[
middle
].
first
>
z
)
if
(
bin
[
middle
].
first
>
x
)
upper
=
middle
;
upper
=
middle
;
else
else
lower
=
middle
+
1
;
lower
=
middle
+
1
;
...
@@ -138,121 +147,144 @@ public:
...
@@ -138,121 +147,144 @@ public:
* Get the voxel index containing a particular location.
* Get the voxel index containing a particular location.
*/
*/
VoxelIndex
getVoxelIndex
(
const
float
*
location
)
const
{
VoxelIndex
getVoxelIndex
(
const
float
*
location
)
const
{
float
x
periodic
,
y
periodic
;
float
y
periodic
,
z
periodic
;
if
(
!
usePeriodic
)
{
if
(
!
usePeriodic
)
{
xperiodic
=
location
[
0
]
-
minx
;
yperiodic
=
location
[
1
]
-
miny
;
yperiodic
=
location
[
1
]
-
miny
;
zperiodic
=
location
[
2
]
-
minz
;
}
}
else
{
else
{
xperiodic
=
location
[
0
]
-
periodicBoxSize
[
0
]
*
floorf
(
location
[
0
]
/
periodicBoxSize
[
0
]);
float
scale2
=
floorf
(
location
[
2
]
*
recipBoxSize
[
2
]);
yperiodic
=
location
[
1
]
-
periodicBoxSize
[
1
]
*
floorf
(
location
[
1
]
/
periodicBoxSize
[
1
]);
yperiodic
=
location
[
1
]
-
periodicBoxVectors
[
2
][
1
]
*
scale2
;
zperiodic
=
location
[
2
]
-
periodicBoxVectors
[
2
][
2
]
*
scale2
;
float
scale1
=
floorf
(
yperiodic
*
recipBoxSize
[
1
]);
yperiodic
-=
periodicBoxVectors
[
1
][
0
]
*
scale1
;
}
}
int
x
=
min
(
nx
-
1
,
int
(
floorf
(
xperiodic
/
voxelSizeX
)));
int
y
=
min
(
ny
-
1
,
int
(
floorf
(
yperiodic
/
voxelSizeY
)));
int
y
=
min
(
ny
-
1
,
int
(
floorf
(
yperiodic
/
voxelSizeY
)));
int
z
=
min
(
nz
-
1
,
int
(
floorf
(
zperiodic
/
voxelSizeZ
)));
return
VoxelIndex
(
x
,
y
);
return
VoxelIndex
(
y
,
z
);
}
}
void
getNeighbors
(
vector
<
int
>&
neighbors
,
int
blockIndex
,
const
fvec4
&
blockCenter
,
const
fvec4
&
blockWidth
,
const
vector
<
int
>&
sortedAtoms
,
vector
<
char
>&
exclusions
,
float
maxDistance
,
const
vector
<
int
>&
blockAtoms
,
const
float
*
atomLocations
,
const
vector
<
VoxelIndex
>&
atomVoxelIndex
)
const
{
void
getNeighbors
(
vector
<
int
>&
neighbors
,
int
blockIndex
,
const
fvec4
&
blockCenter
,
const
fvec4
&
blockWidth
,
const
vector
<
int
>&
sortedAtoms
,
vector
<
char
>&
exclusions
,
float
maxDistance
,
const
vector
<
int
>&
blockAtoms
,
const
float
*
atomLocations
,
const
vector
<
VoxelIndex
>&
atomVoxelIndex
)
const
{
neighbors
.
resize
(
0
);
neighbors
.
resize
(
0
);
exclusions
.
resize
(
0
);
exclusions
.
resize
(
0
);
fvec4
boxSize
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
],
0
);
fvec4
boxSize
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
],
0
);
fvec4
invBoxSize
(
1
/
periodicBoxSize
[
0
],
1
/
periodicBoxSize
[
1
],
1
/
periodicBoxSize
[
2
],
0
);
fvec4
invBoxSize
(
recipBoxSize
[
0
],
recipBoxSize
[
1
],
recipBoxSize
[
2
],
0
);
fvec4
periodicBoxVec4
[
3
];
periodicBoxVec4
[
0
]
=
fvec4
(
periodicBoxVectors
[
0
][
0
],
periodicBoxVectors
[
0
][
1
],
periodicBoxVectors
[
0
][
2
],
0
);
periodicBoxVec4
[
1
]
=
fvec4
(
periodicBoxVectors
[
1
][
0
],
periodicBoxVectors
[
1
][
1
],
periodicBoxVectors
[
1
][
2
],
0
);
periodicBoxVec4
[
2
]
=
fvec4
(
periodicBoxVectors
[
2
][
0
],
periodicBoxVectors
[
2
][
1
],
periodicBoxVectors
[
2
][
2
],
0
);
float
maxDistanceSquared
=
maxDistance
*
maxDistance
;
float
maxDistanceSquared
=
maxDistance
*
maxDistance
;
float
refineCutoff
=
maxDistance
-
max
(
max
(
blockWidth
[
0
],
blockWidth
[
1
]),
blockWidth
[
2
]);
float
refineCutoff
=
maxDistance
-
max
(
max
(
blockWidth
[
0
],
blockWidth
[
1
]),
blockWidth
[
2
]);
float
refineCutoffSquared
=
refineCutoff
*
refineCutoff
;
float
refineCutoffSquared
=
refineCutoff
*
refineCutoff
;
int
dIndex
X
=
int
((
maxDistance
+
blockWidth
[
0
])
/
voxelSize
X
)
+
1
;
// How may voxels away do we have to look?
int
dIndex
Y
=
int
((
maxDistance
+
blockWidth
[
1
])
/
voxelSize
Y
)
+
1
;
// How may voxels away do we have to look?
int
dIndex
Y
=
int
((
maxDistance
+
blockWidth
[
1
])
/
voxelSize
Y
)
+
1
;
int
dIndex
Z
=
int
((
maxDistance
+
blockWidth
[
2
])
/
voxelSize
Z
)
+
1
;
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
dIndexX
=
min
(
nx
/
2
,
dIndexX
);
dIndexY
=
min
(
ny
/
2
,
dIndexY
);
dIndexY
=
min
(
ny
/
2
,
dIndexY
);
dIndexZ
=
min
(
nz
/
2
,
dIndexZ
);
}
}
float
centerPos
[
4
];
float
centerPos
[
4
];
blockCenter
.
store
(
centerPos
);
blockCenter
.
store
(
centerPos
);
VoxelIndex
centerVoxelIndex
=
getVoxelIndex
(
centerPos
);
VoxelIndex
centerVoxelIndex
=
getVoxelIndex
(
centerPos
);
int
startx
=
centerVoxelIndex
.
x
-
dIndexX
;
int
starty
=
centerVoxelIndex
.
y
-
dIndexY
;
// Loop over voxels along the z axis.
int
endx
=
centerVoxelIndex
.
x
+
dIndexX
;
int
endy
=
centerVoxelIndex
.
y
+
dIndexY
;
int
startz
=
centerVoxelIndex
.
z
-
dIndexZ
;
int
numRanges
;
int
endz
=
centerVoxelIndex
.
z
+
dIndexZ
;
if
(
usePeriodic
)
{
if
(
usePeriodic
)
endx
=
min
(
endx
,
centerVoxelIndex
.
x
-
dIndexX
+
nx
-
1
);
endz
=
min
(
endz
,
startz
+
nz
-
1
);
endy
=
min
(
endy
,
centerVoxelIndex
.
y
-
dIndexY
+
ny
-
1
);
}
else
{
else
{
startx
=
max
(
startx
,
0
);
startz
=
max
(
startz
,
0
);
starty
=
max
(
starty
,
0
);
endz
=
min
(
endz
,
nz
-
1
);
endx
=
min
(
endx
,
nx
-
1
);
endy
=
min
(
endy
,
ny
-
1
);
}
}
int
lastSortedIndex
=
blockSize
*
(
blockIndex
+
1
);
int
lastSortedIndex
=
blockSize
*
(
blockIndex
+
1
);
VoxelIndex
voxelIndex
(
0
,
0
);
VoxelIndex
voxelIndex
(
0
,
0
);
for
(
int
x
=
start
x
;
x
<=
end
x
;
++
x
)
{
for
(
int
z
=
start
z
;
z
<=
end
z
;
++
z
)
{
voxelIndex
.
x
=
x
;
voxelIndex
.
z
=
z
;
if
(
usePeriodic
)
if
(
usePeriodic
)
voxelIndex
.
x
=
(
x
<
0
?
x
+
nx
:
(
x
>=
nx
?
x
-
nx
:
x
));
voxelIndex
.
z
=
(
z
<
0
?
z
+
nz
:
(
z
>=
nz
?
z
-
nz
:
z
));
// Loop over voxels along the y axis.
int
boxz
=
(
int
)
floor
((
float
)
z
/
nz
);
int
starty
=
centerVoxelIndex
.
y
-
dIndexY
;
int
endy
=
centerVoxelIndex
.
y
+
dIndexY
;
float
yoffset
=
(
float
)
(
usePeriodic
?
boxz
*
periodicBoxVectors
[
2
][
1
]
:
0
);
if
(
usePeriodic
)
{
starty
-=
(
int
)
ceil
(
yoffset
/
voxelSizeY
);
endy
-=
(
int
)
floor
(
yoffset
/
voxelSizeY
);
endy
=
min
(
endy
,
starty
+
ny
-
1
);
}
else
{
starty
=
max
(
starty
,
0
);
endy
=
min
(
endy
,
ny
-
1
);
}
for
(
int
y
=
starty
;
y
<=
endy
;
++
y
)
{
for
(
int
y
=
starty
;
y
<=
endy
;
++
y
)
{
voxelIndex
.
y
=
y
;
voxelIndex
.
y
=
y
;
if
(
usePeriodic
)
if
(
usePeriodic
)
voxelIndex
.
y
=
(
y
<
0
?
y
+
ny
:
(
y
>=
ny
?
y
-
ny
:
y
));
voxelIndex
.
y
=
(
y
<
0
?
y
+
ny
:
(
y
>=
ny
?
y
-
ny
:
y
));
int
boxy
=
(
int
)
floor
((
float
)
y
/
ny
);
float
xoffset
=
(
float
)
(
usePeriodic
?
boxy
*
periodicBoxVectors
[
1
][
0
]
+
boxz
*
periodicBoxVectors
[
2
][
0
]
:
0
);
// Identify the range of atoms within this bin we need to search. When using periodic boundary
// Identify the range of atoms within this bin we need to search. When using periodic boundary
// conditions, there may be two separate ranges.
// conditions, there may be two separate ranges.
float
min
z
=
centerPos
[
2
];
float
min
x
=
centerPos
[
0
];
float
max
z
=
centerPos
[
2
];
float
max
x
=
centerPos
[
0
];
fvec4
offset
(
voxelSize
X
*
x
+
(
usePeriodic
?
0.0
f
:
min
x
),
voxelSize
Y
*
y
+
(
usePeriodic
?
0.0
f
:
min
y
),
0
,
0
);
fvec4
offset
(
-
xoffset
,
-
yoffset
+
voxelSize
Y
*
y
+
(
usePeriodic
?
0.0
f
:
min
y
),
voxelSize
Z
*
z
+
(
usePeriodic
?
0.0
f
:
min
z
)
,
0
);
for
(
int
k
=
0
;
k
<
(
int
)
blockAtoms
.
size
();
k
++
)
{
for
(
int
k
=
0
;
k
<
(
int
)
blockAtoms
.
size
();
k
++
)
{
const
float
*
atomPos
=
&
atomLocations
[
4
*
blockAtoms
[
k
]];
const
float
*
atomPos
=
&
atomLocations
[
4
*
blockAtoms
[
k
]];
fvec4
posVec
(
atomPos
);
fvec4
posVec
(
atomPos
);
fvec4
delta1
=
offset
-
posVec
;
fvec4
delta1
=
offset
-
posVec
;
fvec4
delta2
=
delta1
+
fvec4
(
voxelSizeX
,
voxelSizeY
,
0
,
0
);
fvec4
delta2
=
delta1
+
fvec4
(
0
,
voxelSizeY
,
voxelSizeZ
,
0
);
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
delta1
-=
round
(
delta1
*
invBoxSize
)
*
boxSize
;
delta1
-=
round
(
delta1
*
invBoxSize
)
*
boxSize
;
delta2
-=
round
(
delta2
*
invBoxSize
)
*
boxSize
;
delta2
-=
round
(
delta2
*
invBoxSize
)
*
boxSize
;
}
}
fvec4
delta
=
min
(
abs
(
delta1
),
abs
(
delta2
));
fvec4
delta
=
min
(
abs
(
delta1
),
abs
(
delta2
));
float
dx
=
(
x
==
atomVoxelIndex
[
k
].
x
?
0.0
f
:
delta
[
0
]);
float
dy
=
(
y
==
atomVoxelIndex
[
k
].
y
?
0.0
f
:
delta
[
1
]);
float
dy
=
(
y
==
atomVoxelIndex
[
k
].
y
?
0.0
f
:
delta
[
1
]);
float
dist2
=
maxDistanceSquared
-
dx
*
dx
-
dy
*
dy
;
float
dz
=
(
z
==
atomVoxelIndex
[
k
].
z
?
0.0
f
:
delta
[
2
]);
float
dist2
=
maxDistanceSquared
-
dy
*
dy
-
dz
*
dz
;
if
(
dist2
>
0
)
{
if
(
dist2
>
0
)
{
float
dist
=
sqrtf
(
dist2
);
float
dist
=
sqrtf
(
dist2
);
min
z
=
min
(
min
z
,
atomPos
[
2
]
-
dist
);
min
x
=
min
(
min
x
,
atomPos
[
0
]
-
dist
-
xoffset
);
max
z
=
max
(
max
z
,
atomPos
[
2
]
+
dist
);
max
x
=
max
(
max
x
,
atomPos
[
0
]
+
dist
-
xoffset
);
}
}
}
}
if
(
min
z
==
max
z
)
if
(
min
x
==
max
x
)
continue
;
continue
;
bool
needPeriodic
=
(
centerPos
[
0
]
-
blockWidth
[
0
]
<
maxDistance
||
centerPos
[
0
]
+
blockWidth
[
0
]
>
periodicBoxSize
[
0
]
-
maxDistance
||
bool
needPeriodic
=
(
centerPos
[
1
]
-
blockWidth
[
1
]
<
maxDistance
||
centerPos
[
1
]
+
blockWidth
[
1
]
>
periodicBoxSize
[
1
]
-
maxDistance
||
centerPos
[
1
]
-
blockWidth
[
1
]
<
maxDistance
||
centerPos
[
1
]
+
blockWidth
[
1
]
>
periodicBoxSize
[
1
]
-
maxDistance
||
centerPos
[
2
]
-
blockWidth
[
2
]
<
maxDistance
||
centerPos
[
2
]
+
blockWidth
[
2
]
>
periodicBoxSize
[
2
]
-
maxDistance
||
minz
<
0.0
f
||
maxz
>
periodicBoxSize
[
2
]);
minx
<
0.0
f
||
maxx
>
periodicBoxVectors
[
0
][
0
]);
int
numRanges
;
int
rangeStart
[
2
];
int
rangeStart
[
2
];
int
rangeEnd
[
2
];
int
rangeEnd
[
2
];
rangeStart
[
0
]
=
findLowerBound
(
voxelIndex
.
x
,
voxelIndex
.
y
,
min
z
);
rangeStart
[
0
]
=
findLowerBound
(
voxelIndex
.
y
,
voxelIndex
.
z
,
min
x
);
if
(
needPeriodic
)
{
if
(
needPeriodic
)
{
numRanges
=
2
;
numRanges
=
2
;
rangeEnd
[
0
]
=
findUpperBound
(
voxelIndex
.
x
,
voxelIndex
.
y
,
max
z
);
rangeEnd
[
0
]
=
findUpperBound
(
voxelIndex
.
y
,
voxelIndex
.
z
,
max
x
);
if
(
rangeStart
[
0
]
>
0
)
{
if
(
rangeStart
[
0
]
>
0
)
{
rangeStart
[
1
]
=
0
;
rangeStart
[
1
]
=
0
;
rangeEnd
[
1
]
=
min
(
findUpperBound
(
voxelIndex
.
x
,
voxelIndex
.
y
,
max
z
-
periodicBoxSize
[
2
]),
rangeStart
[
0
]);
rangeEnd
[
1
]
=
min
(
findUpperBound
(
voxelIndex
.
y
,
voxelIndex
.
z
,
max
x
-
periodicBoxSize
[
0
]),
rangeStart
[
0
]);
}
}
else
{
else
{
rangeStart
[
1
]
=
max
(
findLowerBound
(
voxelIndex
.
x
,
voxelIndex
.
y
,
min
z
+
periodicBoxSize
[
2
]),
rangeEnd
[
0
]);
rangeStart
[
1
]
=
max
(
findLowerBound
(
voxelIndex
.
y
,
voxelIndex
.
z
,
min
x
+
periodicBoxSize
[
0
]),
rangeEnd
[
0
]);
rangeEnd
[
1
]
=
bins
[
voxelIndex
.
x
][
voxelIndex
.
y
].
size
();
rangeEnd
[
1
]
=
bins
[
voxelIndex
.
y
][
voxelIndex
.
z
].
size
();
}
}
}
}
else
{
else
{
numRanges
=
1
;
numRanges
=
1
;
rangeEnd
[
0
]
=
findUpperBound
(
voxelIndex
.
x
,
voxelIndex
.
y
,
max
z
);
rangeEnd
[
0
]
=
findUpperBound
(
voxelIndex
.
y
,
voxelIndex
.
z
,
max
x
);
}
}
bool
periodicRectangular
=
(
needPeriodic
&&
!
triclinic
);
// Loop over atoms and check to see if they are neighbors of this block.
// Loop over atoms and check to see if they are neighbors of this block.
for
(
int
range
=
0
;
range
<
numRanges
;
range
++
)
{
for
(
int
range
=
0
;
range
<
numRanges
;
range
++
)
{
for
(
int
item
=
rangeStart
[
range
];
item
<
rangeEnd
[
range
];
item
++
)
{
for
(
int
item
=
rangeStart
[
range
];
item
<
rangeEnd
[
range
];
item
++
)
{
const
int
sortedIndex
=
bins
[
voxelIndex
.
x
][
voxelIndex
.
y
][
item
].
second
;
const
int
sortedIndex
=
bins
[
voxelIndex
.
y
][
voxelIndex
.
z
][
item
].
second
;
// Avoid duplicate entries.
// Avoid duplicate entries.
if
(
sortedIndex
>=
lastSortedIndex
)
if
(
sortedIndex
>=
lastSortedIndex
)
...
@@ -260,10 +292,15 @@ public:
...
@@ -260,10 +292,15 @@ public:
fvec4
atomPos
(
atomLocations
+
4
*
sortedAtoms
[
sortedIndex
]);
fvec4
atomPos
(
atomLocations
+
4
*
sortedAtoms
[
sortedIndex
]);
fvec4
delta
=
atomPos
-
centerPos
;
fvec4
delta
=
atomPos
-
centerPos
;
if
(
needP
eriodic
)
{
if
(
p
eriodic
Rectangular
)
{
fvec4
base
=
round
(
delta
*
invBoxSize
)
*
boxSize
;
fvec4
base
=
round
(
delta
*
invBoxSize
)
*
boxSize
;
delta
=
delta
-
base
;
delta
=
delta
-
base
;
}
}
else
if
(
needPeriodic
)
{
delta
-=
periodicBoxVec4
[
2
]
*
floorf
(
delta
[
2
]
*
recipBoxSize
[
2
]
+
0.5
f
);
delta
-=
periodicBoxVec4
[
1
]
*
floorf
(
delta
[
1
]
*
recipBoxSize
[
1
]
+
0.5
f
);
delta
-=
periodicBoxVec4
[
0
]
*
floorf
(
delta
[
0
]
*
recipBoxSize
[
0
]
+
0.5
f
);
}
delta
=
max
(
0.0
f
,
abs
(
delta
)
-
blockWidth
);
delta
=
max
(
0.0
f
,
abs
(
delta
)
-
blockWidth
);
float
dSquared
=
dot3
(
delta
,
delta
);
float
dSquared
=
dot3
(
delta
,
delta
);
if
(
dSquared
>
maxDistanceSquared
)
if
(
dSquared
>
maxDistanceSquared
)
...
@@ -277,10 +314,15 @@ public:
...
@@ -277,10 +314,15 @@ public:
for
(
int
k
=
0
;
k
<
(
int
)
blockAtoms
.
size
();
k
++
)
{
for
(
int
k
=
0
;
k
<
(
int
)
blockAtoms
.
size
();
k
++
)
{
fvec4
pos1
(
&
atomLocations
[
4
*
blockAtoms
[
k
]]);
fvec4
pos1
(
&
atomLocations
[
4
*
blockAtoms
[
k
]]);
delta
=
atomPos
-
pos1
;
delta
=
atomPos
-
pos1
;
if
(
needP
eriodic
)
{
if
(
p
eriodic
Rectangular
)
{
fvec4
base
=
round
(
delta
*
invBoxSize
)
*
boxSize
;
fvec4
base
=
round
(
delta
*
invBoxSize
)
*
boxSize
;
delta
=
delta
-
base
;
delta
=
delta
-
base
;
}
}
else
if
(
needPeriodic
)
{
delta
-=
periodicBoxVec4
[
2
]
*
floorf
(
delta
[
2
]
*
recipBoxSize
[
2
]
+
0.5
f
);
delta
-=
periodicBoxVec4
[
1
]
*
floorf
(
delta
[
1
]
*
recipBoxSize
[
1
]
+
0.5
f
);
delta
-=
periodicBoxVec4
[
0
]
*
floorf
(
delta
[
0
]
*
recipBoxSize
[
0
]
+
0.5
f
);
}
float
r2
=
dot3
(
delta
,
delta
);
float
r2
=
dot3
(
delta
,
delta
);
if
(
r2
<
maxDistanceSquared
)
{
if
(
r2
<
maxDistanceSquared
)
{
any
=
true
;
any
=
true
;
...
@@ -308,10 +350,12 @@ public:
...
@@ -308,10 +350,12 @@ public:
private:
private:
int
blockSize
;
int
blockSize
;
float
voxelSizeX
,
voxelSizeY
;
float
voxelSizeY
,
voxelSizeZ
;
float
minx
,
maxx
,
miny
,
maxy
;
float
miny
,
maxy
,
minz
,
maxz
;
int
nx
,
ny
;
int
ny
,
nz
;
const
float
*
periodicBoxSize
;
float
periodicBoxSize
[
3
],
recipBoxSize
[
3
];
bool
triclinic
;
const
RealVec
*
periodicBoxVectors
;
const
bool
usePeriodic
;
const
bool
usePeriodic
;
vector
<
vector
<
vector
<
pair
<
float
,
int
>
>
>
>
bins
;
vector
<
vector
<
vector
<
pair
<
float
,
int
>
>
>
>
bins
;
};
};
...
@@ -331,6 +375,15 @@ CpuNeighborList::CpuNeighborList(int blockSize) : blockSize(blockSize) {
...
@@ -331,6 +375,15 @@ CpuNeighborList::CpuNeighborList(int blockSize) : blockSize(blockSize) {
void
CpuNeighborList
::
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
vector
<
set
<
int
>
>&
exclusions
,
void
CpuNeighborList
::
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
vector
<
set
<
int
>
>&
exclusions
,
const
float
*
periodicBoxSize
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
)
{
const
float
*
periodicBoxSize
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
)
{
RealVec
vectors
[
3
];
vectors
[
0
]
=
RealVec
(
periodicBoxSize
[
0
],
0
,
0
);
vectors
[
1
]
=
RealVec
(
0
,
periodicBoxSize
[
1
],
0
);
vectors
[
2
]
=
RealVec
(
0
,
0
,
periodicBoxSize
[
2
]);
computeNeighborList
(
numAtoms
,
atomLocations
,
exclusions
,
vectors
,
usePeriodic
,
maxDistance
,
threads
);
}
void
CpuNeighborList
::
computeNeighborList
(
int
numAtoms
,
const
AlignedArray
<
float
>&
atomLocations
,
const
vector
<
set
<
int
>
>&
exclusions
,
const
RealVec
*
periodicBoxVectors
,
bool
usePeriodic
,
float
maxDistance
,
ThreadPool
&
threads
)
{
int
numBlocks
=
(
numAtoms
+
blockSize
-
1
)
/
blockSize
;
int
numBlocks
=
(
numAtoms
+
blockSize
-
1
)
/
blockSize
;
blockNeighbors
.
resize
(
numBlocks
);
blockNeighbors
.
resize
(
numBlocks
);
blockExclusions
.
resize
(
numBlocks
);
blockExclusions
.
resize
(
numBlocks
);
...
@@ -340,7 +393,9 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
...
@@ -340,7 +393,9 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
this
->
exclusions
=
&
exclusions
;
this
->
exclusions
=
&
exclusions
;
this
->
atomLocations
=
&
atomLocations
[
0
];
this
->
atomLocations
=
&
atomLocations
[
0
];
this
->
periodicBoxSize
=
periodicBoxSize
;
this
->
periodicBoxVectors
[
0
]
=
periodicBoxVectors
[
0
];
this
->
periodicBoxVectors
[
1
]
=
periodicBoxVectors
[
1
];
this
->
periodicBoxVectors
[
2
]
=
periodicBoxVectors
[
2
];
this
->
numAtoms
=
numAtoms
;
this
->
numAtoms
=
numAtoms
;
this
->
usePeriodic
=
usePeriodic
;
this
->
usePeriodic
=
usePeriodic
;
this
->
maxDistance
=
maxDistance
;
this
->
maxDistance
=
maxDistance
;
...
@@ -371,14 +426,14 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
...
@@ -371,14 +426,14 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
// Build the voxel hash.
// Build the voxel hash.
float
edgeSize
X
,
edgeSize
Y
;
float
edgeSize
Y
,
edgeSize
Z
;
if
(
!
usePeriodic
)
if
(
!
usePeriodic
)
edgeSize
X
=
edgeSize
Y
=
maxDistance
;
// TODO - adjust this as needed
edgeSize
Y
=
edgeSize
Z
=
maxDistance
;
// TODO - adjust this as needed
else
{
else
{
edgeSize
X
=
0.6
f
*
periodicBox
Size
[
0
]
/
floorf
(
periodicBox
Size
[
0
]
/
maxDistance
);
edgeSize
Y
=
0.6
f
*
periodicBox
Vectors
[
1
][
1
]
/
floorf
(
periodicBox
Vectors
[
1
][
1
]
/
maxDistance
);
edgeSize
Y
=
0.6
f
*
periodicBox
Size
[
1
]
/
floorf
(
periodicBox
Size
[
1
]
/
maxDistance
);
edgeSize
Z
=
0.6
f
*
periodicBox
Vectors
[
2
][
2
]
/
floorf
(
periodicBox
Vectors
[
2
][
2
]
/
maxDistance
);
}
}
Voxels
voxels
(
blockSize
,
edgeSize
X
,
edgeSize
Y
,
min
x
,
max
x
,
min
y
,
max
y
,
periodicBox
Size
,
usePeriodic
);
Voxels
voxels
(
blockSize
,
edgeSize
Y
,
edgeSize
Z
,
min
y
,
max
y
,
min
z
,
max
z
,
periodicBox
Vectors
,
usePeriodic
);
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
int
atomIndex
=
atomBins
[
i
].
second
;
int
atomIndex
=
atomBins
[
i
].
second
;
sortedAtoms
[
i
]
=
atomIndex
;
sortedAtoms
[
i
]
=
atomIndex
;
...
@@ -386,7 +441,7 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
...
@@ -386,7 +441,7 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
}
}
voxels
.
sortItems
();
voxels
.
sortItems
();
this
->
voxels
=
&
voxels
;
this
->
voxels
=
&
voxels
;
// Signal the threads to start running and wait for them to finish.
// Signal the threads to start running and wait for them to finish.
threads
.
resumeThreads
();
threads
.
resumeThreads
();
...
...
platforms/cpu/src/CpuNonbondedForce.cpp
View file @
4193a416
...
@@ -463,9 +463,9 @@ void CpuNonbondedForce::getDeltaR(const fvec4& posI, const fvec4& posJ, fvec4& d
...
@@ -463,9 +463,9 @@ void CpuNonbondedForce::getDeltaR(const fvec4& posI, const fvec4& posJ, fvec4& d
deltaR
=
posJ
-
posI
;
deltaR
=
posJ
-
posI
;
if
(
periodic
)
{
if
(
periodic
)
{
if
(
triclinic
)
{
if
(
triclinic
)
{
deltaR
-=
periodicBoxVec4
[
2
]
*
floor
(
deltaR
[
2
]
*
recipBoxSize
[
2
]
+
0.5
f
);
deltaR
-=
periodicBoxVec4
[
2
]
*
floor
f
(
deltaR
[
2
]
*
recipBoxSize
[
2
]
+
0.5
f
);
deltaR
-=
periodicBoxVec4
[
1
]
*
floor
(
deltaR
[
1
]
*
recipBoxSize
[
1
]
+
0.5
f
);
deltaR
-=
periodicBoxVec4
[
1
]
*
floor
f
(
deltaR
[
1
]
*
recipBoxSize
[
1
]
+
0.5
f
);
deltaR
-=
periodicBoxVec4
[
0
]
*
floor
(
deltaR
[
0
]
*
recipBoxSize
[
0
]
+
0.5
f
);
deltaR
-=
periodicBoxVec4
[
0
]
*
floor
f
(
deltaR
[
0
]
*
recipBoxSize
[
0
]
+
0.5
f
);
}
}
else
{
else
{
fvec4
base
=
round
(
deltaR
*
invBoxSize
)
*
boxSize
;
fvec4
base
=
round
(
deltaR
*
invBoxSize
)
*
boxSize
;
...
...
platforms/cpu/tests/TestCpuNeighborList.cpp
View file @
4193a416
...
@@ -48,10 +48,21 @@
...
@@ -48,10 +48,21 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
void
testNeighborList
(
bool
periodic
)
{
void
testNeighborList
(
bool
periodic
,
bool
triclinic
)
{
const
int
numParticles
=
500
;
const
int
numParticles
=
500
;
const
float
cutoff
=
2.0
f
;
const
float
cutoff
=
2.0
f
;
const
float
boxSize
[
3
]
=
{
20.0
f
,
15.0
f
,
22.0
f
};
RealVec
boxVectors
[
3
];
if
(
triclinic
)
{
boxVectors
[
0
]
=
RealVec
(
20
,
0
,
0
);
boxVectors
[
1
]
=
RealVec
(
5
,
15
,
0
);
boxVectors
[
2
]
=
RealVec
(
-
3
,
-
7
,
22
);
}
else
{
boxVectors
[
0
]
=
RealVec
(
20
,
0
,
0
);
boxVectors
[
1
]
=
RealVec
(
0
,
15
,
0
);
boxVectors
[
2
]
=
RealVec
(
0
,
0
,
22
);
}
const
float
boxSize
[
3
]
=
{
boxVectors
[
0
][
0
],
boxVectors
[
1
][
1
],
boxVectors
[
2
][
2
]};
const
int
blockSize
=
8
;
const
int
blockSize
=
8
;
OpenMM_SFMT
::
SFMT
sfmt
;
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
init_gen_rand
(
0
,
sfmt
);
...
@@ -69,7 +80,7 @@ void testNeighborList(bool periodic) {
...
@@ -69,7 +80,7 @@ void testNeighborList(bool periodic) {
}
}
ThreadPool
threads
;
ThreadPool
threads
;
CpuNeighborList
neighborList
(
blockSize
);
CpuNeighborList
neighborList
(
blockSize
);
neighborList
.
computeNeighborList
(
numParticles
,
positions
,
exclusions
,
box
Size
,
periodic
,
cutoff
,
threads
);
neighborList
.
computeNeighborList
(
numParticles
,
positions
,
exclusions
,
box
Vectors
,
periodic
,
cutoff
,
threads
);
// Convert the neighbor list to a set for faster lookup.
// Convert the neighbor list to a set for faster lookup.
...
@@ -90,19 +101,17 @@ void testNeighborList(bool periodic) {
...
@@ -90,19 +101,17 @@ void testNeighborList(bool periodic) {
}
}
// Check each particle pair and figure out whether they should be in the neighbor list.
// Check each particle pair and figure out whether they should be in the neighbor list.
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
j
=
0
;
j
<=
i
;
j
++
)
{
for
(
int
j
=
0
;
j
<=
i
;
j
++
)
{
bool
shouldInclude
=
(
exclusions
[
i
].
find
(
j
)
==
exclusions
[
i
].
end
());
bool
shouldInclude
=
(
exclusions
[
i
].
find
(
j
)
==
exclusions
[
i
].
end
());
float
dx
=
positions
[
4
*
i
]
-
positions
[
4
*
j
];
Vec3
diff
(
positions
[
4
*
i
]
-
positions
[
4
*
j
],
positions
[
4
*
i
+
1
]
-
positions
[
4
*
j
+
1
],
positions
[
4
*
i
+
2
]
-
positions
[
4
*
j
+
2
]);
float
dy
=
positions
[
4
*
i
+
1
]
-
positions
[
4
*
j
+
1
];
float
dz
=
positions
[
4
*
i
+
2
]
-
positions
[
4
*
j
+
2
];
if
(
periodic
)
{
if
(
periodic
)
{
d
x
-=
floor
(
d
x
/
boxSize
[
0
]
+
0.5
f
)
*
boxSize
[
0
]
;
d
iff
-=
boxVectors
[
2
]
*
floor
(
d
iff
[
2
]
/
boxSize
[
2
]
+
0.5
)
;
d
y
-=
floor
(
d
y
/
boxSize
[
1
]
+
0.5
f
)
*
boxSize
[
1
]
;
d
iff
-=
boxVectors
[
1
]
*
floor
(
d
iff
[
1
]
/
boxSize
[
1
]
+
0.5
)
;
d
z
-=
floor
(
d
z
/
boxSize
[
2
]
+
0.5
f
)
*
boxSize
[
2
]
;
d
iff
-=
boxVectors
[
0
]
*
floor
(
d
iff
[
0
]
/
boxSize
[
0
]
+
0.5
)
;
}
}
if
(
d
x
*
dx
+
dy
*
dy
+
dz
*
dz
>
cutoff
*
cutoff
)
if
(
d
iff
.
dot
(
diff
)
>
cutoff
*
cutoff
)
shouldInclude
=
false
;
shouldInclude
=
false
;
bool
isIncluded
=
(
neighbors
.
find
(
make_pair
(
i
,
j
))
!=
neighbors
.
end
()
||
neighbors
.
find
(
make_pair
(
j
,
i
))
!=
neighbors
.
end
());
bool
isIncluded
=
(
neighbors
.
find
(
make_pair
(
i
,
j
))
!=
neighbors
.
end
()
||
neighbors
.
find
(
make_pair
(
j
,
i
))
!=
neighbors
.
end
());
if
(
shouldInclude
)
if
(
shouldInclude
)
...
@@ -116,8 +125,9 @@ int main() {
...
@@ -116,8 +125,9 @@ int main() {
cout
<<
"CPU is not supported. Exiting."
<<
endl
;
cout
<<
"CPU is not supported. Exiting."
<<
endl
;
return
0
;
return
0
;
}
}
testNeighborList
(
false
);
testNeighborList
(
false
,
false
);
testNeighborList
(
true
);
testNeighborList
(
true
,
false
);
testNeighborList
(
true
,
true
);
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/reference/src/SimTKReference/ReferenceNeighborList.cpp
View file @
4193a416
...
@@ -157,9 +157,9 @@ public:
...
@@ -157,9 +157,9 @@ public:
int
miny
=
centerVoxelIndex
.
y
-
dIndexY
;
int
miny
=
centerVoxelIndex
.
y
-
dIndexY
;
int
maxy
=
centerVoxelIndex
.
y
+
dIndexY
;
int
maxy
=
centerVoxelIndex
.
y
+
dIndexY
;
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
int
yoffset
=
(
int
)
ceil
(
boxz
*
periodicBoxVectors
[
2
][
1
]
/
voxelSizeY
)
;
double
yoffset
=
boxz
*
periodicBoxVectors
[
2
][
1
]
/
voxelSizeY
;
miny
-=
yoffset
;
miny
-=
(
int
)
ceil
(
yoffset
)
;
maxy
-=
yoffset
-
1
;
maxy
-=
(
int
)
floor
(
yoffset
)
;
maxy
=
min
(
maxy
,
miny
+
ny
-
1
);
maxy
=
min
(
maxy
,
miny
+
ny
-
1
);
}
}
for
(
int
y
=
miny
;
y
<=
maxy
;
++
y
)
for
(
int
y
=
miny
;
y
<=
maxy
;
++
y
)
...
@@ -168,9 +168,9 @@ public:
...
@@ -168,9 +168,9 @@ public:
int
minx
=
centerVoxelIndex
.
x
-
dIndexX
;
int
minx
=
centerVoxelIndex
.
x
-
dIndexX
;
int
maxx
=
centerVoxelIndex
.
x
+
dIndexX
;
int
maxx
=
centerVoxelIndex
.
x
+
dIndexX
;
if
(
usePeriodic
)
{
if
(
usePeriodic
)
{
int
xoffset
=
(
int
)
ceil
(
(
boxy
*
periodicBoxVectors
[
1
][
0
]
+
boxz
*
periodicBoxVectors
[
2
][
0
])
/
voxelSizeX
)
;
double
xoffset
=
(
boxy
*
periodicBoxVectors
[
1
][
0
]
+
boxz
*
periodicBoxVectors
[
2
][
0
])
/
voxelSizeX
;
minx
-=
xoffset
;
minx
-=
(
int
)
ceil
(
xoffset
)
;
maxx
-=
xoffset
-
1
;
maxx
-=
(
int
)
floor
(
xoffset
)
;
maxx
=
min
(
maxx
,
minx
+
nx
-
1
);
maxx
=
min
(
maxx
,
minx
+
nx
-
1
);
}
}
for
(
int
x
=
minx
;
x
<=
maxx
;
++
x
)
for
(
int
x
=
minx
;
x
<=
maxx
;
++
x
)
...
...
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