Skip to content

Commit 2f0df96

Browse files
committed
Added test for interpolation of initial conditions
1 parent 84cb1d7 commit 2f0df96

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

pySDC/projects/GPU/analysis_scripts/plot_Nu.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,7 @@ def plot_Nu_over_time_Ra1e5(): # pragma: no cover
5959

6060
ref_data = get_pySDC_data(res=res, dt=0.01, config_name='RBC3DG4R4Ra1e5')
6161

62-
_Nu_axs = {'SDC 3': Nu_axs[1], 'SDC': Nu_axs[0], 'RK': Nu_axs[2], 'Euler': Nu_axs[3]}
63-
64-
plot_Nu(
65-
32,
66-
[
67-
0.06,
68-
0.04,
69-
0.02,
70-
],
71-
'RBC3DG4R4SDC34Ra1e5',
72-
ref_data,
73-
Nu_axs[0],
74-
'SDC34',
75-
)
62+
plot_Nu(32, [0.06, 0.04, 0.02], 'RBC3DG4R4SDC34Ra1e5', ref_data, Nu_axs[0], 'SDC34')
7663
plot_Nu(32, [0.06, 0.05, 0.02, 0.01], 'RBC3DG4R4SDC23Ra1e5', ref_data, Nu_axs[1], 'SDC23')
7764
plot_Nu(32, [0.05, 0.04, 0.02, 0.01, 0.005], 'RBC3DG4R4RKRa1e5', ref_data, Nu_axs[2], 'RK443')
7865
plot_Nu(32, [0.02, 0.01, 0.005], 'RBC3DG4R4EulerRa1e5', ref_data, Nu_axs[3], 'RK111')

pySDC/projects/GPU/configs/RBC3D_configs.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def prepare_caches(self, prob):
121121
class RBC3Dverification(RayleighBenard3DRegular):
122122
converged = 0
123123
dt = 1e-2
124-
ic_config = None
124+
ic_config = {
125+
'config': None,
126+
'res': -1,
127+
'dt': -1,
128+
}
125129
res = None
126130
Ra = None
127131
Tend = 100
@@ -159,14 +163,16 @@ def get_description(self, *args, res=-1, dt=-1, **kwargs):
159163
return desc
160164

161165
def get_initial_condition(self, P, *args, restart_idx=0, **kwargs):
162-
if self.ic_config is None or restart_idx != 0:
166+
if self.ic_config['config'] is None or restart_idx != 0:
163167
return super().get_initial_condition(P, *args, restart_idx=restart_idx, **kwargs)
164168

165169
# read initial conditions
166170
from pySDC.helpers.fieldsIO import FieldsIO
167171

168-
ic_config = self.ic_config(args={**self.args, 'res': -1, 'dt': -1})
169-
desc = ic_config.get_description()
172+
ic_config = self.ic_config['config'](
173+
args={**self.args, 'res': self.ic_config['res'], 'dt': self.ic_config['dt']}
174+
)
175+
desc = ic_config.get_description(res=self.ic_config['res'], dt=self.ic_config['dt'])
170176
ic_nx = desc['problem_params']['nx']
171177
ic_ny = desc['problem_params']['ny']
172178
ic_nz = desc['problem_params']['nz']
@@ -180,6 +186,7 @@ def get_initial_condition(self, P, *args, restart_idx=0, **kwargs):
180186

181187
# interpolate the initial conditions using padded transforms
182188
padding = (P.nx / ic_nx, P.ny / ic_ny, P.nz / ic_nz)
189+
P.logger.info(f'Interpolating initial conditions from {ic_nx}x{ic_ny}x{ic_nz} to {P.nx}x{P.ny}x{P.nz}')
183190

184191
ics = _P.xp.array(ics)
185192
_ics_hat = _P.transform(ics)
@@ -243,38 +250,33 @@ def get_description(self, *args, res=-1, dt=-1, **kwargs):
243250
class RBC3DG4R4Ra1e5(RBC3Dverification):
244251
Tend = 200
245252
dt = 6e-2
246-
ic_config = None
247253
res = 32
248254
converged = 50
249255

250256

251257
class RBC3DG4R4SDC23Ra1e5(RBC3DM2K3):
252258
Tend = 200
253259
dt = 6e-2
254-
ic_config = None
255260
res = 32
256261
converged = 50
257262

258263

259264
class RBC3DG4R4SDC34Ra1e5(RBC3DM3K4):
260265
Tend = 200
261266
dt = 6e-2
262-
ic_config = None
263267
res = 32
264268
converged = 50
265269

266270

267271
class RBC3DG4R4RKRa1e5(RBC3DverificationRK):
268272
Tend = 200
269273
dt = 8e-2
270-
ic_config = None
271274
res = 32
272275
converged = 50
273276

274277

275278
class RBC3DG4R4EulerRa1e5(RBC3DverificationEuler):
276279
Tend = 200
277280
dt = 8e-2
278-
ic_config = None
279281
res = 32
280282
converged = 50

pySDC/projects/GPU/tests/test_RBC_3D_analysis.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ def tmp_processed_data(tmp_sim_data, tmp_path):
5555
return generate_processed_file(tmp_path)
5656

5757

58+
def test_ic_interpolation(tmp_sim_data, tmp_path):
59+
from pySDC.projects.GPU.run_experiment import run_experiment
60+
61+
args = get_args(tmp_path)
62+
63+
ic_res = args['res'] * 1
64+
args['res'] *= 2
65+
config = get_config(args)
66+
67+
config.ic_config = {'config': type(config), 'res': ic_res, 'dt': args['dt']}
68+
u = run_experiment(args, config)
69+
assert u.shape[-1] == args['res']
70+
71+
5872
def test_processing(tmp_processed_data):
5973
import pickle
6074

@@ -75,7 +89,6 @@ def test_get_pySDC_data(tmp_processed_data, tmp_path):
7589
assert me in data.keys()
7690

7791

78-
@pytest.mark.base
7992
def test_Nu_interpolation():
8093
from pySDC.projects.GPU.analysis_scripts.plot_Nu import interpolate_NuV_to_reference_times
8194
import numpy as np
@@ -98,13 +111,4 @@ def _get_Nu(_t):
98111
# interpolate to insufficient order
99112
tI, NuI = interpolate_NuV_to_reference_times(data, ref_data, order=4)
100113
assert not np.allclose(NuI, ref_data['Nu']['V'])
101-
assert not np.allclose(data['Nu']['V'], ref_data['Nu']['V'])
102114
assert np.allclose(tI, ref_data['t'])
103-
104-
105-
if __name__ == '__main__':
106-
path = 'tmp'
107-
# generate_simulation_file(path)
108-
processed_path = generate_processed_file(path)
109-
# test_processing(processed_path)
110-
test_get_pySDC_data(None, path)

0 commit comments

Comments
 (0)