-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlsResultFunctionTests.cs
100 lines (85 loc) · 4.12 KB
/
SlsResultFunctionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using AdSecCore;
using AdSecCore.Builders;
using AdSecCore.Functions;
using Oasys.AdSec;
using OasysUnits;
using OasysUnits.Units;
namespace AdSecCoreTests.Functions {
public class SlsResultFunctionTest {
private readonly SlsResultFunction _component;
private static SectionSolution? Solution { get; set; } = null;
public SlsResultFunctionTest() {
_component = new SlsResultFunction();
if (Solution == null) {
Solution = new SolutionBuilder().Build();
}
_component.SolutionInput.Value = Solution;
_component.LoadInput.Value = ILoad.Create(Force.FromKilonewtons(100), Moment.FromKilonewtonMeters(100), Moment.Zero);
}
[Fact]
public void ShouldHaveCorrectMetadata() {
Assert.Equal("Find Crack Load", _component.Metadata.Name);
Assert.Equal("CrackLd", _component.Metadata.NickName);
Assert.Equal("Increases the load until set crack width is reached", _component.Metadata.Description);
}
[Fact]
public void ShouldHaveCorrectInputAttributes() {
var inputs = _component.GetAllInputAttributes();
Assert.Equal(2, inputs.Length);
Assert.IsType<SectionSolutionParameter>(inputs[0]);
Assert.IsType<GenericParameter>(inputs[1]);
}
[Fact]
public void ShouldHaveCorrectOutputAttributes() {
var outputs = _component.GetAllOutputAttributes();
Assert.Equal(7, outputs.Length);
Assert.IsType<LoadParameter>(outputs[0]);
Assert.IsType<CrackArrayParameter>(outputs[1]);
Assert.IsType<CrackParameter>(outputs[2]);
Assert.IsType<DoubleParameter>(outputs[3]);
Assert.IsType<DeformationParameter>(outputs[4]);
Assert.IsType<SecantStiffnessParameter>(outputs[5]);
Assert.IsType<IntervalArrayParameter>(outputs[6]);
}
[Fact]
public void ShoulHaveValidDeformationDescription() {
_component.DeformationDescription(StrainUnit.Ratio, CurvatureUnit.PerMeter);
var description = _component.DeformationOutput.Description;
Assert.Contains("[εm⁻¹]", description);
Assert.Contains("[εm⁻¹]", description);
}
[Fact]
public void ShouldHaveValidSecantStiffnessDescription() {
_component.SecantStiffnessDescription(AxialStiffnessUnit.Newton, BendingStiffnessUnit.NewtonSquareMeter);
var description = _component.SecantStiffnessOutput.Description;
Assert.Contains("[N]", description);
Assert.Contains("[N·m²]", description);
Assert.Contains("[N·m²]", description);
}
[Fact]
public void ShouldHaveValidUncrackedMomentRangesDescription() {
_component.UncrackedMomentRangesDescription(MomentUnit.NewtonMeter);
Assert.Contains("[N·m]", _component.UncrackedMomentRangesOutput.Description);
}
[Fact]
public void ShouldComputeCorrectly() {
_component.Compute();
var expectedLoad = ILoad.Create(Force.FromKilonewtons(100), Moment.FromKilonewtonMeters(100), Moment.Zero);
var expectedDeformation = IDeformation.Create(Strain.FromRatio(0.0014), Curvature.FromPerMeters(0.0064), Curvature.FromPerMeters(0.0029));
Assert.True(IsLoadEqual(expectedLoad, _component.LoadOutput.Value));
Assert.True(IsDeformationEqual(expectedDeformation, _component.DeformationOutput.Value));
Assert.Equal(0.00208, _component.MaximumCrackOutput.Value.Load.Width.Value, new DoubleComparer());
Assert.Equal(5.8156, _component.CrackUtilOutput.Value, new DoubleComparer());
Assert.Single(_component.RemarkMessages);
Assert.Equal(69, _component.CrackOutput.Value.Length);
}
private static bool IsLoadEqual(ILoad expected, ILoad calculated) {
return expected.X.Value.Equals(calculated.X.Value) && expected.YY.Value.Equals(calculated.YY.Value) && expected.ZZ.Value.Equals(calculated.ZZ.Value);
}
private static bool IsDeformationEqual(IDeformation expected, IDeformation calculated) {
var tolernaceStrain = Strain.FromRatio(0.00001);
var tolernaceCurvature = Curvature.FromPerMeters(0.0001);
return expected.X.Equals(calculated.X, tolernaceStrain) && expected.YY.Equals(calculated.YY, tolernaceCurvature) && expected.ZZ.Equals(calculated.ZZ, tolernaceCurvature);
}
}
}