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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
fedce813
Commit
fedce813
authored
May 12, 2020
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Use a more accurate approximation of erfc() in kernel_long_grav_derivatives()
parent
5c45d5b2
No related branches found
No related tags found
1 merge request
!1077
Improved multipole acceptance criterion (MAC)
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/kernel_long_gravity.h
+17
-2
17 additions, 2 deletions
src/kernel_long_gravity.h
tests/testKernelLongGrav.c
+1
-1
1 addition, 1 deletion
tests/testKernelLongGrav.c
with
18 additions
and
3 deletions
src/kernel_long_gravity.h
+
17
−
2
View file @
fedce813
...
@@ -83,9 +83,24 @@ kernel_long_grav_derivatives(const float r, const float r_s_inv,
...
@@ -83,9 +83,24 @@ kernel_long_grav_derivatives(const float r, const float r_s_inv,
const
float
u2
=
u
*
u
;
const
float
u2
=
u
*
u
;
const
float
u4
=
u2
*
u2
;
const
float
u4
=
u2
*
u2
;
const
float
e
=
expf
(
-
u2
);
/* Compute erfcf(u) using eq. 7.1.25 of
Abramowitz & Stegun, 1972. */
const
float
t
=
1
.
f
/
(
1
.
f
+
0
.
47047
f
*
u
);
/* 0.3480242 * t - 0.0958798 * t^2 + 0.7478556 * t^3 */
float
a
=
0
.
7478556
f
;
a
=
a
*
t
-
0
.
0958798
f
;
a
=
a
*
t
+
0
.
3480242
f
;
a
=
a
*
t
;
const
float
erfc_u
=
a
*
e
;
/* C = (1/sqrt(pi)) * expf(-u^2) */
/* C = (1/sqrt(pi)) * expf(-u^2) */
const
float
one_over_sqrt_pi
=
((
float
)(
M_2_SQRTPI
*
0
.
5
));
const
float
one_over_sqrt_pi
=
((
float
)(
M_2_SQRTPI
*
0
.
5
));
const
float
common_factor
=
one_over_sqrt_pi
*
e
xpf
(
-
u2
)
;
const
float
common_factor
=
one_over_sqrt_pi
*
e
;
/* (1/r_s)^n * C */
/* (1/r_s)^n * C */
const
float
r_s_inv_times_C
=
r_s_inv
*
common_factor
;
const
float
r_s_inv_times_C
=
r_s_inv
*
common_factor
;
...
@@ -102,7 +117,7 @@ kernel_long_grav_derivatives(const float r, const float r_s_inv,
...
@@ -102,7 +117,7 @@ kernel_long_grav_derivatives(const float r, const float r_s_inv,
#else
#else
/* erfc(u) */
/* erfc(u) */
derivs
->
chi_0
=
approx_erfcf
(
u
)
;
derivs
->
chi_0
=
erfc_u
;
#endif
#endif
/* (-1/r_s) * (1/sqrt(pi)) * expf(-u^2) */
/* (-1/r_s) * (1/sqrt(pi)) * expf(-u^2) */
...
...
This diff is collapsed.
Click to expand it.
tests/testKernelLongGrav.c
+
1
−
1
View file @
fedce813
...
@@ -65,7 +65,7 @@ int main(int argc, char* argv[]) {
...
@@ -65,7 +65,7 @@ int main(int argc, char* argv[]) {
// message("Testing r_s=%e", r_s);
// message("Testing r_s=%e", r_s);
/* Loop over some radii */
/* Loop over some radii */
for
(
double
i
=
-
2
;
i
<
1
;
i
+=
0
.
001
)
{
for
(
double
i
=
-
4
;
i
<
1
;
i
+=
0
.
001
)
{
/* Get a radius in the relevant range */
/* Get a radius in the relevant range */
const
double
r
=
exp10
(
i
)
*
r_s
;
const
double
r
=
exp10
(
i
)
*
r_s
;
...
...
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
sign in
to comment