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
070221ab
Commit
070221ab
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Dump FMM and exact accelerations to a file for accuracy tests.
parent
9345183e
No related branches found
No related tags found
1 merge request
!324
Gravity multi dt
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/gravity.c
+35
-15
35 additions, 15 deletions
src/gravity.c
with
35 additions
and
15 deletions
src/gravity.c
+
35
−
15
View file @
070221ab
...
...
@@ -20,6 +20,9 @@
/* Config parameters. */
#include
"../config.h"
/* Some standard headers. */
#include
<stdio.h>
/* This object's header. */
#include
"gravity.h"
...
...
@@ -116,7 +119,7 @@ void gravity_exact_force_check(struct space *s, const struct engine *e,
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
//const double const_G = e->physical_constants->const_newton_G;
//
const double const_G = e->physical_constants->const_newton_G;
int
counter
=
0
;
...
...
@@ -127,6 +130,14 @@ void gravity_exact_force_check(struct space *s, const struct engine *e,
float
err_rel_mean2
=
0
.
f
;
float
err_rel_std
=
0
.
f
;
char
file_name
[
100
];
sprintf
(
file_name
,
"gravity_checks_step%d_order%d.dat"
,
e
->
step
,
SELF_GRAVITY_MULTIPOLE_ORDER
);
FILE
*
file
=
fopen
(
file_name
,
"w"
);
fprintf
(
file
,
"# id a_exact[0] a_exact[1] a_exact[2] a_grav[0] a_grav[1] a_grav[2]
\n
"
);
for
(
size_t
i
=
0
;
i
<
s
->
nr_gparts
;
++
i
)
{
struct
gpart
*
gpi
=
&
s
->
gparts
[
i
];
...
...
@@ -135,29 +146,35 @@ void gravity_exact_force_check(struct space *s, const struct engine *e,
if
(
gpi
->
id_or_neg_offset
%
SWIFT_GRAVITY_FORCE_CHECKS
==
0
&&
gpart_is_starting
(
gpi
,
e
))
{
fprintf
(
file
,
"%16lld %12.5e %12.5e %12.5e %12.5e %12.5e %12.5e
\n
"
,
gpi
->
id_or_neg_offset
,
gpi
->
a_grav_exact
[
0
],
gpi
->
a_grav_exact
[
1
],
gpi
->
a_grav_exact
[
2
],
gpi
->
a_grav
[
0
],
gpi
->
a_grav
[
1
],
gpi
->
a_grav
[
2
]);
const
float
diff
[
3
]
=
{
gpi
->
a_grav
[
0
]
-
gpi
->
a_grav_exact
[
0
],
gpi
->
a_grav
[
1
]
-
gpi
->
a_grav_exact
[
1
],
gpi
->
a_grav
[
2
]
-
gpi
->
a_grav_exact
[
2
]};
const
float
diff_norm
=
sqrtf
(
diff
[
0
]
*
diff
[
0
]
+
diff
[
1
]
*
diff
[
1
]
+
diff
[
2
]
*
diff
[
2
]);
const
float
a_norm
=
sqrtf
(
gpi
->
a_grav_exact
[
0
]
*
gpi
->
a_grav_exact
[
0
]
+
gpi
->
a_grav_exact
[
1
]
*
gpi
->
a_grav_exact
[
1
]
+
gpi
->
a_grav_exact
[
2
]
*
gpi
->
a_grav_exact
[
2
]);
gpi
->
a_grav
[
1
]
-
gpi
->
a_grav_exact
[
1
],
gpi
->
a_grav
[
2
]
-
gpi
->
a_grav_exact
[
2
]};
const
float
diff_norm
=
sqrtf
(
diff
[
0
]
*
diff
[
0
]
+
diff
[
1
]
*
diff
[
1
]
+
diff
[
2
]
*
diff
[
2
]);
const
float
a_norm
=
sqrtf
(
gpi
->
a_grav_exact
[
0
]
*
gpi
->
a_grav_exact
[
0
]
+
gpi
->
a_grav_exact
[
1
]
*
gpi
->
a_grav_exact
[
1
]
+
gpi
->
a_grav_exact
[
2
]
*
gpi
->
a_grav_exact
[
2
]);
/* Compute relative error */
const
float
err_rel
=
diff_norm
/
a_norm
;
/* Check that we are not above tolerance */
if
(
err_rel
>
rel_tol
)
{
message
(
"Error too large ! gp->a_grav=[%3.6e %3.6e %3.6e] gp->a_exact=[%3.6e %3.6e %3.6e], "
"Error too large ! gp->a_grav=[%3.6e %3.6e %3.6e] "
"gp->a_exact=[%3.6e %3.6e %3.6e], "
"gp->num_interacted=%lld, err=%f"
,
gpi
->
a_grav
[
0
],
gpi
->
a_grav
[
1
],
gpi
->
a_grav
[
2
],
gpi
->
a_grav_exact
[
0
],
gpi
->
a_grav_exact
[
1
],
gpi
->
a_grav_exact
[
2
],
gpi
->
num_interacted
,
err_rel
);
continue
;
continue
;
}
/* Construct some statistics */
...
...
@@ -169,6 +186,9 @@ void gravity_exact_force_check(struct space *s, const struct engine *e,
}
}
/* Be nice */
fclose
(
file
);
/* Final operation on the stats */
if
(
counter
>
0
)
{
err_rel_mean
/=
counter
;
...
...
@@ -178,8 +198,8 @@ void gravity_exact_force_check(struct space *s, const struct engine *e,
/* Report on the findings */
message
(
"Checked gravity for %d gparts."
,
counter
);
message
(
"Error on |a_grav|: min=%e max=%e mean=%e std=%e"
,
err_rel_min
,
err_rel_max
,
err_rel_mean
,
err_rel_std
);
message
(
"Error on |a_grav|: min=%e max=%e mean=%e std=%e"
,
err_rel_min
,
err_rel_max
,
err_rel_mean
,
err_rel_std
);
#else
error
(
"Gravity checking function called without the corresponding flag."
);
...
...
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