Skip to content
Snippets Groups Projects
Commit 2bfe2f88 authored by Mladen Ivkovic's avatar Mladen Ivkovic Committed by Matthieu Schaller
Browse files

Timeline unit tests

parent 14c9cfad
Branches
Tags
2 merge requests!1548Mayor Sync,!1543Timeline unit tests
...@@ -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
...@@ -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;
......
...@@ -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;
......
...@@ -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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment