From fbaad517744618a5360891e6a3205726434d4047 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Fri, 1 Dec 2023 21:49:48 +0100 Subject: [PATCH] GSAGH-149 component tests --- .../1_Properties/CreateSpringProperty.cs | 40 ++- GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs | 1 + .../GH_OasysPersistentParamTest.cs | 3 +- .../1_Properties/CreateSpringPropertyTests.cs | 260 ++++++++++++++++++ 4 files changed, 291 insertions(+), 13 deletions(-) create mode 100644 GsaGHTests/3_Components/1_Properties/CreateSpringPropertyTests.cs diff --git a/GsaGH/Components/1_Properties/CreateSpringProperty.cs b/GsaGH/Components/1_Properties/CreateSpringProperty.cs index 62090fb8f..940f5fae2 100644 --- a/GsaGH/Components/1_Properties/CreateSpringProperty.cs +++ b/GsaGH/Components/1_Properties/CreateSpringProperty.cs @@ -14,7 +14,6 @@ using OasysGH.Units.Helpers; using OasysUnits; using OasysUnits.Units; -using Rhino.Runtime; using LengthUnit = OasysUnits.Units.LengthUnit; namespace GsaGH.Components { @@ -89,11 +88,11 @@ public override void SetSelected(int i, int j) { _selectedItems[i] = _dropDownItems[i][j]; SpringPropertyType mode = GetModeBy(_selectedItems[0]); - ParseSelectedItems(mode); if (i == 0) { UpdateParameters(mode); UpdateDropDownItems(mode); } + ParseSelectedItems(mode); base.UpdateUI(); } @@ -114,6 +113,7 @@ public override void VariableParameterMaintenance() { case SpringPropertyType.Torsional: SetInputProperties(1, "Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "Stiffness xx"); + SetDampingRatioInputAt(2); return; case SpringPropertyType.General: @@ -137,8 +137,8 @@ public override void VariableParameterMaintenance() { case SpringPropertyType.Lockup: SetStiffnessInputAt(1, true); - SetInputProperties(2, "Lockup +ve [" + lengthAbr + "]", "L+ve", "Lockup +ve", false); - SetInputProperties(3, "Lockup -ve [" + lengthAbr + "]", "L-ve", "Lockup -ve", false); + SetInputProperties(2, "Lockup -ve [" + lengthAbr + "]", "L-ve", "Lockup -ve", false); + SetInputProperties(3, "Lockup +ve [" + lengthAbr + "]", "L+ve", "Lockup +ve", false); SetDampingRatioInputAt(4); return; @@ -177,7 +177,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager[0].Optional = true; pManager[2].Optional = true; } - + protected override void RegisterOutputParams(GH_OutputParamManager pManager) { pManager.AddParameter(new GsaSpringPropertyParameter()); } @@ -188,18 +188,22 @@ protected override void SolveInternal(IGH_DataAccess da) { double stiffness = 0; switch (_mode) { case SpringPropertyType.Axial: - case SpringPropertyType.Torsional: case SpringPropertyType.TensionOnly: case SpringPropertyType.CompressionOnly: case SpringPropertyType.Lockup: case SpringPropertyType.Gap: stiffness = Input.UnitNumber(this, da, 1, _stiffnessUnit).As(ForcePerLengthUnit.NewtonPerMeter); break; + + case SpringPropertyType.Torsional: + stiffness = Input.UnitNumber(this, da, 1, _rotationalStiffnessUnit).As(RotationalStiffnessUnit.NewtonMeterPerRadian); + break; } double stiffnessX; double stiffnessY; double stiffnessZ; + int dampingRatioIndex = 2; switch (_mode) { case SpringPropertyType.Axial: @@ -217,6 +221,7 @@ protected override void SolveInternal(IGH_DataAccess da) { break; case SpringPropertyType.General: + dampingRatioIndex = 7; // do want to add spring curves?? @@ -267,17 +272,21 @@ protected override void SolveInternal(IGH_DataAccess da) { break; case SpringPropertyType.Connector: + dampingRatioIndex = 1; + var connectorProperty = new ConnectorSpringProperty(); spring = new GsaSpringProperty(connectorProperty); break; case SpringPropertyType.Lockup: - double positiveLockup = Input.UnitNumber(this, da, 2, _lengthUnit).As(LengthUnit.Meter); - double negativeLockup = Input.UnitNumber(this, da, 3, _lengthUnit).As(LengthUnit.Meter); + dampingRatioIndex = 4; + + double negativeLockup = Input.UnitNumber(this, da, 2, _lengthUnit).As(LengthUnit.Meter); + double positiveLockup = Input.UnitNumber(this, da, 3, _lengthUnit).As(LengthUnit.Meter); var lockupProperty = new LockupSpringProperty { Stiffness = stiffness, - PositiveLockup = positiveLockup, - NegativeLockup = negativeLockup + NegativeLockup = negativeLockup, + PositiveLockup = positiveLockup }; spring = new GsaSpringProperty(lockupProperty); break; @@ -290,11 +299,13 @@ protected override void SolveInternal(IGH_DataAccess da) { break; case SpringPropertyType.Friction: + dampingRatioIndex = 5; + stiffnessX = Input.UnitNumber(this, da, 1, _stiffnessUnit).As(ForcePerLengthUnit.NewtonPerMeter); stiffnessY = Input.UnitNumber(this, da, 2, _stiffnessUnit).As(ForcePerLengthUnit.NewtonPerMeter); stiffnessZ = Input.UnitNumber(this, da, 3, _stiffnessUnit).As(ForcePerLengthUnit.NewtonPerMeter); double frictionCoefficient = 0; - if (da.GetData(0, ref frictionCoefficient)) { + if (da.GetData(4, ref frictionCoefficient)) { var frictionProperty = new FrictionSpringProperty { StiffnessX = stiffnessX, StiffnessY = stiffnessY, @@ -317,6 +328,11 @@ protected override void SolveInternal(IGH_DataAccess da) { spring.ApiProperty.Name = name; } + double dampingRatio = 0; + if (da.GetData(dampingRatioIndex, ref dampingRatio)) { + spring.ApiProperty.DampingRatio = dampingRatio; + } + da.SetData(0, new GsaSpringPropertyGoo(spring)); } @@ -482,8 +498,8 @@ private void UpdateParameters(SpringPropertyType mode) { break; case SpringPropertyType.Matrix: - Params.RegisterInputParam(new Param_GenericObject()); Params.RegisterInputParam(new Param_Integer()); + Params.RegisterInputParam(new Param_Number()); break; case SpringPropertyType.Connector: diff --git a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs index 852c44965..a8cb109fb 100644 --- a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs +++ b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs @@ -29,6 +29,7 @@ public class GhOasysGooTest { [InlineData(typeof(GsaSectionGoo), typeof(GsaSection))] [InlineData(typeof(GsaSectionModifierGoo), typeof(GsaSectionModifier))] [InlineData(typeof(GsaProperty2dModifierGoo), typeof(GsaProperty2dModifier))] + [InlineData(typeof(GsaSpringPropertyGoo), typeof(GsaSpringProperty))] // 2_Geometry [InlineData(typeof(GsaElement1dGoo), typeof(GsaElement1d))] [InlineData(typeof(GsaElement2dGoo), typeof(GsaElement2d))] diff --git a/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs b/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs index ff7ec3cbd..0b41baaaf 100644 --- a/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs +++ b/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs @@ -23,8 +23,9 @@ public class GH_OasysPersistentParamTest { [InlineData(typeof(GsaProperty3dParameter))] [InlineData(typeof(GsaSectionModifierParameter))] [InlineData(typeof(GsaSectionParameter))] + [InlineData(typeof(GsaSpringPropertyParameter))] // 2_Geometry - [InlineData(typeof(GsaGH.Parameters.GsaElement1dParameter))] + [InlineData(typeof(GsaElement1dParameter))] [InlineData(typeof(GsaElement2dParameter))] [InlineData(typeof(GsaElement3dParameter))] [InlineData(typeof(GsaMember1dParameter))] diff --git a/GsaGHTests/3_Components/1_Properties/CreateSpringPropertyTests.cs b/GsaGHTests/3_Components/1_Properties/CreateSpringPropertyTests.cs new file mode 100644 index 000000000..e4d7c6431 --- /dev/null +++ b/GsaGHTests/3_Components/1_Properties/CreateSpringPropertyTests.cs @@ -0,0 +1,260 @@ +using GsaAPI; +using GsaGH.Components; +using GsaGH.Parameters; +using GsaGHTests.Helpers; +using OasysGH.Components; +using Xunit; + +namespace GsaGHTests.Components.Properties { + [Collection("GrasshopperFixture collection")] + public class CreateSpringPropertyTests { + public static GH_OasysDropDownComponent AxialComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 0); + comp.SetSelected(1, 2); // N/m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + public static GH_OasysDropDownComponent CompressionOnlyComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 1); + comp.SetSelected(1, 2); // N/m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + public static GH_OasysDropDownComponent ConnectorComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 2); + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 0.1, 1); + + return comp; + } + + public static GH_OasysDropDownComponent FrictionComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 3); + comp.SetSelected(1, 2); // N/m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 1.3, 2); + ComponentTestHelper.SetInput(comp, 1.4, 3); + ComponentTestHelper.SetInput(comp, 0.5, 4); + ComponentTestHelper.SetInput(comp, 0.1, 5); + + return comp; + } + + public static GH_OasysDropDownComponent GapComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 4); + comp.SetSelected(1, 2); // N/m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + public static GH_OasysDropDownComponent GeneralComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 5); + comp.SetSelected(1, 2); // N/m + comp.SetSelected(2, 1); // Nm/rad + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 1.3, 2); + ComponentTestHelper.SetInput(comp, 1.4, 3); + ComponentTestHelper.SetInput(comp, 1.5, 4); + ComponentTestHelper.SetInput(comp, 1.6, 5); + ComponentTestHelper.SetInput(comp, 1.7, 6); + ComponentTestHelper.SetInput(comp, 0.1, 7); + + return comp; + } + + public static GH_OasysDropDownComponent LockupComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 6); + comp.SetSelected(1, 2); // N/m + comp.SetSelected(2, 2); // m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 1.3, 2); + ComponentTestHelper.SetInput(comp, 1.4, 3); + ComponentTestHelper.SetInput(comp, 0.1, 4); + + return comp; + } + + public static GH_OasysDropDownComponent MatrixComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 7); + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + public static GH_OasysDropDownComponent TensionOnlyComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 8); + comp.SetSelected(1, 2); // N/m + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + public static GH_OasysDropDownComponent TorsionalComponentMother() { + var comp = new CreateSpringProperty(); + comp.CreateAttributes(); + + comp.SetSelected(0, 9); + comp.SetSelected(1, 1); // Nm/rad + ComponentTestHelper.SetInput(comp, "Name", 0); + ComponentTestHelper.SetInput(comp, 1.2, 1); + ComponentTestHelper.SetInput(comp, 0.1, 2); + + return comp; + } + + [Fact] + public void CreateCompressionOnlyComponent() { + GH_OasysDropDownComponent comp = CompressionOnlyComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((CompressionSpringProperty)output.Value.ApiProperty).Stiffness, 8); + } + + [Fact] + public void CreateConnectorComponent() { + GH_OasysDropDownComponent comp = ConnectorComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + } + + [Fact] + public void CreateFrictionComponent() { + GH_OasysDropDownComponent comp = FrictionComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((FrictionSpringProperty)output.Value.ApiProperty).StiffnessX, 8); + Assert.Equal(1.3, ((FrictionSpringProperty)output.Value.ApiProperty).StiffnessY, 8); + Assert.Equal(1.4, ((FrictionSpringProperty)output.Value.ApiProperty).StiffnessZ, 8); + Assert.Equal(0.5, ((FrictionSpringProperty)output.Value.ApiProperty).FrictionCoefficient, 8); + } + + + [Fact] + public void CreateGapComponent() { + GH_OasysDropDownComponent comp = GapComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((GapSpringProperty)output.Value.ApiProperty).Stiffness, 8); + } + + + [Fact] + public void CreateGeneralComponent() { + GH_OasysDropDownComponent comp = GeneralComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessX); + Assert.Equal(1.3, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessY); + Assert.Equal(1.4, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessZ); + Assert.Equal(1.5, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessXX); + Assert.Equal(1.6, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessYY); + Assert.Equal(1.7, ((GeneralSpringProperty)output.Value.ApiProperty).StiffnessZZ); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveX); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveY); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveZ); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveXX); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveYY); + Assert.Null(((GeneralSpringProperty)output.Value.ApiProperty).SpringCurveZZ); + } + + + [Fact] + public void CreateLockupComponent() { + GH_OasysDropDownComponent comp = LockupComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((LockupSpringProperty)output.Value.ApiProperty).Stiffness, 8); + Assert.Equal(1.3, ((LockupSpringProperty)output.Value.ApiProperty).NegativeLockup, 8); + Assert.Equal(1.4, ((LockupSpringProperty)output.Value.ApiProperty).PositiveLockup, 8); + } + + + [Fact] + public void CreateMatrixComponent() { + GH_OasysDropDownComponent comp = MatrixComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(2, ((MatrixSpringProperty)output.Value.ApiProperty).SpringMatrix); + } + + [Fact] + public void CreateTensionOnlyComponent() { + GH_OasysDropDownComponent comp = TensionOnlyComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((TensionSpringProperty)output.Value.ApiProperty).Stiffness, 8); + } + + + [Fact] + public void CreateTorsionalComponent() { + GH_OasysDropDownComponent comp = TorsionalComponentMother(); + + var output = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal("Name", output.Value.ApiProperty.Name); + Assert.Equal(0.1, output.Value.ApiProperty.DampingRatio); + Assert.Equal(1.2, ((TorsionalSpringProperty)output.Value.ApiProperty).Stiffness, 8); + } + } +}