Skip to content

Commit 1ad9994

Browse files
committed
Pinning initial spectra comparison
1 parent c85e781 commit 1ad9994

7 files changed

+569
-24
lines changed

low_freq_dev/transform_norm.md low_freq_dev/MM_old/transform_norm.md

-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ We set `blend_num` to `0`, so `buffer_extension = 2 * self.n_buffer` where
7070
`self.n_buffer` is the somewhat arbitrary buffer size `ceil( (3 * Gamma * L) / dx)`
7171

7272
Now, `n_margin_y, n_margin_z` are just `ceil(L / dy), ceil(L / dz)`
73-
File renamed without changes.

low_freq_dev/simulator.py low_freq_dev/less_old/simulator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def _initialize_grid(self):
6565

6666
def sqrtSpectralTensor_isotropic(self):
6767
"""
68-
68+
6969
"""
7070
common_factor = self.c / (
71-
np.pi *
71+
np.pi *
7272
(self.L_2d**-2 + self.kappa**2) ** (7 / 3) *
7373
(1 + (self.kappa * self.z_i)**2)
7474
)

low_freq_dev/progress.py low_freq_dev/most_recent.py

+88-21
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, config):
4545
self.c = (8.0 * self.sigma2) / (9.0 * (self.L_2d**(2 / 3)))
4646

4747

48-
def generate(self):
48+
def generate(self, eta_ones=False):
4949

5050
# Fourier space
5151
k_mag = self.k1**2 + self.k2**2
@@ -55,7 +55,11 @@ def generate(self):
5555
C2 = 1j * phi_ * (-1 * self.k1)
5656

5757
# Random noise
58-
eta = np.fft.fft2(np.random.normal(0, 1, size=(self.N1, self.N2)))
58+
eta: np.ndarray
59+
if eta_ones:
60+
eta = np.ones_like(self.k1)
61+
else:
62+
eta = np.random.normal(0, 1, size=(self.N1, self.N2))
5963

6064
u1_freq = C1 * eta
6165
u2_freq = C2 * eta
@@ -71,7 +75,15 @@ def generate(self):
7175
return u1, u2
7276

7377

74-
def mesh_study():
78+
def mesh_independence_study(von_karman=False):
79+
"""
80+
Mesh independence study.
81+
"""
82+
83+
print("="*80)
84+
print("MESH INDEPENDENCE STUDY")
85+
print("="*80)
86+
print(" Square mesh")
7587

7688
config = {
7789
"sigma2": 2.0, # m²/s²
@@ -85,40 +97,98 @@ def mesh_study():
8597
"N2": 9, # Grid points in y direction
8698
}
8799

88-
89-
gen = generator(config)
90-
91-
# Ok, x-axis = exponent of 2 for N1 and N2
92-
93-
exponents = np.arange(4, 12)
100+
exponents = np.arange(4, 15)
94101

95102
u1_norms = []
96103
u2_norms = []
97104

98105
for x in exponents:
99-
100106
config["N1"] = x
101107
config["N2"] = x
102108

103109
gen = generator(config)
110+
u1, u2 = gen.generate_von_karman(epsilon=1.0, L=1.0, eta_ones=True) if von_karman else gen.generate(eta_ones=True)
104111

105-
u1, u2 = gen.generate()
112+
u1_norms.append(
113+
np.linalg.norm(u1) * gen.dx * gen.dy
114+
)
115+
u2_norms.append(
116+
np.linalg.norm(u2) * gen.dx * gen.dy
117+
)
106118

107-
u1_norm = np.linalg.norm(u1) * gen.dx * gen.dy
108-
u2_norm = np.linalg.norm(u2) * gen.dx * gen.dy
109119

120+
print("\tvariance of u1 norm", np.var(u1_norms))
121+
print("\tvariance of u2 norm", np.var(u2_norms), "\n")
122+
print("\tmean of u1 norm", np.mean(u1_norms))
123+
print("\tmean of u2 norm", np.mean(u2_norms))
110124

111-
u1_norms.append(u1_norm)
112-
u2_norms.append(u2_norm)
125+
plt.plot(exponents, u1_norms, label="u1")
126+
plt.plot(exponents, u2_norms, label="u2")
127+
plt.title(r"Square mesh, $N_1 = N_2 \in [4,14]$")
128+
plt.legend()
129+
plt.show()
113130

131+
print(" Rectangular mesh")
132+
133+
u1_norms = []
134+
u2_norms = []
135+
136+
for x in exponents:
137+
config["N1"] = x
138+
config["N2"] = 4
139+
140+
gen = generator(config)
141+
u1, u2 = gen.generate_von_karman(epsilon=1.0, L=1.0) if von_karman else gen.generate(eta_ones=True)
142+
143+
u1_norms.append(
144+
np.linalg.norm(u1) * gen.dx * gen.dy
145+
)
146+
u2_norms.append(
147+
np.linalg.norm(u2) * gen.dx * gen.dy
148+
)
149+
150+
print("\tvariance of u1 norm", np.var(u1_norms))
151+
print("\tvariance of u2 norm", np.var(u2_norms))
152+
print("\tmean of u1 norm", np.mean(u1_norms))
153+
print("\tmean of u2 norm", np.mean(u2_norms))
114154

115155
plt.plot(exponents, u1_norms, label="u1")
116156
plt.plot(exponents, u2_norms, label="u2")
157+
plt.title(r"Rectangular mesh, $N_1 \in [4,14], N_2 = 4$")
117158
plt.legend()
118159
plt.show()
119160

120161

162+
def length_independence_study():
163+
"""
164+
Tests several length scales L_2d as well as several L1_factor and L2_factor
165+
values to determine how dependent the method is on these domain sizes.
166+
"""
167+
168+
print("="*80)
169+
print("LENGTH INDEPENDENCE STUDY")
170+
print("="*80)
171+
172+
config = {
173+
"sigma2": 2.0,
174+
"L_2d": 1.0,
175+
"psi": np.deg2rad(45.0),
176+
"z_i": 1.0,
177+
178+
"L1_factor": 1,
179+
"L2_factor": 1,
180+
181+
"N1": 9,
182+
"N2": 9,
183+
}
184+
185+
pass
186+
187+
121188
def debug_plot(u1, u2):
189+
"""Recreates roughly fig 3 from simulation paper."""
190+
191+
fig, axs = plt.subplots(2, 1)
122192

123193
pass
124194

@@ -137,14 +207,11 @@ def debug_plot(u1, u2):
137207
"N2": 9, # Grid points in y direction
138208
}
139209

140-
gen = generator(fig2a_full_dom)
210+
# gen = generator(fig2a_full_dom)
141211

142-
u1, u2 = gen.generate()
212+
# u1, u2 = gen.generate()
143213

144-
mesh_study()
214+
mesh_independence_study(von_karman=True)
145215

146216

147217
# for _ in range(10):
148-
149-
150-

low_freq_dev/random.ipynb

+97
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)