Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arbd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tbgl
tools
arbd
Commits
428d610c
Commit
428d610c
authored
5 years ago
by
cmaffeo2
Browse files
Options
Downloads
Patches
Plain Diff
Fix previous commit so grid filename (and not grid key) are used by RBC
parent
f5b58527
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/RigidBodyController.cu
+52
-48
52 additions, 48 deletions
src/RigidBodyController.cu
src/RigidBodyType.cu
+8
-6
8 additions, 6 deletions
src/RigidBodyType.cu
src/RigidBodyType.h
+5
-1
5 additions, 1 deletion
src/RigidBodyType.h
with
65 additions
and
55 deletions
src/RigidBodyController.cu
+
52
−
48
View file @
428d610c
...
...
@@ -82,7 +82,7 @@ RigidBodyController::RigidBodyController(const Configuration& c, const char* pre
random
=
new
RandomCPU
(
conf
.
seed
+
repID
+
1
);
/* +1 to avoid using same seed as RandomCUDA */
initializeForcePairs
();
initializeForcePairs
();
// Must run after construct_grids()
gpuErrchk
(
cudaDeviceSynchronize
());
/* RBTODO: this should be extraneous */
//Boltzmann distribution
...
...
@@ -117,7 +117,7 @@ void RigidBodyController::construct_grids() {
// typedef std::tuple<String, float> GridKey;
// Build dictionary to reuse grids across all types, first finding scale factors
std
::
vector
<
GridKey
>
all_
key
s
;
std
::
vector
<
GridKey
>
all_
file
s
;
std
::
vector
<
GridKey
>::
iterator
itr
;
for
(
int
t_idx
=
0
;
t_idx
<
conf
.
numRigidTypes
;
++
t_idx
)
...
...
@@ -129,10 +129,10 @@ void RigidBodyController::construct_grids() {
t
.
potential_grid_idx
=
new
size_t
[
t
.
numPotGrids
];
// TODO; don't allocate here
t
.
density_grid_idx
=
new
size_t
[
t
.
numDenGrids
];
// TODO; don't allocate here
t
.
pmf_grid_idx
=
new
size_t
[
t
.
numPmfs
];
// TODO; don't allocate here
for
(
int
i
=
0
;
i
<
t
.
potentialGrid
Key
s
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
t
.
potentialGrid
File
s
.
size
();
++
i
)
{
String
&
name
=
t
.
potentialGrid
Key
s
[
i
];
String
&
name
=
t
.
potentialGrid
File
s
[
i
];
float
scale
=
1.0
f
;
for
(
int
j
=
0
;
j
<
t
.
potentialGridScaleKeys
.
size
();
++
j
)
{
...
...
@@ -143,27 +143,27 @@ void RigidBodyController::construct_grids() {
GridKey
key
=
GridKey
(
name
,
scale
);
int
key_idx
=
-
1
;
// Find key if it exists
itr
=
std
::
find
(
all_
key
s
.
begin
(),
all_
key
s
.
end
(),
key
);
if
(
itr
==
all_
key
s
.
end
())
itr
=
std
::
find
(
all_
file
s
.
begin
(),
all_
file
s
.
end
(),
key
);
if
(
itr
==
all_
file
s
.
end
())
{
key_idx
=
all_
key
s
.
size
();
all_
key
s
.
push_back
(
key
);
key_idx
=
all_
file
s
.
size
();
all_
file
s
.
push_back
(
key
);
}
else
{
key_idx
=
std
::
distance
(
all_
key
s
.
begin
(),
itr
);
key_idx
=
std
::
distance
(
all_
file
s
.
begin
(),
itr
);
}
// Assign index into all_
key
s to RigidBodyType
// Assign index into all_
file
s to RigidBodyType
t
.
potential_grid_idx
[
i
]
=
key_idx
;
}
// Density
for
(
int
i
=
0
;
i
<
t
.
densityGrid
Key
s
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
t
.
densityGrid
File
s
.
size
();
++
i
)
{
String
&
name
=
t
.
densityGrid
Key
s
[
i
];
String
&
name
=
t
.
densityGrid
File
s
[
i
];
float
scale
=
1.0
f
;
for
(
int
j
=
0
;
j
<
t
.
densityGridScaleKeys
.
size
();
++
j
)
{
...
...
@@ -174,26 +174,26 @@ void RigidBodyController::construct_grids() {
GridKey
key
=
GridKey
(
name
,
scale
);
int
key_idx
=
-
1
;
// Find key if it exists
itr
=
std
::
find
(
all_
key
s
.
begin
(),
all_
key
s
.
end
(),
key
);
if
(
itr
==
all_
key
s
.
end
())
itr
=
std
::
find
(
all_
file
s
.
begin
(),
all_
file
s
.
end
(),
key
);
if
(
itr
==
all_
file
s
.
end
())
{
key_idx
=
all_
key
s
.
size
();
all_
key
s
.
push_back
(
key
);
key_idx
=
all_
file
s
.
size
();
all_
file
s
.
push_back
(
key
);
}
else
{
key_idx
=
std
::
distance
(
all_
key
s
.
begin
(),
itr
);
key_idx
=
std
::
distance
(
all_
file
s
.
begin
(),
itr
);
}
// Assign index into all_
key
s to RigidBodyType
// Assign index into all_
file
s to RigidBodyType
t
.
density_grid_idx
[
i
]
=
key_idx
;
}
//PMF
for
(
int
i
=
0
;
i
<
t
.
pmf
Key
s
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
t
.
pmf
File
s
.
size
();
++
i
)
{
String
&
name
=
t
.
pmf
Key
s
[
i
];
String
&
name
=
t
.
pmf
File
s
[
i
];
float
scale
=
1.0
f
;
for
(
int
j
=
0
;
j
<
t
.
pmfScaleKeys
.
size
();
++
j
)
{
...
...
@@ -204,18 +204,18 @@ void RigidBodyController::construct_grids() {
GridKey
key
=
GridKey
(
name
,
scale
);
int
key_idx
=
-
1
;
// Find key if it exists
itr
=
std
::
find
(
all_
key
s
.
begin
(),
all_
key
s
.
end
(),
key
);
if
(
itr
==
all_
key
s
.
end
())
itr
=
std
::
find
(
all_
file
s
.
begin
(),
all_
file
s
.
end
(),
key
);
if
(
itr
==
all_
file
s
.
end
())
{
key_idx
=
all_
key
s
.
size
();
all_
key
s
.
push_back
(
key
);
key_idx
=
all_
file
s
.
size
();
all_
file
s
.
push_back
(
key
);
}
else
{
key_idx
=
std
::
distance
(
all_
key
s
.
begin
(),
itr
);
key_idx
=
std
::
distance
(
all_
file
s
.
begin
(),
itr
);
}
// Assign index into all_
key
s to RigidBodyType
// Assign index into all_
file
s to RigidBodyType
t
.
pmf_grid_idx
[
i
]
=
key_idx
;
}
...
...
@@ -232,27 +232,32 @@ void RigidBodyController::construct_grids() {
}
// Store grids
grids
=
new
BaseGrid
[
all_
key
s
.
size
()];
gpuErrchk
(
cudaMalloc
(
&
grids_d
,
sizeof
(
RigidBodyGrid
)
*
all_
key
s
.
size
()
));
grids
=
new
BaseGrid
[
all_
file
s
.
size
()];
gpuErrchk
(
cudaMalloc
(
&
grids_d
,
sizeof
(
RigidBodyGrid
)
*
all_
file
s
.
size
()
));
// Read and scale grids, then copy to GPU
for
(
size_t
i
=
0
;
i
<
all_
key
s
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
all_
file
s
.
size
();
++
i
)
{
GridKey
&
key
=
all_keys
[
i
];
BaseGrid
&
g
=
grids
[
i
];
g
=
BaseGrid
(
key
.
name
);
g
.
scale
(
key
.
scale
);
GridKey
&
key
=
all_files
[
i
];
BaseGrid
&
g0
=
grids
[
i
];
g0
=
BaseGrid
(
key
.
name
);
g0
.
scale
(
key
.
scale
);
RigidBodyGrid
g
=
RigidBodyGrid
();
g
.
nx
=
g0
.
nx
;
g
.
ny
=
g0
.
ny
;
g
.
nz
=
g0
.
nz
;
g
.
size
=
g0
.
size
;
g
.
val
=
g0
.
val
;
// Copy to GPU, starting with grid data
float
*
tmp1
;
float
*
tmp2
;
float
*
tmp
;
size_t
sz
=
sizeof
(
float
)
*
g
.
getSize
();
gpuErrchk
(
cudaMalloc
(
&
tmp
1
,
sz
));
gpuErrchk
(
cudaMemcpy
(
tmp
1
,
g
.
val
,
sz
,
cudaMemcpyHostToDevice
));
gpuErrchk
(
cudaMalloc
(
&
tmp
,
sz
));
gpuErrchk
(
cudaMemcpy
(
tmp
,
g
.
val
,
sz
,
cudaMemcpyHostToDevice
));
// Set grid pointer to device
tmp2
=
g
.
val
;
g
.
val
=
tmp1
;
g
.
val
=
tmp
;
// Copy grid
sz
=
sizeof
(
RigidBodyGrid
);
...
...
@@ -260,9 +265,8 @@ void RigidBodyController::construct_grids() {
gpuErrchk
(
cudaMemcpy
(
&
grids_d
[
i
],
&
g
,
sz
,
cudaMemcpyHostToDevice
));
// Restore pointer
g
.
val
=
tmp2
;
tmp1
=
NULL
;
tmp2
=
NULL
;
// probably unnecessary
g
.
val
=
NULL
;
tmp
=
NULL
;
}
}
...
...
@@ -372,8 +376,8 @@ void RigidBodyController::initializeForcePairs() {
// keys1[k1].printInline(); printf(":"); keys2[k2].print();
if
(
keys1
[
k1
]
==
keys2
[
k2
]
)
{
gridKeyId1
.
push_back
(
k1
);
gridKeyId2
.
push_back
(
k2
);
gridKeyId1
.
push_back
(
t1
.
density_grid_idx
[
k1
]
);
gridKeyId2
.
push_back
(
t2
.
potential_grid_idx
[
k2
]
);
paired
=
true
;
}
}
...
...
@@ -415,9 +419,9 @@ void RigidBodyController::initializeForcePairs() {
for
(
int
k1
=
0
;
k1
<
keys1
.
size
();
k1
++
)
{
for
(
int
k2
=
0
;
k2
<
keys2
.
size
();
k2
++
)
{
if
(
keys1
[
k1
]
==
keys2
[
k2
]
)
{
gridKeyId1
.
push_back
(
k1
);
gridKeyId2
.
push_back
(
k2
);
paired
=
true
;
gridKeyId1
.
push_back
(
t1
.
density_grid_idx
[
k1
]
);
gridKeyId2
.
push_back
(
t1
.
pmf_grid_idx
[
k2
]
);
paired
=
true
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/RigidBodyType.cu
+
8
−
6
View file @
428d610c
...
...
@@ -79,7 +79,7 @@ void RigidBodyType::setDampingCoeffs(float timestep) { /* MUST ONLY BE CALLED ON
}
void
RigidBodyType
::
addGrid
(
String
s
,
std
::
vector
<
String
>
&
keys
)
{
void
RigidBodyType
::
addGrid
(
String
s
,
std
::
vector
<
String
>
&
keys
,
std
::
vector
<
String
>
&
files
)
{
// tokenize and return
int
numTokens
=
s
.
tokenCount
();
if
(
numTokens
!=
2
)
{
...
...
@@ -88,17 +88,18 @@ void RigidBodyType::addGrid(String s, std::vector<String> &keys) {
}
String
*
token
=
new
String
[
numTokens
];
s
.
tokenize
(
token
);
String
key
=
token
[
0
];
keys
.
push_back
(
key
);
keys
.
push_back
(
String
(
token
[
0
])
);
files
.
push_back
(
String
(
token
[
1
])
);
delete
[]
token
;
}
void
RigidBodyType
::
addPotentialGrid
(
String
s
)
{
addGrid
(
s
,
potentialGridKeys
);
addGrid
(
s
,
potentialGridKeys
,
potentialGridFiles
);
}
void
RigidBodyType
::
addDensityGrid
(
String
s
)
{
addGrid
(
s
,
densityGridKeys
);
addGrid
(
s
,
densityGridKeys
,
potentialGridFiles
);
}
void
RigidBodyType
::
addPMF
(
String
s
)
{
addGrid
(
s
,
pmfKeys
);
addGrid
(
s
,
pmfKeys
,
potentialGridFiles
);
}
void
RigidBodyType
::
addScaleFactor
(
String
s
,
std
::
vector
<
String
>
&
keys
,
std
::
vector
<
float
>
&
vals
)
{
...
...
@@ -114,6 +115,7 @@ void RigidBodyType::addScaleFactor(String s, std::vector<String> &keys, std::vec
float
v
=
(
float
)
strtod
(
token
[
1
],
NULL
);
keys
.
push_back
(
key
);
vals
.
push_back
(
v
);
delete
[]
token
;
}
void
RigidBodyType
::
scalePotentialGrid
(
String
s
)
{
addScaleFactor
(
s
,
potentialGridScaleKeys
,
potentialGridScale
);
...
...
This diff is collapsed.
Click to expand it.
src/RigidBodyType.h
+
5
−
1
View file @
428d610c
...
...
@@ -32,7 +32,7 @@ private:
void
clear
();
// void copy(const RigidBodyType& src);
void
addGrid
(
String
s
,
std
::
vector
<
String
>
&
keys
);
void
addGrid
(
String
s
,
std
::
vector
<
String
>
&
keys
,
std
::
vector
<
String
>
&
files
);
void
addScaleFactor
(
String
s
,
std
::
vector
<
String
>
&
keys
,
std
::
vector
<
float
>
&
vals
);
public
:
...
...
@@ -75,6 +75,10 @@ public:
std
::
vector
<
String
>
densityGridKeys
;
std
::
vector
<
String
>
pmfKeys
;
std
::
vector
<
String
>
potentialGridFiles
;
std
::
vector
<
String
>
densityGridFiles
;
std
::
vector
<
String
>
pmfFiles
;
std
::
vector
<
String
>
potentialGridScaleKeys
;
std
::
vector
<
String
>
densityGridScaleKeys
;
std
::
vector
<
String
>
pmfScaleKeys
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment