Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
9bdbc12d
Commit
9bdbc12d
authored
Oct 04, 2017
by
James Willis
Browse files
testActivePair now tests the same scenarios for dopair2.
parent
c815239e
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/testActivePair.c
View file @
9bdbc12d
...
...
@@ -29,6 +29,9 @@
/* Local headers. */
#include
"swift.h"
/* Typdef function pointer for interaction function. */
typedef
void
(
*
interaction_func
)(
struct
runner
*
,
struct
cell
*
,
struct
cell
*
);
/**
* @brief Constructs a cell and all of its particle in a valid state prior to
* a DOPAIR or DOSELF calcuation.
...
...
@@ -108,6 +111,12 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
else
part
->
time_bin
=
num_time_bins
+
1
;
part
->
rho
=
1
.
f
;
part
->
force
.
f
=
1
.
f
;
part
->
force
.
P_over_rho2
=
1
.
f
;
part
->
force
.
balsara
=
1
.
f
;
part
->
force
.
soundspeed
=
1
.
f
;
#ifdef SWIFT_DEBUG_CHECKS
part
->
ti_drift
=
8
;
part
->
ti_kick
=
8
;
...
...
@@ -156,6 +165,11 @@ void clean_up(struct cell *ci) {
void
zero_particle_fields
(
struct
cell
*
c
)
{
for
(
int
pid
=
0
;
pid
<
c
->
count
;
pid
++
)
{
hydro_init_part
(
&
c
->
parts
[
pid
],
NULL
);
c
->
parts
[
pid
].
rho
=
1
.
f
;
c
->
parts
[
pid
].
force
.
f
=
1
.
f
;
c
->
parts
[
pid
].
force
.
P_over_rho2
=
1
.
f
;
c
->
parts
[
pid
].
force
.
balsara
=
1
.
f
;
c
->
parts
[
pid
].
force
.
soundspeed
=
1
.
f
;
}
}
...
...
@@ -179,20 +193,22 @@ void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) {
FILE
*
file
=
fopen
(
fileName
,
"a"
);
/* Write header */
fprintf
(
file
,
"# %4s %13s
\n
"
,
"ID"
,
"wcount"
);
fprintf
(
file
,
"# %4s
%13s
%13s
\n
"
,
"ID"
,
"wcount"
,
"h_dt"
);
fprintf
(
file
,
"# ci --------------------------------------------
\n
"
);
for
(
int
pid
=
0
;
pid
<
ci
->
count
;
pid
++
)
{
fprintf
(
file
,
"%6llu %13e
\n
"
,
ci
->
parts
[
pid
].
id
,
ci
->
parts
[
pid
].
density
.
wcount
);
fprintf
(
file
,
"%6llu %13e %13e
\n
"
,
ci
->
parts
[
pid
].
id
,
ci
->
parts
[
pid
].
density
.
wcount
,
ci
->
parts
[
pid
].
force
.
h_dt
);
}
fprintf
(
file
,
"# cj --------------------------------------------
\n
"
);
for
(
int
pjd
=
0
;
pjd
<
cj
->
count
;
pjd
++
)
{
fprintf
(
file
,
"%6llu %13e
\n
"
,
cj
->
parts
[
pjd
].
id
,
cj
->
parts
[
pjd
].
density
.
wcount
);
fprintf
(
file
,
"%6llu %13e %13e
\n
"
,
cj
->
parts
[
pjd
].
id
,
cj
->
parts
[
pjd
].
density
.
wcount
,
cj
->
parts
[
pjd
].
force
.
h_dt
);
}
fclose
(
file
);
...
...
@@ -200,6 +216,7 @@ void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) {
/* Just a forward declaration... */
void
runner_dopair1_density
(
struct
runner
*
r
,
struct
cell
*
ci
,
struct
cell
*
cj
);
void
runner_dopair2_force_vec
(
struct
runner
*
r
,
struct
cell
*
ci
,
struct
cell
*
cj
);
void
runner_doself1_density_vec
(
struct
runner
*
r
,
struct
cell
*
ci
);
void
runner_dopair1_branch_density
(
struct
runner
*
r
,
struct
cell
*
ci
,
struct
cell
*
cj
);
...
...
@@ -210,7 +227,7 @@ void runner_dopair1_branch_density(struct runner *r, struct cell *ci,
*/
void
test_pair_interactions
(
struct
runner
*
runner
,
struct
cell
**
ci
,
struct
cell
**
cj
,
char
*
swiftOutputFileName
,
char
*
bruteForceOutputFileName
)
{
char
*
bruteForceOutputFileName
,
interaction_func
serial_interaction
,
interaction_func
vec_interaction
)
{
runner_do_sort
(
runner
,
*
ci
,
0x1FFF
,
0
,
0
);
runner_do_sort
(
runner
,
*
cj
,
0x1FFF
,
0
,
0
);
...
...
@@ -220,7 +237,7 @@ void test_pair_interactions(struct runner *runner, struct cell **ci,
zero_particle_fields
(
*
cj
);
/* Run the test */
runner_dopair1_branch_density
(
runner
,
*
ci
,
*
cj
);
vec_interaction
(
runner
,
*
ci
,
*
cj
);
/* Let's get physical ! */
end_calculation
(
*
ci
);
...
...
@@ -236,7 +253,7 @@ void test_pair_interactions(struct runner *runner, struct cell **ci,
zero_particle_fields
(
*
cj
);
/* Run the brute-force test */
pairs_all_density
(
runner
,
*
ci
,
*
cj
);
serial_interaction
(
runner
,
*
ci
,
*
cj
);
/* Let's get physical ! */
end_calculation
(
*
ci
);
...
...
@@ -253,7 +270,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
double
rho
,
long
long
*
partId
,
double
perturbation
,
double
h_pert
,
char
*
swiftOutputFileName
,
char
*
bruteForceOutputFileName
)
{
char
*
bruteForceOutputFileName
,
interaction_func
serial_interaction
,
interaction_func
vec_interaction
)
{
double
offset1
[
3
]
=
{
0
,
0
,
0
};
struct
cell
*
ci
,
*
cj
;
...
...
@@ -265,7 +282,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
1
.);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -277,7 +294,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
1
.);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -289,7 +306,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.
5
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -301,7 +318,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -313,7 +330,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.
1
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -325,7 +342,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -337,7 +354,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
1
.
0
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -347,7 +364,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
cj
=
make_cell
(
2
,
offset2
,
size
,
h
,
rho
,
partId
,
perturbation
,
h_pert
,
1
.
0
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -357,7 +374,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
cj
=
make_cell
(
3
,
offset2
,
size
,
h
,
rho
,
partId
,
perturbation
,
h_pert
,
0
.
75
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -369,7 +386,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
clean_up
(
ci
);
clean_up
(
cj
);
...
...
@@ -381,7 +398,7 @@ void test_all_pair_interactions(struct runner *runner, double *offset2,
0
.
5
);
test_pair_interactions
(
runner
,
&
ci
,
&
cj
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_interaction
,
vec_interaction
);
/* Clean things to make the sanitizer happy ... */
clean_up
(
ci
);
...
...
@@ -406,7 +423,7 @@ int main(int argc, char *argv[]) {
clocks_set_cpufreq
(
cpufreq
);
/* Choke on FP-exceptions */
feenableexcept
(
FE_DIVBYZERO
|
FE_INVALID
|
FE_OVERFLOW
);
//
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
/* Generate a RNG seed from time. */
unsigned
int
seed
=
time
(
NULL
);
...
...
@@ -482,7 +499,7 @@ int main(int argc, char *argv[]) {
/* Create output file names. */
sprintf
(
swiftOutputFileName
,
"swift_dopair_%s.dat"
,
outputFileNameExtension
);
sprintf
(
bruteForceOutputFileName
,
"brute_force_%s.dat"
,
sprintf
(
bruteForceOutputFileName
,
"brute_force_
pair_
%s.dat"
,
outputFileNameExtension
);
/* Delete files if they already exist. */
...
...
@@ -498,10 +515,48 @@ int main(int argc, char *argv[]) {
double
offset
[
3
]
=
{
1
.,
0
.,
0
.};
/* Define which interactions to call */
interaction_func
serial_inter_func
=
&
pairs_all_density
;
interaction_func
vec_inter_func
=
&
runner_dopair1_branch_density
;
/* Test a pair of cells face-on. */
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
/* Test a pair of cells edge-on. */
offset
[
0
]
=
1
.;
offset
[
1
]
=
1
.;
offset
[
2
]
=
0
.;
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
/* Test a pair of cells corner-on. */
offset
[
0
]
=
1
.;
offset
[
1
]
=
1
.;
offset
[
2
]
=
1
.;
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
/* Re-assign function pointers. */
serial_inter_func
=
&
pairs_all_force
;
vec_inter_func
=
&
runner_dopair2_force_vec
;
/* Create new output file names. */
sprintf
(
swiftOutputFileName
,
"swift_dopair2_force_%s.dat"
,
outputFileNameExtension
);
sprintf
(
bruteForceOutputFileName
,
"brute_force_dopair2_%s.dat"
,
outputFileNameExtension
);
/* Delete files if they already exist. */
remove
(
swiftOutputFileName
);
remove
(
bruteForceOutputFileName
);
/* Test a pair of cells face-on. */
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
/* Test a pair of cells edge-on. */
offset
[
0
]
=
1
.;
...
...
@@ -509,7 +564,7 @@ int main(int argc, char *argv[]) {
offset
[
2
]
=
0
.;
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
/* Test a pair of cells corner-on. */
offset
[
0
]
=
1
.;
...
...
@@ -517,6 +572,6 @@ int main(int argc, char *argv[]) {
offset
[
2
]
=
1
.;
test_all_pair_interactions
(
runner
,
offset
,
particles
,
size
,
h
,
rho
,
&
partId
,
perturbation
,
h_pert
,
swiftOutputFileName
,
bruteForceOutputFileName
);
bruteForceOutputFileName
,
serial_inter_func
,
vec_inter_func
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment