···11-import torch as t;from PIL import Image as I;w,h,iters,save_every,r,dt,conv=2**11,2**11,100000,1,10,0.005,lambda f,k:t.nn.functional.conv2d(f.unsqueeze(0),k,bias=None,padding=[0],stride=[1])[0]
11+import torch as t;from PIL import Image as I;w,h,iters,save_every,r,dt,conv=2**10,2**10,100000,1,10,0.005,lambda f,k:t.nn.functional.conv2d(f.unsqueeze(0),k,bias=None,padding=[0],stride=[1])[0]
22t.set_default_device("cuda");kd,kph,kpv=t.tensor([[[[0,1,0],[1,0,1],[0,1,0]]]],dtype=t.float),t.tensor([[[[0,0,0],[1,0,-1],[0,0,0]]]],dtype=t.float),t.tensor([[[[0,1,0],[0,0,0],[0,-1,0]]]], dtype=t.float)
33def bd(f,lt=lambda t:(t[0],t[1])):f[(0,-1)],f[:,(0,-1)]=lt((f[(1,-2)],f[:,(1,-2)]));f[(0,0,-1,-1),(0,-1,0,-1)]=0.5*(f[(0,0,-2,-2),(1,-2,0,-1)]+f[(1,1,-1,-1),(0,-1,1,-2)])
44ind,lim=t.stack((t.arange(1,h-1,dtype=t.float).repeat(w-2,1).t(),t.arange(1,w-1,dtype=t.float).repeat(h-2,1))),1/(dt*1.4142)
···1414 div,p=(conv(f[1],kph)+conv(f[0],kpv))*0.5,t.zeros_like(f[0])
1515 for i in range(80):p[1:h-1,1:w-1]=(div+conv(p,kd))/4;bd(p)
1616 f[1,1:h-1,1:w-1]+=0.5*conv(p,kph);f[0,1:h-1,1:w-1]+=0.5*conv(p,kpv);bd(f[1],lambda t:(-t[0],t[1]));bd(f[0],lambda t:(t[0],-t[1]))
1717-v,d,i=t.nn.Upsample(size=[h,w],mode='bilinear')((t.randn([2,h//128,w//128])*150).unsqueeze(0))[0],t.ones([1,h,w])*0.1,1
1717+v,d,i=t.nn.Upsample(size=[h,w],mode='bilinear')((t.randn([2,h//128,w//128])*50).unsqueeze(0))[0],t.ones([1,h,w])*0.1,1
1818d[0,:,tuple(x*w//20 for x in range(20))]+=0.8;d[0,tuple(x*h//20 for x in range(20)),:]+=0.8
1919for it in range(iters):
2020 d.add_(0.003);v[1,h//3:2*h//3,w//8].add_(40).clamp_(-lim,lim);v[0,1:h-1,1:w-1]=(v[0,1:h-1,1:w-1]+dt*r*conv(v[0],kd))/(1+4*dt*r)