Skip to content

Commit

Permalink
GSAGH-499: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
SandeepArup committed Feb 4, 2025
1 parent 1518c3e commit 9c01221
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 272 deletions.
140 changes: 89 additions & 51 deletions GsaGH/Components/4_Analysis/CreateModalDynamicParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,60 +125,102 @@ protected override void SolveInternal(IGH_DataAccess da) {
da.SetData(0, new GsaModalDynamicGoo(taskParameter));
}

private bool ValidateNumberOfModeMethod(GsaModalDynamic parameter) {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByNumberOfModes;
if (method.NumberOfModes < 1) {
this.AddRuntimeError("Number of mode should be greater than 1");
return false;
}
return true;
}

private bool ValidateLowerFrequency(GsaModalDynamic parameter) {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByFrequency;
double higherFrequency = method.HigherFrequency ?? double.MaxValue;
if (method.LowerFrequency.HasValue && (!GsaGH.Helpers.Utility.IsInRange
(method.LowerFrequency.Value, 0, higherFrequency) || GsaGH.Helpers.Utility.IsApproxEqual(method.LowerFrequency.Value, higherFrequency))) {
this.AddRuntimeError("Lower frquency should be positive value and less than higher frquency");
return false;
}
return true;
}

private bool ValidateUpperFrequency(GsaModalDynamic parameter) {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByFrequency;
double lowerFrequency = method.LowerFrequency ?? 0;
if (method.HigherFrequency.HasValue && (!GsaGH.Helpers.Utility.IsInRange
(method.HigherFrequency.Value, lowerFrequency, method.HigherFrequency.Value) || GsaGH.Helpers.Utility.IsApproxEqual(method.HigherFrequency.Value, lowerFrequency))) {
this.AddRuntimeError("Upper frquency should be positive value and greater than lower frquency");
return false;

Check warning on line 154 in GsaGH/Components/4_Analysis/CreateModalDynamicParameter.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/4_Analysis/CreateModalDynamicParameter.cs#L153-L154

Added lines #L153 - L154 were not covered by tests
}
return true;
}

private bool ValidateFrequencyRangeMethod(GsaModalDynamic parameter) {
return ValidateLowerFrequency(parameter) && ValidateUpperFrequency(parameter);
}

private bool ValidateTargetMassMethod(GsaModalDynamic parameter) {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByMassParticipation;
if (!GsaGH.Helpers.Utility.IsInRange(method.TargetMassInXDirection, 0, 100) || !GsaGH.Helpers.Utility.IsInRange(method.TargetMassInYDirection, 0, 100) || !GsaGH.Helpers.Utility.IsInRange(method.TargetMassInZDirection, 0, 100)) {
this.AddRuntimeError("Target Mass participation ratio should be within the range of [0:100]");
return false;
}
return true;
}

private bool ValidateMassScalefactor(GsaModalDynamic parameter) {
if (parameter.MassOption.ScaleFactor < 0) {
this.AddRuntimeError("Mass scale factor should have positive value");
return false;
}
return true;
}

private bool ValidateLoadScalefactor(GsaModalDynamic parameter) {
if (parameter.AdditionalMassDerivedFromLoads.ScaleFactor < 0) {
this.AddRuntimeError("Load scale factor should have positive value");
return false;
}
return true;
}

private bool ValidateDampingStiffness(GsaModalDynamic parameter) {
double? dampingStiffness = parameter.ModalDamping.StiffnessProportion;
if (dampingStiffness.HasValue && !GsaGH.Helpers.Utility.IsInRange(dampingStiffness.Value, 0, 1)) {
this.AddRuntimeError("Damping stiffness should be within the range [0:1]");
return false;
}
return true;
}

