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
f79c7d7c
Commit
f79c7d7c
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Use a separate function to interpolate the cosmological time table.
parent
b5c5b5aa
No related branches found
No related tags found
1 merge request
!509
Cosmological time integration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cosmology.c
+38
-15
38 additions, 15 deletions
src/cosmology.c
with
38 additions
and
15 deletions
src/cosmology.c
+
38
−
15
View file @
f79c7d7c
...
...
@@ -35,9 +35,34 @@
#include
<gsl/gsl_integration.h>
#endif
/*! Number of values stored in the cosmological interpolation tables */
const
int
cosmology_table_length
=
10000
;
const
size_t
GSL_workspace_size
=
10000
;
/**
* @brief Returns the interpolated value from a table.
*
* Uses linear interpolation.
*
* @brief table The table of value to interpolate from (should be of length
* cosmology_table_length).
* @brief x The value to interpolate at.
* @brief x_min The mininum of the range of x.
* @brief x_max The maximum of the range of x.
*/
static
INLINE
double
interp_table
(
double
*
table
,
double
x
,
double
x_min
,
double
x_max
)
{
const
double
xx
=
((
x
-
x_min
)
/
(
x_max
-
x_min
))
*
cosmology_table_length
;
const
int
i
=
(
int
)
xx
;
const
int
ii
=
(
i
>=
cosmology_table_length
)
?
cosmology_table_length
-
1
:
i
;
if
(
ii
<=
1
)
return
table
[
0
]
*
xx
;
else
return
table
[
ii
-
1
]
+
(
table
[
ii
]
-
table
[
ii
-
1
])
*
(
xx
-
ii
);
}
/**
* @brief Compute \f$ E(z) \f$.
*/
...
...
@@ -48,22 +73,20 @@ static INLINE double E(double Or, double Om, double Ok, double Ol,
Ok
*
a_inv
*
a_inv
+
Ol
);
}
double
cosmology_get_time
(
const
struct
cosmology
*
c
,
double
a
)
{
const
double
log_a
=
log
(
a
);
/**
* @brief Returns the time (in internal units) since Big Bang at a given
* scale-factor.
*
* @param c The current #cosmology.
* @param a Scale-factor of interest.
*/
double
cosmology_get_time_since_big_bang
(
const
struct
cosmology
*
c
,
double
a
)
{
/* Position in the table */
const
double
x
=
((
log_a
-
c
->
log_a_begin
)
/
(
c
->
log_a_end
-
c
->
log_a_begin
))
*
cosmology_table_length
;
const
int
i
=
((
int
)
x
>=
cosmology_table_length
)
?
cosmology_table_length
-
1
:
(
int
)
x
;
/* Time between a_begin and a */
const
double
delta_t
=
interp_table
(
c
->
time_interp_table
,
log
(
a
),
c
->
log_a_begin
,
c
->
log_a_end
);
if
(
i
<=
1
)
return
c
->
time_interp_table_offset
+
x
*
c
->
time_interp_table
[
0
];
else
return
c
->
time_interp_table_offset
+
c
->
time_interp_table
[
i
-
1
]
+
(
c
->
time_interp_table
[
i
]
-
c
->
time_interp_table
[
i
-
1
])
*
(
x
-
i
);
return
c
->
time_interp_table_offset
+
delta_t
;
}
/**
...
...
@@ -94,7 +117,7 @@ void cosmology_update(struct cosmology *c, const struct engine *e) {
c
->
H
=
c
->
H0
*
E_z
;
/* Time since Big Bang */
c
->
time
=
cosmology_get_time
(
c
,
a
);
c
->
time
=
cosmology_get_time
_since_big_bang
(
c
,
a
);
}
void
cosmology_init_tables
(
struct
cosmology
*
c
)
{
...
...
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