commit 08293bbf3a20eed0182ce341cd4c82b108b45c21 Author: hzhang Date: Wed Jan 8 21:05:36 2025 +0000 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/Hermeteus.csproj b/Hermeteus.csproj new file mode 100644 index 0000000..f3b5ad3 --- /dev/null +++ b/Hermeteus.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/Hermeteus.sln b/Hermeteus.sln new file mode 100644 index 0000000..2b2346f --- /dev/null +++ b/Hermeteus.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hermeteus", "Hermeteus.csproj", "{65C35817-9FA0-4AC6-B798-4AFBFC66A7C7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skeleton", "..\Skeleton\Skeleton.csproj", "{D8D5EFCF-16AD-4E1F-ACF6-B47367A5CDB6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {65C35817-9FA0-4AC6-B798-4AFBFC66A7C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65C35817-9FA0-4AC6-B798-4AFBFC66A7C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65C35817-9FA0-4AC6-B798-4AFBFC66A7C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65C35817-9FA0-4AC6-B798-4AFBFC66A7C7}.Release|Any CPU.Build.0 = Release|Any CPU + {D8D5EFCF-16AD-4E1F-ACF6-B47367A5CDB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8D5EFCF-16AD-4E1F-ACF6-B47367A5CDB6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8D5EFCF-16AD-4E1F-ACF6-B47367A5CDB6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8D5EFCF-16AD-4E1F-ACF6-B47367A5CDB6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/HomogeneousMixture.cs b/src/HomogeneousMixture.cs new file mode 100644 index 0000000..102df0a --- /dev/null +++ b/src/HomogeneousMixture.cs @@ -0,0 +1,25 @@ +namespace Hermeteus; + +public class HomogeneousMixture +{ + public HomogeneousMixture() + { + Components = new Dictionary(); + } + + internal Dictionary Components { get; } + + internal SU3 EigenState => Components.Keys + .Select(x => x.EigenState.Log() * Ratio(x)) + .Aggregate((a, b) => a + b) + .Exp(); + + public double Amount => Components.Sum(p => p.Value); + + public double Ratio(Molecule m) => Amount == 0 + ? 0 + : Components.GetValueOrDefault(m, 0) / Amount; + + +} + diff --git a/src/Measurements/Basic.cs b/src/Measurements/Basic.cs new file mode 100644 index 0000000..d0708d9 --- /dev/null +++ b/src/Measurements/Basic.cs @@ -0,0 +1,37 @@ +namespace Hermeteus.Measurements; + +public static partial class Measurement +{ + private static double MolecularMass(this Molecule m) + { + H3 w = m.EigenState.ConjugateOn(new DiagR3(Math.PI / 32, Math.PI * 2, Math.PI * 8)); + double r0 = w.Rayleigh( + m.EigenState.Log().ColumnAverageBivariant + + m.EigenState.ColumnAverage + ); + return r0 * r0 / 8d; + } + + private static double MolecularDensity(this Molecule m) + { + H3 w = m.EigenState.ConjugateOn(new DiagR3(-Math.PI, 0, Math.PI)); + double r0 = w.Rayleigh( + m.EigenState.ColumnAverageBivariant - + m.EigenState.Log().ColumnAverage + ); + return r0 * r0 / 3d; + } + + public static double Mass(this HomogeneousMixture h) => + h.Components + .Select(p => p.Key.MolecularMass() * p.Value) + .Sum(); + + public static double Density(this HomogeneousMixture h) => + h.Components.Keys + .Select(x => x.MolecularDensity() * h.Ratio(x)) + .Sum(); + + + +} diff --git a/src/Measurements/Color.cs b/src/Measurements/Color.cs new file mode 100644 index 0000000..2619d5f --- /dev/null +++ b/src/Measurements/Color.cs @@ -0,0 +1,70 @@ +using Skeleton.Constants; + +namespace Hermeteus.Measurements; + +public static partial class Measurement +{ + private static readonly U3 RedFilter = new LieU3 + ( + I, 0, -1, + 0, I, 0, + 1, 0, -I + ).Exp(); + + private static readonly U3 GreenFilter = new LieU3 + ( + 0, -I, 0, + -I, 0, -1, + 0, 1, 0 + ).Exp(); + + private static readonly U3 BlueFilter = new LieU3 + ( + 0, 0, -I, + 0, 0, -1, + -I, 1, 0 + ).Exp(); + + private static readonly U3 OpacityFilter = new LieU3( + I, -I, -I, + -I, I, -1, + -I, 1, -I + ).Exp(); + + + private static readonly H3 RedDefinite = RedFilter.ConjugateOn(AlgebraConstant.UniformSpectrum3); + + private static readonly H3 GreenDefinite = GreenFilter.ConjugateOn(AlgebraConstant.UniformSpectrum3); + + private static readonly H3 BlueDefinite = BlueFilter.ConjugateOn(AlgebraConstant.UniformSpectrum3); + + private static readonly H3 OpacityDefinite = OpacityFilter.ConjugateOn(new DiagR3(0.05d, 0.74d, 1d)); + + public static Byte Red(HomogeneousMixture m) => (Byte) + ( + m.EigenState + .ConjugateOn(RedDefinite) + .Rayleigh(Ita(m)) * 255 + ); + + public static Byte Green(HomogeneousMixture m) => (Byte) + ( + m.EigenState + .ConjugateOn(GreenDefinite) + .Rayleigh(Ita(m)) * 255 + ); + + public static Byte Blue(HomogeneousMixture m) => (Byte) + ( + m.EigenState + .ConjugateOn(BlueDefinite) + .Rayleigh(Ita(m)) * 255 + ); + + public static Byte Alpha(HomogeneousMixture m) => (Byte) + ( + m.EigenState + .ConjugateOn(OpacityDefinite) + .Rayleigh(Ita(m)) * 255 + ); +} diff --git a/src/Measurements/Measurement.cs b/src/Measurements/Measurement.cs new file mode 100644 index 0000000..99cd280 --- /dev/null +++ b/src/Measurements/Measurement.cs @@ -0,0 +1,11 @@ +using System.Numerics; + +namespace Hermeteus.Measurements; + +public static partial class Measurement +{ + private static Complex I => Complex.ImaginaryOne; + public static C3 Ita(this HomogeneousMixture h) => h.Components.Keys + .Select(x => x.EigenState.ColumnAverageBivariant * h.Ratio(x)) + .Aggregate((a, b) => a + b); +} \ No newline at end of file diff --git a/src/Measurements/Reaction.cs b/src/Measurements/Reaction.cs new file mode 100644 index 0000000..5687d66 --- /dev/null +++ b/src/Measurements/Reaction.cs @@ -0,0 +1,12 @@ +namespace Hermeteus.Measurements; + +public static partial class Measurement +{ + public static double[] Negativity(this Molecule m) => + m.EigenState.EigenValues() + .Select(eiv => eiv.Phase/Math.PI) + .ToArray(); + + + +} diff --git a/src/Molecule.cs b/src/Molecule.cs new file mode 100644 index 0000000..76b21ae --- /dev/null +++ b/src/Molecule.cs @@ -0,0 +1,13 @@ + +namespace Hermeteus; + +public class Molecule +{ + internal SU3 EigenState { get; set; } + + public Molecule(SU3 eigenState) + { + EigenState = eigenState; + } + +} \ No newline at end of file diff --git a/src/Using.cs b/src/Using.cs new file mode 100644 index 0000000..386b906 --- /dev/null +++ b/src/Using.cs @@ -0,0 +1,23 @@ +global using C3 = Skeleton.Algebra.CategoryOf.OnField.FVector; + +global using R3 = Skeleton.Algebra.CategoryOf.OnField.FVector; + +global using C33 = Skeleton.Algebra.CategoryOf.OnField.FMatrix; + +global using R33 = Skeleton.Algebra.CategoryOf.OnField.FMatrix; + +global using U3 = Skeleton.Algebra.CategoryOf.FUnitaryMatrix; + +global using SU3 = Skeleton.Algebra.CategoryOf.FSpecialUnitaryMatrix; + +global using LieU3 = Skeleton.Algebra.CategoryOf.FLieUnitaryMatrix; + +global using LieSU3 = Skeleton.Algebra.CategoryOf.FSpecialLieUnitaryMatrix; + +global using C3Space = Skeleton.Algebra.CategoryOf.OnField.FVectorSpace; + +global using R3Space = Skeleton.Algebra.CategoryOf.OnField.FVectorSpace; + +global using DiagR3 = Skeleton.Algebra.CategoryOf.OnField.FDiagonalMatrix; + +global using H3 = Skeleton.Algebra.CategoryOf.FHermitianMatrix; \ No newline at end of file