Skip to content

Commit

Permalink
GSAGH-550: Analysis case is not consistent with the Load case in Gsa_GH
Browse files Browse the repository at this point in the history
  • Loading branch information
SandeepArup committed Dec 19, 2024
1 parent a1e85a4 commit e649a84
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 79 deletions.
10 changes: 2 additions & 8 deletions GsaGH/Components/4_Analysis/AnalyseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,15 @@ protected override void SolveInternal(IGH_DataAccess da) {
if (_analysis) {
IReadOnlyDictionary<int, AnalysisTask> gsaTasks = model.ApiModel.AnalysisTasks();
if (gsaTasks.Count < 1) {
var task = new GsaAnalysisTask {
Id = model.ApiModel.AddAnalysisTask(),
};
task.CreateDefaultCases(model);
int taskId = TaskHelper.CreateDefaultStaticAnalysisTask(ref model);
var task = new GsaAnalysisTask(taskId, model.ApiModel);
if (task.Cases == null || task.Cases.Count == 0) {
this.AddRuntimeWarning(
" Model contains no loads and has not been analysed, but has been assembled.");
} else {
this.AddRuntimeRemark(
" Model contained no Analysis Tasks. Default Task has been created containing " +
"all cases found in model");
foreach (GsaAnalysisCase ca in task.Cases) {
model.ApiModel.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition);
}

gsaTasks = model.ApiModel.AnalysisTasks();
}
}
Expand Down
4 changes: 2 additions & 2 deletions GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ protected override void SolveInstance(IGH_DataAccess da) {
}

if (ghTyp.Value is GsaAnalysisCaseGoo goo) {
da.SetData(0, goo.Value.Name);
da.SetData(1, goo.Value.Definition);
da.SetData(0, goo.Value.ApiCase.Name);
da.SetData(1, goo.Value.ApiCase.Description);
da.SetData(2, goo.Value.Id);
} else {
string type = ghTyp.Value.GetType().ToString();
Expand Down
7 changes: 2 additions & 5 deletions GsaGH/Components/4_Analysis/CreateAnalysisTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,9 @@ private bool GetAnalysisCases(IGH_DataAccess da, string name, out List<GsaAnalys
this.AddRuntimeRemark("Default Task has been created; it will by default contain all cases found in model");
}
} else {
cases = new List<GsaAnalysisCase>();
var footfallAnalysisCase = new GsaAnalysisCase {
Name = name,
Definition = "Footfall",
cases = new List<GsaAnalysisCase> {
new GsaAnalysisCase(name, "Footfall")
};
cases.Add(footfallAnalysisCase);
}

return true;
Expand Down
18 changes: 5 additions & 13 deletions GsaGH/Helpers/Assembly/ModelAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,11 @@ private void ConvertAndAssembleAnalysisTasks(List<GsaAnalysisTask> analysisTasks
ReadOnlyDictionary<int, AnalysisTask> existingTasks = _model.AnalysisTasks();
foreach (GsaAnalysisTask task in analysisTasks) {
if (!existingTasks.Keys.Contains(task.Id)) {
task.Id = _model.AddAnalysisTask(task.ApiTask);
}

if (task.Cases == null || task.Cases.Count == 0) {
task.CreateDefaultCases(_gsaModel);
}

if (task.Cases == null) {
continue;
}

foreach (GsaAnalysisCase ca in task.Cases) {
_model.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition);
var analysisCases = new Dictionary<int, AnalysisCase>();
foreach (GsaAnalysisCase analysisCase in task.Cases) {
analysisCases.Add(analysisCase.Id, analysisCase.ApiCase);
}
TaskHelper.ImportAnalysisTask(task, analysisCases, ref _model);
}
}
}
Expand Down
29 changes: 5 additions & 24 deletions GsaGH/Parameters/0_Model/GsaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,40 +153,21 @@ internal void SetUserDefaultUnits() {

internal Tuple<List<GsaAnalysisTaskGoo>, List<GsaAnalysisCaseGoo>> GetAnalysisTasksAndCombinations() {
ReadOnlyDictionary<int, AnalysisTask> tasks = ApiModel.AnalysisTasks();
ReadOnlyDictionary<int, LoadCase> loadCases = ApiModel.LoadCases();
ReadOnlyDictionary<int, AnalysisCase> analysisCases = ApiModel.AnalysisCases();

var tasksList = new List<GsaAnalysisTaskGoo>();
var caseList = new List<GsaAnalysisCaseGoo>();
var caseIDs = new List<int>();


foreach (KeyValuePair<int, AnalysisTask> item in tasks) {
var task = new GsaAnalysisTask(item.Key, item.Value, ApiModel);
var task = new GsaAnalysisTask(item.Key, ApiModel);
tasksList.Add(new GsaAnalysisTaskGoo(task));
caseIDs.AddRange(task.Cases.Select(acase => acase.Id));
}

caseIDs.AddRange(GetLoadCases());

foreach (int caseId in caseIDs) {
string caseName = ApiModel.AnalysisCaseName(caseId);
if (caseName == string.Empty) {
if (loadCases.ContainsKey(caseId)) {
caseName = loadCases[caseId].Name;
}
if (caseName == string.Empty) {
caseName = "Case " + caseId;
}
}

string caseDescription = ApiModel.AnalysisCaseDescription(caseId);
if (caseDescription == string.Empty) {
caseDescription = "L" + caseId;
}

foreach (KeyValuePair<int, AnalysisCase> item in analysisCases) {
caseList.Add(
new GsaAnalysisCaseGoo(new GsaAnalysisCase(caseId, caseName, caseDescription)));
new GsaAnalysisCaseGoo(new GsaAnalysisCase(item.Key, item.Value.Name, item.Value.Description)));
}

return new Tuple<List<GsaAnalysisTaskGoo>, List<GsaAnalysisCaseGoo>>(tasksList, caseList);
}

Expand Down
29 changes: 12 additions & 17 deletions GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
using GsaGH.Helpers;
using System.Xml.Linq;

using GsaAPI;

using GsaGH.Helpers;

namespace GsaGH.Parameters {
/// <summary>
/// Analysis Case definition, for instance `L1` for LoadCase 1 or `L1 + L2` for combining multiple load cases in one Analysis case.
/// <para>Refer to <see href="https://docs.oasys-software.com/structural/gsa/references/analysiscases.html">Analysis cases</see> to read more.</para>
/// </summary>
public class GsaAnalysisCase {
public string Definition { get; set; }
public string Name { get; set; }
public AnalysisCase ApiCase { get; set; }
internal int Id { get; set; } = 0;

public GsaAnalysisCase() { }
public GsaAnalysisCase() { ApiCase = new AnalysisCase("", ""); }

public GsaAnalysisCase(string name, string description) {
Name = name;
Definition = description;
ApiCase = new AnalysisCase(name, description);
}

internal GsaAnalysisCase(int id, string name, string description = "") {
Id = id;
Name = name;
Definition = description;
ApiCase = new AnalysisCase(name, description);
}

public GsaAnalysisCase Duplicate() {
return new GsaAnalysisCase(Id, Name, Definition);
return new GsaAnalysisCase(Id, ApiCase.Name, ApiCase.Description);
}

public override string ToString() {
string id = Id == 0 ? string.Empty : "ID:" + Id + " ";
string s = string.Empty;
if (Name != null) {
s += " '" + Name + "'";
}

if (Definition != null) {
s += " " + Definition;
}

s += " '" + ApiCase.Name + "'";
s += " " + ApiCase.Description;
return string.Join(" ", id, s).TrimSpaces();
}
}
Expand Down
13 changes: 3 additions & 10 deletions GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,19 @@ public GsaAnalysisTask() {
Id = 0;
}

internal GsaAnalysisTask(int id, AnalysisTask task, Model model) {
internal GsaAnalysisTask(int id, Model model) {
Id = id;
foreach (int caseId in task.Cases) {
ApiTask = model.AnalysisTasks()[Id];
foreach (int caseId in ApiTask.Cases) {
string caseName = model.AnalysisCaseName(caseId);
string caseDescription = model.AnalysisCaseDescription(caseId);
Cases.Add(new GsaAnalysisCase(caseId, caseName, caseDescription));
}

ApiTask = task;
}

public override string ToString() {
return (Id > 0 ? $"ID:{Id} " : string.Empty) + $"'{ApiTask.Name}' {ApiTask.Type}".Replace("_", " ")
.TrimSpaces();
}

internal void CreateDefaultCases(GsaModel gsaModel) {
Tuple<List<GsaAnalysisTaskGoo>, List<GsaAnalysisCaseGoo>> tuple
= gsaModel.GetAnalysisTasksAndCombinations();
Cases = tuple.Item2.Select(x => x.Value).ToList();
}
}
}

0 comments on commit e649a84

Please sign in to comment.