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
326102a4
Commit
326102a4
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Add support for the Gadget-2 softening choice.
parent
e04fdd9d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/plot_gravity_checks.py
+11
-3
11 additions, 3 deletions
examples/plot_gravity_checks.py
src/kernel_gravity.h
+48
-0
48 additions, 0 deletions
src/kernel_gravity.h
with
59 additions
and
3 deletions
examples/plot_gravity_checks.py
+
11
−
3
View file @
326102a4
...
@@ -72,6 +72,8 @@ exact_pos = exact_pos[sort_index, :]
...
@@ -72,6 +72,8 @@ exact_pos = exact_pos[sort_index, :]
exact_a
=
exact_a
[
sort_index
,
:]
exact_a
=
exact_a
[
sort_index
,
:]
exact_pot
=
exact_pot
[
sort_index
]
exact_pot
=
exact_pot
[
sort_index
]
exact_a_norm
=
np
.
sqrt
(
exact_a
[:,
0
]
**
2
+
exact_a
[:,
1
]
**
2
+
exact_a
[:,
2
]
**
2
)
exact_a_norm
=
np
.
sqrt
(
exact_a
[:,
0
]
**
2
+
exact_a
[:,
1
]
**
2
+
exact_a
[:,
2
]
**
2
)
print
"
Number of particles tested:
"
,
np
.
size
(
exact_ids
)
# Start the plot
# Start the plot
plt
.
figure
()
plt
.
figure
()
...
@@ -93,6 +95,7 @@ if len(gadget2_file_list) != 0:
...
@@ -93,6 +95,7 @@ if len(gadget2_file_list) != 0:
gadget2_ids
=
gadget2_ids
[
sort_index
]
gadget2_ids
=
gadget2_ids
[
sort_index
]
gadget2_pos
=
gadget2_pos
[
sort_index
,
:]
gadget2_pos
=
gadget2_pos
[
sort_index
,
:]
gadget2_a_exact
=
gadget2_a_exact
[
sort_index
,
:]
gadget2_a_exact
=
gadget2_a_exact
[
sort_index
,
:]
gadget2_exact_a_norm
=
np
.
sqrt
(
gadget2_a_exact
[:,
0
]
**
2
+
gadget2_a_exact
[:,
1
]
**
2
+
gadget2_a_exact
[:,
2
]
**
2
)
gadget2_a_grav
=
gadget2_a_grav
[
sort_index
,
:]
gadget2_a_grav
=
gadget2_a_grav
[
sort_index
,
:]
# Cross-checks
# Cross-checks
...
@@ -104,9 +107,14 @@ if len(gadget2_file_list) != 0:
...
@@ -104,9 +107,14 @@ if len(gadget2_file_list) != 0:
index
=
np
.
argmax
(
exact_pos
[:,
0
]
**
2
+
exact_pos
[:,
1
]
**
2
+
exact_pos
[:,
2
]
**
2
-
gadget2_pos
[:,
0
]
**
2
-
gadget2_pos
[:,
1
]
**
2
-
gadget2_pos
[:,
2
]
**
2
)
index
=
np
.
argmax
(
exact_pos
[:,
0
]
**
2
+
exact_pos
[:,
1
]
**
2
+
exact_pos
[:,
2
]
**
2
-
gadget2_pos
[:,
0
]
**
2
-
gadget2_pos
[:,
1
]
**
2
-
gadget2_pos
[:,
2
]
**
2
)
print
"
Gadget2 (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
exact (id=%d):
"
%
exact_ids
[
index
],
exact_pos
[
index
,:],
"
\n
"
print
"
Gadget2 (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
exact (id=%d):
"
%
exact_ids
[
index
],
exact_pos
[
index
,:],
"
\n
"
if
np
.
max
(
np
.
abs
(
exact_a
-
gadget2_a_exact
)
/
np
.
abs
(
gadget2_a_exact
))
>
2e-6
:
diff
=
np
.
abs
(
exact_a_norm
-
gadget2_exact_a_norm
)
/
np
.
abs
(
gadget2_exact_a_norm
)
print
"
Comparing different exact accelerations ! max difference:
"
max_diff
=
np
.
max
(
diff
)
index
=
np
.
argmax
(
exact_a
[:,
0
]
**
2
+
exact_a
[:,
1
]
**
2
+
exact_a
[:,
2
]
**
2
-
gadget2_a_exact
[:,
0
]
**
2
-
gadget2_a_exact
[:,
1
]
**
2
-
gadget2_a_exact
[:,
2
]
**
2
)
if
max_diff
>
2e-6
:
print
"
Comparing different exact accelerations !
"
print
"
Median=
"
,
np
.
median
(
diff
),
"
Mean=
"
,
np
.
mean
(
diff
),
"
99%=
"
,
np
.
percentile
(
diff
,
99
)
print
"
max difference ( relative diff =
"
,
max_diff
,
"
):
"
#index = np.argmax(exact_a[:,0]**2 + exact_a[:,1]**2 + exact_a[:,2]**2 - gadget2_a_exact[:,0]**2 - gadget2_a_exact[:,1]**2 - gadget2_a_exact[:,2]**2)
index
=
np
.
argmax
(
diff
)
print
"
a_exact --- Gadget2:
"
,
gadget2_a_exact
[
index
,:],
"
exact:
"
,
exact_a
[
index
,:]
print
"
a_exact --- Gadget2:
"
,
gadget2_a_exact
[
index
,:],
"
exact:
"
,
exact_a
[
index
,:]
print
"
pos --- Gadget2: (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
exact (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
\n
"
print
"
pos --- Gadget2: (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
exact (id=%d):
"
%
gadget2_ids
[
index
],
gadget2_pos
[
index
,:],
"
\n
"
...
...
This diff is collapsed.
Click to expand it.
src/kernel_gravity.h
+
48
−
0
View file @
326102a4
...
@@ -26,9 +26,17 @@
...
@@ -26,9 +26,17 @@
#include
"inline.h"
#include
"inline.h"
#include
"minmax.h"
#include
"minmax.h"
//#define GADGET2_SOFTENING_CORRECTION
#ifdef GADGET2_SOFTENING_CORRECTION
/*! Conversion factor between Plummer softening and internal softening */
#define kernel_gravity_softening_plummer_equivalent 2.8
#define kernel_gravity_softening_plummer_equivalent_inv (1. / 2.8)
#else
/*! Conversion factor between Plummer softening and internal softening */
/*! Conversion factor between Plummer softening and internal softening */
#define kernel_gravity_softening_plummer_equivalent 3.
#define kernel_gravity_softening_plummer_equivalent 3.
#define kernel_gravity_softening_plummer_equivalent_inv (1. / 3.)
#define kernel_gravity_softening_plummer_equivalent_inv (1. / 3.)
#endif
/* GADGET2_SOFTENING_CORRECTION */
/**
/**
* @brief Computes the gravity softening function for potential.
* @brief Computes the gravity softening function for potential.
...
@@ -41,6 +49,15 @@
...
@@ -41,6 +49,15 @@
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_pot_eval
(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_pot_eval
(
float
u
,
float
*
const
W
)
{
float
u
,
float
*
const
W
)
{
#ifdef GADGET2_SOFTENING_CORRECTION
if
(
u
<
0
.
5
f
)
*
W
=
-
2
.
8
f
+
u
*
u
*
(
5
.
333333333333
f
+
u
*
u
*
(
6
.
4
f
*
u
-
9
.
6
f
));
else
*
W
=
-
3
.
2
f
+
0
.
066666666667
f
/
u
+
u
*
u
*
(
10
.
666666666667
f
+
u
*
(
-
16
.
f
+
u
*
(
9
.
6
f
-
2
.
133333333333
f
*
u
)));
#else
/* W(u) = 3u^7 - 15u^6 + 28u^5 - 21u^4 + 7u^2 - 3 */
/* W(u) = 3u^7 - 15u^6 + 28u^5 - 21u^4 + 7u^2 - 3 */
*
W
=
3
.
f
*
u
-
15
.
f
;
*
W
=
3
.
f
*
u
-
15
.
f
;
*
W
=
*
W
*
u
+
28
.
f
;
*
W
=
*
W
*
u
+
28
.
f
;
...
@@ -49,6 +66,7 @@ __attribute__((always_inline)) INLINE static void kernel_grav_pot_eval(
...
@@ -49,6 +66,7 @@ __attribute__((always_inline)) INLINE static void kernel_grav_pot_eval(
*
W
=
*
W
*
u
+
7
.
f
;
*
W
=
*
W
*
u
+
7
.
f
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
-
3
.
f
;
*
W
=
*
W
*
u
-
3
.
f
;
#endif
}
}
/**
/**
...
@@ -62,12 +80,21 @@ __attribute__((always_inline)) INLINE static void kernel_grav_pot_eval(
...
@@ -62,12 +80,21 @@ __attribute__((always_inline)) INLINE static void kernel_grav_pot_eval(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_force_eval
(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_force_eval
(
float
u
,
float
*
const
W
)
{
float
u
,
float
*
const
W
)
{
#ifdef GADGET2_SOFTENING_CORRECTION
if
(
u
<
0
.
5
f
)
*
W
=
10
.
6666667
f
+
u
*
u
*
(
32
.
f
*
u
-
38
.
4
f
);
else
*
W
=
21
.
3333333
f
-
48
.
f
*
u
+
38
.
4
f
*
u
*
u
-
10
.
6666667
f
*
u
*
u
*
u
-
0
.
06666667
f
/
(
u
*
u
*
u
);
#else
/* W(u) = 21u^5 - 90u^4 + 140u^3 - 84u^2 + 14 */
/* W(u) = 21u^5 - 90u^4 + 140u^3 - 84u^2 + 14 */
*
W
=
21
.
f
*
u
-
90
.
f
;
*
W
=
21
.
f
*
u
-
90
.
f
;
*
W
=
*
W
*
u
+
140
.
f
;
*
W
=
*
W
*
u
+
140
.
f
;
*
W
=
*
W
*
u
-
84
.
f
;
*
W
=
*
W
*
u
-
84
.
f
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
+
14
.
f
;
*
W
=
*
W
*
u
+
14
.
f
;
#endif
}
}
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
...
@@ -84,6 +111,15 @@ __attribute__((always_inline)) INLINE static void kernel_grav_force_eval(
...
@@ -84,6 +111,15 @@ __attribute__((always_inline)) INLINE static void kernel_grav_force_eval(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_eval_pot_double
(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_eval_pot_double
(
double
u
,
double
*
const
W
)
{
double
u
,
double
*
const
W
)
{
#ifdef GADGET2_SOFTENING_CORRECTION
if
(
u
<
0
.
5
)
*
W
=
-
2
.
8
+
u
*
u
*
(
5
.
333333333333
+
u
*
u
*
(
6
.
4
*
u
-
9
.
6
));
else
*
W
=
-
3
.
2
+
0
.
066666666667
/
u
+
u
*
u
*
(
10
.
666666666667
+
u
*
(
-
16
.
0
+
u
*
(
9
.
6
-
2
.
133333333333
*
u
)));
#else
/* W(u) = 3u^7 - 15u^6 + 28u^5 - 21u^4 + 7u^2 - 3 */
/* W(u) = 3u^7 - 15u^6 + 28u^5 - 21u^4 + 7u^2 - 3 */
*
W
=
3
.
*
u
-
15
.;
*
W
=
3
.
*
u
-
15
.;
*
W
=
*
W
*
u
+
28
.;
*
W
=
*
W
*
u
+
28
.;
...
@@ -92,6 +128,7 @@ __attribute__((always_inline)) INLINE static void kernel_grav_eval_pot_double(
...
@@ -92,6 +128,7 @@ __attribute__((always_inline)) INLINE static void kernel_grav_eval_pot_double(
*
W
=
*
W
*
u
+
7
.;
*
W
=
*
W
*
u
+
7
.;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
-
3
;
*
W
=
*
W
*
u
-
3
;
#endif
}
}
/**
/**
...
@@ -106,15 +143,26 @@ __attribute__((always_inline)) INLINE static void kernel_grav_eval_pot_double(
...
@@ -106,15 +143,26 @@ __attribute__((always_inline)) INLINE static void kernel_grav_eval_pot_double(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_eval_force_double
(
__attribute__
((
always_inline
))
INLINE
static
void
kernel_grav_eval_force_double
(
double
u
,
double
*
const
W
)
{
double
u
,
double
*
const
W
)
{
#ifdef GADGET2_SOFTENING_CORRECTION
if
(
u
<
0
.
5
)
*
W
=
10
.
666666666667
+
u
*
u
*
(
32
.
0
*
u
-
38
.
4
);
else
*
W
=
21
.
333333333333
-
48
.
0
*
u
+
38
.
4
*
u
*
u
-
10
.
666666666667
*
u
*
u
*
u
-
0
.
066666666667
/
(
u
*
u
*
u
);
#else
/* W(u) = 21u^5 - 90u^4 + 140u^3 - 84u^2 + 14 */
/* W(u) = 21u^5 - 90u^4 + 140u^3 - 84u^2 + 14 */
*
W
=
21
.
*
u
-
90
.;
*
W
=
21
.
*
u
-
90
.;
*
W
=
*
W
*
u
+
140
.;
*
W
=
*
W
*
u
+
140
.;
*
W
=
*
W
*
u
-
84
.;
*
W
=
*
W
*
u
-
84
.;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
;
*
W
=
*
W
*
u
+
14
.;
*
W
=
*
W
*
u
+
14
.;
#endif
}
}
#endif
/* SWIFT_GRAVITY_FORCE_CHECKS */
#endif
/* SWIFT_GRAVITY_FORCE_CHECKS */
#undef GADGET2_SOFTENING_CORRECTION
/************************************************/
/************************************************/
/* Derivatives of softening kernel used for FMM */
/* Derivatives of softening kernel used for FMM */
/************************************************/
/************************************************/
...
...
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