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
b5e886c9
Commit
b5e886c9
authored
6 years ago
by
Loic Hausammann
Browse files
Options
Downloads
Patches
Plain Diff
Fix a(t) in cosmo
parent
6d1e59da
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!592
Fix a(t) in cosmo
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cosmology.c
+29
-18
29 additions, 18 deletions
src/cosmology.c
tests/testCosmology.c
+2
-1
2 additions, 1 deletion
tests/testCosmology.c
with
31 additions
and
19 deletions
src/cosmology.c
+
29
−
18
View file @
b5e886c9
...
...
@@ -374,31 +374,45 @@ void cosmology_init_tables(struct cosmology *c) {
GSL_INTEG_GAUSS61
,
space
,
&
result
,
&
abserr
);
c
->
universe_age_at_present_day
=
result
;
/* Inverse t(a) */
const
double
time_init
=
c
->
time_interp_table_offset
;
/* Update the times */
c
->
time_begin
=
cosmology_get_time_since_big_bang
(
c
,
c
->
a_begin
);
c
->
time_end
=
cosmology_get_time_since_big_bang
(
c
,
c
->
a_end
);
/*
* Inverse t(a)
*/
const
double
delta_t
=
(
c
->
universe_age_at_present_day
-
time_init
)
/
cosmology_table_length
;
(
c
->
time_end
-
c
->
time_begin
)
/
cosmology_table_length
;
int
i_prev
=
0
;
for
(
int
i
=
0
;
i
<
cosmology_table_length
;
i
++
)
{
/* Current time */
double
time_interp
=
delta_t
*
i
;
/* index in the time_interp_table */
int
i_a
=
0
;
for
(
int
i_time
=
0
;
i_time
<
cosmology_table_length
;
i_time
++
)
{
/* Current time
* time_interp_table = \int_a_begin^a => no need of time_begin */
double
time_interp
=
delta_t
*
(
i_time
+
1
);
/* Find next time in time_interp_table */
while
(
i_
prev
<
cosmology_table_length
&&
c
->
time_interp_table
[
i_
prev
]
<=
time_interp
)
{
i_
prev
++
;
while
(
i_
a
<
cosmology_table_length
&&
c
->
time_interp_table
[
i_
a
]
<=
time_interp
)
{
i_
a
++
;
}
/* Find linear interpolation scaling */
double
scale
=
time_interp
-
c
->
time_interp_table
[
i_prev
-
1
];
scale
/=
c
->
time_interp_table
[
i_prev
]
-
c
->
time_interp_table
[
i_prev
-
1
];
scale
+=
i_prev
;
double
scale
=
0
;
if
(
i_a
!=
cosmology_table_length
)
{
scale
=
time_interp
-
c
->
time_interp_table
[
i_a
-
1
];
scale
/=
c
->
time_interp_table
[
i_a
]
-
c
->
time_interp_table
[
i_a
-
1
];
}
scale
+=
i_a
;
/* Compute interpolated scale factor */
double
log_a
=
c
->
log_a_begin
+
scale
*
(
c
->
log_a_end
-
c
->
log_a_begin
)
/
cosmology_table_length
;
c
->
scale_factor_interp_table
[
i
]
=
exp
(
log_a
)
-
c
->
a_begin
;
cosmology_table_length
;
c
->
scale_factor_interp_table
[
i
_time
]
=
exp
(
log_a
)
-
c
->
a_begin
;
}
/* Free the workspace and temp array */
...
...
@@ -672,9 +686,6 @@ double cosmology_get_delta_time(const struct cosmology *c,
/**
* @brief Compute scale factor from time since big bang (in internal units).
*
* WARNING: This method has a low accuracy at high redshift.
* The relative error is around 1e-3 (testCosmology.c is measuring it).
*
* @param c The current #cosmology.
* @param t time since the big bang
* @return The scale factor.
...
...
This diff is collapsed.
Click to expand it.
tests/testCosmology.c
+
2
−
1
View file @
b5e886c9
...
...
@@ -24,7 +24,7 @@
#include
"swift.h"
#define N_CHECK 20
#define TOLERANCE 1e-
3
#define TOLERANCE 1e-
7
void
test_params_init
(
struct
swift_params
*
params
)
{
parser_init
(
""
,
params
);
...
...
@@ -72,5 +72,6 @@ int main(int argc, char *argv[]) {
message
(
"Everything seems fine with cosmology."
);
cosmology_clean
(
&
cosmo
);
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