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
1f81ee19
Commit
1f81ee19
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Test the potential calculation also with the long-range truncation.
parent
bab1068c
No related branches found
No related tags found
1 merge request
!512
Gravitational potential
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/kernel_long_gravity.h
+2
-2
2 additions, 2 deletions
src/kernel_long_gravity.h
tests/testPotential.c
+47
-8
47 additions, 8 deletions
tests/testPotential.c
with
49 additions
and
10 deletions
src/kernel_long_gravity.h
+
2
−
2
View file @
1f81ee19
...
@@ -49,7 +49,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
...
@@ -49,7 +49,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
#else
#else
const
float
x
=
2
.
f
*
u
;
const
float
x
=
2
.
f
*
u
;
const
float
exp_x
=
good_approx_
expf
(
x
);
const
float
exp_x
=
expf
(
x
);
const
float
alpha
=
1
.
f
/
(
1
.
f
+
exp_x
);
const
float
alpha
=
1
.
f
/
(
1
.
f
+
exp_x
);
/* We want 2 - 2 exp(x) * alpha */
/* We want 2 - 2 exp(x) * alpha */
...
@@ -83,7 +83,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
...
@@ -83,7 +83,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
#else
#else
const
float
arg
=
2
.
f
*
u
;
const
float
arg
=
2
.
f
*
u
;
const
float
exp_arg
=
good_approx_
expf
(
arg
);
const
float
exp_arg
=
expf
(
arg
);
const
float
term
=
1
.
f
/
(
1
.
f
+
exp_arg
);
const
float
term
=
1
.
f
/
(
1
.
f
+
exp_arg
);
*
W
=
arg
*
exp_arg
*
term
*
term
-
exp_arg
*
term
+
1
.
f
;
*
W
=
arg
*
exp_arg
*
term
*
term
-
exp_arg
*
term
+
1
.
f
;
...
...
This diff is collapsed.
Click to expand it.
tests/testPotential.c
+
47
−
8
View file @
1f81ee19
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include
"../config.h"
#include
"../config.h"
/* Some standard headers. */
/* Some standard headers. */
#include
<math.h>
#include
<fenv.h>
#include
<fenv.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
...
@@ -30,25 +31,58 @@
...
@@ -30,25 +31,58 @@
#include
"runner_doiact_grav.h"
#include
"runner_doiact_grav.h"
const
int
num_tests
=
100
;
const
int
num_tests
=
100
;
const
double
eps
=
0
.
01
;
/* Definitions of the potential and force that match
exactly the theory document */
double
S
(
double
x
)
{
return
exp
(
x
)
/
(
1
.
+
exp
(
x
));
}
double
potential
(
double
r
,
double
H
,
double
rlr
)
{
const
double
u
=
r
/
H
;
const
double
x
=
r
/
rlr
;
double
pot
;
if
(
u
>
1
.)
pot
=
-
1
.
/
r
;
else
pot
=
-
(
-
3
.
*
u
*
u
*
u
*
u
*
u
*
u
*
u
+
15
.
*
u
*
u
*
u
*
u
*
u
*
u
-
28
.
*
u
*
u
*
u
*
u
*
u
+
21
.
*
u
*
u
*
u
*
u
-
7
.
*
u
*
u
+
3
.)
/
H
;
return
pot
*
(
2
.
-
2
.
*
S
(
2
.
*
x
));
}
int
main
()
{
int
main
()
{
/* Initialize CPU frequency, this also starts time. */
/* Initialize CPU frequency, this also starts time. */
unsigned
long
long
cpufreq
=
0
;
unsigned
long
long
cpufreq
=
0
;
clocks_set_cpufreq
(
cpufreq
);
clocks_set_cpufreq
(
cpufreq
);
/* Initialise a few things to get us going */
struct
engine
e
;
struct
engine
e
;
e
.
max_active_bin
=
num_time_bins
;
e
.
max_active_bin
=
num_time_bins
;
e
.
time
=
0
.
1
f
;
e
.
time
=
0
.
1
f
;
e
.
ti_current
=
8
;
e
.
ti_current
=
8
;
e
.
time
B
ase
=
1e-10
;
e
.
time
_b
ase
=
1e-10
;
struct
space
s
;
s
.
width
[
0
]
=
0
.
2
;
s
.
width
[
1
]
=
0
.
2
;
s
.
width
[
2
]
=
0
.
2
;
e
.
s
=
&
s
;
struct
gravity_props
props
;
props
.
a_smooth
=
1
.
25
;
e
.
gravity_properties
=
&
props
;
struct
runner
r
;
struct
runner
r
;
bzero
(
&
r
,
sizeof
(
struct
runner
));
bzero
(
&
r
,
sizeof
(
struct
runner
));
r
.
e
=
&
e
;
r
.
e
=
&
e
;
gravity_cache_init
(
&
r
.
ci_gravity_cache
,
num_tests
*
2
)
;
const
double
rlr
=
props
.
a_smooth
*
s
.
width
[
0
]
;
/* Init the cache for gravity interaction */
gravity_cache_init
(
&
r
.
ci_gravity_cache
,
num_tests
*
2
);
/* Let's create one cell with a massive particle and a bunch of test particles */
/* Let's create one cell with a massive particle and a bunch of test particles */
struct
cell
c
;
struct
cell
c
;
...
@@ -69,7 +103,7 @@ int main() {
...
@@ -69,7 +103,7 @@ int main() {
c
.
gparts
[
0
].
x
[
1
]
=
0
.
5
;
c
.
gparts
[
0
].
x
[
1
]
=
0
.
5
;
c
.
gparts
[
0
].
x
[
2
]
=
0
.
5
;
c
.
gparts
[
0
].
x
[
2
]
=
0
.
5
;
c
.
gparts
[
0
].
mass
=
1
.;
c
.
gparts
[
0
].
mass
=
1
.;
c
.
gparts
[
0
].
epsilon
=
0
.
;
c
.
gparts
[
0
].
epsilon
=
eps
;
c
.
gparts
[
0
].
time_bin
=
1
;
c
.
gparts
[
0
].
time_bin
=
1
;
c
.
gparts
[
0
].
type
=
swift_type_dark_matter
;
c
.
gparts
[
0
].
type
=
swift_type_dark_matter
;
c
.
gparts
[
0
].
id_or_neg_offset
=
1
;
c
.
gparts
[
0
].
id_or_neg_offset
=
1
;
...
@@ -86,19 +120,24 @@ int main() {
...
@@ -86,19 +120,24 @@ int main() {
gp
->
x
[
1
]
=
0
.
5
;
gp
->
x
[
1
]
=
0
.
5
;
gp
->
x
[
2
]
=
0
.
5
;
gp
->
x
[
2
]
=
0
.
5
;
gp
->
mass
=
0
.;
gp
->
mass
=
0
.;
gp
->
epsilon
=
0
.
;
gp
->
epsilon
=
eps
;
gp
->
time_bin
=
1
;
gp
->
time_bin
=
1
;
gp
->
type
=
swift_type_dark_matter
;
gp
->
type
=
swift_type_dark_matter
;
gp
->
id_or_neg_offset
=
n
+
1
;
gp
->
id_or_neg_offset
=
n
+
1
;
#ifdef SWIFT_DEBUG_CHECKS
#ifdef SWIFT_DEBUG_CHECKS
gp
->
ti_drift
=
8
;
gp
->
ti_drift
=
8
;
#endif
#endif
}
}
/* Now compute the forces */
/* Now compute the forces */
runner_doself_grav_pp_full
(
&
r
,
&
c
);
runner_doself_grav_pp_truncated
(
&
r
,
&
c
);
for
(
int
n
=
1
;
n
<
num_tests
+
1
;
++
n
)
{
const
struct
gpart
*
gp
=
&
c
.
gparts
[
n
];
message
(
"x=%f pot=%f true=%f"
,
gp
->
x
[
0
],
gp
->
potential
,
potential
(
gp
->
x
[
0
],
gp
->
epsilon
,
rlr
));
}
free
(
c
.
gparts
);
free
(
c
.
gparts
);
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