Flow Around a Cylinder
Flow around a small cylinder, with dye trails to show its path. A simplified fluid model.
Published
No video preview yet
Source
use "@hyle/maths";
use models { ChannelFlow, Cylinder, ChannelFrame };
fn edge(x: Int) -> Float {
if x == -20 { return -1.0; }
if x == 59 { return 1.0; }
return 0.0;
}
// 80 x 32 x 24 volume. Hoist cross-section equilibrium out of the X loop so
// construction stays comfortably inside the normal world-builder operation limit.
for zIndex in -12..12 {
for yIndex in -16..16 {
let y=yIndex+0.5; let z=zIndex+0.5;
let shape=(1.0-y*y/256.0)*(1.0-z*z/144.0);
let ux=0.08*shape;
// Tiny transverse seed, then dynamics are entirely governed by the flow.
let uy=0.0003*shape; let uz=0.0002*shape;
let u2=ux*ux+uy*uy+uz*uz;
let populations=[equilibrium(0.3333333333333333,1.0,0.0,u2),equilibrium(0.027777777777777776,1.0,(-1.0*ux)+(-1.0*uy),u2),equilibrium(0.027777777777777776,1.0,(-1.0*ux)+(-1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(-1.0*ux),u2),equilibrium(0.027777777777777776,1.0,(-1.0*ux)+(1.0*uz),u2),equilibrium(0.027777777777777776,1.0,(-1.0*ux)+(1.0*uy),u2),equilibrium(0.027777777777777776,1.0,(-1.0*uy)+(-1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(-1.0*uy),u2),equilibrium(0.027777777777777776,1.0,(-1.0*uy)+(1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(-1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(1.0*uz),u2),equilibrium(0.027777777777777776,1.0,(1.0*uy)+(-1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(1.0*uy),u2),equilibrium(0.027777777777777776,1.0,(1.0*uy)+(1.0*uz),u2),equilibrium(0.027777777777777776,1.0,(1.0*ux)+(-1.0*uy),u2),equilibrium(0.027777777777777776,1.0,(1.0*ux)+(-1.0*uz),u2),equilibrium(0.05555555555555555,1.0,(1.0*ux),u2),equilibrium(0.027777777777777776,1.0,(1.0*ux)+(1.0*uz),u2),equilibrium(0.027777777777777776,1.0,(1.0*ux)+(1.0*uy),u2)];
let dye=(maths::exp(-(y-5.0)*(y-5.0)/2.0)+maths::exp(-(y+5.0)*(y+5.0)/2.0))
*(maths::exp(-(z-4.0)*(z-4.0)/2.0)+maths::exp(-(z+4.0)*(z+4.0)/2.0));
place ChannelFlow in box([-20,yIndex,zIndex],[60,yIndex+1,zIndex+1]) {
set target.f=populations;
set target.ux=ux; set target.uy=uy; set target.uz=uz;
set target.profile=shape;
set target.boundary=edge(position.x);
set target.injector=dye; set target.dye=0.4*dye;
set target.sponge=maths::clip((position.x-47)/12.0,0.0,1.0);
}
}
}
place Cylinder in cylinder([0,0,-9],[0,0,9],4.0);
// Open edges identify duct extent without covering its interior.
for y in -1..2 {
for z in -1..2 {
if y != 0 && z != 0 {
place ChannelFrame in box([-20,y*17,z*13],[60,y*17+1,z*13+1]);
}
}
}