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
61dcf239
Commit
61dcf239
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Make the gravity kernel testing script closer to the Gadget code.
parent
23741d2d
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
tests/testKernelGrav.c
+45
-36
45 additions, 36 deletions
tests/testKernelGrav.c
with
45 additions
and
36 deletions
tests/testKernelGrav.c
+
45
−
36
View file @
61dcf239
...
@@ -31,26 +31,31 @@
...
@@ -31,26 +31,31 @@
/**
/**
* @brief The Gadget-2 gravity kernel function
* @brief The Gadget-2 gravity kernel function
*
*
* Taken from Gadget-2.0.7's forcetree.c lines 2755-2800
*
* @param r The distance between particles
* @param r The distance between particles
* @param h The cut-off distance of the kernel
* @param h The cut-off distance of the kernel
*/
*/
float
gadget
(
float
r
,
float
h
)
{
float
gadget
(
float
r
,
float
epsilon
)
{
float
fac
;
const
float
r2
=
r
*
r
;
const
float
h
=
epsilon
;
if
(
r
>=
h
)
const
float
h_inv
=
1
.
f
/
h
;
fac
=
1
.
0
f
/
(
r2
*
r
);
else
{
const
float
u
=
r
*
h_inv
;
const
float
h_inv
=
1
.
/
h
;
const
float
h_inv3
=
h_inv
*
h_inv
*
h_inv
;
if
(
u
>=
1
)
{
const
float
u
=
r
*
h_inv
;
const
float
r_inv
=
1
.
/
r
;
return
r_inv
*
r_inv
*
r_inv
;
}
else
{
if
(
u
<
0
.
5
)
if
(
u
<
0
.
5
)
fac
=
h_inv3
*
(
10
.
666666666667
+
u
*
u
*
(
32
.
0
*
u
-
38
.
4
));
return
h_inv
*
h_inv
*
h_inv
*
(
10
.
666666666667
+
u
*
u
*
(
32
.
0
*
u
-
38
.
4
));
else
else
fac
=
return
h_inv
*
h_inv
*
h_inv
*
h_inv3
*
(
21
.
333333333333
-
48
.
0
*
u
+
38
.
4
*
u
*
u
-
(
21
.
333333333333
-
48
.
0
*
u
+
38
.
4
*
u
*
u
-
10
.
666666666667
*
u
*
u
*
u
-
0
.
066666666667
/
(
u
*
u
*
u
));
10
.
666666666667
*
u
*
u
*
u
-
0
.
066666666667
/
(
u
*
u
*
u
));
}
}
return
fac
;
}
}
int
main
()
{
int
main
()
{
...
@@ -61,20 +66,22 @@ int main() {
...
@@ -61,20 +66,22 @@ int main() {
for
(
int
k
=
1
;
k
<
numPoints
;
++
k
)
{
for
(
int
k
=
1
;
k
<
numPoints
;
++
k
)
{
const
float
r
=
(
r_max
*
k
)
/
numPoints
;
const
float
r
=
(
r_max
*
k
)
/
numPoints
;
const
float
u
=
r
/
h
;
const
float
gadget_w
=
gadget
(
r
,
h
);
const
float
gadget_w
=
gadget
(
r
,
h
);
const
float
h_inv
=
1
.
f
/
h
;
const
float
h_inv3
=
h_inv
*
h_inv
*
h_inv
;
const
float
u
=
r
*
h_inv
;
float
swift_w
;
float
swift_w
;
if
(
u
<
1
.)
{
if
(
r
>=
h
)
{
kernel_grav_eval
(
u
,
&
swift_w
);
swift_w
*=
(
1
/
(
h
*
h
*
h
));
}
else
{
swift_w
=
1
/
(
r
*
r
*
r
);
swift_w
=
1
/
(
r
*
r
*
r
);
}
else
{
kernel_grav_eval
(
u
,
&
swift_w
);
swift_w
*=
h_inv3
;
}
}
if
(
fabsf
(
gadget_w
-
swift_w
)
>
2
e-
7
)
{
if
(
fabsf
(
gadget_w
-
swift_w
)
>
1
e-
5
*
fabsf
(
gadget_w
)
)
{
printf
(
"%2d: r= %f h= %f u= %f Wg(r,h)= %f Ws(r,h)= %f
\n
"
,
k
,
r
,
h
,
u
,
printf
(
"%2d: r= %f h= %f u= %f Wg(r,h)= %f Ws(r,h)= %f
\n
"
,
k
,
r
,
h
,
u
,
gadget_w
,
swift_w
);
gadget_w
,
swift_w
);
...
@@ -87,28 +94,30 @@ int main() {
...
@@ -87,28 +94,30 @@ int main() {
printf
(
"
\n
All values are consistent
\n
"
);
printf
(
"
\n
All values are consistent
\n
"
);
/* Now test the long range function */
/* Now test the long range function */
const
float
a_smooth
=
4
.
5
f
;
/*
const float a_smooth = 4.5f;
*/
for
(
int
k
=
1
;
k
<
numPoints
;
++
k
)
{
/*
for (int k = 1; k < numPoints; ++k) {
*/
const
float
r
=
(
r_max
*
k
)
/
numPoints
;
/*
const float r = (r_max * k) / numPoints;
*/
const
float
u
=
r
/
a_smooth
;
/*
const float u = r / a_smooth;
*/
float
swift_w
;
/*
float swift_w;
*/
kernel_long_grav_eval
(
u
,
&
swift_w
);
/*
kernel_long_grav_eval(u, &swift_w);
*/
float
gadget_w
=
erfc
(
u
/
2
)
+
u
*
exp
(
-
u
*
u
/
4
)
/
sqrt
(
M_PI
);
/*
float gadget_w = erfc
f
(u / 2) + u * exp
f
(-u * u / 4) / sqrt
f
(M_PI);
*/
if
(
fabsf
(
gadget_w
-
swift_w
)
>
2
e-
7
)
{
/*
if (fabsf(gadget_w - swift_w) >
1
e-
4 * fabsf(gadget_w)) { */
printf
(
"%2d: r= %f r_lr= %f u= %f Ws(r)= %f Wg(r)= %f
\n
"
,
k
,
r
,
a_smooth
,
/* printf("%2d: r= %f r_lr= %f u= %f Ws(r)= %f Wg(r)= %f\n", k, r,
u
,
swift_w
,
gadget_w
);
* a_smooth, */
/* u, swift_w, gadget_w); */
printf
(
"Invalid value ! Gadget= %e, SWIFT= %e
\n
"
,
gadget_w
,
swift_w
);
/* printf("Invalid value ! Gadget= %e, SWIFT= %e\n", gadget_w, swift_w);
return
1
;
*/
}
/* return 1; */
}
/* } */
/* } */
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