using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Azimuth; using Annulus; using Slipstream.IdealFluid; namespace Slipstream.Testbed.Demos { public class Airfoil : Demo { AbstractBoundaryBody _body; public override void Start(FluidWorld world) { var airfoil = new SimplePolygon(new Vector[] { new Vector(0, 0), new Vector(-100, 0) / 4, // 10 new Vector(-124, 7) / 4, // 25 new Vector(-119, 19) / 4, // 13 new Vector(-95, 26) / 4, // 25 new Vector(-83, 31) / 4, // 13 }); _body = new IdealFluidBoundaryBody(airfoil, Vector.Zero, 0.0, 86); 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 newPos = new Vector(100 * Math.Cos(angularVelocity * cycleCount), 0); var velocity = new Vector(100 * angularVelocity * -Math.Sin(angularVelocity * cycleCount), 0); _body.Position = newPos; _body.LinearVelocity = velocity; _body.Orientation = 0; _body.AngularVelocity = 0; { Scalar totalEnergyCount; // world.IntegrateVortonMotion(1.0 / 60.0); world.EnforceBoundaryConditions(); world.IntegrateTracerParticles(1.0 / 60.0, out totalEnergyCount); foreach (var bb in world.Boundaries) { var boundaryBody = bb as IdealFluid.IdealFluidBoundaryBody; boundaryBody._group.CalculatePressureAtControlPoints(); Vector netForce; Scalar netTorque; boundaryBody.CalculatePressureForces(1.0, out netForce, out netTorque); System.Console.WriteLine(netForce / 10000 + " " + netTorque); } } } public override void Reset(FluidWorld world) { cycleCount = 0; } } }