Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSAGH-560: Analysis task is missing when adding 1D geometries or Loads from other models #722

Draft
wants to merge 3 commits into
base: release/10.2.14
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion GsaGH/Helpers/Assembly/ModelAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,34 @@
continue;
}

int numberOfDynamicMode = NumberOfDynamicMode(task.ApiTask);
foreach (GsaAnalysisCase ca in task.Cases) {
_model.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition);
if (numberOfDynamicMode > 0) {
int mode = Convert.ToInt32(ca.Definition.ToLower().Replace("m", ""));
_model.AddAnalysisCaseToTask(task.Id, ca.Name, mode);
} else {
_model.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition);
}
}
}
}
}
private int NumberOfDynamicMode(AnalysisTask task) {
try {
var parameter = new ModalDynamicTaskParameter(task);
ModeCalculationStrategy modelCalculationMethod = parameter.ModeCalculationStrategy;
if (modelCalculationMethod is ModeCalculationStrategyByFrequency) {
return (modelCalculationMethod as ModeCalculationStrategyByFrequency).MaximumNumberOfModes;
} else if (modelCalculationMethod is ModeCalculationStrategyByMassParticipation) {
return (modelCalculationMethod as ModeCalculationStrategyByMassParticipation).MaximumNumberOfModes;
} else {
return (modelCalculationMethod as ModeCalculationStrategyByNumberOfModes).NumberOfModes;
}
} catch {

Check warning on line 290 in GsaGH/Helpers/Assembly/ModelAssembly.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Helpers/Assembly/ModelAssembly.cs#L290

Added line #L290 was not covered by tests
//not modal analysis task
return 0;

Check warning on line 292 in GsaGH/Helpers/Assembly/ModelAssembly.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Helpers/Assembly/ModelAssembly.cs#L292

Added line #L292 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create a test, where we return zero? Why the try catch? Perhaps we do catch on the method above and leave this private one to throw the error?

}
}

private void ConvertAndAssembleCombinations(List<GsaCombinationCase> combinations) {
if (combinations.IsNullOrEmpty()) {
Expand Down
74 changes: 74 additions & 0 deletions GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using GsaGH.Helpers.Assembly;
using GsaGH.Helpers.GsaApi.EnumMappings;
using GsaGH.Helpers.Import;
using GsaGH.Parameters;

using GsaGHTests.Helper;
Expand Down Expand Up @@ -130,5 +131,78 @@ public void TestModelLengthUnit() {

Assert.Equal(LengthUnit.Foot, UnitMapping.GetUnit(m.ApiModel.UiUnits().LengthLarge));
}

[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
public void ModalAnalysisTaskAreCopiedInDuplicateModel(int methodId) {
var original = new GsaModel();
int numberOfMode = 5;
// Task
var massOption = new MassOption(ModalMassOption.LumpMassAtNode, 1);
var additionalMassDerivedFromLoads = new AdditionalMassDerivedFromLoads(
"L1",
Direction.Z,
1
);
var ModalDamping = new ModalDamping(0.5);
var modalDynamicTaskParameter = new ModalDynamicTaskParameter(
ModeCalculationMethod(methodId, numberOfMode),
massOption,
additionalMassDerivedFromLoads,
ModalDamping
);

int taskId = original.ApiModel.AddAnalysisTask(
AnalysisTaskFactory.CreateModalDynamicAnalysisTask(
"task1",
modalDynamicTaskParameter
)
);
for (int mode = 1; mode <= numberOfMode; mode++) {
original.ApiModel.AddAnalysisCaseToTask(taskId, "test case", mode);
}
System.Collections.ObjectModel.ReadOnlyDictionary<int, AnalysisTask> taskIn = original.ApiModel.AnalysisTasks();

//assemble model and get task
var analysis = new GsaAnalysis();
foreach (KeyValuePair<int, AnalysisTask> analysisTask in taskIn) {
analysis.AnalysisTasks.Add(new GsaAnalysisTask(analysisTask.Key, analysisTask.Value, original.ApiModel));
}
var assembly = new ModelAssembly(new GsaModel(), null, null, null, null, null, analysis,
LengthUnit.Meter, Length.Zero, false, null);
var assembled = new GsaModel() {
ApiModel = assembly.GetModel()
};
System.Collections.ObjectModel.ReadOnlyDictionary<int, AnalysisTask> taskOut = assembled.ApiModel.AnalysisTasks();

Assert.Equal(taskIn.Count, taskIn.Count);
foreach (int key in taskIn.Keys) {
Assert.Equal(taskIn[key].Name, taskOut[key].Name);
foreach (int caseId in taskIn[key].Cases) {
Assert.Equal(assembled.ApiModel.AnalysisCaseName(caseId), original.ApiModel.AnalysisCaseName(caseId));
Assert.Equal(assembled.ApiModel.AnalysisCaseDescription(caseId), original.ApiModel.AnalysisCaseDescription(caseId));
}
}
}
Comment on lines +139 to +188
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too big

Can you create one test per exist condition of your new method?

You need 3 tests where the numberOfDynamicMode is larger that 0 but comes from the 3 different type of modelCalculationStrategy that it should have the analysisCaseToTask being added like that _model.AddAnalysisCaseToTask(task.Id, ca.Name, mode); and another case where the numberOfDynamicMode is Zero and the analysisCastToTask has been added through _model.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition);

internal ModeCalculationStrategy ModeCalculationMethod(int Id, int numberOfMode) {
switch (Id) {
case 0:
return new ModeCalculationStrategyByNumberOfModes(numberOfMode);
case 1:
return new ModeCalculationStrategyByFrequency(2, 15, numberOfMode);
case 2:
return new ModeCalculationStrategyByMassParticipation(
85,
92,
10,
numberOfMode,
true
);
default:
throw new InvalidOperationException("not supported");
}
}
}
}
Loading