using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Azimuth; using Annulus; using Slipstream.StokesFlow; namespace Slipstream.Testbed.Demos { class UniformFlowStokesPanelSphere : Demo { StokesPanelGroup _group; SimplePolygon _polygon; const float radius = 10; const int subdivisions = 16; public override void Start(FluidWorld world) { var points = new List(); for (int i = 0; i < subdivisions; ++i) { points.Add(radius * new Vector(Math.Cos(2 * Math.PI * i / subdivisions), Math.Sin(2 * Math.PI * i / subdivisions))); } _polygon = new SimplePolygon(points); _group = new StokesPanelGroup(_polygon, subdivisions); world.AddBoundary(_group); Random rand = new Random(1); for (int i = 0; i < 1000; ++i) { world.AddTracerParticle(new Vector(2 * rand.NextDouble() - 1, 2 * rand.NextDouble() - 1) * 100); } } Scalar cycleCount = 0; public override void Update(FluidWorld world) { cycleCount += 1.0 / 60.0; Scalar period = 10; Scalar angularVelocity = (1.0 / period) * (2 * Math.PI); var velocity = new Vector(100 * angularVelocity * Math.Sin(angularVelocity * cycleCount), 0); world.FluidBaseVelocity = velocity; _group.EnforceBoundaryConditions(velocity); Scalar totalEnergyCount; Action groupVelocities = (x, y, velx, vely) => { // x, y are now the particle positions in model space of the body for (int i = 0; i < x.Length; ++i) { var velocityOut = _group.VelocityAtPoint(new Vector(x[i], y[i])); velx[i] += velocityOut.X; vely[i] += velocityOut.Y; } }; world.IntegrateTracerParticles(groupVelocities, 1.0 / 60.0, out totalEnergyCount); } public override void Reset(FluidWorld world) { cycleCount = 0; } public override Blacklight.Core.Cel Draw(FluidWorld world) { var cel = new Blacklight.Core.Cel(); var collage = new Blacklight.Core.Drawables.Collage(); var panelCollage = new Blacklight.Core.Drawables.Collage(); var panel = new Blacklight.Core.Drawables.Rectangle { InsideColor = new Blacklight.Core.Color(0.84, 0.84, 0), ShellColor = new Blacklight.Core.Color(0.84, 0.25, 0), ShellPixelThickness = 0, ShellModelSpaceThickness = 0, SmoothBorder = false, }; panelCollage.AddDrawable(panel, new AffineMatrix( new Vector(_group.PanelLength * 0.5 * 0.90, 0), new Vector(0, 0.5), new Vector(0, 0))); foreach (var panelTransform in _group.PanelsModelToWorld) { collage.AddDrawable(panelCollage, panelTransform); } cel.AddEntity(new Blacklight.Core.Entity { drawable = collage, modelToWorld = AffineMatrix.Identity, }); return cel; } } }