From 20f66b53d1b3fe00bfaa184dafac77c5c0dd0da5 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:26:51 -0500 Subject: [PATCH 1/9] Update DifGeo.cs - Update comments --- .../DifferentialGeometry/DifGeo.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index fb47bc3d..ced254e2 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -377,9 +377,7 @@ public static void Christoffel( // Tensor contractions // - // // Rank-one and Rank-one - // [GenerateTensorContractions] public static TN Contract(in IRankOneTensor> a, in IRankOneTensor> b) @@ -397,9 +395,7 @@ public static TN Contract(in IRankOneTensor, TN, TI> Contract( @@ -443,9 +439,7 @@ public static Tensor, TN, TI> Contract( return new(vector); } - // // Rank-one and Rank-three - // [GenerateTensorContractions] public static Tensor, TN, TI1, TI2> Contract( @@ -497,9 +491,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2, TI3> Contract( @@ -559,9 +551,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, TI1, TI2> Contract( @@ -588,9 +578,7 @@ public static Tensor, TN, TI1, TI2> Contract, TN, TI1, TI2, TI3> Contract( @@ -650,9 +638,7 @@ public static Tensor, TN, TI1, TI2, TI3> Contract, TN, TI1, TI2, TI3, TI4> Contract( @@ -720,9 +706,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract( @@ -757,9 +741,7 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract(in IRankTwoTensor, Index> a) From 6a8a36f35f8db2968fe4a66eb1c7628bb0d3519c Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:25:32 -0500 Subject: [PATCH 2/9] Update DifGeo.cs - Add method to compute the derivatives of Christoffel symbols of the first kind --- .../DifferentialGeometry/DifGeo.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index ced254e2..e42bdbf7 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -373,6 +373,47 @@ public static void Christoffel( >(ref result); } + /// Compute the derivative of a Christoffel symbol of the first kind given a metric tensor. + /// A type that implements and + /// The index of the point at which to compute the Christoffel symbol + /// The name of the first index + /// The name of the second index + /// The name of the third index + /// The name of the fourth index + /// A Hessian tape + /// A metric tensor field + /// A point on the manifold + /// The result + public static void DerivativeOfChristoffel( + HessianTape tape, + MetricTensorField, Matrix4x4, TN, Index> metric, + AutoDiffTensor4> point, + out Tensor, TN, Index, Index, Index, Index> derivative) + where TN : IComplex, IDifferentiableFunctions + where TPIN : ISymbol + where TI1N : ISymbol + where TI2N : ISymbol + where TI3N : ISymbol + where TI4N : ISymbol + { + SecondDerivative(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> secondDerivativeOfMetric); + + derivative = new(); + for (int m = 0; m < 4; m++) + { + for (int k = 0; k < 4; k++) + { + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + derivative[m, k, i, j] = 0.5 * (secondDerivativeOfMetric[m, j, k, i] + secondDerivativeOfMetric[m, i, k, j] - secondDerivativeOfMetric[m, k, i, j]); + } + } + } + } + } + // // Tensor contractions // From f520195511d99684014e6aa6d38d74d354bd7414 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:28:44 -0500 Subject: [PATCH 3/9] Update DifGeo.cs - Fix tensor contraction involving rank-four and rank-two tensors --- src/Mathematics.NET/DifferentialGeometry/DifGeo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index e42bdbf7..5bdc29aa 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -717,9 +717,9 @@ public static Tensor, TN, TI1, TI2, TI3, TI4> Contract, TN, TI1, TI2, TI3, TI4> Contract( in IRankFourTensor, TN, Index, TI1, TI2, TI3> a, - in IRankTwoTensor, TN, Index, TI4> b) + in IRankTwoTensor, TN, Index, TI4> b) where TR4T : IRankFourTensor, TN, Index, TI1, TI2, TI3> - where TR2T : IRankTwoTensor, TN, Index, TI4> + where TR2T : IRankTwoTensor, TN, Index, TI4> where TN : IComplex, IDifferentiableFunctions where TCI : ISymbol where TI1 : IIndex From be87a786b0db53b68a0033833140e503e67f70a8 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:29:20 -0500 Subject: [PATCH 4/9] Update DifGeo.cs - Add method to compute the derivatives of Christoffel symbols of the second kind --- .../DifferentialGeometry/DifGeo.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index 5bdc29aa..2aab5fb9 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -414,6 +414,53 @@ public static void DerivativeOfChristoffel( } } + /// Compute the derivative of a Christoffel symbol of the second kind given a metric tensor. + /// A type that implements and + /// The index of the point at which to compute the Christoffel symbol + /// The name of the first index + /// The name of the second index + /// The name of the third index + /// The name of the fourth index + /// A Hessian tape + /// A metric tensor field + /// A point on the manifold + /// The result + public static void DerivativeOfChristoffel( + HessianTape tape, + MetricTensorField, Matrix4x4, TN, Index> metric, + AutoDiffTensor4> point, + out Tensor, TN, Index, Index, Index, Index> derivative) + where TN : IComplex, IDifferentiableFunctions + where TPIN : ISymbol + where TI1N : ISymbol + where TI2N : ISymbol + where TI3N : ISymbol + where TI4N : ISymbol + { + Derivative(tape, metric, point, out Tensor, TN, Index, Index, Index> derivativeOfInverseMetric); + Christoffel(tape, metric, point, out Christoffel, TN, Index, TI3N, TI4N> christoffel); + var inverseMetric = metric.ComputeInverse(tape, point); + DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> derivativeOfChristoffel); + + var firstPart = Contract(derivativeOfInverseMetric, christoffel); + var secondPart = Contract(inverseMetric, derivativeOfChristoffel); + + derivative = new(); + for (int m = 0; m < 4; m++) + { + for (int k = 0; k < 4; k++) + { + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + derivative[m, k, i, j] = firstPart[m, k, i, j] + secondPart[k, m, i, j]; + } + } + } + } + } + // // Tensor contractions // From 621287733a001905b1096d96bd08731f5f710978 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:01:21 -0500 Subject: [PATCH 5/9] Update DifGeo.cs - Add a method for computing Riemann tensors --- .../DifferentialGeometry/DifGeo.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index 2aab5fb9..d095e7e0 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -461,6 +461,54 @@ public static void DerivativeOfChristoffel( } } + // + // Riemann tensor + // + + /// Compute a Riemann tensor given a metric tensor. + /// A type that implements and + /// The name of the index of the point at which to compute the Riemann tensor + /// The name of the first index + /// The name of the second index + /// The name of the third index + /// The name of the fourth index + /// A Hessian tape + /// A metric tensor field + /// A point on the manifold + /// The result + public static void Riemann( + HessianTape tape, + MetricTensorField, Matrix4x4, TN, Index> metric, + AutoDiffTensor4> point, + out Tensor, TN, Index, Index, Index, Index> riemann) + where TN : IComplex, IDifferentiableFunctions + where TPIN : ISymbol + where TI1N : ISymbol + where TI2N : ISymbol + where TI3N : ISymbol + where TI4N : ISymbol + { + DerivativeOfChristoffel(tape, metric, point, out Tensor, TN, Index, Index, Index, Index> derivativeOfChristoffel); + Christoffel(tape, metric, point, out Christoffel, TN, Index, InternalIndex1, TI3N> christoffel); + var contractedChristoffels = Contract(christoffel, christoffel.WithIndex1>().WithIndex2Name().WithIndex3Name()); + + riemann = new(); + for (int r = 0; r < 4; r++) + { + for (int s = 0; s < 4; s++) + { + for (int m = 0; m < 4; m++) + { + for (int n = 0; n < 4; n++) + { + riemann[r, s, m, n] = + derivativeOfChristoffel[m, r, s, n] - derivativeOfChristoffel[n, r, s, m] + contractedChristoffels[r, m, s, n] - contractedChristoffels[r, n, s, m]; + } + } + } + } + } + // // Tensor contractions // From 1258d3c9b9e3d51e4fcf246cd36f33e96b9ddd0a Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:01:35 -0500 Subject: [PATCH 6/9] Update DifGeo.cs - Update documentation comments --- src/Mathematics.NET/DifferentialGeometry/DifGeo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs index d095e7e0..bd949fc8 100644 --- a/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs +++ b/src/Mathematics.NET/DifferentialGeometry/DifGeo.cs @@ -299,7 +299,7 @@ public static void SecondDerivativeCompute the Christoffel symbol of the first kind given a metric tensor. + /// Compute a Christoffel symbol of the first kind given a metric tensor. /// A type that implements /// A type that implements and /// The index of the point at which to compute the Christoffel symbol @@ -337,7 +337,7 @@ public static void Christoffel( } } - /// Compute the Christoffel symbol of the second kind given a metric tensor. + /// Compute a Christoffel symbol of the second kind given a metric tensor. /// A type that implements /// A type that implements and /// The index of the point at which to compute the Christoffel symbol @@ -375,7 +375,7 @@ public static void Christoffel( /// Compute the derivative of a Christoffel symbol of the first kind given a metric tensor. /// A type that implements and - /// The index of the point at which to compute the Christoffel symbol + /// The name of the index of the point at which to compute the Christoffel symbol /// The name of the first index /// The name of the second index /// The name of the third index @@ -416,7 +416,7 @@ public static void DerivativeOfChristoffel( /// Compute the derivative of a Christoffel symbol of the second kind given a metric tensor. /// A type that implements and - /// The index of the point at which to compute the Christoffel symbol + /// The name of the index of the point at which to compute the Christoffel symbol /// The name of the first index /// The name of the second index /// The name of the third index From 3855343bcfc5ffc5305d883faf05d48c4f127d12 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:05:06 -0500 Subject: [PATCH 7/9] Update MetricTensorField.cs - Add method for computing the value of the inverse of a metric tensor --- .../DifferentialGeometry/MetricTensorField.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs index 1834baa6..6e57a371 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs @@ -67,4 +67,12 @@ public MetricTensorField() { } tape.IsTracking = true; return new MetricTensor, TN, Lower, TI1, TI2>(result); } + + public MetricTensor, TN, Upper, TI1, TI2> ComputeInverse(TT tape, AutoDiffTensor4 point) + where TI1 : ISymbol + where TI2 : ISymbol + { + var value = Compute(tape, point); + return value.Inverse(); + } } From bd6f89ddabbcd0d0539641054d25c3fd9803d90c Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:05:20 -0500 Subject: [PATCH 8/9] Update MetricTensorField.cs - Rename parameters --- src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs index 6e57a371..b62ac905 100644 --- a/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs +++ b/src/Mathematics.NET/DifferentialGeometry/MetricTensorField.cs @@ -46,7 +46,7 @@ public abstract class MetricTensorField : TensorField4x4, TN, Lower, TI1, TI2> Compute(TT tape, AutoDiffTensor4 x) + public new MetricTensor, TN, Lower, TI1, TI2> Compute(TT tape, AutoDiffTensor4 point) where TI1 : ISymbol where TI2 : ISymbol { @@ -59,7 +59,7 @@ public MetricTensorField() { } { if (_buffer[i][j] is Func, Variable> function) { - result[i, j] = function(tape, x).Value; + result[i, j] = function(tape, point).Value; } } } From af902369d764ec30abc15d4693bab19af15ff28e Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Tue, 16 Apr 2024 03:04:49 -0500 Subject: [PATCH 9/9] Update LinAlgExtensions.cs - Fix how commas are displayed for 4D arrays --- src/Mathematics.NET/LinearAlgebra/LinAlgExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mathematics.NET/LinearAlgebra/LinAlgExtensions.cs b/src/Mathematics.NET/LinearAlgebra/LinAlgExtensions.cs index 5fb3b82d..0042cca2 100644 --- a/src/Mathematics.NET/LinearAlgebra/LinAlgExtensions.cs +++ b/src/Mathematics.NET/LinearAlgebra/LinAlgExtensions.cs @@ -399,7 +399,7 @@ public static string ToDisplayString(this T[,,,] array, string? format = null builder.Append(k != 0 ? " [" : "["); for (int l = 0; l < e3Length; l++) { - string value = k != e3Length - 1 ? $"{strings[i, j, k, l]}, " : strings[i, j, k, l]; + string value = l != e3Length - 1 ? $"{strings[i, j, k, l]}, " : strings[i, j, k, l]; builder.Append(value.PadRight(maxElementLength)); } builder.CloseGroup(newlineChars);