|
7 | 7 | ) |
8 | 8 | import xarray as xr |
9 | 9 | import numpy as np |
| 10 | +import matplotlib.pyplot as plt |
10 | 11 |
|
11 | 12 |
|
12 | 13 | # use DefaultBlobFactory to define distribution functions fo random variables |
13 | 14 | bf = DefaultBlobFactory(A_dist=DistributionEnum.deg, vy_dist=DistributionEnum.zeros) |
14 | 15 |
|
15 | | -t_loss = 2.0 |
16 | | - |
| 16 | +t_drain = 2 |
| 17 | +Nx, Lx = 10, 10 |
17 | 18 | tmp = Model( |
18 | | - Nx=100, |
| 19 | + Nx=Nx, |
19 | 20 | Ny=1, |
20 | | - Lx=10, |
| 21 | + Lx=Lx, |
21 | 22 | Ly=0, |
22 | | - dt=0.1, |
| 23 | + dt=1, |
23 | 24 | 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, |
28 | 27 | periodic_y=False, |
29 | 28 | num_blobs=10000, |
30 | 29 | blob_factory=bf, |
31 | | - t_init=10, |
32 | 30 | one_dimensional=True, |
33 | 31 | ) |
34 | 32 |
|
35 | | -tmp.make_realization(file_name="test_analytical.nc", speed_up=True, error=1e-2) |
36 | | - |
37 | 33 |
|
38 | 34 | def test_convergence_to_analytical_solution(): |
39 | 35 | """ |
40 | 36 | Checks that the mean value of a one-dimensional realization with constant velocities agrees with the |
41 | 37 | analytical derived results. See O. E. Garcia, et al.; Phys. Plasmas 1 May 2016; 23 (5): 052308. https://doi.org/10.1063/1.4951016 |
42 | 38 | """ |
43 | | - ds = xr.open_dataset("test_analytical.nc") |
| 39 | + ds = tmp.make_realization(speed_up=True, error=1e-10) |
44 | 40 | model_profile = ds.n.isel(y=0).mean(dim="t") |
45 | 41 |
|
46 | | - x = np.linspace(0, 10, 100) |
| 42 | + x = np.arange(0, Lx, Lx / Nx) |
47 | 43 | t_p = 1 # vx/ell |
48 | 44 | t_w = 1 / 10 |
49 | 45 | amp = 1 |
50 | 46 | 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) |
54 | 48 |
|
| 49 | + analytical_profile = t_d / t_w * amp * np.exp(-x / (v_p * t_drain)) |
55 | 50 | error = np.mean(abs(model_profile.values - analytical_profile)) |
56 | 51 |
|
57 | 52 | assert error < 0.1, "Numerical error too big" |
0 commit comments