Skip to content

Commit 63c79cb

Browse files
wilfonbaBenjamin Alexander Wilfong
andauthored
Add CFL Based Adaptive Time-Stepping (#515)
Co-authored-by: wilfonba <[email protected]> Co-authored-by: Benjamin Alexander Wilfong <[email protected]>
1 parent 1f586b9 commit 63c79cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2916
-255
lines changed

docs/documentation/case.md

Lines changed: 63 additions & 39 deletions
Large diffs are not rendered by default.

docs/documentation/running.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ When used, `--omni` will output profiling information for all subroutines, inclu
108108
Adding this argument will moderately slow down the simulation and run the MFC executable several times.
109109
For this reason, it should only be used with case files with few timesteps.
110110

111-
111+
<a name="restarting-cases"></a>
112112
### Restarting Cases
113113

114114
When running a simulation, MFC generates a `./restart_data` folder in the case directory that contains `lustre_*.dat` files that can be used to restart a simulation from saved timesteps.
@@ -117,11 +117,15 @@ The user can also choose to add new patches at the intermediate timestep.
117117

118118
If you want to restart a simulation,
119119

120-
- Set up the initial simulation, with:
120+
- For a simulation that uses a constant time step set up the initial case file with:
121121
- `t_step_start` : $t_i$
122122
- `t_step_stop` : $t_f$
123-
- `t_step_save` : $SF$
124-
in which $t_i$ is the starting time, $t_f$ is the final time, and $SF$ is the saving frequency time.
123+
- `t_step_save` : $SF$ in which $t_i$ is the starting time, $t_f$ is the final time, and $SF$ is the saving frequency time.
124+
For a simulation that uses adaptive time-stepping, set up the initial case file with:
125+
- `n_start` : $t_i$
126+
- `t_stop` : $t_f$
127+
- `t_save` : $SF$ in which $t_i$ is the starting time, $t_f$ is the final time, and $SF$ is the saving frequency time.
128+
125129
- Run `pre_process` and `simulation` on the case.
126130
- `./mfc.sh run case.py -t pre_process simulation `
127131
- As the simulation runs, Lustre files will be created for each saved timestep in `./restart_data`.
@@ -137,10 +141,16 @@ in which $t_i$ is the starting time, $t_f$ is the final time, and $SF$ is the sa
137141
- `a_(xyz)`
138142
- `(xyz)_a`
139143
- `(xyz)_b`
140-
- Alter the following:
144+
- When using a constant time-step, alter the following:
141145
- `t_step_start` : $t_s$ (the point at which the simulation will restart)
142146
- `t_step_stop` : $t_{f2}$ (new final simulation time, which can be the same as $t_f$)
143147
- `t_step_save` : ${SF}_2$ (if interested in changing the saving frequency)
148+
149+
If using a CFL-based time-step, alter the following:
150+
- `n_start` : $t_s$ (the save file at which the simulation will restart)
151+
- `t_stop` : $t_{f2}$ (new final simulation time, which can be the same as $t_f$)
152+
- `t_save` : ${SF}_2$ (if interested in changing the saving frequency)
153+
144154
- Add the following:
145155
- `old_ic` : 'T' (to specify that we have initial conditions from previous simulations)
146156
- `old_grid` : 'T' (to specify that we have a grid from previous simulations)

examples/2D_ibm_cfl_dt/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 2D IBM CFL dt (2D)
2+
3+
## Result
4+
5+
![Result](result.png)

examples/2D_ibm_cfl_dt/case.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import json
2+
import math
3+
4+
Mu = 1.84E-05
5+
gam_a = 1.4
6+
7+
# Configuring case dictionary
8+
print(json.dumps({
9+
# Logistics ================================================================
10+
'run_time_info' : 'T',
11+
# ==========================================================================
12+
13+
# Computational Domain Parameters ==========================================
14+
# For these computations, the cylinder is placed at the (0,0,0)
15+
# domain origin.
16+
# axial direction
17+
'x_domain%beg' : 0.0E+00,
18+
'x_domain%end' : 8.0E-03,
19+
# r direction
20+
'y_domain%beg' : 0.0E+00,
21+
'y_domain%end' : 6.0E-03,
22+
'cyl_coord' : 'F',
23+
'm' : 199,
24+
'n' : 139,
25+
'p' : 0,
26+
'cfl_adap_dt' : 'T',
27+
'cfl_target' : 0.3,
28+
'n_start' : 0,
29+
't_save' : 8e-5,
30+
't_stop' : 8e-3,
31+
# ==========================================================================
32+
33+
# Simulation Algorithm Parameters ==========================================
34+
# Only one patches are necessary, the air tube
35+
'num_patches' : 1,
36+
# Use the 5 equation model
37+
'model_eqns' : 2,
38+
'alt_soundspeed' : 'F',
39+
# One fluids: air
40+
'num_fluids' : 1,
41+
# No need to ensure the volume fractions sum to unity at the end of each
42+
# time step
43+
'mpp_lim' : 'F',
44+
# Correct errors when computing speed of sound
45+
'mixture_err' : 'T',
46+
# Use TVD RK3 for time marching
47+
'time_stepper' : 3,
48+
# Use WENO5
49+
'weno_order' : 5,
50+
'weno_eps' : 1.E-16,
51+
# 'weno_Re_flux' : 'T',
52+
'weno_avg' : 'T',
53+
'avg_state' : 2,
54+
'mapped_weno' : 'T',
55+
'null_weights' : 'F',
56+
'mp_weno' : 'T',
57+
'riemann_solver' : 2,
58+
'wave_speeds' : 1,
59+
# We use ghost-cell
60+
'bc_x%beg' : -3,
61+
'bc_x%end' : -3,
62+
'bc_y%beg' : -2,
63+
'bc_y%end' : -2,
64+
# Set IB to True and add 1 patch
65+
'ib' : 'T',
66+
'num_ibs' : 1,
67+
# ==========================================================================
68+
69+
# Formatted Database Files Structure Parameters ============================
70+
'format' : 1,
71+
'precision' : 2,
72+
'prim_vars_wrt' :'T',
73+
'E_wrt' :'T',
74+
'parallel_io' :'T',
75+
'c_wrt' :'T',
76+
# ==========================================================================
77+
78+
# Patch: Constant Tube filled with air =====================================
79+
# Specify the cylindrical air tube grid geometry
80+
'patch_icpp(1)%geometry' : 3,
81+
'patch_icpp(1)%x_centroid' : 4.0E-03,
82+
# Uniform medium density, centroid is at the center of the domain
83+
'patch_icpp(1)%y_centroid' : 3.0E-03,
84+
'patch_icpp(1)%length_x' : 8.0E-03,
85+
'patch_icpp(1)%length_y' : 6.0E-03,
86+
# Specify the patch primitive variables
87+
'patch_icpp(1)%vel(1)' : 5E+00,
88+
'patch_icpp(1)%vel(2)' : 0.0E+00,
89+
'patch_icpp(1)%pres' : 1.E+00,
90+
'patch_icpp(1)%alpha_rho(1)' : 1.E+00,
91+
'patch_icpp(1)%alpha(1)' : 1.E+00,
92+
# # ========================================================================
93+
94+
# Patch: Cylinder Immersed Boundary ========================================
95+
'patch_ib(1)%geometry' : 2,
96+
'patch_ib(1)%x_centroid' : 1.5E-03,
97+
'patch_ib(1)%y_centroid' : 3E-03,
98+
'patch_ib(1)%radius' : 0.4E-03,
99+
'patch_ib(1)%slip' : 'F',
100+
# # ========================================================================
101+
102+
# Fluids Physical Parameters ===============================================
103+
'fluid_pp(1)%gamma' : 1.E+00/(gam_a-1.E+00), # 2.50(Not 1.40)
104+
'fluid_pp(1)%pi_inf' : 0,
105+
'fluid_pp(1)%Re(1)' : 250000,
106+
# ==========================================================================
107+
}))

examples/2D_ibm_cfl_dt/result.png

109 KB
Loading

src/common/m_checker_common.fpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ contains
6060
!> Checks constraints on the time-stepping parameters.
6161
!! Called by s_check_inputs_common for simulation and post-processing
6262
subroutine s_check_inputs_time_stepping
63-
@:PROHIBIT(t_step_start < 0)
64-
@:PROHIBIT(t_step_stop <= t_step_start)
65-
@:PROHIBIT(t_step_save > t_step_stop - t_step_start)
63+
if (cfl_dt) then
64+
@:PROHIBIT(cfl_target < 0 .or. cfl_target > 1d0)
65+
@:PROHIBIT(t_stop <= 0)
66+
@:PROHIBIT(t_save <= 0)
67+
@:PROHIBIT(t_save > t_stop)
68+
@:PROHIBIT(n_start < 0)
69+
else
70+
@:PROHIBIT(t_step_start < 0)
71+
@:PROHIBIT(t_step_stop <= t_step_start)
72+
@:PROHIBIT(t_step_save > t_step_stop - t_step_start)
73+
end if
6674
end subroutine s_check_inputs_time_stepping
6775

6876
!> Checks constraints on the finite difference parameters.

src/common/m_constants.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ module m_constants
2424
integer, parameter :: nnode = 4 !< Number of QBMM nodes
2525
real(kind(0d0)), parameter :: capillary_cutoff = 1e-6 !< color function gradient magnitude at which to apply the surface tension fluxes
2626
real(kind(0d0)), parameter :: acoustic_spatial_support_width = 2.5d0 !< Spatial support width of acoustic source, used in s_source_spatial
27+
real(kind(0d0)), parameter :: dflt_vcfl_dt = 100d0 !< value of vcfl_dt when viscosity is off for computing adaptive timestep size
2728

2829
end module m_constants

src/post_process/m_global_parameters.fpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ module m_global_parameters
7676
integer :: t_step_stop !< Last time-step directory
7777
integer :: t_step_save !< Interval between consecutive time-step directory
7878

79+
!> @name IO options for adaptive time-stepping
80+
!> @{
81+
logical :: cfl_adap_dt, cfl_const_dt, cfl_dt
82+
real(kind(0d0)) :: t_save
83+
real(kind(0d0)) :: t_stop
84+
real(kind(0d0)) :: cfl_target
85+
integer :: n_save
86+
integer :: n_start
87+
!> @}
88+
7989
! NOTE: The variables m_root, x_root_cb and x_root_cc contain the grid data
8090
! of the defragmented computational domain. They are only used in 1D. For
8191
! serial simulations, they are equal to m, x_cb and x_cc, respectively.
@@ -278,6 +288,14 @@ contains
278288
t_step_stop = dflt_int
279289
t_step_save = dflt_int
280290

291+
cfl_adap_dt = .false.
292+
cfl_const_dt = .false.
293+
cfl_dt = .false.
294+
cfl_target = dflt_real
295+
t_save = dflt_real
296+
n_start = dflt_int
297+
t_stop = dflt_real
298+
281299
! Simulation algorithm parameters
282300
model_eqns = dflt_int
283301
num_fluids = dflt_int

src/post_process/m_mpi_proxy.fpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ contains
158158
& 't_step_start', 't_step_stop', 't_step_save', 'weno_order', &
159159
& 'model_eqns', 'num_fluids', 'bc_x%beg', 'bc_x%end', 'bc_y%beg', &
160160
& 'bc_y%end', 'bc_z%beg', 'bc_z%end', 'flux_lim', 'format', &
161-
& 'precision', 'fd_order', 'thermal', 'nb', 'relax_model' ]
161+
& 'precision', 'fd_order', 'thermal', 'nb', 'relax_model', &
162+
& 'n_start' ]
162163
call MPI_BCAST(${VAR}$, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
163164
#:endfor
164165
@@ -168,7 +169,7 @@ contains
168169
& 'heat_ratio_wrt', 'pi_inf_wrt', 'pres_inf_wrt', 'cons_vars_wrt', &
169170
& 'prim_vars_wrt', 'c_wrt', 'qm_wrt','schlieren_wrt', 'bubbles', 'qbmm', &
170171
& 'polytropic', 'polydisperse', 'file_per_process', 'relax', 'cf_wrt', &
171-
& 'adv_n', 'ib' ]
172+
& 'adv_n', 'ib', 'cfl_adap_dt', 'cfl_const_dt', 'cfl_dt' ]
172173
call MPI_BCAST(${VAR}$, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
173174
#:endfor
174175
@@ -189,7 +190,7 @@ contains
189190
end do
190191
191192
#:for VAR in [ 'pref', 'rhoref', 'R0ref', 'poly_sigma', 'Web', 'Ca', &
192-
& 'Re_inv', 'sigma' ]
193+
& 'Re_inv', 'sigma', 't_save', 't_stop' ]
193194
call MPI_BCAST(${VAR}$, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
194195
#:endfor
195196
call MPI_BCAST(schlieren_alpha(1), num_fluids_max, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)

src/post_process/m_start_up.f90

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ subroutine s_read_input_file
7474
parallel_io, rhoref, pref, bubbles, qbmm, sigR, &
7575
R0ref, nb, polytropic, thermal, Ca, Web, Re_inv, &
7676
polydisperse, poly_sigma, file_per_process, relax, &
77-
relax_model, cf_wrt, sigma, adv_n, ib
77+
relax_model, cf_wrt, sigma, adv_n, ib, &
78+
cfl_adap_dt, cfl_const_dt, t_save, t_stop, n_start, &
79+
cfl_target
7880

7981
! Inquiring the status of the post_process.inp file
8082
file_loc = 'post_process.inp'
@@ -102,6 +104,9 @@ subroutine s_read_input_file
102104
p_glb = p
103105

104106
nGlobal = (m_glb + 1)*(n_glb + 1)*(p_glb + 1)
107+
108+
if (cfl_adap_dt .or. cfl_const_dt) cfl_dt = .true.
109+
105110
else
106111
call s_mpi_abort('File post_process.inp is missing. Exiting ...')
107112
end if
@@ -142,11 +147,17 @@ subroutine s_perform_time_step(t_step)
142147

143148
integer, intent(inout) :: t_step
144149
if (proc_rank == 0) then
145-
print '(" ["I3"%] Saving "I8" of "I0" @ t_step = "I0"")', &
146-
int(ceiling(100d0*(real(t_step - t_step_start)/(t_step_stop - t_step_start + 1)))), &
147-
(t_step - t_step_start)/t_step_save + 1, &
148-
(t_step_stop - t_step_start)/t_step_save + 1, &
149-
t_step
150+
if (cfl_dt) then
151+
print '(" ["I3"%] Saving "I8" of "I0"")', &
152+
int(ceiling(100d0*(real(t_step - n_start)/(n_save)))), &
153+
t_step, n_save
154+
else
155+
print '(" ["I3"%] Saving "I8" of "I0" @ t_step = "I0"")', &
156+
int(ceiling(100d0*(real(t_step - t_step_start)/(t_step_stop - t_step_start + 1)))), &
157+
(t_step - t_step_start)/t_step_save + 1, &
158+
(t_step_stop - t_step_start)/t_step_save + 1, &
159+
t_step
160+
end if
150161
end if
151162

152163
! Populating the grid and conservative variables

0 commit comments

Comments
 (0)