To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

generate_multi_vortex_256.py 2.26 KB
Newer Older
Jingwei Tang's avatar
Jingwei Tang committed
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
80
81
82
83
84
85
import os
import sys
import torch
import numpy as np

sys.path.append(os.getcwd())
from lib.dfluids.solver import FluidSolver
from lib.dfluids.grid import GridType
import lib.dfluids.utils as utils

# 2d big curl force
res = 256
solver = FluidSolver(grid_size=(res, res))
ext = solver.create_extforces()
mac_op = solver.create_grid_operator(GridType.MAC)
real_op = solver.create_grid_operator(GridType.REAL)
node_op = solver.create_grid_operator(GridType.NODE)
flags, phi_obs = ext.init_flags(phi=True, boundary_width=0, wall="xXyY")

curl = 0

# large scale
phi = node_op.get_gaussian(
    mu=torch.Tensor([0.0, 0.0]),
    sig=torch.Tensor([[0.1, 0], [0, 0.1]]),
    amp=torch.Tensor([-0.03]),
)
curl = curl + node_op.get_curl(phi)

# middle scale
phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.4, -0.4]),
    sig=torch.Tensor([[0.04, 0], [0, 0.04]]),
    amp=torch.Tensor([0.03]),
)
curl = curl + node_op.get_curl(phi)

phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.35, 0.1]),
    sig=torch.Tensor([[0.01, 0], [0, 0.01]]),
    amp=torch.Tensor([0.02]),
)
curl = curl + node_op.get_curl(phi)

# small scale
phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.2, 0.2]),
    sig=torch.Tensor([[0.001, 0], [0, 0.001]]),
    amp=torch.Tensor([0.01]),
)
curl = curl + node_op.get_curl(phi)

phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.25, 0.4]),
    sig=torch.Tensor([[0.001, 0], [0, 0.001]]),
    amp=torch.Tensor([-0.01]),
)
curl = curl + node_op.get_curl(phi)

phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.5, 0.35]),
    sig=torch.Tensor([[0.001, 0], [0, 0.001]]),
    amp=torch.Tensor([0.01]),
)
curl = curl + node_op.get_curl(phi)

phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.7, 0.2]),
    sig=torch.Tensor([[0.001, 0], [0, 0.001]]),
    amp=torch.Tensor([0.01]),
)
curl = curl + node_op.get_curl(phi)

phi = node_op.get_gaussian(
    mu=torch.Tensor([-0.7, 0.0]),
    sig=torch.Tensor([[0.001, 0], [0, 0.001]]),
    amp=torch.Tensor([-0.01]),
)
curl = curl + node_op.get_curl(phi)


utils.mkdir("forces/data/2d_256_multi_vortex/")
mac_op.save_img(curl, "forces/data/2d_256_multi_vortex/lic.png", colormap="LIC")
mac_op.save_img(curl, "forces/data/2d_256_multi_vortex/arrow.png", colormap="ARROW")
np.savez("forces/data/2d_256_multi_vortex/000.npz", force=mac_op.grid2array(curl))