Skip to content

Commit c467e47

Browse files
committed
Fix model stop on speed up and test
1 parent 1f9f207 commit c467e47

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

blobmodel/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ def _compute_start_stop(self, blob: Blob, speed_up: bool, error: float):
339339
# ignores t_drain when calculating stop time
340340
stop = np.minimum(
341341
self._geometry.t.size,
342-
start
343-
+ int(
344-
(
342+
int(
343+
blob.t_init
344+
+ (
345345
-blob.width_prop * np.log(error * np.sqrt(np.pi))
346346
+ self._geometry.Lx
347347
- blob.pos_x

examples/compare_to_analytical_sol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
)
3131

3232
ds = tmp.make_realization(speed_up=True, error=1e-10)
33-
x = np.linspace(0, 10, 100)
33+
x = np.linspace(0, 10, 20)
3434
t_p = 1
3535
t_w = 1 / 10
3636
amp = 1

tests/test_analytical.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,46 @@
77
)
88
import xarray as xr
99
import numpy as np
10+
import matplotlib.pyplot as plt
1011

1112

1213
# use DefaultBlobFactory to define distribution functions fo random variables
1314
bf = DefaultBlobFactory(A_dist=DistributionEnum.deg, vy_dist=DistributionEnum.zeros)
1415

15-
t_loss = 2.0
16-
16+
t_drain = 2
17+
Nx, Lx = 10, 10
1718
tmp = Model(
18-
Nx=100,
19+
Nx=Nx,
1920
Ny=1,
20-
Lx=10,
21+
Lx=Lx,
2122
Ly=0,
22-
dt=0.1,
23+
dt=1,
2324
T=1000,
24-
t_drain=t_loss,
25-
blob_shape=BlobShapeImpl(
26-
BlobShapeEnum.exp, BlobShapeEnum.gaussian
27-
), # Analytical form only applies to exp shape
25+
blob_shape=BlobShapeImpl(BlobShapeEnum.exp, BlobShapeEnum.gaussian),
26+
t_drain=t_drain,
2827
periodic_y=False,
2928
num_blobs=10000,
3029
blob_factory=bf,
31-
t_init=10,
3230
one_dimensional=True,
3331
)
3432

35-
tmp.make_realization(file_name="test_analytical.nc", speed_up=True, error=1e-2)
36-
3733

3834
def test_convergence_to_analytical_solution():
3935
"""
4036
Checks that the mean value of a one-dimensional realization with constant velocities agrees with the
4137
analytical derived results. See O. E. Garcia, et al.; Phys. Plasmas 1 May 2016; 23 (5): 052308. https://doi.org/10.1063/1.4951016
4238
"""
43-
ds = xr.open_dataset("test_analytical.nc")
39+
ds = tmp.make_realization(speed_up=True, error=1e-10)
4440
model_profile = ds.n.isel(y=0).mean(dim="t")
4541

46-
x = np.linspace(0, 10, 100)
42+
x = np.arange(0, Lx, Lx / Nx)
4743
t_p = 1 # vx/ell
4844
t_w = 1 / 10
4945
amp = 1
5046
v_p = 1.0
51-
t_d = t_loss * t_p / (t_loss + t_p)
52-
53-
analytical_profile = t_d / t_w * amp * np.exp(-x / (v_p * t_loss))
47+
t_d = t_drain * t_p / (t_drain + t_p)
5448

49+
analytical_profile = t_d / t_w * amp * np.exp(-x / (v_p * t_drain))
5550
error = np.mean(abs(model_profile.values - analytical_profile))
5651

5752
assert error < 0.1, "Numerical error too big"

0 commit comments

Comments
 (0)