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
ce1448b9
Commit
ce1448b9
authored
1 year ago
by
Mladen Ivkovic
Committed by
Matthieu Schaller
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent overflows in time step calculations with RT
parent
b8157dc7
No related branches found
No related tags found
3 merge requests
!1887
Updating . . .
,
!1878
updating working branch
,
!1819
Prevent overflows in time step calculations with RT
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/rt.h
+15
-1
15 additions, 1 deletion
src/rt.h
src/runner_time_integration.c
+4
-0
4 additions, 0 deletions
src/runner_time_integration.c
src/space_first_init.c
+1
-0
1 addition, 0 deletions
src/space_first_init.c
src/timestep.h
+15
-1
15 additions, 1 deletion
src/timestep.h
with
35 additions
and
2 deletions
src/rt.h
+
15
−
1
View file @
ce1448b9
...
@@ -21,7 +21,8 @@
...
@@ -21,7 +21,8 @@
/**
/**
* @file src/rt.h
* @file src/rt.h
* @brief Branches between the different radiative transfer schemes.
* @brief Branches between the different radiative transfer schemes. Also
* contains some globally valid functions related to time bin data.
*/
*/
/* Config parameters. */
/* Config parameters. */
...
@@ -44,6 +45,19 @@
...
@@ -44,6 +45,19 @@
#error "Invalid choice of radiation scheme"
#error "Invalid choice of radiation scheme"
#endif
#endif
/**
* @brief Initialise RT time step data. This struct should be hidden from users,
* so we do it for all schemes here.
*
* @param p The #part.
*/
__attribute__
((
always_inline
))
INLINE
static
void
rt_first_init_timestep_data
(
struct
part
*
restrict
p
)
{
p
->
rt_time_data
.
min_ngb_time_bin
=
num_time_bins
+
1
;
p
->
rt_time_data
.
time_bin
=
0
;
}
/**
/**
* @brief Prepare the rt *time step* quantities for a *hydro force* calculation.
* @brief Prepare the rt *time step* quantities for a *hydro force* calculation.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/runner_time_integration.c
+
4
−
0
View file @
ce1448b9
...
@@ -740,6 +740,10 @@ void runner_do_timestep(struct runner *r, struct cell *c, const int timer) {
...
@@ -740,6 +740,10 @@ void runner_do_timestep(struct runner *r, struct cell *c, const int timer) {
* debugging/consistency check. */
* debugging/consistency check. */
rt_debugging_check_timestep
(
p
,
&
ti_rt_new_step
,
&
ti_new_step
,
rt_debugging_check_timestep
(
p
,
&
ti_rt_new_step
,
&
ti_new_step
,
e
->
max_nr_rt_subcycles
,
e
->
time_base
);
e
->
max_nr_rt_subcycles
,
e
->
time_base
);
if
(
ti_rt_new_step
<=
0LL
)
error
(
"Got integer time step <= 0? %lld %lld"
,
get_part_rt_timestep
(
p
,
xp
,
e
),
ti_new_step
);
#endif
#endif
/* Update particle */
/* Update particle */
...
...
This diff is collapsed.
Click to expand it.
src/space_first_init.c
+
1
−
0
View file @
ce1448b9
...
@@ -144,6 +144,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count,
...
@@ -144,6 +144,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count,
particle_splitting_mark_part_as_not_split
(
&
xp
[
k
].
split_data
,
p
[
k
].
id
);
particle_splitting_mark_part_as_not_split
(
&
xp
[
k
].
split_data
,
p
[
k
].
id
);
/* And the radiative transfer */
/* And the radiative transfer */
rt_first_init_timestep_data
(
&
p
[
k
]);
rt_first_init_part
(
&
p
[
k
],
cosmo
,
rt_props
);
rt_first_init_part
(
&
p
[
k
],
cosmo
,
rt_props
);
#ifdef SWIFT_DEBUG_CHECKS
#ifdef SWIFT_DEBUG_CHECKS
...
...
This diff is collapsed.
Click to expand it.
src/timestep.h
+
15
−
1
View file @
ce1448b9
...
@@ -218,7 +218,21 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep(
...
@@ -218,7 +218,21 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep(
/* enforce dt_hydro <= nsubcycles * dt_rt. The rare case where
/* enforce dt_hydro <= nsubcycles * dt_rt. The rare case where
* new_dti_rt > new_dti will be handled in the parent function
* new_dti_rt > new_dti will be handled in the parent function
* that calls this one. */
* that calls this one. */
const
integertime_t
max_subcycles
=
max
(
e
->
max_nr_rt_subcycles
,
1
);
integertime_t
max_subcycles
=
max
(
e
->
max_nr_rt_subcycles
,
1
);
if
(
max_nr_timesteps
/
max_subcycles
<
new_dti_rt
)
{
/* multiplication new_dti_rt * max_subcycles would overflow. This can
* happen in rare cases, especially if the total physical time the
* simulation should cover is small. So limit max_subcycles to a
* reasonable value.
* First find an integer guess for the maximal permissible number
* of sub-cycles. Then find highest power-of-two below that guess.
* Divide the guess by a factor of 2 to simplify the subsequent while
* loop. The max() is there to prevent bad things happening. */
const
integertime_t
max_subcycles_guess
=
max
(
1LL
,
max_nr_timesteps
/
(
new_dti_rt
*
2LL
));
max_subcycles
=
1LL
;
while
(
max_subcycles_guess
>
max_subcycles
)
max_subcycles
*=
2LL
;
}
new_dti
=
min
(
new_dti
,
new_dti_rt
*
max_subcycles
);
new_dti
=
min
(
new_dti
,
new_dti_rt
*
max_subcycles
);
}
}
}
}
...
...
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