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 { public class UniformFlowStokeslet : Demo { public static Vector PositionAtIndex(int index) { Scalar t = (Scalar)index / (count - 1); return new Vector(-panelLength/2 + panelLength * t, 0); } public const int count = 20; public const float panelLength = 10; AbstractBoundaryBody body; public override void Start(FluidWorld world) { var points = new List(); for (int i = 0; i < count; ++i) { points.Add(PositionAtIndex(i)); } body = new StokesBoundaryBody(points, Vector.Zero, 0); world.AddBoundary(body); 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(0, 50 * angularVelocity * Math.Cos(angularVelocity * cycleCount)); world.FluidBaseVelocity = velocity; Scalar totalEnergyCount; world.EnforceBoundaryConditions(); world.IntegrateTracerParticles(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 ellipse = new Blacklight.Core.Drawables.Ellipse { InsideColor = new Blacklight.Core.Color(0.84, 0, 0), ShellColor = new Blacklight.Core.Color(0.25, 0, 0), ShellPixelThickness = 0, ShellModelSpaceThickness = 0.25, SmoothBorder = false, }; for (int i = 0; i < count; ++i) { collage.AddDrawable(ellipse, AffineMatrix.BuildFromTranslation(PositionAtIndex(i)) * AffineMatrix.BuildFromScale(1)); } cel.AddEntity(new Blacklight.Core.Entity { drawable = collage, modelToWorld = body.ModelToWorld, }); return cel; } } }