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
3f7769ae
Commit
3f7769ae
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Revert to using the approximate exponential in the gravity long-range truncation.
parent
07f1e5b1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/approx_math.h
+12
-0
12 additions, 0 deletions
src/approx_math.h
src/kernel_long_gravity.h
+3
-3
3 additions, 3 deletions
src/kernel_long_gravity.h
tests/testPotentialSelf.c
+6
-3
6 additions, 3 deletions
tests/testPotentialSelf.c
with
21 additions
and
6 deletions
src/approx_math.h
+
12
−
0
View file @
3f7769ae
...
...
@@ -49,4 +49,16 @@ __attribute__((always_inline)) INLINE static float good_approx_expf(float x) {
x
*
((
1
.
f
/
120
.
f
)
+
(
1
.
f
/
720
.
f
)
*
x
)))));
}
/**
* @brief Approximate version of exp(x) using a 6th order Taylor expansion
*/
__attribute__
((
always_inline
))
INLINE
static
double
good_approx_exp
(
double
x
)
{
return
1
.
+
x
*
(
1
.
+
x
*
(
0
.
5
+
x
*
((
1
.
/
6
.)
+
x
*
((
1
.
/
24
.)
+
x
*
((
1
.
/
120
.)
+
(
1
.
/
720
.)
*
x
)))));
}
#endif
/* SWIFT_APPROX_MATH_H */
This diff is collapsed.
Click to expand it.
src/kernel_long_gravity.h
+
3
−
3
View file @
3f7769ae
...
...
@@ -49,7 +49,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
#else
const
float
x
=
2
.
f
*
u
;
const
float
exp_x
=
expf
(
x
);
const
float
exp_x
=
good_approx_
expf
(
x
);
const
float
alpha
=
1
.
f
/
(
1
.
f
+
exp_x
);
/* We want 2 - 2 exp(x) * alpha */
...
...
@@ -83,7 +83,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
#else
const
float
arg
=
2
.
f
*
u
;
const
float
exp_arg
=
expf
(
arg
);
const
float
exp_arg
=
good_approx_
expf
(
arg
);
const
float
term
=
1
.
f
/
(
1
.
f
+
exp_arg
);
*
W
=
arg
*
exp_arg
*
term
*
term
-
exp_arg
*
term
+
1
.
f
;
...
...
@@ -111,4 +111,4 @@ __attribute__((always_inline)) INLINE static void fourier_kernel_long_grav_eval(
#endif
}
#endif
/
/ SWIFT_KERNEL_LONG_GRAVITY_H
#endif
/
*
SWIFT_KERNEL_LONG_GRAVITY_H
*/
This diff is collapsed.
Click to expand it.
tests/testPotentialSelf.c
+
6
−
3
View file @
3f7769ae
...
...
@@ -41,15 +41,18 @@ const double eps = 0.02;
* @param s String used to identify this check in messages
*/
void
check_value
(
double
a
,
double
b
,
const
char
*
s
)
{
if
(
fabs
(
a
-
b
)
/
fabs
(
a
+
b
)
>
2
e-6
&&
fabs
(
a
-
b
)
>
1.e-6
)
if
(
fabs
(
a
-
b
)
/
fabs
(
a
+
b
)
>
1
e-6
&&
fabs
(
a
-
b
)
>
1.e-6
)
error
(
"Values are inconsistent: %12.15e %12.15e (%s)!"
,
a
,
b
,
s
);
}
/* Definitions of the potential and force that match
exactly the theory document */
double
S
(
double
x
)
{
return
exp
(
x
)
/
(
1
.
+
exp
(
x
));
}
double
S
(
double
x
)
{
return
good_approx_
exp
(
x
)
/
(
1
.
+
good_approx_
exp
(
x
));
}
double
S_prime
(
double
x
)
{
return
exp
(
x
)
/
((
1
.
+
exp
(
x
))
*
(
1
.
+
exp
(
x
)));
}
double
S_prime
(
double
x
)
{
return
good_approx_exp
(
x
)
/
((
1
.
+
good_approx_exp
(
x
))
*
(
1
.
+
good_approx_exp
(
x
)));
}
double
potential
(
double
mass
,
double
r
,
double
H
,
double
rlr
)
{
...
...
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