private bool ValidateMassParticipation(GsaModalDynamic parameter) {
bool validationStatus = true;
switch (parameter.Method()) {
switch (parameter.ModeCalculationOption()) {
case ModeCalculationMethod.NumberOfMode: {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByNumberOfModes;
if (method.NumberOfModes < 1) {
this.AddRuntimeError("Number of mode should be greater than 1");
validationStatus = false;
}
validationStatus = ValidateNumberOfModeMethod(parameter);
}
break;
case ModeCalculationMethod.FrquencyRange: {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByFrequency;
double higherFrequency = method.HigherFrequency ?? double.MaxValue;
if (method.LowerFrequency.HasValue && (!GsaGH.Helpers.Utility.IsInRange
(method.LowerFrequency.Value, 0, higherFrequency) || GsaGH.Helpers.Utility.IsApproxEqual(method.LowerFrequency.Value, higherFrequency))) {
this.AddRuntimeError("Lower frquency should be positive value and less than higher frquency");
validationStatus = false;
}
double lowerFrequency = method.LowerFrequency ?? 0;
if (method.HigherFrequency.HasValue && (!GsaGH.Helpers.Utility.IsInRange
(method.HigherFrequency.Value, lowerFrequency, method.HigherFrequency.Value) || GsaGH.Helpers.Utility.IsApproxEqual(method.HigherFrequency.Value, lowerFrequency))) {
this.AddRuntimeError("Upper frquency should be positive value and greater than lower frquency");
validationStatus = false;
}

validationStatus = ValidateFrequencyRangeMethod(parameter);
}
break;
case ModeCalculationMethod.TargetMassRatio: {
var method = parameter.ModeCalculationStrategy as ModeCalculationStrategyByMassParticipation;
if (!GsaGH.Helpers.Utility.IsInRange(method.TargetMassInXDirection, 0, 100) || !GsaGH.Helpers.Utility.IsInRange(method.TargetMassInYDirection, 0, 100) || !GsaGH.Helpers.Utility.IsInRange(method.TargetMassInZDirection, 0, 100)) {
this.AddRuntimeError("Target Mass participation ratio should be within the range of [0:100]");
validationStatus = false;
}
validationStatus = ValidateTargetMassMethod(parameter);
}
break;
}

double? dampingStiffness = parameter.ModalDamping.StiffnessProportion;
if (dampingStiffness.HasValue && !GsaGH.Helpers.Utility.IsInRange(dampingStiffness.Value, 0, 1)) {
this.AddRuntimeError("Damping stiffness should be within the range [0:1]");
validationStatus = false;
}
if (!ValidateDampingStiffness(parameter)) { validationStatus = false; }

if (parameter.AdditionalMassDerivedFromLoads.ScaleFactor < 0) {
this.AddRuntimeError("Load scale factor should have positive value");
if (!ValidateLoadScalefactor(parameter)) {
validationStatus = false;
}

if (parameter.MassOption.ScaleFactor < 0) {
this.AddRuntimeError("Mass scale factor should have positive value");
if (!ValidateMassScalefactor(parameter)) {
validationStatus = false;
}

return validationStatus;
}

Expand Down Expand Up @@ -225,30 +267,26 @@ private void UnregisterParameters() {
}

public override void VariableParameterMaintenance() {

int index = 0;
if (_modeMethod == ModeCalculationMethod.NumberOfMode) {
CreateParameter.Create(Params, new Param_Integer(), index++, "Modes", "Md", "Set number of mode", GH_ParamAccess.item);
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Modes", NickName = "Md", Description = "Set number of mode", Access = GH_ParamAccess.item, ParamType = new Param_Integer(), Optional = true });
} else if (_modeMethod == ModeCalculationMethod.FrquencyRange) {
CreateParameter.Create(Params, new Param_Number(), index++, "Lower frequency", "LF", "Set lower frequency range", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index++, "Upper frequency", "UF", "Set upper frequency range", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Integer(), index++, "Limiting modes", "LM", "Limit maximum number of mode", GH_ParamAccess.item);

CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Lower frequency", NickName = "LF", Description = "Set lower frequency range", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Upper frequency", NickName = "UF", Description = "Set upper frequency range", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Limiting modes", NickName = "LM", Description = "Limit maximum number of mode", Access = GH_ParamAccess.item, ParamType = new Param_Integer(), Optional = true });
} else {
CreateParameter.Create(Params, new Param_Number(), index++, "X-direction mass participation", "X", "Set x-direction mass participation", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index++, "Y-direction mass participation", "Y", "Set y-direction mass participation", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index++, "Z-direction mass participation", "Z", "Set z-direction mass participation", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Integer(), index++, "Limiting modes", "LM", "Set limiting maximum number of mode", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Boolean(), index++, "Skip modes with low mass participation", "MASIL", "Set the value to true to use the Masil algorithm", GH_ParamAccess.item);
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "X-direction mass participation", NickName = "X", Description = "Set x-direction mass participation", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Y-direction mass participation", NickName = "Y", Description = "Set y-direction mass participation", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Z-direction mass participation", NickName = "Z", Description = "Set z-direction mass participation", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Limiting modes", NickName = "LM", Description = "Set limiting maximum number of mode", Access = GH_ParamAccess.item, ParamType = new Param_Integer(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Skip modes with low mass participation", NickName = "MASIL", Description = "Set the value to true to use the Masil algorithm", Access = GH_ParamAccess.item, ParamType = new Param_Boolean(), Optional = true });
}
CreateParameter.Create(Params, new Param_String(), index++, "Load case ", "LC", "Additional mass load case", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index++, "Load scale factor", "LSF", "Set load scale factor", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index++, "Mass scale factor", "MSF", "Set mass scale factor", GH_ParamAccess.item);
CreateParameter.Create(Params, new Param_Number(), index, "Damping stiffness proportion", "DSP", "Set model damping stiffness proportion", GH_ParamAccess.item);

CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Load case", NickName = "LC", Description = "Additional mass load case", Access = GH_ParamAccess.item, ParamType = new Param_String(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Load scale factor", NickName = "LSF", Description = "Set load scale factor", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index++, new InputAttributes() { Name = "Mass scale factor", NickName = "MSF", Description = "Set mass scale factor", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
CreateParameter.Create(Params, index, new InputAttributes() { Name = "Damping stiffness proportion", NickName = "DSP", Description = "Set model damping stiffness proportion", Access = GH_ParamAccess.item, ParamType = new Param_Number(), Optional = true });
}


protected override void InitialiseDropdowns() {
_spacerDescriptions = new List<string>(new[] {
"Mode Strategy",
Expand Down
26 changes: 13 additions & 13 deletions GsaGH/Helpers/GH/InputAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace GsaGH.Helpers.GH {
public struct InputAttributes {
public IGH_Param ParamType;
public string NickName;
public string Name;
public string Description;
public GH_ParamAccess Access;
public bool Optional;
public string Name { get; set; }
public string NickName { get; set; }
public string Description { get; set; }
public IGH_Param ParamType { get; set; }
public GH_ParamAccess Access { get; set; }
public bool Optional { get; set; }
}

public static class CreateParameter {
public static void Create(
GH_ComponentParamServer parameters, IGH_Param parameter, int index, string name, string nickname, string description, GH_ParamAccess access, bool optional = true) {
parameters.RegisterInputParam(parameter, index);
parameters.Input[index].Name = name;
parameters.Input[index].NickName = nickname;
parameters.Input[index].Description = description;
parameters.Input[index].Access = access;
parameters.Input[index].Optional = optional;
GH_ComponentParamServer parameters, int index, InputAttributes inputAttribute) {
parameters.RegisterInputParam(inputAttribute.ParamType, index);
parameters.Input[index].Name = inputAttribute.Name;
parameters.Input[index].NickName = inputAttribute.NickName;
parameters.Input[index].Description = inputAttribute.Description;
parameters.Input[index].Access = inputAttribute.Access;
parameters.Input[index].Optional = inputAttribute.Optional;
}
}
}
4 changes: 2 additions & 2 deletions GsaGH/Parameters/4_Analysis/GsaModalDynamicAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal GsaModalDynamic(AnalysisTask apiAnalysisTask) {
}


public ModeCalculationMethod Method() {
public ModeCalculationMethod ModeCalculationOption() {

if (ModeCalculationStrategy is ModeCalculationStrategyByNumberOfModes) {
return ModeCalculationMethod.NumberOfMode;
Expand All @@ -61,7 +61,7 @@ public ModeCalculationMethod Method() {
}

public override string ToString() {
return Method().ToString();
return ModeCalculationOption().ToString();
}

}
Expand Down
6 changes: 3 additions & 3 deletions GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public static CreateAnalysisTask CreateAnalysisTaskComponent(ModeCalculationMeth
component.SetSelected(0, 3);
switch (modeMethod) {
case ModeCalculationMethod.NumberOfMode:
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByNumberOfModesTests.ComponentMother(ModalMassOption.MassFromElementShapeFunction, Direction.Y)), 2);
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByNumberOfModesTests.ComponentMother()), 2);
break;
case ModeCalculationMethod.FrquencyRange:
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByFrquencyRangeTest.ComponentMother(ModalMassOption.MassFromElementShapeFunction, Direction.Y)), 2);
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByFrquencyRangeTest.ComponentMother()), 2);
break;
case ModeCalculationMethod.TargetMassRatio:
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByTargetMassParticipationTest.ComponentMother(ModalMassOption.MassFromElementShapeFunction, Direction.Y)), 2);
ComponentTestHelper.SetInput(component, ComponentTestHelper.GetOutput(CreateModalDynamicParameterByTargetMassParticipationTest.ComponentMother()), 2);
break;
}
return component;
Expand Down
Loading

0 comments on commit 9c01221

Please sign in to comment.