From e9c07e79630a2ef8f3ce9666dceabda1cb673dff Mon Sep 17 00:00:00 2001 From: kpne Date: Mon, 11 Nov 2024 17:40:25 +0100 Subject: [PATCH] Perimeter radius of gyration --- SectionProperties/Utility/PerimeterProfile.cs | 14 ++++++ SectionProperties/Utility/RadiusOfGyration.cs | 13 ++++- .../Utility/PerimeterProfileTests.cs | 47 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/SectionProperties/Utility/PerimeterProfile.cs b/SectionProperties/Utility/PerimeterProfile.cs index e51c036..548d5db 100644 --- a/SectionProperties/Utility/PerimeterProfile.cs +++ b/SectionProperties/Utility/PerimeterProfile.cs @@ -53,6 +53,20 @@ internal static ILocalPoint2d CalculateCentroid(IPerimeter perimeter) }; } + internal static Length CalculateRadiusOfGyrationYy(IPerimeter perimeter) + { + OasysUnits.Area area = CalculateArea(perimeter); + AreaMomentOfInertia inertia = CalculateInertiaYy(perimeter); + return RadiusOfGyration.CalculateRadiusOfGyration(area, inertia); + } + + internal static Length CalculateRadiusOfGyrationZz(IPerimeter perimeter) + { + OasysUnits.Area area = CalculateArea(perimeter); + AreaMomentOfInertia inertia = CalculateInertiaZz(perimeter); + return RadiusOfGyration.CalculateRadiusOfGyration(area, inertia); + } + internal static AreaMomentOfInertia CalculateInertiaYy(IPerimeter perimeter) { IPerimeter centredOnElasticCentroid = MoveToElasticCentroid(perimeter); diff --git a/SectionProperties/Utility/RadiusOfGyration.cs b/SectionProperties/Utility/RadiusOfGyration.cs index dd01c3b..b6bc134 100644 --- a/SectionProperties/Utility/RadiusOfGyration.cs +++ b/SectionProperties/Utility/RadiusOfGyration.cs @@ -10,6 +10,11 @@ public static class RadiusOfGyration { public static Length CalculateRadiusOfGyrationYy(IProfile profile) { + if (profile is IPerimeter perim) + { + return PerimeterProfile.CalculateRadiusOfGyrationYy(perim); + } + return CalculateRadiusOfGyrationYy(ProfileParts.GetParts(profile)); } @@ -22,6 +27,11 @@ internal static Length CalculateRadiusOfGyrationYy(IList parts) public static Length CalculateRadiusOfGyrationZz(IProfile profile) { + if (profile is IPerimeter perim) + { + return PerimeterProfile.CalculateRadiusOfGyrationZz(perim); + } + return CalculateRadiusOfGyrationZz(ProfileParts.GetParts(profile)); } @@ -32,8 +42,7 @@ internal static Length CalculateRadiusOfGyrationZz(IList parts) return CalculateRadiusOfGyration(area, inertia); } - - private static Length CalculateRadiusOfGyration(OasysUnits.Area area, AreaMomentOfInertia inertia) + internal static Length CalculateRadiusOfGyration(OasysUnits.Area area, AreaMomentOfInertia inertia) { Length.TryParse($"0 {OasysUnits.Area.GetAbbreviation(area.Unit).Replace("²", string.Empty)}", out Length unit); OasysUnits.Area.TryParse($"0 {Length.GetAbbreviation(unit.Unit)}²", out OasysUnits.Area m2); diff --git a/SectionPropertiesTests/Utility/PerimeterProfileTests.cs b/SectionPropertiesTests/Utility/PerimeterProfileTests.cs index c15a1a9..168194a 100644 --- a/SectionPropertiesTests/Utility/PerimeterProfileTests.cs +++ b/SectionPropertiesTests/Utility/PerimeterProfileTests.cs @@ -6,6 +6,7 @@ using MagmaWorks.Taxonomy.Sections.SectionProperties.Utility; using OasysUnits; using SectionPropertiesTests.TestUtility; +using Utility = MagmaWorks.Taxonomy.Sections.SectionProperties.Utility; namespace SectionPropertiesTests { @@ -28,6 +29,52 @@ public void MoveToElasticCentroidTest(ISection section) Assert.Equal(0, newCentroid.Z.Value, 12); } + [Theory] + [ClassData(typeof(SectionGenerator))] + public void AreaTests(ISection section) + { + // skip back to back profiles as they do not convert to a single Perimeter profile + if (section.Profile is IBackToBack) + { + return; + } + + // Assemble + OasysUnits.Area originalA = Utility.Area.CalculateArea(section.Profile); + IPerimeter perimeter = new Perimeter(section.Profile); + + // Act + OasysUnits.Area area = Utility.Area.CalculateArea(perimeter); + + // Assert + Assert.Equal(originalA.SquareCentimeters, area.SquareCentimeters, 0.05 * area.SquareCentimeters); + } + + + [Theory] + [ClassData(typeof(SectionGenerator))] + public void RadiusOfGyrationTests(ISection section) + { + // skip back to back profiles as they do not convert to a single Perimeter profile + if (section.Profile is IBackToBack) + { + return; + } + + // Assemble + Length originalYy = RadiusOfGyration.CalculateRadiusOfGyrationYy(section.Profile); + Length originalZz = RadiusOfGyration.CalculateRadiusOfGyrationZz(section.Profile); + IPerimeter perimeter = new Perimeter(section.Profile); + + // Act + Length radiusOfGyrationYy = RadiusOfGyration.CalculateRadiusOfGyrationYy(perimeter); + Length radiusOfGyrationZz = RadiusOfGyration.CalculateRadiusOfGyrationZz(perimeter); + + // Assert + Assert.Equal(originalYy.Centimeters, radiusOfGyrationYy.Centimeters, 0.05 * radiusOfGyrationYy.Centimeters); + Assert.Equal(originalZz.Centimeters, radiusOfGyrationZz.Centimeters, 0.05 * radiusOfGyrationZz.Centimeters); + } + [Theory] [ClassData(typeof(SectionGenerator))] public void MomentOfInertiaTests(ISection section)