Skip to content

Commit

Permalink
Perimeter radius of gyration
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne committed Nov 11, 2024
1 parent 5bb154c commit e9c07e7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
14 changes: 14 additions & 0 deletions SectionProperties/Utility/PerimeterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions SectionProperties/Utility/RadiusOfGyration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -22,6 +27,11 @@ internal static Length CalculateRadiusOfGyrationYy(IList<IPart> parts)

public static Length CalculateRadiusOfGyrationZz(IProfile profile)
{
if (profile is IPerimeter perim)
{
return PerimeterProfile.CalculateRadiusOfGyrationZz(perim);
}

return CalculateRadiusOfGyrationZz(ProfileParts.GetParts(profile));
}

Expand All @@ -32,8 +42,7 @@ internal static Length CalculateRadiusOfGyrationZz(IList<IPart> 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);
Expand Down
47 changes: 47 additions & 0 deletions SectionPropertiesTests/Utility/PerimeterProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MagmaWorks.Taxonomy.Sections.SectionProperties.Utility;
using OasysUnits;
using SectionPropertiesTests.TestUtility;
using Utility = MagmaWorks.Taxonomy.Sections.SectionProperties.Utility;

namespace SectionPropertiesTests
{
Expand All @@ -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)
Expand Down

0 comments on commit e9c07e7

Please sign in to comment.