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
cb0d7c26
Commit
cb0d7c26
authored
6 years ago
by
lhausamm
Committed by
Loic Hausammann
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add function giving scale factor from time
parent
81cf00f7
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!560
Output time from a file
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cosmology.c
+41
-0
41 additions, 0 deletions
src/cosmology.c
src/cosmology.h
+2
-0
2 additions, 0 deletions
src/cosmology.h
with
43 additions
and
0 deletions
src/cosmology.c
+
41
−
0
View file @
cb0d7c26
...
...
@@ -650,6 +650,47 @@ double cosmology_get_a_from_z(const struct cosmology *c, double redshift) {
return
1
.
/
(
1
.
+
redshift
);
}
/**
* @brief Compute scale factor from time since big bang.
*
* WARNING: This function is slow, therefore it should not be called more than
* once per time step.
*
* Find the scale factor from the time since big bang using the bisection method
* on $ t - f(a) = 0 $ where $ f(a) $ is #cosmology_get_time_since_big_bang
*
* By knowing that this function is a decreasing monotonic function, we can
* avoid a few checks.
*
* @param cosmo The current #cosmology.
* @param t since the big bang
* @return The scale factor.
*/
double
cosmology_get_scale_factor
(
const
struct
cosmology
*
cosmo
,
double
t
)
{
/* convergence limit and current error */
const
double
limit
=
1e-8
;
double
eps
=
1
.;
/* limits in scale factor */
double
a_low
=
1e-9
;
double
a_up
=
1
.;
/* do the bisection method */
while
(
eps
>
limit
)
{
double
a_tmp
=
0
.
5
*
(
a_low
+
a_up
);
double
f_tmp
=
t
-
cosmology_get_time_since_big_bang
(
cosmo
,
a_tmp
);
if
(
f_tmp
>
0
)
a_low
=
a_tmp
;
else
a_up
=
a_tmp
;
eps
=
a_up
-
a_low
;
}
return
0
.
5
*
(
a_low
+
a_up
);
}
/**
* @brief Prints the #cosmology model to stdout.
*/
...
...
This diff is collapsed.
Click to expand it.
src/cosmology.h
+
2
−
0
View file @
cb0d7c26
...
...
@@ -186,6 +186,8 @@ double cosmology_get_delta_time(const struct cosmology *c, double a1,
double
cosmology_get_a_from_z
(
const
struct
cosmology
*
c
,
double
redshift
);
double
cosmology_get_scale_factor
(
const
struct
cosmology
*
cosmo
,
double
t
);
double
cosmology_get_time_since_big_bang
(
const
struct
cosmology
*
c
,
double
a
);
void
cosmology_init
(
struct
swift_params
*
params
,
const
struct
unit_system
*
us
,
const
struct
phys_const
*
phys_const
,
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