Skip to content

Commit c6535ab

Browse files
committed
Console app added
1 parent 1caa717 commit c6535ab

10 files changed

+353
-1
lines changed

ODEPlotter.sln

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODEPlotter", "ODEPlotter\OD
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RK", "RK\RK.csproj", "{BDD96468-7968-48C4-8D7F-3CCD28333FAB}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODEPlotterConsole", "ODEPlotterConsole\ODEPlotterConsole.csproj", "{CE6D6192-051C-42DA-8B80-1992BCF11F13}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -35,6 +37,16 @@ Global
3537
{BDD96468-7968-48C4-8D7F-3CCD28333FAB}.Release|Mixed Platforms.Build.0 = Release|x86
3638
{BDD96468-7968-48C4-8D7F-3CCD28333FAB}.Release|x86.ActiveCfg = Release|x86
3739
{BDD96468-7968-48C4-8D7F-3CCD28333FAB}.Release|x86.Build.0 = Release|x86
40+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
43+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
44+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Debug|x86.ActiveCfg = Debug|Any CPU
45+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
48+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Release|Mixed Platforms.Build.0 = Release|Any CPU
49+
{CE6D6192-051C-42DA-8B80-1992BCF11F13}.Release|x86.ActiveCfg = Release|Any CPU
3850
EndGlobalSection
3951
GlobalSection(SolutionProperties) = preSolution
4052
HideSolutionNode = FALSE

ODEPlotterConsole/Angles.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
namespace ODEPlotterConsole
4+
{
5+
public static class Angles
6+
{
7+
public static double GetPsi(this double[] y)
8+
{
9+
var alpha1 = y[0] * y[0] + y[1] * y[1] - y[2] * y[2] - y[3] * y[3];
10+
var beta1 = 2 * (y[1] * y[2] + y[0] * y[3]);
11+
return Math.Abs(Math.Atan(beta1 / alpha1));
12+
}
13+
14+
public static double GetPhi(this double[] y)
15+
{
16+
var gamma2 = 2 * (y[2] * y[3] + y[0] * y[1]);
17+
var gamma3 = y[0] * y[0] - y[1] * y[1] - y[2] * y[2] + y[3] * y[3];
18+
return Math.Abs(Math.Atan(gamma2 / gamma3));
19+
}
20+
21+
public static double GetTheta(this double[] y)
22+
{
23+
var gamma1 = 2 * (y[1] * y[3] - y[0] * y[2]);
24+
return Math.Abs(-Math.Asin(gamma1));
25+
}
26+
27+
}
28+
}

ODEPlotterConsole/App.config

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
<appSettings>
7+
<!-- Период времени -->
8+
<add key="timePeriod" value="500"/>
9+
<!-- Шаг интегрирования -->
10+
<add key="timeStep" value="0,1"/>
11+
<!-- Самолетные углы в долях Пи -->
12+
<add key="phi0" value="0,05"/>
13+
<add key="psi0" value="0,05"/>
14+
<add key="theta0" value="0,05"/>
15+
<!-- ... -->
16+
</appSettings>
17+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace ODEPlotterConsole
2+
{
3+
public class GravitationalMomentEquations : RungeKuttaBase
4+
{
5+
private readonly double _epsilon;
6+
private readonly double _delta;
7+
8+
public GravitationalMomentEquations(double epsilon, double delta) : base(7)
9+
{
10+
_epsilon = epsilon;
11+
_delta = delta;
12+
}
13+
14+
public override void Equations(double t, double[] y, ref double[] yDot)
15+
{
16+
var p = y[0] * y[0] + y[1] * y[1] + y[2] * y[2] + y[3] * y[3] - 1;
17+
yDot[0] = -0.5 * y[1] * y[4] - 0.5 * y[2] * y[5] - 0.5 * y[3] * y[6] + 0.5 * y[2] - 0.5 * y[0] * p;
18+
yDot[1] = 0.5 * y[0] * y[4] + 0.5 * y[2] * y[6] - 0.5 * y[3] * y[5] - 0.5 * y[3] - 0.5 * y[1] * p;
19+
yDot[2] = 0.5 * y[0] * y[5] + 0.5 * y[3] * y[4] - 0.5 * y[1] * y[6] - 0.5 * y[0] - 0.5 * y[2] * p;
20+
yDot[3] = 0.5 * y[0] * y[6] + 0.5 * y[1] * y[5] - 0.5 * y[2] * y[4] + 0.5 * y[1] - 0.5 * y[3] * p;
21+
yDot[4] = (_epsilon - _delta) * (-y[5] * y[6] + 3 * (2 * y[2] * y[3] + 2 * y[0] * y[1])
22+
* (y[0] * y[0] - y[1] * y[1] - y[2] * y[2] + y[3] * y[3]));
23+
yDot[5] = (1 - _epsilon) / _delta * (-y[6] * y[4] + 3 * (2 * y[1] * y[3] - 2 * y[0] * y[2])
24+
* (y[0] * y[0] - y[1] * y[1] - y[2] * y[2] + y[3] * y[3]));
25+
yDot[6] = (_delta - 1) / _epsilon * (-y[4] * y[5] + 3 * (2 * y[1] * y[3] - 2 * y[0] * y[2])
26+
* (2 * y[2] * y[3] + 2 * y[0] * y[1]));
27+
}
28+
}
29+
}
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{CE6D6192-051C-42DA-8B80-1992BCF11F13}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ODEPlotterConsole</RootNamespace>
11+
<AssemblyName>ODEPlotterConsole</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Configuration" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="GravitationalMomentEquations.cs" />
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="RungeKuttaBase.cs" />
49+
<Compile Include="Solver.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="App.config" />
53+
</ItemGroup>
54+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
55+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
56+
Other similar extension points exist, see Microsoft.Common.targets.
57+
<Target Name="BeforeBuild">
58+
</Target>
59+
<Target Name="AfterBuild">
60+
</Target>
61+
-->
62+
</Project>

