-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_wave.py
executable file
·113 lines (78 loc) · 2.28 KB
/
sound_wave.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# encoding: utf-8
# SPDX-License-Identifier: MIT
# Copyright (c) 2021 ETH Zurich, Luc Grosheintz-Laval
import numpy as np
from morinth.euler_experiment import EulerExperiment
from morinth.weno import OptimalWENO
from morinth.boundary_conditions import Periodic
from morinth.math_tools import gaussian
class SoundWaveIC(object):
"""Small smooth pressure bump."""
def __init__(self, model):
self.model = model
def __call__(self, grid):
x = grid.cell_centers[:,0]
mean, sigma, offset = 0.1, 0.1, 0.5
u0 = np.empty((4, x.shape[0]))
u0[0,...] = 1.0
u0[1,...] = 0.0
u0[2,...] = 0.0
u0[3,...] = 1.0 + mean*gaussian(x - offset, sigma)
return self.model.conserved_variables(u0)
class AdvectiveIC(object):
def __init__(self, model):
self.model = model
def __call__(self, grid):
x = grid.cell_centers[:,0]
u0 = np.empty((4, x.shape[0]))
u0[0,...] = 1.0
u0[1,...] = 0.3*np.sin(2*np.pi*x)
u0[2,...] = 0.0
u0[3,...] = 1.0
return self.model.conserved_variables(u0)
class PeriodicEulerExperiment(EulerExperiment):
@property
def boundary_condition(self):
return Periodic(self.grid)
@property
def order(self):
return 5
class SoundWave(PeriodicEulerExperiment):
"""Sound wave in a periodic box."""
@property
def n_cells(self):
return 200
@property
def final_time(self):
return 3.0
@property
def initial_condition(self):
return SoundWaveIC(self.model)
@property
def output_filename(self):
return "img/sound_wave"
@property
def steps_per_frame(self):
return 30
class SmoothAdvection(PeriodicEulerExperiment):
"""Advection test-case."""
@property
def final_time(self):
return 3.0
@property
def n_cells(self):
return 200
@property
def initial_condition(self):
return AdvectiveIC(self.model)
@property
def output_filename(self):
return "img/smooth_advection"
@property
def steps_per_frame(self):
return 10
if __name__ == '__main__':
all_experiments = [SoundWave(), SmoothAdvection()]
for experiment in all_experiments:
experiment()