Skip to content

Commit a22818f

Browse files
authored
Review (#388)
* Bug is fixed and added new code * new code for the table * Edits in markdown file * some edits in test * Bugs fix * Codecov * I cleaned up my code and separated classes to make it easier to work with. It is not ready yet; if Codecov fails, I will include more tests. * forgot black * flake8 * bug fix * Edits codes according to the comments * Edited codes according to the comments in the GitHub * Defined new function in stability_simulation.py to check stability for given points and excluded codecov function that generates a table. * small edits for codecov * removed no cover
1 parent 2d391ff commit a22818f

16 files changed

+1043
-927
lines changed

pySDC/implementations/problem_classes/HarmonicOscillator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class harmonic_oscillator(ptype):
2828
Phase of the oscillation.
2929
amp : float, optional
3030
Amplitude of the oscillation.
31+
Source: https://beltoforion.de/en/harmonic_oscillator/
3132
"""
3233

3334
dtype_u = particles

pySDC/projects/Second_orderSDC/README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11
# Spectral Deferred Correction Methods for Second-Order Problems
22

3+
**Title:** Spectral Deferred Correction Methods for Second-order Problems
4+
5+
**Authors:** Ikrom Akramov, Sebastian Götschel, Michael Minion, Daniel Ruprecht, and Robert Speck.
6+
7+
38
Python code for implementing the paper's plots on Second-order SDC methods.
49

510
## Attribution
611
You are welcome to use and adapt this code under the terms of the BSD license.
712
If you utilize it, either in whole or in part, for a publication, please provide proper citation:
813

9-
**Title:** Spectral Deferred Correction Methods for Second-order Problems
10-
11-
**Authors:** Ikrom Akramov, Sebastian Götschel, Michael Minion, Daniel Ruprecht, and Robert Speck.
1214

13-
[![DOI](http://example.com)](http://example.com)
15+
16+
**BibTeX formatted citation:**
17+
18+
@misc{akramov2023spectral,
19+
title={Spectral deferred correction methods for second-order problems},
20+
author={Ikrom Akramov and Sebastian Götschel and Michael Minion and Daniel Ruprecht and Robert Speck},
21+
year={2023},
22+
eprint={2310.08352},
23+
archivePrefix={arXiv},
24+
primaryClass={math.NA}
25+
26+
27+
28+
29+
30+
[![arXiv](https://img.shields.io/badge/arXiv-2310.08352-b31b1b.svg)](https://arxiv.org/abs/2310.08352)
1431

1532
## Reproducing Figures from the Publication
1633

17-
- **Fig. 1:** Execute `dampedharmonic_oscillator_run_stability.py` while setting `kappa_max=18` and `mu_max=18`.
18-
- **Fig. 2:** Run `dampedharmonic_oscillator_run_stability.py` with the following configurations:
34+
- **Fig. 1:** Execute `harmonic_oscillator_run_stability.py` while setting `kappa_max=18` and `mu_max=18`.
35+
- **Fig. 2:** Run `harmonic_oscillator_run_stability.py` with the following configurations:
1936
- Set `kappa_max=30` and `mu_max=30`.
2037
- Adjust `maxiter` to 1, 2, 3, or 4 and execute each individually.
38+
- **Table 1:** Execute `harmonic_socillator_run_stab_interval.py`:
39+
- To save the results set: `save_file=True`
40+
41+
- Use the script `harmonic_oscillator_run_points.py` to create a table based on given $(\kappa, \mu)$ points. This table assists in determining suitable values for `M`, `K`, and `quadrature nodes` to ensure stability in the SDC method.
42+
- To save the results set: `save_file=True`
43+
2144
- **Fig. 3:** Run `penningtrap_run_error.py` (Run local convergence: `conv.run_local_error()`) with `dt=0.015625/4` and `axes=(0,)`.
2245
- **Fig. 4:** Run `penningtrap_run_error.py` (Run local convergence: `conv.run_local_error()`) using `dt=0.015625*4` and `axes=(2,)`.
2346
- **Fig. 5:** Run `penningtrap_run_error.py` (Run global convergence: `conv.run_global_error()`) with `dt=0.015625*2`:
2447
- Note: Perform each run individually: first with `axes=(0,)`, then with `axes=(2,)`.
2548
- Manually set y-axis limits in `penningtrap_run_error.py`, specifically in lines 147-148.
26-
- **Table 1:** Execute `penningtrap_run_error.py` (Run global convergence: `conv.run_global_error()`) with the following settings:
49+
- **Table 2:** Execute `penningtrap_run_error.py` (Run global convergence: `conv.run_global_error()`) with the following settings:
2750
- Expected order and approximate order are saved in the file: `data/global_order_vs_approx_order.csv`
2851
- Set: `K_iter=(2, 3, 4, 10)`
2952
- For `M=2`:

pySDC/projects/Second_orderSDC/check_data_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
folder_name = "./data"
44

55
# Check if the folder already exists
6-
if not os.path.isdir(folder_name): # pragma: no cover
6+
if not os.path.isdir(folder_name):
77
# Create the folder
88
os.makedirs(folder_name)
99
else:

pySDC/projects/Second_orderSDC/dampedharmonic_oscillator_run_stability.py

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
from pySDC.implementations.problem_classes.HarmonicOscillator import harmonic_oscillator
3+
from pySDC.implementations.sweeper_classes.boris_2nd_order import boris_2nd_order
4+
5+
6+
def get_default_harmonic_oscillator_description():
7+
"""
8+
Routine to compute modules of the stability function
9+
10+
Returns:
11+
description (dict): A dictionary containing parameters for the damped harmonic oscillator problem
12+
"""
13+
14+
# Initialize level parameters
15+
level_params = {'restol': 1e-16, 'dt': 1.0}
16+
17+
# Initialize problem parameters for the Damped harmonic oscillator problem
18+
problem_params = {'k': 0, 'mu': 0, 'u0': np.array([1, 1])}
19+
20+
# Initialize sweeper parameters
21+
sweeper_params = {'quad_type': 'GAUSS', 'num_nodes': 3, 'do_coll_update': True, 'picard_mats_sweep': True}
22+
23+
# Initialize step parameters
24+
step_params = {'maxiter': 5}
25+
26+
# Fill description dictionary for easy step instantiation
27+
description = {
28+
'problem_class': harmonic_oscillator,
29+
'problem_params': problem_params,
30+
'sweeper_class': boris_2nd_order,
31+
'sweeper_params': sweeper_params,
32+
'level_params': level_params,
33+
'step_params': step_params,
34+
}
35+
36+
return description
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import numpy as np
2+
from pySDC.projects.Second_orderSDC.harmonic_oscillator_params import get_default_harmonic_oscillator_description
3+
from pySDC.projects.Second_orderSDC.stability_simulation import compute_and_generate_table
4+
5+
6+
if __name__ == '__main__':
7+
'''
8+
This script generates table for the given points to compare in what quadrature type,
9+
number of nodes and number of iterations the SDC iteration is stable or not.
10+
Additional parameter:
11+
To save the table set: save_points_table=True
12+
Change filename: points_table_filename='FILENAME' by default: './data/point_table.txt'
13+
'''
14+
# Get default parameters for the harmonic osicillator problem
15+
description = get_default_harmonic_oscillator_description()
16+
# Additonal params to compute stability points
17+
helper_params = {
18+
'quad_type_list': ('GAUSS', 'LOBATTO'),
19+
'Num_iter': (2, 2),
20+
'num_nodes_list': np.arange(3, 6, 1),
21+
'max_iter_list': np.arange(2, 10, 1),
22+
}
23+
24+
points = ((1, 100), (3, 100), (10, 100))
25+
# Iterate through points and perform stability check
26+
for ii in points:
27+
compute_and_generate_table(description, helper_params, ii, check_stability_point=True)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import numpy as np
2+
from pySDC.projects.Second_orderSDC.harmonic_oscillator_params import get_default_harmonic_oscillator_description
3+
from pySDC.projects.Second_orderSDC.stability_simulation import compute_and_generate_table
4+
5+
6+
if __name__ == '__main__':
7+
'''
8+
To compute maximum stable values for SDC and Picard iterations for the purely oscillatory case with
9+
no damping (mu=0)
10+
Additional parameter:
11+
To save the table set: save_interval_file=True
12+
Change filename: interval_filename='FILENAME' by default: './data/stab_interval.txt'
13+
Output:
14+
it generates to compare with different values of M (number of nodes) and K (maximal number of iterations)
15+
'''
16+
# Ger default parameters
17+
description = get_default_harmonic_oscillator_description()
18+
# Additional parameters to compute stability interval on the kappa
19+
helper_params = {
20+
'quad_type_list': ('GAUSS',),
21+
'Num_iter': (2000, 1),
22+
'num_nodes_list': np.arange(2, 7, 1),
23+
'max_iter_list': np.arange(1, 11, 1),
24+
}
25+
26+
points = ((100, 1e-10),)
27+
# Iterate through points and perform stability check
28+
for ii in points:
29+
compute_and_generate_table(description, helper_params, ii, compute_interval=True)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pySDC.projects.Second_orderSDC.harmonic_oscillator_params import get_default_harmonic_oscillator_description
2+
from pySDC.projects.Second_orderSDC.stability_simulation import StabilityImplementation
3+
4+
5+
if __name__ == '__main__':
6+
"""
7+
To implement Stability region for the Harmonic Oscillator problem
8+
Run for
9+
SDC stability region: model_stab.run_SDC_stability()
10+
Picard stability region: model_stab.run_Picard_stability()
11+
Runge-Kutta-Nzström stability region: model_run_RKN_stability()
12+
To implement spectral radius of iteration matrix
13+
Run:
14+
Iteration matrix of SDC method: model_stab.run_Ksdc()
15+
Iteration matrix of Picard method: model_stab.run_Kpicard()
16+
17+
"""
18+
# Execute the stability analysis for the damped harmonic oscillator
19+
description = get_default_harmonic_oscillator_description()
20+
model_stab = StabilityImplementation(description, kappa_max=30, mu_max=30, Num_iter=(200, 200))
21+
22+
model_stab.run_SDC_stability()
23+
model_stab.run_Picard_stability()
24+
model_stab.run_RKN_stability()
25+
model_stab.run_Ksdc()
26+
# model_stab.run_Kpicard()

0 commit comments

Comments
 (0)