diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index 01de3fa2a..1b214fe76 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -264,12 +264,34 @@ private void ConvertAndAssembleAnalysisTasks(List analysisTasks 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 { + //not modal analysis task + return 0; + } + } private void ConvertAndAssembleCombinations(List combinations) { if (combinations.IsNullOrEmpty()) { diff --git a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs index 9c7514e13..e9dafcab8 100644 --- a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs +++ b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs @@ -6,6 +6,7 @@ using GsaGH.Helpers.Assembly; using GsaGH.Helpers.GsaApi.EnumMappings; +using GsaGH.Helpers.Import; using GsaGH.Parameters; using GsaGHTests.Helper; @@ -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 taskIn = original.ApiModel.AnalysisTasks(); + + //assemble model and get task + var analysis = new GsaAnalysis(); + foreach (KeyValuePair 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 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)); + } + } + } + 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"); + } + } } }