Skip to content

Commit 71ac6c7

Browse files
committed
Implemented configurations for faults in RBC
1 parent 31eb63d commit 71ac6c7

File tree

6 files changed

+97
-25
lines changed

6 files changed

+97
-25
lines changed

pySDC/helpers/plot_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ def figsize_by_journal(journal, scale, ratio): # pragma: no cover
4343
'JSC_beamer': 426.79135,
4444
'Springer_Numerical_Algorithms': 338.58778,
4545
'JSC_thesis': 434.26027,
46+
'TUHH_thesis': 426.79135,
4647
}
4748
# store text height in points here, get this from LaTeX using \the\textheight
4849
textheights = {
4950
'JSC_beamer': 214.43411,
5051
'JSC_thesis': 635.5,
52+
'TUHH_thesis': 631.65118,
5153
}
5254
assert (
5355
journal in textwidths.keys()

pySDC/projects/Resilience/RBC.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def u_exact(self, t, u_init=None, t_init=None, recompute=False):
2828
from pySDC.implementations.convergence_controller_classes.adaptivity import Adaptivity
2929

3030
convergence_controllers = {
31-
Adaptivity: {'e_tol': 1e-8, 'dt_rel_min_slope': 0.25},
31+
Adaptivity: {'e_tol': 1e-8, 'dt_rel_min_slope': 0.25, 'dt_min': 1e-5},
3232
}
3333
desc = {'convergence_controllers': convergence_controllers}
3434

@@ -54,32 +54,36 @@ def u_exact(self, t, u_init=None, t_init=None, recompute=False):
5454
RayleighBenard.u_exact = u_exact
5555
EstimateExtrapolationErrorNonMPI.get_extrapolated_error = get_extrapolated_error_DAE
5656

57+
PROBLEM_PARAMS = {'Rayleigh': 2e4, 'nx': 256, 'nz': 128}
58+
5759

5860
class ReachTendExactly(ConvergenceController):
5961

6062
def setup(self, controller, params, description, **kwargs):
6163
defaults = {
6264
"control_order": +50,
6365
"Tend": None,
66+
'min_step_size': 1e-9,
6467
}
6568
return {**defaults, **super().setup(controller, params, description, **kwargs)}
6669

6770
def get_new_step_size(self, controller, step, **kwargs):
6871
L = step.levels[0]
6972
dt = L.status.dt_new if L.status.dt_new else L.params.dt
70-
if self.params.Tend - L.time - L.dt < dt:
71-
L.status.dt_new = min([dt, self.params.Tend - L.time - L.dt])
73+
time_left = self.params.Tend - L.time - L.dt
74+
if time_left < dt:
75+
L.status.dt_new = min([dt, max([time_left, self.params.min_step_size])])
7276

7377

7478
def run_RBC(
7579
custom_description=None,
7680
num_procs=1,
77-
Tend=14.0,
81+
Tend=21.0,
7882
hook_class=LogData,
7983
fault_stuff=None,
8084
custom_controller_params=None,
8185
u0=None,
82-
t0=11,
86+
t0=20.0,
8387
use_MPI=False,
8488
**kwargs,
8589
):
@@ -112,7 +116,7 @@ def run_RBC(
112116

113117
from mpi4py import MPI
114118

115-
problem_params = {'comm': MPI.COMM_SELF}
119+
problem_params = {'comm': MPI.COMM_SELF, **PROBLEM_PARAMS}
116120

117121
step_params = {}
118122
step_params['maxiter'] = 5
@@ -176,8 +180,11 @@ def run_RBC(
176180

177181

178182
def generate_data_for_fault_stats():
179-
prob = RayleighBenard()
180-
for t in [11.0, 14.0]:
183+
prob = RayleighBenard(**PROBLEM_PARAMS)
184+
for t in [
185+
20,
186+
21,
187+
]:
181188
prob.u_exact(t)
182189

183190

@@ -251,5 +258,5 @@ def test_order(t=14, dt=1e-1, steps=6):
251258

252259
if __name__ == '__main__':
253260
generate_data_for_fault_stats()
254-
test_order()
261+
# test_order()
255262
# stats, _, _ = run_RBC()

pySDC/projects/Resilience/README.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,21 @@ Then, navigate to this directory, `pySDC/projects/Resilience/` and run the follo
5050
.. code-block:: bash
5151
5252
mpirun -np 4 python work_precision.py
53-
mpirun -np 4 python fault_stats.py prob run_vdp
54-
mpirun -np 4 python fault_stats.py prob run_quench
55-
mpirun -np 4 python fault_stats.py prob run_AC
56-
mpirun -np 4 python fault_stats.py prob run_Schroedinger
57-
python paper_plots.py
53+
python paper_plots.py --target=adaptivity
5854
5955
Possibly, you need to create some directories in this one to store and load things, if path errors occur.
56+
57+
Reproduction of the plots in the resilience paper
58+
-------------------------------------------------
59+
To reproduce the plots you need to install pySDC using this project's `environment.yml` file, which is in the same directory as this README.
60+
61+
.. code-block:: bash
62+
63+
mpirun -np 4 python work_precision.py
64+
mpirun -np 4 python fault_stats.py prob run_Lorenz
65+
mpirun -np 4 python fault_stats.py prob run_Schroedinger
66+
mpirun -np 4 python fault_stats.py prob run_AC
67+
mpirun -np 4 python fault_stats.py prob run_RBC
68+
python paper_plots.py --target=resilience
69+
70+
Please be aware that generating the fault data for Rayleigh-Benard requires generating reference solutions, which may take several hours.

pySDC/projects/Resilience/fault_stats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pySDC.projects.Resilience.Schroedinger import run_Schroedinger
2222
from pySDC.projects.Resilience.quench import run_quench
2323
from pySDC.projects.Resilience.AC import run_AC
24+
from pySDC.projects.Resilience.RBC import run_RBC
2425

2526
from pySDC.projects.Resilience.strategies import BaseStrategy, AdaptivityStrategy, IterateStrategy, HotRodStrategy
2627
import logging
@@ -632,6 +633,8 @@ def get_name(self, strategy=None, faults=True, mode=None):
632633
prob_name = 'Quench'
633634
elif self.prob.__name__ == 'run_AC':
634635
prob_name = 'Allen-Cahn'
636+
elif self.prob.__name__ == 'run_RBC':
637+
prob_name = 'Rayleigh-Benard'
635638
else:
636639
raise NotImplementedError(f'Name not implemented for problem {self.prob}')
637640

@@ -1565,6 +1568,10 @@ def parse_args():
15651568
kwargs['prob'] = run_Schroedinger
15661569
elif sys.argv[i + 1] == 'run_quench':
15671570
kwargs['prob'] = run_quench
1571+
elif sys.argv[i + 1] == 'run_AC':
1572+
kwargs['prob'] = run_AC
1573+
elif sys.argv[i + 1] == 'run_RBC':
1574+
kwargs['prob'] = run_RBC
15681575
else:
15691576
raise NotImplementedError
15701577
elif 'num_procs' in sys.argv[i]:
@@ -1654,7 +1661,7 @@ def compare_adaptivity_modes():
16541661

16551662
def main():
16561663
kwargs = {
1657-
'prob': run_AC,
1664+
'prob': run_RBC,
16581665
'num_procs': 1,
16591666
'mode': 'default',
16601667
'runs': 2000,

pySDC/projects/Resilience/paper_plots.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
run_vdp,
1010
run_quench,
1111
run_AC,
12+
run_RBC,
1213
RECOVERY_THRESH_ABS,
1314
)
1415
from pySDC.projects.Resilience.strategies import (
@@ -196,7 +197,7 @@ def compare_recovery_rate_problems(**kwargs): # pragma: no cover
196197
None
197198
"""
198199
stats = [
199-
get_stats(run_vdp, **kwargs),
200+
get_stats(run_RBC, **kwargs),
200201
get_stats(run_quench, **kwargs),
201202
get_stats(run_Schroedinger, **kwargs),
202203
get_stats(run_AC, **kwargs),
@@ -614,8 +615,35 @@ def make_plots_for_notes(): # pragma: no cover
614615
analyse_resilience(run_quench, format='png')
615616

616617

618+
def make_plots_for_thesis(): # pragma: no cover
619+
global JOURNAL
620+
JOURNAL = 'TUHH_thesis'
621+
622+
# plot_adaptivity_stuff()
623+
# plot_vdp_solution()
624+
compare_recovery_rate_problems(num_procs=1, strategy_type='SDC')
625+
626+
617627
if __name__ == "__main__":
618-
# make_plots_for_notes()
619-
# make_plots_for_SIAM_CSE23()
620-
# make_plots_for_TIME_X_website()
621-
make_plots_for_adaptivity_paper()
628+
import argparse
629+
630+
parser = argparse.ArgumentParser()
631+
parser.add_argument(
632+
'--target', choices=['adaptivity', 'resilience', 'thesis', 'notes', 'SIAM_CSE23', 'TIME_X_website'], type=str
633+
)
634+
args = parser.parse_args()
635+
636+
if args.target == 'adaptivity':
637+
make_plots_for_adaptivity_paper()
638+
elif args.target == 'resilience':
639+
make_plots_for_resilience_paper()
640+
elif args.target == 'thesis':
641+
make_plots_for_thesis()
642+
elif args.target == 'notes':
643+
make_plots_for_notes()
644+
elif args.target == 'SIAM_CSE23':
645+
make_plots_for_SIAM_CSE23()
646+
elif args.target == 'TIME_X_website':
647+
make_plots_for_TIME_X_website()
648+
else:
649+
raise NotImplementedError(f'Don\'t know how to make plots for target {args.target}')

pySDC/projects/Resilience/strategies.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_fault_args(self, problem, num_procs):
131131
elif problem.__name__ == "run_AC":
132132
args['time'] = 1e-2
133133
elif problem.__name__ == "run_RBC":
134-
args['time'] = 11.5
134+
args['time'] = 20.09
135135

136136
return args
137137

@@ -209,7 +209,7 @@ def get_Tend(cls, problem, num_procs=1):
209209
elif problem.__name__ == "run_AC":
210210
return 0.025
211211
elif problem.__name__ == "run_RBC":
212-
return 14
212+
return 21
213213
else:
214214
raise NotImplementedError('I don\'t have a final time for your problem!')
215215

@@ -274,7 +274,7 @@ def get_base_parameters(self, problem, num_procs=1):
274274
}
275275
custom_description['level_params'] = {'restol': -1, 'dt': 0.1 * eps**2}
276276
elif problem.__name__ == 'run_RBC':
277-
custom_description['level_params']['dt'] = 5e-3
277+
custom_description['level_params']['dt'] = 5e-2
278278
custom_description['step_params'] = {'maxiter': 5}
279279

280280
custom_description['convergence_controllers'] = {
@@ -381,7 +381,7 @@ def get_custom_description(self, problem, num_procs=1):
381381
'maxiter': 15,
382382
}
383383

384-
if self.newton_inexactness and problem.__name__ not in ['run_Schroedinger', 'run_AC']:
384+
if self.newton_inexactness and problem.__name__ not in ['run_Schroedinger', 'run_AC', 'run_RBC']:
385385
if problem.__name__ == 'run_quench':
386386
inexactness_params['ratio'] = 1e-1
387387
inexactness_params['min_tol'] = 1e-11
@@ -769,6 +769,8 @@ def get_custom_description(self, problem, num_procs):
769769
restol = 1e-7
770770
elif problem.__name__ == "run_AC":
771771
restol = 1e-11
772+
elif problem.__name__ == "run_RBC":
773+
restol = 1e-4
772774
else:
773775
raise NotImplementedError(
774776
'I don\'t have a residual tolerance for your problem. Please add one to the \
@@ -840,6 +842,8 @@ def get_custom_description(self, problem, num_procs, *args, **kwargs):
840842
elif problem.__name__ == "run_AC":
841843
desc['level_params']['restol'] = 1e-11
842844
desc['level_params']['dt'] = 0.4 * desc['problem_params']['eps'] ** 2 / 8.0
845+
elif problem.__name__ == "run_RBC":
846+
desc['level_params']['restol'] = 1e-4
843847
return desc
844848

845849
def get_custom_description_for_faults(self, problem, *args, **kwargs):
@@ -942,7 +946,7 @@ def get_custom_description(self, problem, num_procs):
942946
HotRod_tol = 9.564437e-06
943947
maxiter = 6
944948
elif problem.__name__ == 'run_RBC':
945-
HotRod_tol = 1e0 # 1.#4e-1
949+
HotRod_tol = 6.34e-6
946950
maxiter = 6
947951
else:
948952
raise NotImplementedError(
@@ -1880,7 +1884,10 @@ def get_custom_description(self, problem, num_procs):
18801884
dt_max = np.inf
18811885
restol_rel = 1e-4
18821886
restol_min = 1e-12
1887+
restol_max = 1e-5
1888+
dt_slope_min = 0
18831889
dt_min = 0
1890+
abort_at_growing_residual = True
18841891
level_params = {}
18851892
problem_params = {}
18861893

@@ -1906,6 +1913,13 @@ def get_custom_description(self, problem, num_procs):
19061913
e_tol = 1.0e-4
19071914
restol_rel = 1e-3
19081915
# dt_max = 0.1 * base_params['problem_params']['eps'] ** 2
1916+
elif problem.__name__ == "run_RBC":
1917+
e_tol = 1e-3
1918+
dt_slope_min = 0.25
1919+
abort_at_growing_residual = False
1920+
restol_rel = 1e-4
1921+
restol_max = 1e-1
1922+
restol_min = 1e-6
19091923
else:
19101924
raise NotImplementedError(
19111925
'I don\'t have a tolerance for adaptivity for your problem. Please add one to the\
@@ -1917,14 +1931,17 @@ def get_custom_description(self, problem, num_procs):
19171931
'e_tol': e_tol,
19181932
'restol_rel': restol_rel if self.use_restol_rel else 1e-11,
19191933
'restol_min': restol_min if self.use_restol_rel else 1e-12,
1934+
'restol_max': restol_max if self.use_restol_rel else 1e-5,
19201935
'restart_at_maxiter': True,
19211936
'factor_if_not_converged': self.max_slope,
19221937
'interpolate_between_restarts': self.interpolate_between_restarts,
1938+
'abort_at_growing_residual': abort_at_growing_residual,
19231939
},
19241940
StepSizeLimiter: {
19251941
'dt_max': dt_max,
19261942
'dt_slope_max': self.max_slope,
19271943
'dt_min': dt_min,
1944+
'dt_rel_min_slope': dt_slope_min,
19281945
},
19291946
}
19301947
custom_description['level_params'] = level_params

0 commit comments

Comments
 (0)