ODEPlotterConsole/Program.cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Configuration;
3+
4+
namespace ODEPlotterConsole
5+
{
6+
public class Program
7+
{
8+
private static void Main(string[] args)
9+
{
10+
var timePeriod = double.Parse(ConfigurationManager.AppSettings["timePeriod"]);
11+
var timeStep = double.Parse(ConfigurationManager.AppSettings["timeStep"]);
12+
var phi0 = double.Parse(ConfigurationManager.AppSettings["phi0"]);
13+
var psi0 = double.Parse(ConfigurationManager.AppSettings["psi0"]);
14+
var theta0 = double.Parse(ConfigurationManager.AppSettings["theta0"]);
15+
Console.WriteLine("Вычисления ведутся с параметрами:" + Environment.NewLine +
16+
"Шаг интегрирования = {1}" + Environment.NewLine +
17+
"Начальные условия для самолетных углов:" + Environment.NewLine +
18+
"Угол Phi = {2}" + Environment.NewLine +
19+
"Угол Psi = {3}" + Environment.NewLine +
20+
"Угол Theta = {4}" + Environment.NewLine +
21+
"Угол = {0}" + Environment.NewLine,
22+
timePeriod, timeStep, phi0, psi0, theta0);
23+
var initConditions = Solver.InitialConditions(phi0, theta0, psi0);
24+
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ODEPlotterConsole")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ODEPlotterConsole")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("8323ae54-a996-4046-a307-3bf0543d1080")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

ODEPlotterConsole/RungeKuttaBase.cs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
3+
namespace ODEPlotterConsole
4+
{
5+
public class RungeKuttaBase
6+
{
7+
public int N;
8+
double _t; // current time
9+
public double[] Y; //solutions
10+
11+
private double[] _y1, _y2, _y3, _y4, _yy;
12+
13+
private void BaseSetup(int aN)
14+
{
15+
N = aN; // сохранить размерность системы
16+
17+
if (N < 1)
18+
{
19+
N = -1; // если размерность меньше единицы, то установить флаг ошибки
20+
return; // и выйти из конструктора
21+
}
22+
23+
Y = new double[N]; // создать вектор решения
24+
_yy = new double[N]; // и внутренних решений
25+
_y1 = new double[N];
26+
_y2 = new double[N];
27+
_y3 = new double[N];
28+
_y4 = new double[N];
29+
}
30+
31+
public RungeKuttaBase(int aN) // aN - размерность системы
32+
{
33+
BaseSetup(aN);
34+
}
35+
36+
public RungeKuttaBase(int aN, double t0, double[] y0)
37+
{
38+
BaseSetup(aN);
39+
SetInit(t0, y0);
40+
}
41+
42+
public void SetInit(double t0, double[] y0) // установить начальные условия.
43+
{ // t0 - начальное время, Y0 - начальное условие
44+
_t = t0;
45+
int i;
46+
for (i = 0; i < N; i++)
47+
{
48+
Y[i] = y0[i];
49+
}
50+
}
51+
52+
public double GetTime()
53+
{
54+
return _t;
55+
}
56+
57+
public virtual void Equations(double t, double[] y, ref double[] yDot)
58+
{
59+
throw new NotImplementedException();
60+
}
61+
62+
public void NextStep(double dt) // следующий шаг метода Рунге-Кутта, dt - шаг по времени (может быть переменным)
63+
{
64+
if (dt < 0)
65+
{
66+
return;
67+
}
68+
69+
int i;
70+
71+
Equations(_t, Y, ref _y1); // расчитать Y1
72+
73+
for (i = 0; i < N; i++)
74+
{
75+
_yy[i] = Y[i] + _y1[i] * (dt / 2.0);
76+
}
77+
Equations(_t + dt / 2.0, _yy, ref _y2); // расчитать Y2
78+
79+
for (i = 0; i < N; i++)
80+
{
81+
_yy[i] = Y[i] + _y2[i] * (dt / 2.0);
82+
}
83+
Equations(_t + dt / 2.0, _yy, ref _y3); // расчитать Y3
84+
85+
for (i = 0; i < N; i++)
86+
{
87+
_yy[i] = Y[i] + _y3[i] * dt;
88+
}
89+
Equations(_t + dt, _yy, ref _y4); // расчитать Y4
90+
91+
for (i = 0; i < N; i++)
92+
{
93+
Y[i] = Y[i] + dt / 6.0 * (_y1[i] + 2.0 * _y2[i] + 2.0 * _y3[i] + _y4[i]); // расчитать решение на новом шаге
94+
}
95+
96+
_t = _t + dt; // увеличить шаг
97+
98+
}
99+
}
100+
}

ODEPlotterConsole/Solver.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
3+
namespace ODEPlotterConsole
4+
{
5+
public class Solver
6+
{
7+
public const double Pi = Math.PI;
8+
9+
//углы указываются в долях Пи
10+
public static double[] InitialConditions(double phi0, double theta0, double psi0)
11+
{
12+
var sPh0 = Math.Sin(phi0 * Pi / 2);
13+
var sPs0 = Math.Sin(psi0 * Pi / 2);
14+
var sTh0 = Math.Sin(theta0 * Pi / 2);
15+
var cPh0 = Math.Cos(phi0 * Pi / 2);
16+
var cPs0 = Math.Cos(psi0 * Pi / 2);
17+
var cTh0 = Math.Cos(theta0 * Pi / 2);
18+
19+
var lambda0 = cPh0*cPs0*cTh0 + sPh0*sPs0*sTh0;
20+
var lambda1 = sPh0*cPs0*cTh0 - cPh0*sPs0*sTh0;
21+
var lambda2 = cPh0*cPs0*sTh0 + sPh0*sPs0*cTh0;
22+
var lambda3 = cPh0*sPs0*cTh0 - sPh0*cPs0*sTh0;
23+
return new[] { lambda0, lambda1, lambda2, lambda3, 0, 1, 0 };
24+
25+
}
26+
27+
public void SolveOnePoint(double tInit, double[] yInit,
28+
double epsilon, double delta,
29+
double timePeriod, double timeStep)
30+
{
31+
var rk4 = new GravitationalMomentEquations(epsilon, delta);
32+
rk4.SetInit(tInit, yInit);
33+
34+
while (rk4.GetTime() < timePeriod)
35+
{
36+
//rk4.Y
37+
rk4.NextStep(timeStep);
38+
}
39+
}
40+
}
41+
}

RK/RK.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
88
<ProjectGuid>{BDD96468-7968-48C4-8D7F-3CCD28333FAB}</ProjectGuid>
9-
<OutputType>Library</OutputType>
9+
<OutputType>Exe</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>RK</RootNamespace>
1212
<AssemblyName>RK</AssemblyName>

0 commit comments

Comments
 (0)