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
fc71d4df
Commit
fc71d4df
authored
5 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Fix a race condition problem with the usage of the GSL for interpolating the cosmology tables.
parent
c4bf296b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cosmology.c
+18
-3
18 additions, 3 deletions
src/cosmology.c
tests/testIntegration.c
+1
-1
1 addition, 1 deletion
tests/testIntegration.c
with
19 additions
and
4 deletions
src/cosmology.c
+
18
−
3
View file @
fc71d4df
...
...
@@ -82,14 +82,17 @@ static INLINE double interp_table(const double *restrict y_table,
#ifdef SWIFT_DEBUG_CHECKS
if
(
ii
<=
1
)
error
(
"Wrong ii - too small!"
);
if
(
ii
>=
cosmology_table_length
-
1
)
error
(
"Wrong ii - too large!"
);
if
(
x
<
x_table
[
ii
-
2
]
||
x
>
x_table
[
ii
+
1
])
error
(
"Extrapolating not interpolating!"
);
#endif
/* Initialise the interpolation range with 4 data points
* The point of interest is in the range [ii - 1, ii] */
gsl_interp_init
(
poly
,
&
x_table
[
ii
-
2
],
&
y_table
[
ii
-
2
],
4
);
//
gsl_interp_init(poly, &x_table[ii - 2], &y_table[ii - 2], 4);
/* Interpolate! */
return
gsl_interp_eval
(
poly
,
&
x_table
[
ii
-
2
],
&
y_table
[
ii
-
2
],
x
,
acc
);
// return gsl_interp_eval(poly, &x_table[ii - 2], &y_table[ii - 2], x, acc);
return
y_table
[
ii
-
1
]
+
(
y_table
[
ii
]
-
y_table
[
ii
-
1
])
*
(
xx
-
ii
);
}
/**
...
...
@@ -351,7 +354,7 @@ void cosmology_init_tables(struct cosmology *c) {
/* We want to extend the tables on both sides so that we never
have to worry about edges when interpolating */
const
double
fac
=
1
.
+
1
0
.
/
((
double
)
cosmology_table_length
);
const
double
fac
=
1
.
+
1
6
.
/
((
double
)
cosmology_table_length
);
const
double
a_begin
=
c
->
a_begin
/
fac
;
const
double
a_end
=
c
->
a_end
*
fac
;
c
->
log_a_table_begin
=
log
(
a_begin
);
...
...
@@ -641,6 +644,8 @@ double cosmology_get_drift_factor(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
@@ -671,6 +676,8 @@ double cosmology_get_grav_kick_factor(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
@@ -702,6 +709,8 @@ double cosmology_get_hydro_kick_factor(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
@@ -733,6 +742,8 @@ double cosmology_get_corr_kick_factor(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
@@ -764,6 +775,8 @@ double cosmology_get_therm_kick_factor(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
@@ -814,6 +827,8 @@ double cosmology_get_delta_time(const struct cosmology *c,
if
(
ti_end
<
ti_start
)
error
(
"ti_end must be >= ti_start"
);
#endif
// if (ti_start == ti_end) return 0.;
const
double
log_a_start
=
c
->
log_a_begin
+
ti_start
*
c
->
time_base
;
const
double
log_a_end
=
c
->
log_a_begin
+
ti_end
*
c
->
time_base
;
...
...
This diff is collapsed.
Click to expand it.
tests/testIntegration.c
+
1
−
1
View file @
fc71d4df
...
...
@@ -160,7 +160,7 @@ int main(int argc, char *argv[]) {
message
(
"Sum error: %14e"
,
sum_err
);
message
(
"Mean error: %14e"
,
sum_err
/
num_steps
);
if
(
max_err
>
1e-
8
||
min_err
<
-
1e-
8
)
if
(
max_err
>
1e-
4
||
min_err
<
-
1e-
4
)
error
(
"Error too large to be acceptable"
);
}
...
...
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