Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
43b7823b
Commit
43b7823b
authored
8 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Added function pointers to test function so the force interaction can also be tested.
parent
fa504958
No related branches found
No related tags found
1 merge request
!204
Intrinsic vectorisation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/testNonSymInt.c
+56
-22
56 additions, 22 deletions
tests/testNonSymInt.c
with
56 additions
and
22 deletions
tests/testNonSymInt.c
+
56
−
22
View file @
43b7823b
...
@@ -24,8 +24,8 @@
...
@@ -24,8 +24,8 @@
#include
<unistd.h>
#include
<unistd.h>
#include
"swift.h"
#include
"swift.h"
char
*
serial_filename
=
"test_nonsym_serial.dat"
;
typedef
void
(
*
serial_interaction
)(
float
,
float
*
,
float
,
float
,
struct
part
*
,
struct
part
*
)
;
char
*
vec_filename
=
"test_nonsym_vec.dat"
;
typedef
void
(
*
vec_interaction
)(
float
*
,
float
*
,
float
*
,
float
*
,
struct
part
**
,
struct
part
**
)
;
/**
/**
* @brief Constructs an array of particles in a valid state prior to
* @brief Constructs an array of particles in a valid state prior to
...
@@ -67,6 +67,20 @@ struct part *make_particles(int count, double *offset, double spacing, double h,
...
@@ -67,6 +67,20 @@ struct part *make_particles(int count, double *offset, double spacing, double h,
return
particles
;
return
particles
;
}
}
/**
* @brief Populates particle properties needed for the force calculation.
*/
void
prepare_force
(
struct
part
*
parts
)
{
struct
part
p
;
for
(
size_t
i
=
0
;
i
<
VEC_SIZE
+
1
;
++
i
)
{
p
=
parts
[
i
];
p
.
rho
=
i
;
p
.
force
.
balsara
=
i
;
p
.
force
.
P_over_rho2
=
i
;
}
}
/**
/**
* @brief Dumps all particle information to a file
* @brief Dumps all particle information to a file
*/
*/
...
@@ -76,20 +90,21 @@ void dump_indv_particle_fields(char *fileName, struct part *p) {
...
@@ -76,20 +90,21 @@ void dump_indv_particle_fields(char *fileName, struct part *p) {
fprintf
(
fprintf
(
file
,
file
,
"%6llu %10f %10f %10f %10f %10f %10f %13e %13e %13e %13e %13e "
"%6llu %10f %10f %10f %10f %10f %10f
%10f %10f %10f %13e %13e
%13e %13e %13e %13e %13e "
"%13e %13e %13e
\n
"
,
"%13e %13e %13e
%10f
\n
"
,
p
->
id
,
p
->
x
[
0
],
p
->
x
[
1
],
p
->
id
,
p
->
x
[
0
],
p
->
x
[
1
],
p
->
x
[
2
],
p
->
v
[
0
],
p
->
v
[
1
],
p
->
x
[
2
],
p
->
v
[
0
],
p
->
v
[
1
],
p
->
v
[
2
],
p
->
rho
,
p
->
rho_dh
,
p
->
v
[
2
],
p
->
a_hydro
[
0
],
p
->
a_hydro
[
1
],
p
->
density
.
wcount
,
p
->
density
.
wcount_dh
,
p
->
a_hydro
[
2
],
p
->
rho
,
p
->
rho_dh
,
p
->
density
.
wcount
,
p
->
density
.
wcount_dh
,
p
->
h_dt
,
p
->
force
.
v_sig
,
#if defined(GADGET2_SPH)
#if defined(GADGET2_SPH)
p
->
div_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
div_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
]
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
]
,
p
->
force
.
entropy_dt
#elif defined(DEFAULT_SPH)
#elif defined(DEFAULT_SPH)
p
->
density
.
div_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
div_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
]
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
]
,
0
.
#else
#else
0
.,
0
.,
0
.,
0
.
0
.,
0
.,
0
.,
0
.
,
0
.,
0
.,
0
.,
0
.,
0
.,
0
.
#endif
#endif
);
);
fclose
(
file
);
fclose
(
file
);
...
@@ -103,10 +118,10 @@ void write_header(char *fileName) {
...
@@ -103,10 +118,10 @@ void write_header(char *fileName) {
FILE
*
file
=
fopen
(
fileName
,
"w"
);
FILE
*
file
=
fopen
(
fileName
,
"w"
);
/* Write header */
/* Write header */
fprintf
(
file
,
fprintf
(
file
,
"# %4s %10s %10s %10s %10s %10s %10s %13s %13s %13s %13s %13s "
"# %4s %10s %10s %10s %10s %10s %10s
%10s %10s %10s
%13s %13s %13s %13s %13s
%13s %13s
"
"%13s %13s %13s
\n
"
,
"%13s %13s
%13s
%13s
\n
"
,
"ID"
,
"pos_x"
,
"pos_y"
,
"pos_z"
,
"v_x"
,
"v_y"
,
"v_z"
,
"rho"
,
"rho_dh"
,
"ID"
,
"pos_x"
,
"pos_y"
,
"pos_z"
,
"v_x"
,
"v_y"
,
"v_z"
,
"a_x"
,
"a_y"
,
"a_z"
,
"rho"
,
"rho_dh"
,
"wcount"
,
"wcount_dh"
,
"div_v"
,
"curl_vx"
,
"curl_vy"
,
"curl_vz"
);
"wcount"
,
"wcount_dh"
,
"dh/dt"
,
"v_sig"
,
"div_v"
,
"curl_vx"
,
"curl_vy"
,
"curl_vz"
,
"dS/dt"
);
fprintf
(
file
,
"
\n
PARTICLES BEFORE INTERACTION:
\n
"
);
fprintf
(
file
,
"
\n
PARTICLES BEFORE INTERACTION:
\n
"
);
fclose
(
file
);
fclose
(
file
);
}
}
...
@@ -118,12 +133,20 @@ void write_header(char *fileName) {
...
@@ -118,12 +133,20 @@ void write_header(char *fileName) {
* @param count No. of particles to be interacted
* @param count No. of particles to be interacted
*
*
*/
*/
void
test_
nonsym_density_
interaction
(
struct
part
*
parts
,
int
count
)
{
void
test_interaction
s
(
struct
part
*
parts
,
int
count
,
serial_interaction
serial_inter_func
,
vec_interaction
vec_inter_func
,
char
*
filePrefix
)
{
/* Use the first particle in the array as the one that gets updated. */
/* Use the first particle in the array as the one that gets updated. */
struct
part
pi
=
parts
[
0
];
struct
part
pi
=
parts
[
0
];
FILE
*
file
;
FILE
*
file
;
char
serial_filename
[
200
]
=
""
;
char
vec_filename
[
200
]
=
""
;
strcpy
(
serial_filename
,
filePrefix
);
strcpy
(
vec_filename
,
filePrefix
);
sprintf
(
serial_filename
+
strlen
(
serial_filename
),
"_serial.dat"
);
sprintf
(
vec_filename
+
strlen
(
vec_filename
),
"_vec.dat"
);
write_header
(
serial_filename
);
write_header
(
serial_filename
);
write_header
(
vec_filename
);
write_header
(
vec_filename
);
...
@@ -154,7 +177,7 @@ void test_nonsym_density_interaction(struct part *parts, int count) {
...
@@ -154,7 +177,7 @@ void test_nonsym_density_interaction(struct part *parts, int count) {
r2
+=
dx
[
k
]
*
dx
[
k
];
r2
+=
dx
[
k
]
*
dx
[
k
];
}
}
runn
er
_
ia
ct_nonsym_density
(
r2
,
dx
,
pi
.
h
,
parts
[
i
].
h
,
&
pi
,
&
parts
[
i
]);
s
eria
l_inter_func
(
r2
,
dx
,
pi
.
h
,
parts
[
i
].
h
,
&
pi
,
&
parts
[
i
]);
}
}
file
=
fopen
(
serial_filename
,
"a"
);
file
=
fopen
(
serial_filename
,
"a"
);
...
@@ -191,7 +214,7 @@ void test_nonsym_density_interaction(struct part *parts, int count) {
...
@@ -191,7 +214,7 @@ void test_nonsym_density_interaction(struct part *parts, int count) {
dump_indv_particle_fields
(
vec_filename
,
pjq
[
i
]);
dump_indv_particle_fields
(
vec_filename
,
pjq
[
i
]);
/* Perform vector interaction. */
/* Perform vector interaction. */
runner_iact_nonsym_vec_density
(
r2q
,
dxq
,
hiq
,
hjq
,
piq
,
pjq
);
vec_inter_func
(
r2q
,
dxq
,
hiq
,
hjq
,
piq
,
pjq
);
file
=
fopen
(
vec_filename
,
"a"
);
file
=
fopen
(
vec_filename
,
"a"
);
fprintf
(
file
,
"
\n
PARTICLES AFTER INTERACTION:
\n
"
);
fprintf
(
file
,
"
\n
PARTICLES AFTER INTERACTION:
\n
"
);
...
@@ -234,19 +257,30 @@ int main(int argc, char *argv[]) {
...
@@ -234,19 +257,30 @@ int main(int argc, char *argv[]) {
"
\n
These are then interacted using runner_iact_density and runner_iact_vec_density."
"
\n
These are then interacted using runner_iact_density and runner_iact_vec_density."
"
\n\n
Options:"
"
\n\n
Options:"
"
\n
-h DISTANCE=1.2348 - Smoothing length in units of <x>"
"
\n
-h DISTANCE=1.2348 - Smoothing length in units of <x>"
"
\n
-s spacing - Spacing between particles"
"
\n
-s spacing - Spacing between particles"
,
"
\n
-v type (0,1,2,3) - Velocity field: (zero, random, divergent, "
"rotating)"
,
argv
[
0
]);
argv
[
0
]);
exit
(
1
);
exit
(
1
);
}
}
/* Define which interactions to call */
serial_interaction
serial_inter_func
=
&
runner_iact_nonsym_density
;
vec_interaction
vec_inter_func
=
&
runner_iact_nonsym_vec_density
;
/* Build the infrastructure */
/* Build the infrastructure */
static
long
long
partId
=
0
;
static
long
long
partId
=
0
;
struct
part
*
particles
=
make_particles
(
count
,
offset
,
spacing
,
h
,
&
partId
);
struct
part
*
density_particles
=
make_particles
(
count
,
offset
,
spacing
,
h
,
&
partId
);
struct
part
*
force_particles
=
make_particles
(
count
,
offset
,
spacing
,
h
,
&
partId
);
prepare_force
(
force_particles
);
/* Call the test non-sym density test. */
/* Call the test non-sym density test. */
test_
nonsym_density_interaction
(
particles
,
count
);
test_
interactions
(
density_particles
,
count
,
serial_inter_func
,
vec_inter_func
,
"test_nonsym_density"
);
/* Re-assign function pointers. */
serial_inter_func
=
&
runner_iact_nonsym_force
;
vec_inter_func
=
&
runner_iact_nonsym_vec_force
;
/* Call the test non-sym force test. */
test_interactions
(
density_particles
,
count
,
serial_inter_func
,
vec_inter_func
,
"test_nonsym_force"
);
return
0
;
return
0
;
}
}
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