Skip to content

Commit

Permalink
updated tests for gsaResult
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Dec 1, 2023
1 parent d199145 commit adb1835
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 70 deletions.
65 changes: 26 additions & 39 deletions GsaGH/Parameters/5_Results/2_Results/GsaResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ public override string ToString() {
}

internal ReadOnlyCollection<int> NodeIds(string nodeList) {
if (string.IsNullOrEmpty(nodeList)) {
return new ReadOnlyCollection<int>(new List<int>());
}

var entityList = new EntityList() {
Definition = nodeList,
Type = GsaAPI.EntityType.Node,
Expand All @@ -167,20 +163,11 @@ internal ReadOnlyCollection<int> NodeIds(string nodeList) {
}

internal ReadOnlyCollection<int> ElementIds(string elementList, int dimension) {
string filter = string.Empty;
switch (dimension) {
case 1:
filter = " not (PA PV)";
break;

case 2:
filter = " not (PB PV)";
break;

case 3:
filter = " not (PB PA)";
break;
}
string filter = dimension switch {
1 => " not (PA PV)",
2 => " not (PB PV)",
3 => " not (PB PA)",
};

var entityList = new EntityList() {
Definition = elementList + filter,
Expand All @@ -201,15 +188,7 @@ internal ReadOnlyCollection<int> MemberIds(string memberList) {

private void InitialiseAnalysisCaseResults(
GsaModel model, AnalysisCaseResult result, int caseId) {
if (model == null || result == null || caseId <= 0) {
return;
}

Model = model;
CaseType = CaseType.AnalysisCase;
CaseId = caseId;
CaseName = model.Model.AnalysisCaseName(CaseId);


Element1dAverageStrainEnergyDensities = new Element1dAverageStrainEnergyDensityCache(result);
Element1dDisplacements = new Element1dDisplacementCache(result);
Element1dInternalForces = new Element1dInternalForceCache(result);
Expand All @@ -227,7 +206,7 @@ private void InitialiseAnalysisCaseResults(
Element3dStresses = new Element3dStressCache(result);

NodeDisplacements = new NodeDisplacementCache(result);
NodeReactionForces = new NodeReactionForceCache(result, model.Model);
NodeReactionForces = new NodeReactionForceCache(result, model?.Model);
NodeSpringForces = new NodeSpringForceCache(result);
NodeResonantFootfalls = new NodeResonantFootfallCache(result);
NodeTransientFootfalls = new NodeTransientFootfallCache(result);
Expand All @@ -236,20 +215,19 @@ private void InitialiseAnalysisCaseResults(
Member1dDisplacements = new Member1dDisplacementCache(result);

GlobalResults = new GlobalResultsCache(result);
}

private void InitialiseCombinationsCaseResults(
GsaModel model, CombinationCaseResult result, int caseId, IEnumerable<int> permutations) {
if (model == null || result == null || caseId <= 0 || permutations == null || !permutations.Any()) {
return;
}

Model = model;
CaseType = CaseType.CombinationCase;
CaseType = CaseType.AnalysisCase;
CaseId = caseId;
CaseName = model.Model.CombinationCases()[caseId].Name;
SelectedPermutationIds = permutations.ToList();
if (model?.Model?.Results()?.ContainsKey(caseId) != true) {
return;
}
CaseName = model.Model.AnalysisCaseName(CaseId);
}

private void InitialiseCombinationsCaseResults(
GsaModel model, CombinationCaseResult result, int caseId, IEnumerable<int> permutations) {

Element1dAverageStrainEnergyDensities = new Element1dAverageStrainEnergyDensityCache(result);
Element1dDisplacements = new Element1dDisplacementCache(result);
Element1dInternalForces = new Element1dInternalForceCache(result);
Expand All @@ -267,13 +245,22 @@ private void InitialiseCombinationsCaseResults(
Element3dStresses = new Element3dStressCache(result);

NodeDisplacements = new NodeDisplacementCache(result);
NodeReactionForces = new NodeReactionForceCache(result, model.Model);
NodeReactionForces = new NodeReactionForceCache(result, model?.Model);
NodeSpringForces = new NodeSpringForceCache(result);
NodeResonantFootfalls = new NodeResonantFootfallCache(result);
NodeTransientFootfalls = new NodeTransientFootfallCache(result);

Member1dDisplacements = new Member1dDisplacementCache(result);
Member1dInternalForces = new Member1dInternalForceCache(result);

Model = model;
CaseType = CaseType.CombinationCase;
CaseId = caseId;
SelectedPermutationIds = permutations?.ToList();
if (model?.Model?.CombinationCases()?.ContainsKey(caseId) != true) {
return;
}
CaseName = model.Model.CombinationCases()[CaseId].Name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private bool IsNotNaN(Double6 values) {
}

private void SetSupportNodeIds(Model model) {
if (model == null) { return;}
ConcurrentBag<int> supportnodeIDs = null;
supportnodeIDs = new ConcurrentBag<int>();
ReadOnlyDictionary<int, Node> nodes = model.Nodes();
Expand Down
85 changes: 54 additions & 31 deletions GsaGHTests/1_BaseParameters/5_Results/Collections/GsaResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,57 @@ CombinationCaseResult combinationCaseResult
: new GsaResult(model, combinationCaseResult, caseId, permutationEmpty ? null : new List<int>(){1});

Assert.NotNull(results);
Assert.Null(results.Model);
Assert.Equal(0, results.CaseId);
Assert.Null(results.CaseName);
Assert.Equal(0, (int)results.CaseType);
Assert.Null(results.SelectedPermutationIds);
if (model == null) {
Assert.Null(results.Model);
} else {
Assert.NotNull(results.Model);
}
switch (resultsAreNull) {
case true when analysisCase:
Assert.Equal("DL", results.CaseName);
break;
case true when !analysisCase:
Assert.Equal("ULS", results.CaseName);
break;
default:
Assert.Null(results.CaseName);
break;
}

Assert.Equal(caseId, results.CaseId);
Assert.Equal(analysisCase ? CaseType.AnalysisCase : CaseType.CombinationCase, results.CaseType);
if (!permutationEmpty && !analysisCase) {
Assert.Single(results.SelectedPermutationIds);
} else {
Assert.Null(results.SelectedPermutationIds);
}
//fields
Assert.Null(results.Element1dAverageStrainEnergyDensities);
Assert.Null(results.Element1dDisplacements);
Assert.Null(results.Element1dInternalForces);
Assert.Null(results.Element1dDerivedStresses);
Assert.Null(results.Element1dStrainEnergyDensities);
Assert.Null(results.Element1dStresses);
Assert.Null(results.Element2dDisplacements);
Assert.Null(results.Element2dForces);
Assert.Null(results.Element2dMoments);
Assert.Null(results.Element2dShearForces);
Assert.Null(results.Element2dStresses);
Assert.Null(results.Element3dDisplacements);
Assert.Null(results.Element3dStresses);
Assert.Null(results.NodeDisplacements);
Assert.Null(results.NodeReactionForces);
Assert.Null(results.NodeSpringForces);
Assert.Null(results.NodeResonantFootfalls);
Assert.Null(results.NodeTransientFootfalls);
Assert.Null(results.Member1dInternalForces);
Assert.Null(results.Member1dDisplacements);
Assert.Null(results.GlobalResults);
Assert.NotNull(results.Element1dAverageStrainEnergyDensities);
Assert.NotNull(results.Element1dDisplacements);
Assert.NotNull(results.Element1dInternalForces);
Assert.NotNull(results.Element1dDerivedStresses);
Assert.NotNull(results.Element1dStrainEnergyDensities);
Assert.NotNull(results.Element1dStresses);
Assert.NotNull(results.Element2dDisplacements);
Assert.NotNull(results.Element2dForces);
Assert.NotNull(results.Element2dMoments);
Assert.NotNull(results.Element2dShearForces);
Assert.NotNull(results.Element2dStresses);
Assert.NotNull(results.Element3dDisplacements);
Assert.NotNull(results.Element3dStresses);
Assert.NotNull(results.NodeDisplacements);
Assert.NotNull(results.NodeReactionForces);
Assert.NotNull(results.NodeSpringForces);
Assert.NotNull(results.NodeResonantFootfalls);
Assert.NotNull(results.NodeTransientFootfalls);
Assert.NotNull(results.Member1dInternalForces);
Assert.NotNull(results.Member1dDisplacements);

if(analysisCase) {
Assert.NotNull(results.GlobalResults);
} else {
Assert.Null(results.GlobalResults);
}
}

[Theory]
Expand All @@ -127,11 +151,10 @@ public void ToStringReturnsValidString(bool isAnalysisCase) {
public void NodeIdsReturnsValidNumbers() {
var result = (GsaResult)AnalysisCaseResult(GsaFile.SteelDesignSimple, 1);

Assert.Empty(result.NodeIds(null));
Assert.Empty(result.NodeIds(string.Empty));
Assert.Empty(result.NodeIds("0"));
Assert.Equal(new List<int>() {1} ,result.NodeIds("1"));
Assert.Equal(new List<int>() { 10 }, result.NodeIds("10 20 30"));
Assert.Equal(new ReadOnlyCollection<int>(new List<int>(){1, 2}) ,result.NodeIds("all"));
Assert.Equal(new ReadOnlyCollection<int>(new List<int>(){1}) ,result.NodeIds("1"));
Assert.Equal(new ReadOnlyCollection<int>(new List<int>(){1, 2}), result.NodeIds("1 2"));
Assert.Equal(new ReadOnlyCollection<int>(new List<int>(){}), result.NodeIds("10 20"));
}
}
}

0 comments on commit adb1835

Please sign in to comment.