コード例 #1
0
position = np.zeros((width, width), dtype=complex)

# position = np.array([[np.sin(x/width*10*pi) * np.sin(y/width*10*pi) for x in range(width)] for y in range(width)], dtype=complex)

# position = np.array([[np.sin(x/width*10*pi + y/width*10*pi) for x in range(width)] for y in range(width)], dtype=complex)

# position = np.array([[np.exp(1j * (x+y)/width*2*pi*10) for x in range(width)] for y in range(width)], dtype=complex)

# add_point(position, 168, 168, width=10, turns=0)
# add_point(position, 107, 107, width=30, turns=0, mag=-1)
# add_point(position, 207, 207, width=20, turns=0, mag=1)
# add_point(position, 50, 50, width=10, turns=1, mag=1)
# add_point(position, 180, 180, width=10, turns=2, mag=1)
# add_packet(position, 150,150, width=20, momentum=10, direction=0)
# add_packet(position, 350,150, width=30, momentum=1, direction=pi/-2)
add_packet(position, 107, 107, width=8, momentum=0, direction=0)
# add_packet(position, 147,147, width=10, momentum=0, direction=0, mag=-1)
# add_packet(position, 350, 350, width=30, momentum=3, direction=2*pi/4)
# add_packet(position, 5,5,width=3)
# position *= 1j
# add_packet(position, 130, 100, width=10, momentum=-3, direction=3*pi/4)
# position /= np.sum(np.abs(position))
position /= np.max(np.abs(position))
position *= 1.0
# position = np.abs(position)

vel = np.zeros_like(position)
nonlinear_vel = np.zeros_like(position)

# position[3,3] = 1
コード例 #2
0
#         dist = np.sqrt((x - center[0]) ** 2 + (y - center[1]) ** 2)
#         if 1<dist < 100:
#             val = complex(x - center[0], y - center[0]) / 100
#             val = val * (100 - dist) / 100
#             initial_data_a[x,y,0] = val.real
#             initial_data_a[x,y,1] = val.imag

# for x in range(width):
#     for y in range(height):
#         center = (width // 2, height // 2)
#         dist = np.sqrt((x - center[0])**2 + (y - center[1])**2)
#         if (dist < 100):
#             initial_data_a[x,y,0] = (100 - dist) / 100
# add_point(initial_data_a, 400, 400, turns=1)
# add_point(initial_data_a, 300, 600, turns=0)
add_packet(initial_data_a, 300, 600, momentum=1)

context = mg.create_context()
point_buffer_a = context.buffer(np.array(initial_data_a, dtype='f4').tobytes())
point_buffer_b = context.buffer(np.array(initial_data_b, dtype='f4').tobytes())
acc_buffer = context.buffer(np.array(initial_data_acc, dtype='f4').tobytes())
grad_buffer = context.buffer(np.array(initial_data_acc, dtype='f4').tobytes())
grav_buffer = context.buffer(np.array(initial_data_acc, dtype='f4').tobytes())

pos_compute_shader = context.compute_shader(pos_compute_shader_code)
acc_compute_shader = context.compute_shader(acc_compute_shader_code)
grad_compute_shader = context.compute_shader(grad_compute_shader_code)
acc_buffer.bind_to_storage_buffer(3)
grad_buffer.bind_to_storage_buffer(4)
grav_buffer.bind_to_storage_buffer(5)
# text = ctx.buffer(grid.tobytes())
コード例 #3
0
# diffusion speed of field
field_SPREAD_RATE = 1.1

# rate of change of g
dg_dt = np.zeros_like(g)

field = np.zeros_like(g)
# dg_dt[20:22,20:22] = 1

# field[20:22,20:22] = 1
# field[30:32,30:32] = 1

# add_field(field, 30,30, width=40, amount=0.05)
# add_field(field, 40,40, width=40, amount=0.05)
add_packet(field, 20, 20, width=10, momentum=10)

# field[20:35, 20:35] = 1
# field[35, 30] = 1

# timestep
dt = 0.005

total_iterations = 1000000
substeps = 30
for i in range(total_iterations):
    print(f'Iteration: {i}')

    # if i % 40 < 10:
    #     field = np.roll(field, 1, axis=0)
    # elif i%40 < 20:
コード例 #4
0
#             val = val * (100 - dist) / 100
#             initial_data_a[x,y,0] = val.real
#             initial_data_a[x,y,1] = val.imag

# for x in range(width):
#     for y in range(height):
#         center = (width // 2, height // 2)
#         dist = np.sqrt((x - center[0])**2 + (y - center[1])**2)
#         if (dist < 100):
#             initial_data_a[x,y,0] = (100 - dist) / 100
# add_point(initial_data_a, 400, 400, turns=1)
# add_point(initial_data_a, 512, 552, turns=5, mag=0.1)
# add_packet(initial_data_a, 300, 300, width=20, momentum=15)
add_packet(initial_data_a,
           512,
           630,
           width=20,
           momentum=6,
           direction=2 * math.pi / 2)
context = mg.create_context()
point_buffer_a = context.buffer(np.array(initial_data_a, dtype='f4').tobytes())
point_buffer_b = context.buffer(np.array(initial_data_b, dtype='f4').tobytes())
pot_buffer = context.buffer(np.array(initial_data_pot, dtype='f4').tobytes())
k1_buffer = context.buffer(np.array(initial_data_zero, dtype='f4').tobytes())
k2_buffer = context.buffer(np.array(initial_data_zero, dtype='f4').tobytes())
k3_buffer = context.buffer(np.array(initial_data_zero, dtype='f4').tobytes())
k4_buffer = context.buffer(np.array(initial_data_zero, dtype='f4').tobytes())
rk_step_buffer_a = context.buffer(b'\x01')
rk_step_buffer_b = context.buffer(b'\x01')

starting_mag = total_mag(point_buffer_a)
# grad_buffer = context.buffer(np.array(initial_data_acc, dtype='f4').tobytes())
コード例 #5
0
from math import pi
from coloring import colorize
from util import first_unoccupied
import imageio

width = 512
position = np.zeros((width, width), dtype=complex)

# position = np.array([[np.sin(x/width*10*pi) * np.sin(y/width*10*pi) for x in range(width)] for y in range(width)], dtype=complex)

# position = np.array([[np.sin(x/width*10*pi + y/width*10*pi) for x in range(width)] for y in range(width)], dtype=complex)

# position = np.array([[np.exp(1j * (x+y)/width*2*pi*10) for x in range(width)] for y in range(width)], dtype=complex)

# add_point(position, 256, 256, width=20, turns=1)
add_packet(position, 256, 256, width=30, momentum=3)
add_packet(position, 350, 350, width=30, momentum=3, direction=2 * pi / 4)
position *= 0.25
# add_packet(position, 130, 100, width=10, momentum=-3, direction=3*pi/4)

dt = 100

coords = np.array(np.linspace(-1, 1, width))
# coords = np.roll(coords, width//2)

momentum_map = np.array([coords]).repeat(width, axis=0)
# np.roll(momentum_map, width//2, axis=0)
momentum_map = momentum_map * momentum_map
# momentum_map = momentum_map + momentum_map.transpose()
# momentum_map *=1.11
momentum_map = np.sqrt(momentum_map + momentum_map.transpose())