Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Add clear kernels and consolidate kernel loading and unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-guillet committed Aug 2, 2024
1 parent 91cd985 commit 3a1743d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 30 deletions.
2 changes: 1 addition & 1 deletion IO.Astrodynamics.CLI/IO.Astrodynamics.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FileVersion>0.0.1</FileVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>astro</ToolCommandName>
<Version>0.1.13</Version>
<Version>0.2.0</Version>
<Title>Astrodynamics command line interface</Title>
<Authors>Sylvain Guillet</Authors>
<Description>This CLI allows end user to exploit IO.Astrodynamics framework </Description>
Expand Down
75 changes: 53 additions & 22 deletions IO.Astrodynamics.Tests/APITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace IO.Astrodynamics.Tests;


public class APITest
{
public APITest()
Expand Down Expand Up @@ -307,7 +308,7 @@ public async Task ReadOrientation()
spacecraft.AddPayload(new Payload("payload1", 50.0, "pay01"));
spacecraft.AddCircularInstrument(-1794600, "CAM600", "mod1", 1.5, Vector3.VectorZ, Vector3.VectorX, Vector3.VectorX);

spacecraft.SetStandbyManeuver(new NadirAttitude(TestHelpers.EarthAtJ2000,DateTime.MinValue, TimeSpan.Zero,
spacecraft.SetStandbyManeuver(new NadirAttitude(TestHelpers.EarthAtJ2000, DateTime.MinValue, TimeSpan.Zero,
spacecraft.Engines.First()));

scenario.AddSpacecraft(spacecraft);
Expand All @@ -322,12 +323,12 @@ public async Task ReadOrientation()

//Read results
Assert.Equal(0.70710678118654757, res.ElementAt(0).Rotation.W);
Assert.Equal(0.0, res.ElementAt(0).Rotation.VectorPart.X,6);
Assert.Equal(0.0, res.ElementAt(0).Rotation.VectorPart.Y,6);
Assert.Equal(0.0, res.ElementAt(0).Rotation.VectorPart.X, 6);
Assert.Equal(0.0, res.ElementAt(0).Rotation.VectorPart.Y, 6);
Assert.Equal(0.70710678118654746, res.ElementAt(0).Rotation.VectorPart.Z);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.X,6);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.Y,6);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.Z,6);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.X, 6);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.Y, 6);
Assert.Equal(0.0, res.ElementAt(0).AngularVelocity.Z, 6);
Assert.Equal(window.StartDate, res.ElementAt(0).Epoch);
Assert.Equal(Frames.Frame.ICRF, res.ElementAt(0).ReferenceFrame);

Expand Down Expand Up @@ -542,28 +543,60 @@ void LoadKernelException()
Assert.Throws<ArgumentNullException>(() => API.Instance.LoadKernels(null));
}

private static object lockobj = new Object();
[Fact]
void UnloadKernels()
{
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Sites/MySite/Ephemeris/MySite.spk"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
API.Instance.LoadKernels(new DirectoryInfo(@"Data/UserDataTest/scn100"));
API.Instance.UnloadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
Assert.Equal(2,API.Instance.GetLoadedKernels().Count());
Assert.Equal(@"Data\UserDataTest\scn100\Sites\MySite\Ephemeris\MySite.spk",API.Instance.GetLoadedKernels().ElementAt(0).FullName);
Assert.Equal(@"Data\UserDataTest\scn100",API.Instance.GetLoadedKernels().ElementAt(1).FullName);
lock (lockobj)
{
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Sites/MySite/Ephemeris/MySite.spk"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
API.Instance.LoadKernels(new DirectoryInfo(@"Data/UserDataTest/scn100"));
API.Instance.UnloadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
var kernels = API.Instance.GetLoadedKernels().ToArray();
Assert.Equal(1, @kernels.Count(x => x.FullName.Contains("scn100")));
}
}

[Fact]
void UnloadKernels2()
{
lock (lockobj)
{
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Clocks/DRAGONFLY32.tsc"));

API.Instance.UnloadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Clocks/DRAGONFLY32.tsc"));
var kernels = API.Instance.GetLoadedKernels().ToArray();
Assert.Equal(0, kernels.Count(x => x.FullName.Contains("DRAGONFLY32.tsc")));
}
}

