-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom_blobfactory.py
74 lines (64 loc) · 1.72 KB
/
custom_blobfactory.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
from blobmodel import (
Model,
BlobFactory,
Blob,
show_model,
AbstractBlobShape,
)
import numpy as np
# create custom class that inherits from BlobFactory
# 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.linspace(0.01, 1, num=num_blobs)
width = np.linspace(0.01, 1, num=num_blobs)
vx = np.linspace(0.01, 1, num=num_blobs)
vy = np.linspace(0.01, 1, num=num_blobs)
posx = np.zeros(num_blobs)
posy = np.random.uniform(low=0.0, high=Ly, size=num_blobs)
t_init = np.random.uniform(low=0, high=T, size=num_blobs)
# sort blobs by _t_init
t_init = np.sort(t_init)
return [
Blob(
blob_id=i,
blob_shape=blob_shape,
amplitude=amp[i],
width_prop=width[i],
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,
)
for i in range(num_blobs)
]
def is_one_dimensional(self) -> bool:
return False
bf = CustomBlobFactory()
tmp = Model(
Nx=32,
Ny=32,
Lx=10,
Ly=10,
dt=0.1,
T=10,
t_drain=2,
periodic_y=True,
num_blobs=100,
blob_factory=bf,
)
ds = tmp.make_realization(speed_up=True, error=1e-1)
show_model(dataset=ds)