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
2bfe2f88
Commit
2bfe2f88
authored
3 years ago
by
Mladen Ivkovic
Committed by
Matthieu Schaller
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Timeline unit tests
parent
14c9cfad
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!1548
Mayor Sync
,
!1543
Timeline unit tests
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
src/timeline.h
+22
-11
22 additions, 11 deletions
src/timeline.h
src/tools.c
+3
-1
3 additions, 1 deletion
src/tools.c
tests/Makefile.am
+4
-2
4 additions, 2 deletions
tests/Makefile.am
tests/testTimeline.c
+551
-0
551 additions, 0 deletions
tests/testTimeline.c
with
582 additions
and
15 deletions
.gitignore
+
2
−
1
View file @
2bfe2f88
...
@@ -179,6 +179,7 @@ tests/testHashmap
...
@@ -179,6 +179,7 @@ tests/testHashmap
tests/testNeutrinoCosmology
tests/testNeutrinoCosmology
tests/testNeutrinoFermiDirac
tests/testNeutrinoFermiDirac
tests/testLog
tests/testLog
tests/testTimeline
tests/*.png
tests/*.png
tests/*.txt
tests/*.txt
...
@@ -378,4 +379,4 @@ sympy-plots-for-*.tex/
...
@@ -378,4 +379,4 @@ sympy-plots-for-*.tex/
black_formatting_env
black_formatting_env
# vscode
# vscode
*.json
*.json
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/timeline.h
+
22
−
11
View file @
2bfe2f88
...
@@ -56,7 +56,7 @@ typedef int8_t timebin_t;
...
@@ -56,7 +56,7 @@ typedef int8_t timebin_t;
* @param bin The time bin of interest.
* @param bin The time bin of interest.
*/
*/
__attribute__
((
const
))
static
INLINE
integertime_t
__attribute__
((
const
))
static
INLINE
integertime_t
get_integer_timestep
(
timebin_t
bin
)
{
get_integer_timestep
(
const
timebin_t
bin
)
{
if
(
bin
<=
0
)
return
0
;
if
(
bin
<=
0
)
return
0
;
return
1LL
<<
(
bin
+
1
);
return
1LL
<<
(
bin
+
1
);
...
@@ -71,9 +71,11 @@ get_integer_timestep(timebin_t bin) {
...
@@ -71,9 +71,11 @@ get_integer_timestep(timebin_t bin) {
* We use a fast (but exact for any non-zero value) logarithm in base 2
* We use a fast (but exact for any non-zero value) logarithm in base 2
* calculation based on the bit representation of the number:
* calculation based on the bit representation of the number:
* log_2(x) = (number of bits in the type) - (number of leading 0-bits in x) - 1
* log_2(x) = (number of bits in the type) - (number of leading 0-bits in x) - 1
*
* @param time_step An integer time-step length.
*/
*/
__attribute__
((
const
))
static
INLINE
timebin_t
__attribute__
((
const
))
static
INLINE
timebin_t
get_time_bin
(
integertime_t
time_step
)
{
get_time_bin
(
const
integertime_t
time_step
)
{
/* ((int) log_2(time_step)) - 1 */
/* ((int) log_2(time_step)) - 1 */
return
(
timebin_t
)((
8
*
sizeof
(
integertime_t
)
-
2
)
-
return
(
timebin_t
)((
8
*
sizeof
(
integertime_t
)
-
2
)
-
...
@@ -86,8 +88,8 @@ get_time_bin(integertime_t time_step) {
...
@@ -86,8 +88,8 @@ get_time_bin(integertime_t time_step) {
* @param bin The time bin of interest.
* @param bin The time bin of interest.
* @param time_base the minimal time-step size of the simulation.
* @param time_base the minimal time-step size of the simulation.
*/
*/
__attribute__
((
const
))
static
INLINE
double
get_timestep
(
timebin_t
bin
,
__attribute__
((
const
))
static
INLINE
double
get_timestep
(
double
time_base
)
{
const
timebin_t
bin
,
const
double
time_base
)
{
return
get_integer_timestep
(
bin
)
*
time_base
;
return
get_integer_timestep
(
bin
)
*
time_base
;
}
}
...
@@ -95,12 +97,14 @@ __attribute__((const)) static INLINE double get_timestep(timebin_t bin,
...
@@ -95,12 +97,14 @@ __attribute__((const)) static INLINE double get_timestep(timebin_t bin,
/**
/**
* @brief Returns the integer time corresponding to the start of the time-step
* @brief Returns the integer time corresponding to the start of the time-step
* given by a time-bin.
* given by a time-bin.
* If the current time is a possible beginning for the given time-bin, return
* the current time minus the time-step size.
*
*
* @param ti_current The current time on the integer time line.
* @param ti_current The current time on the integer time line.
* @param bin The time bin of interest.
* @param bin The time bin of interest.
*/
*/
__attribute__
((
const
))
static
INLINE
integertime_t
__attribute__
((
const
))
static
INLINE
integertime_t
get_integer_time_begin
(
integertime_t
ti_current
,
timebin_t
bin
)
{
get_integer_time_begin
(
const
integertime_t
ti_current
,
const
timebin_t
bin
)
{
const
integertime_t
dti
=
get_integer_timestep
(
bin
);
const
integertime_t
dti
=
get_integer_timestep
(
bin
);
if
(
dti
==
0
)
if
(
dti
==
0
)
...
@@ -110,20 +114,27 @@ get_integer_time_begin(integertime_t ti_current, timebin_t bin) {
...
@@ -110,20 +114,27 @@ get_integer_time_begin(integertime_t ti_current, timebin_t bin) {
}
}
/**
/**
* @brief Returns the integer time corresponding to the
start
of the time-step
* @brief Returns the integer time corresponding to the
end
of the time-step
* given by a time-bin.
* given by a time-bin.
* If the current time is a possible end for the given time-bin, return the
* current time.
*
*
* @param ti_current The current time on the integer time line.
* @param ti_current The current time on the integer time line.
* @param bin The time bin of interest.
* @param bin The time bin of interest.
*/
*/
__attribute__
((
const
))
static
INLINE
integertime_t
__attribute__
((
const
))
static
INLINE
integertime_t
get_integer_time_end
(
integertime_t
ti_current
,
timebin_t
bin
)
{
get_integer_time_end
(
const
integertime_t
ti_current
,
const
timebin_t
bin
)
{
const
integertime_t
dti
=
get_integer_timestep
(
bin
);
const
integertime_t
dti
=
get_integer_timestep
(
bin
);
if
(
dti
==
0
)
if
(
dti
==
0
)
return
0
;
return
0
;
else
else
{
return
dti
*
ceil
((
double
)
ti_current
/
(
double
)
dti
);
const
integertime_t
mod
=
ti_current
%
dti
;
if
(
mod
==
0
)
return
ti_current
;
else
return
ti_current
-
mod
+
dti
;
}
}
}
/**
/**
...
@@ -132,7 +143,7 @@ get_integer_time_end(integertime_t ti_current, timebin_t bin) {
...
@@ -132,7 +143,7 @@ get_integer_time_end(integertime_t ti_current, timebin_t bin) {
* @param time The current point on the time line.
* @param time The current point on the time line.
*/
*/
__attribute__
((
const
))
static
INLINE
timebin_t
__attribute__
((
const
))
static
INLINE
timebin_t
get_max_active_bin
(
integertime_t
time
)
{
get_max_active_bin
(
const
integertime_t
time
)
{
if
(
time
==
0
)
return
num_time_bins
;
if
(
time
==
0
)
return
num_time_bins
;
...
@@ -149,7 +160,7 @@ get_max_active_bin(integertime_t time) {
...
@@ -149,7 +160,7 @@ get_max_active_bin(integertime_t time) {
* @param ti_old The last synchronisation point on the time line.
* @param ti_old The last synchronisation point on the time line.
*/
*/
__attribute__
((
const
))
static
INLINE
timebin_t
__attribute__
((
const
))
static
INLINE
timebin_t
get_min_active_bin
(
integertime_t
ti_current
,
integertime_t
ti_old
)
{
get_min_active_bin
(
const
integertime_t
ti_current
,
const
integertime_t
ti_old
)
{
const
timebin_t
min_bin
=
get_max_active_bin
(
ti_current
-
ti_old
);
const
timebin_t
min_bin
=
get_max_active_bin
(
ti_current
-
ti_old
);
return
min_bin
;
return
min_bin
;
...
...
This diff is collapsed.
Click to expand it.
src/tools.c
+
3
−
1
View file @
2bfe2f88
...
@@ -793,7 +793,9 @@ void engine_single_force(double *dim, long long int pid,
...
@@ -793,7 +793,9 @@ void engine_single_force(double *dim, long long int pid,
}
}
/**
/**
* Returns a random number (uniformly distributed) in [a,b[
* Returns a random number (uniformly distributed) in [a,b)
*
* This function is *not* thread-safe.
*/
*/
double
random_uniform
(
double
a
,
double
b
)
{
double
random_uniform
(
double
a
,
double
b
)
{
return
(
rand
()
/
(
double
)
RAND_MAX
)
*
(
b
-
a
)
+
a
;
return
(
rand
()
/
(
double
)
RAND_MAX
)
*
(
b
-
a
)
+
a
;
...
...
This diff is collapsed.
Click to expand it.
tests/Makefile.am
+
4
−
2
View file @
2bfe2f88
...
@@ -35,7 +35,7 @@ TESTS = testGreetings testMaths testReading.sh testKernel testKernelLongGrav \
...
@@ -35,7 +35,7 @@ TESTS = testGreetings testMaths testReading.sh testKernel testKernelLongGrav \
testCbrt testCosmology testOutputList testFormat.sh
\
testCbrt testCosmology testOutputList testFormat.sh
\
test27cellsStars.sh test27cellsStarsPerturbed.sh testHydroMPIrules
\
test27cellsStars.sh test27cellsStarsPerturbed.sh testHydroMPIrules
\
testAtomic testGravitySpeed testNeutrinoCosmology.sh testNeutrinoFermiDirac
\
testAtomic testGravitySpeed testNeutrinoCosmology.sh testNeutrinoFermiDirac
\
testLog testDistance
testLog testDistance
testTimeline
# List of test programs to compile
# List of test programs to compile
check_PROGRAMS
=
testGreetings testReading testTimeIntegration testKernelLongGrav
\
check_PROGRAMS
=
testGreetings testReading testTimeIntegration testKernelLongGrav
\
...
@@ -49,7 +49,7 @@ check_PROGRAMS = testGreetings testReading testTimeIntegration testKernelLongGra
...
@@ -49,7 +49,7 @@ check_PROGRAMS = testGreetings testReading testTimeIntegration testKernelLongGra
testSelectOutput testCbrt testCosmology testOutputList test27cellsStars
\
testSelectOutput testCbrt testCosmology testOutputList test27cellsStars
\
test27cellsStars_subset testCooling testComovingCooling testFeedback testHashmap
\
test27cellsStars_subset testCooling testComovingCooling testFeedback testHashmap
\
testAtomic testHydroMPIrules testGravitySpeed testNeutrinoCosmology
\
testAtomic testHydroMPIrules testGravitySpeed testNeutrinoCosmology
\
testNeutrinoFermiDirac testLog
testNeutrinoFermiDirac testLog
testTimeline
# Rebuild tests when SWIFT is updated.
# Rebuild tests when SWIFT is updated.
$(check_PROGRAMS)
:
../src/.libs/libswiftsim.a
$(check_PROGRAMS)
:
../src/.libs/libswiftsim.a
...
@@ -162,6 +162,8 @@ testHashmap_SOURCES = testHashmap.c
...
@@ -162,6 +162,8 @@ testHashmap_SOURCES = testHashmap.c
testLog_SOURCES
=
testLog.c
testLog_SOURCES
=
testLog.c
testTimeline_SOURCES
=
testTimeline.c
testHydroMPIrules
=
testHydroMPIrules.c
testHydroMPIrules
=
testHydroMPIrules.c
# Files necessary for distribution
# Files necessary for distribution
...
...
This diff is collapsed.
Click to expand it.
tests/testTimeline.c
0 → 100644
+
551
−
0
View file @
2bfe2f88
This diff is collapsed.
Click to expand it.
Matthieu Schaller
@matthieu
mentioned in issue
#840 (closed)
·
2 years ago
mentioned in issue
#840 (closed)
mentioned in issue #840
Toggle commit list
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