-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsingle_blob.py
79 lines (68 loc) · 1.76 KB
/
single_blob.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
from blobmodel import (
Model,
show_model,
BlobFactory,
Blob,
AbstractBlobShape,
BlobShapeImpl,
BlobShapeEnum,
)
import numpy as np
# here you can define your custom parameter distributions
class CustomBlobFactory(BlobFactory):
def __init__(self) -> None:
pass
def sample_blobs(
self,
Ly: float,
T: float,
num_blobs: int,
blob_shape: AbstractBlobShape,
t_drain: float,
) -> list[Blob]:
# set custom parameter distributions
amp = np.ones(num_blobs)
width = np.ones(num_blobs)
vx = np.ones(num_blobs)
vy = np.ones(num_blobs) * 5
posx = np.zeros(num_blobs)
posy = np.ones(num_blobs) * Ly / 2
t_init = np.ones(num_blobs) * 0
return [
Blob(
blob_id=i,
blob_shape=blob_shape,
amplitude=amp[i],
width_prop=width[i] * 3,
width_perp=width[i],
v_x=vx[i],
v_y=vy[i],
pos_x=posx[i],
pos_y=posy[i],
t_init=t_init[i],
t_drain=t_drain,
blob_alignment=False,
theta=np.pi / 3,
)
for i in range(num_blobs)
]
def is_one_dimensional(self) -> bool:
return False
bf = CustomBlobFactory()
bm = Model(
Nx=100,
Ny=100,
Lx=10,
Ly=10,
dt=0.1,
T=10,
periodic_y=True,
blob_shape=BlobShapeImpl(BlobShapeEnum.rect, BlobShapeEnum.rect),
num_blobs=1,
blob_factory=bf,
t_drain=1e10,
)
# create data
ds = bm.make_realization(speed_up=True, error=1e-2)
# show animation and save as gif
show_model(dataset=ds, interval=100, gif_name="example.gif", fps=10)