public void CreateEquationMatrix_WithUnitCubeInput_CreatesTheCorrectRHS() { // Arrange UnitStrengthRectangularSourcePanel[] sourcePanels = new UnitStrengthRectangularSourcePanel[6] { new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(-0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, -0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, 0.5F), U = Vector3.UnitX, V = Vector3.UnitY }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, -0.5F), U = Vector3.UnitX, V = Vector3.UnitY } }; Vector3 vPanels = new Vector3(10, 0, 0); double[] correctRHS = new double[6] { 10, 10, 0, 0, 0, 0 }; // Act double[,] result = Solver.CreateEquationMatrix(sourcePanels, vPanels); bool rhsIsCorrect = true; for (int i = 0; i < correctRHS.Length; i++) { if (result[i, 6] != correctRHS[i]) { rhsIsCorrect = false; } } // Assert Assert.IsTrue(rhsIsCorrect); }
public void GlobalSetup() { Random random = new Random(); float yaw = (float)random.NextDouble() * 2 * MathF.PI; float pitch = (float)random.NextDouble() * 2 * MathF.PI; float roll = (float)random.NextDouble() * 2 * MathF.PI; Matrix4x4 rotationMatrix = Matrix4x4.CreateFromYawPitchRoll(yaw, pitch, roll); _r = new Vector3( (float)(random.NextDouble() - 0.5) * float.MaxValue, (float)(random.NextDouble() - 0.5) * float.MaxValue, (float)(random.NextDouble() - 0.5) * float.MaxValue); _sourcePanel = new UnitStrengthRectangularSourcePanel { AOver2 = (float)random.NextDouble() * float.MaxValue, BOver2 = (float)random.NextDouble() * float.MaxValue, Position = new Vector3( (float)(random.NextDouble() - 0.5) * float.MaxValue, (float)(random.NextDouble() - 0.5) * float.MaxValue, (float)(random.NextDouble() - 0.5) * float.MaxValue), U = Vector3.Transform(Vector3.UnitX, rotationMatrix), V = Vector3.Transform(Vector3.UnitY, rotationMatrix) }; }
public void SolveForSourcePanelStrengths_WithUnitCubeInput_SatisfiesTheTangentialFlowConstraint() { // Arrange UnitStrengthRectangularSourcePanel[] sourcePanels = new UnitStrengthRectangularSourcePanel[6] { new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(-0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, -0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, 0.5F), U = Vector3.UnitX, V = Vector3.UnitY }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, -0.5F), U = Vector3.UnitX, V = Vector3.UnitY } }; Vector3 vPanels = new Vector3(10, 0, 0); // Act double[] strengths = Solver.SolveForSourcePanelStrengths(sourcePanels, vPanels); bool flowIsTangentialAtEachControlPoint = true; for (int i = 0; i < sourcePanels.Length; i++) { Vector3 surfaceNormal = Vector3.Cross(sourcePanels[i].U, sourcePanels[i].V); Vector3 velocity = vPanels; for (int j = 0; j < sourcePanels.Length; j++) { velocity += (float)strengths[j] * Velocity.ComputeSteadyState(sourcePanels[i].Position, sourcePanels[j]); } if (Vector3.Dot(velocity, surfaceNormal) != 0) { flowIsTangentialAtEachControlPoint = false; } } // Assert Assert.IsTrue(flowIsTangentialAtEachControlPoint); }
/// <summary> /// Computes the steady state velocity potential at the point r due to /// the unit-strength rectangular source panel provided. /// </summary> /// <param name="r"> /// The position vector of the point at which the velocity potential is /// computed. /// </param> /// <param name="sourcePanel"> /// The rectangular source panel causing the velocity potential. /// </param> /// <returns>The scalar velocity potential at the point r.</returns> public static float ComputeSteadyState( Vector3 r, UnitStrengthRectangularSourcePanel sourcePanel) { float velocityPotential = ComputeSteadyState( sourcePanel.AOver2, sourcePanel.BOver2, r - sourcePanel.Position, sourcePanel.U, sourcePanel.V); return(velocityPotential); }
/// <summary> /// Computes the steady state velocity at the point r due to the /// unit-strength rectangular source panel provided. /// </summary> /// <param name="r"> /// The position vector of the point at which the velocity is computed. /// </param> /// <param name="sourcePanel"> /// The rectangular source panel causing the velocity. /// </param> /// <returns>The flow velocity vector at the point r.</returns> public static Vector3 ComputeSteadyState( Vector3 r, UnitStrengthRectangularSourcePanel sourcePanel) { Vector3 velocity = ComputeSteadyState( sourcePanel.AOver2, sourcePanel.BOver2, r - sourcePanel.Position, sourcePanel.U, sourcePanel.V); return(velocity); }
public void CreateEquationMatrix_WithUnitCubeInput_CreatesAMAtrixWith6RowsAnd7Columns() { // Arrange UnitStrengthRectangularSourcePanel[] sourcePanels = new UnitStrengthRectangularSourcePanel[6] { new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(-0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, -0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, 0.5F), U = Vector3.UnitX, V = Vector3.UnitY }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, -0.5F), U = Vector3.UnitX, V = Vector3.UnitY } }; Vector3 vPanels = new Vector3(10, 0, 0); // Act double[,] result = Solver.CreateEquationMatrix(sourcePanels, vPanels); int rows = result.GetLength(0); int columns = result.GetLength(1); // Assert Assert.IsTrue((rows == 6) && (columns == 7)); }
public void CreateEquationMatrix_WithUnitCubeInput_CreatesTheCorrectLHS() { // Arrange UnitStrengthRectangularSourcePanel[] sourcePanels = new UnitStrengthRectangularSourcePanel[6] { new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(-0.5F, 0, 0), U = Vector3.UnitY, V = Vector3.UnitZ }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, -0.5F, 0), U = Vector3.UnitZ, V = Vector3.UnitX }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, 0.5F), U = Vector3.UnitX, V = Vector3.UnitY }, new UnitStrengthRectangularSourcePanel { AOver2 = 0.5F, BOver2 = 0.5F, Position = new Vector3(0, 0, -0.5F), U = Vector3.UnitX, V = Vector3.UnitY } }; Vector3 vPanels = new Vector3(10, 0, 0); double[,] correctLHS = new double[6, 6] { { Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[0]).X, Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[1]).X, Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[2]).X, Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[3]).X, Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[4]).X, Velocity.ComputeSteadyState(sourcePanels[0].Position, sourcePanels[5]).X }, { Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[0]).X, Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[1]).X, Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[2]).X, Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[3]).X, Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[4]).X, Velocity.ComputeSteadyState(sourcePanels[1].Position, sourcePanels[5]).X }, { Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[0]).Y, Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[1]).Y, Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[2]).Y, Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[3]).Y, Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[4]).Y, Velocity.ComputeSteadyState(sourcePanels[2].Position, sourcePanels[5]).Y }, { Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[0]).Y, Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[1]).Y, Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[2]).Y, Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[3]).Y, Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[4]).Y, Velocity.ComputeSteadyState(sourcePanels[3].Position, sourcePanels[5]).Y }, { Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[0]).Z, Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[1]).Z, Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[2]).Z, Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[3]).Z, Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[4]).Z, Velocity.ComputeSteadyState(sourcePanels[4].Position, sourcePanels[5]).Z }, { Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[0]).Z, Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[1]).Z, Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[2]).Z, Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[3]).Z, Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[4]).Z, Velocity.ComputeSteadyState(sourcePanels[5].Position, sourcePanels[5]).Z } }; // Act double[,] result = Solver.CreateEquationMatrix(sourcePanels, vPanels); bool lhsIsCorrect = true; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (result[i, j] != correctLHS[i, j]) { lhsIsCorrect = false; } } } // Assert Assert.IsTrue(lhsIsCorrect); }