// --------------------------------------------------------
// Program.cs
//
// Author: Vit Buchta
// Date : June 06, 2007
// --------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace NystromNDim
{
/// <summary>
/// Testing the integration of a set of differential equations
/// of second order with initial conditions
/// </summary>
class Program
{
/// <summary>
/// Flight of the projectile. This test calculates and print the flight
/// of two projectiles. One of them neglects the air draw. The other projectile
/// consideres the drag.
/// </summary>
static void Test1()
{
FlyingBall2 projectileA = new FlyingBall2(0.1, 600, 0.0, 9.81, 1.29);
SecondDerivativeN accelFunctionA = (SecondDerivativeN)projectileA;
FlyingBall2 projectileB = new FlyingBall2(0.1, 600, 0.5, 9.81, 1.29);
SecondDerivativeN accelFunctionB = (SecondDerivativeN)projectileB;
double t0 = 0;
double tmax = 12;
double h = 0.5;
PointN startPosition = new PointN(2);
startPosition[0] = 0;
startPosition[1] = 0;
PointN startVelocity = new PointN(2);
startVelocity[0] = 50;
startVelocity[1] = 50;
PointN startAccelerationA = accelFunctionA.GetValue(t0, startPosition, startVelocity);
NystromN integratorA = new NystromN(accelFunctionA, t0, startPosition, startVelocity,
h, startAccelerationA);
PointN startAccelerationB = accelFunctionB.GetValue(t0, startPosition, startVelocity);
NystromN integratorB = new NystromN(accelFunctionA, t0, startPosition, startVelocity,
h, startAccelerationB);
Console.WriteLine("TEST1 - Flight of the projectile");
Console.WriteLine(" t,s xA,m yA,m xB,m yB,m");
Console.WriteLine("------------------------------------");
Console.WriteLine("{0,4:F1}{1,8:F2}{2,8:F2}{3,8:F2}{4,8:F2}", t0,
startPosition[0], startPosition[1],
startPosition[0], startPosition[1]);
double t;
PointN positionA, velocityA, accelerationA;
PointN positionB, velocityB, accelerationB;
do
{
integratorA.Step(out t, out positionA, out velocityA, out accelerationA);
integratorB.Step(out t, out positionB, out velocityB, out accelerationB);
Console.WriteLine("{0,4:F1}{1,8:F2}{2,8:F2}{3,8:F2}{4,8:F2}", t,
positionA[0], positionA[1],
positionB[0], positionB[1]);
} while (t < tmax);
Console.WriteLine();
}
/// <summary>
/// Mechanical system with two degrees of freedom. This test calculates
/// the dynamical response of a system consisting from two masses
/// and three springs.
/// </summary>
static void Test2()
{
CoupledOscillators couple = new CoupledOscillators(
1.0, 1.0,
40.0, 40.0, 10.0);
SecondDerivativeN accelFunction = (SecondDerivativeN)couple;
double t0 = 0, tmax = 6, h = 0.05;
PointN startPosition = new PointN(2);
startPosition[0] = 0.1;
PointN startVelocity = new PointN(2);
PointN startAcceleration = accelFunction.GetValue(t0, startPosition, startVelocity);
NystromN integrator = new NystromN(accelFunction, t0, startPosition, startVelocity,
h, startAcceleration);
Console.WriteLine("TEST2 - Coupled oscillations");
Console.WriteLine(" t,s x0,m x1,m v0,m/s v1,m/s");
Console.WriteLine("-------------------------------------------");
Console.WriteLine("{0,4:F2}{1,10:F3}{2,10:F3}{3,10:F3}{4,10:F3}", t0,
startPosition[0], startPosition[1],
startVelocity[0], startVelocity[1]);
double t;
PointN position, velocity, acceleration;
do
{
integrator.Step(out t, out position, out velocity, out acceleration);
Console.WriteLine("{0,4:F2}{1,10:F3}{2,10:F3}{3,10:F3}{4,10:F3}", t,
position[0], position[1],
velocity[0], velocity[1]);
} while (t < tmax);
Console.WriteLine();
}
static void Main(string[] args)
{
//Test1();
Test2();
}
}
}