[Fact]
void LoadKernels()
{
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Sites/MySite/Ephemeris/MySite.spk"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
API.Instance.LoadKernels(new DirectoryInfo(@"Data/UserDataTest/scn100"));

Assert.Equal(2,API.Instance.GetLoadedKernels().Count());
Assert.Equal(Constants.SolarSystemKernelPath,API.Instance.GetLoadedKernels().ElementAt(0));
Assert.Equal(@"scn100",API.Instance.GetLoadedKernels().ElementAt(1).Name);
lock (lockobj)
{
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Sites/MySite/Ephemeris/MySite.spk"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
API.Instance.LoadKernels(new DirectoryInfo(@"Data/UserDataTest/scn100"));

var kernels = API.Instance.GetLoadedKernels().ToArray();
Assert.Equal(1, @kernels.Count(x => x.FullName.Contains("scn100")));
}
}

[Fact]
void LoadKernels2()
{
lock (lockobj)
{
API.Instance.LoadKernels(new DirectoryInfo(@"Data/UserDataTest/scn100"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Spacecrafts/DRAGONFLY32/Ephemeris/DRAGONFLY32.spk"));
API.Instance.LoadKernels(new FileInfo(@"Data/UserDataTest/scn100/Sites/MySite/Ephemeris/MySite.spk"));

var kernels = API.Instance.GetLoadedKernels().ToArray();
Assert.Equal(1, @kernels.Count(x => x.FullName.Contains("scn100")));
}
}

[Fact]
Expand Down Expand Up @@ -598,6 +631,4 @@ void TLEElements()
Assert.Equal(9, tle.O);
Assert.Equal(10, tle.M);
}


}
4 changes: 4 additions & 0 deletions IO.Astrodynamics.Tests/IO.Astrodynamics.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
<Content Include="Data\UserDataTest\scn100\Sites\MySite\Ephemeris\MySite.spk">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Data\UserDataTest\scn100\Spacecrafts\DRAGONFLY32\Clocks\DRAGONFLY32.tsc" />
<Content Include="Data\UserDataTest\scn100\Spacecrafts\DRAGONFLY32\Clocks\DRAGONFLY32.tsc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
30 changes: 24 additions & 6 deletions IO.Astrodynamics/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,20 @@ public IEnumerable<FileSystemInfo> GetLoadedKernels()
public void LoadKernels(FileSystemInfo path)
{
if (path == null) throw new ArgumentNullException(nameof(path));
if (_kernels.Any(x => x.FullName == path.FullName))
{
return;
}

lock (lockObject)
{
if (_kernels.Any(x => path.FullName.Contains(x.FullName)))
{
foreach (var kernel in _kernels.Where(x => path.FullName.Contains(x.FullName)).ToArray())
{
UnloadKernels(kernel);
LoadKernels(kernel);
}

return;
}


var existingKernels = _kernels.Where(x => x.FullName.Contains(path.FullName)).ToArray();
foreach (var existingKernel in existingKernels)
{
Expand Down Expand Up @@ -208,14 +215,25 @@ public void UnloadKernels(FileSystemInfo path)
}

_kernels.RemoveAll(x => x.FullName == path.FullName);
foreach (var kernel in _kernels.Where(x=>x.FullName.Contains(path.FullName)).ToArray())
foreach (var kernel in _kernels.Where(x => x.FullName.Contains(path.FullName)).ToArray())
{
UnloadKernels(kernel);
}
}
}
}

public void ClearKernels()
{
lock (lockObject)
{
foreach (var kernel in _kernels.ToArray())
{
UnloadKernels(kernel);
}
}
}

/// <summary>
/// Find launch windows
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion IO.Astrodynamics/IO.Astrodynamics.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<id>IO.Astrodynamics</id>
<authors>Sylvain Guillet</authors>
<copyright>Sylvain Guillet</copyright>
<version>3.2.3</version>
<version>3.3.0</version>
<title>Astrodynamics framework</title>
<icon>images\dragonfly-dark-trans.png</icon>
<readme>docs\README.md</readme>
Expand Down

0 comments on commit 3a1743d

Please sign in to comment.