-
Notifications
You must be signed in to change notification settings - Fork 0
/
resistance_test.go
215 lines (196 loc) · 7.01 KB
/
resistance_test.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package bolt_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"text/tabwriter"
"github.com/Konstantin8105/bolt"
)
func ExampleShearResistance() {
b := bolt.New(bolt.D24, bolt.G5p8)
sr := bolt.ShearResistance{B: b, Position: bolt.ThreadShear}
fmt.Printf("%s\n", sr)
// Output:
// Calculation of shear resistance for HM24Cl5.8:
// γM2 = 1.250
// αν = 0.500 - Shear plane passes through the threaded portion of the bolt
// Fub = 500.0 MPa
// As = 352.8 mm²
// In according to table 3.4 EN1993-1-8:
// Shear resistance is 70.6 kN
}
func ExampleTensionResistance() {
b := bolt.New(bolt.D24, bolt.G5p8)
t := bolt.TensionResistance{B: b, BT: bolt.UsuallyBolt}
fmt.Printf("%s\n", t)
// Output:
// Calculation of tension resistance for HM24Cl5.8:
// γM2 = 1.250
// k2 = 0.900 - no-countersunk bolt
// Fub = 500.0 MPa
// As = 352.8 mm²
// In according to table 3.4 EN1993-1-8:
// Tension resistance is 127.0 kN
}
func Example() {
var (
D = bolt.GetBoltDiameterList()
Cl = bolt.GetBoltClassList()
)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
fmt.Fprintf(w, "| Diameter\t| Class\t| Tension, kN\t| Shear, kN\t|\n")
for _, d := range D {
for _, cl := range Cl {
b := bolt.New(d, cl)
nt := bolt.TensionResistance{B: b, BT: bolt.UsuallyBolt}
ns := bolt.ShearResistance{B: b, Position: bolt.ThreadShear}
fmt.Fprintf(w, "| %v\t| %v\t| %5.1f\t| %5.1f\t|\n", d, cl, nt.Value()/1000, ns.Value()/1000)
}
fmt.Fprintf(w, "|\t|\t|\t|\t|\n")
}
w.Flush()
// Output:
// | Diameter | Class | Tension, kN | Shear, kN |
// | HM12 | Cl4.6 | 24.3 | 16.2 |
// | HM12 | Cl4.8 | 24.3 | 13.5 |
// | HM12 | Cl5.6 | 30.4 | 20.2 |
// | HM12 | Cl5.8 | 30.4 | 16.9 |
// | HM12 | Cl6.8 | 36.4 | 20.2 |
// | HM12 | Cl8.8 | 48.6 | 32.4 |
// | HM12 | Cl10.9 | 60.7 | 33.7 |
// | | | | |
// | HM16 | Cl4.6 | 45.2 | 30.1 |
// | HM16 | Cl4.8 | 45.2 | 25.1 |
// | HM16 | Cl5.6 | 56.4 | 37.6 |
// | HM16 | Cl5.8 | 56.4 | 31.4 |
// | HM16 | Cl6.8 | 67.7 | 37.6 |
// | HM16 | Cl8.8 | 90.3 | 60.2 |
// | HM16 | Cl10.9 | 112.9 | 62.7 |
// | | | | |
// | HM20 | Cl4.6 | 70.6 | 47.0 |
// | HM20 | Cl4.8 | 70.6 | 39.2 |
// | HM20 | Cl5.6 | 88.2 | 58.8 |
// | HM20 | Cl5.8 | 88.2 | 49.0 |
// | HM20 | Cl6.8 | 105.8 | 58.8 |
// | HM20 | Cl8.8 | 141.1 | 94.1 |
// | HM20 | Cl10.9 | 176.4 | 98.0 |
// | | | | |
// | HM24 | Cl4.6 | 101.6 | 67.7 |
// | HM24 | Cl4.8 | 101.6 | 56.4 |
// | HM24 | Cl5.6 | 127.0 | 84.7 |
// | HM24 | Cl5.8 | 127.0 | 70.6 |
// | HM24 | Cl6.8 | 152.4 | 84.7 |
// | HM24 | Cl8.8 | 203.2 | 135.5 |
// | HM24 | Cl10.9 | 254.0 | 141.1 |
// | | | | |
// | HM30 | Cl4.6 | 161.6 | 107.7 |
// | HM30 | Cl4.8 | 161.6 | 89.8 |
// | HM30 | Cl5.6 | 202.0 | 134.6 |
// | HM30 | Cl5.8 | 202.0 | 112.2 |
// | HM30 | Cl6.8 | 242.4 | 134.6 |
// | HM30 | Cl8.8 | 323.1 | 215.4 |
// | HM30 | Cl10.9 | 403.9 | 224.4 |
// | | | | |
// | HM36 | Cl4.6 | 235.4 | 156.9 |
// | HM36 | Cl4.8 | 235.4 | 130.8 |
// | HM36 | Cl5.6 | 294.2 | 196.2 |
// | HM36 | Cl5.8 | 294.2 | 163.5 |
// | HM36 | Cl6.8 | 353.1 | 196.2 |
// | HM36 | Cl8.8 | 470.8 | 313.9 |
// | HM36 | Cl10.9 | 588.5 | 326.9 |
// | | | | |
// | HM42 | Cl4.6 | 323.1 | 215.4 |
// | HM42 | Cl4.8 | 323.1 | 179.5 |
// | HM42 | Cl5.6 | 403.8 | 269.2 |
// | HM42 | Cl5.8 | 403.8 | 224.3 |
// | HM42 | Cl6.8 | 484.6 | 269.2 |
// | HM42 | Cl8.8 | 646.1 | 430.7 |
// | HM42 | Cl10.9 | 807.6 | 448.7 |
// | | | | |
// | HM48 | Cl4.6 | 424.6 | 283.0 |
// | HM48 | Cl4.8 | 424.6 | 235.9 |
// | HM48 | Cl5.6 | 530.7 | 353.8 |
// | HM48 | Cl5.8 | 530.7 | 294.8 |
// | HM48 | Cl6.8 | 636.8 | 353.8 |
// | HM48 | Cl8.8 | 849.1 | 566.1 |
// | HM48 | Cl10.9 | 1061.4 | 589.7 |
// | | | | |
}
func boltShearResistance(b bolt.Bolt) (s string) {
{
sr := bolt.ShearResistance{B: b, Position: bolt.ThreadShear}
s += fmt.Sprintf("%s\n", sr)
}
{
sr := bolt.ShearResistance{B: b, Position: bolt.UnthreadShear}
s += fmt.Sprintf("%s\n", sr)
}
return
}
func testCase(t *testing.T, filename, result string) {
t.Run(filename, func(t *testing.T) {
// name of test folder
const folder string = "testdata"
filename = filepath.Join(folder, filename)
// for update test screens run in console:
// UPDATE=true go test
if os.Getenv("UPDATE") == "true" {
if err := ioutil.WriteFile(filename, []byte(result), 0644); err != nil {
t.Fatalf("Cannot write snapshot to file: %v", err)
}
}
// compare datas
content, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatalf("Cannot read snapshot file: %v", err)
}
if !bytes.Equal([]byte(result), content) {
t.Errorf("Snapshots is not same:\n%s\n%s", result, string(content))
}
})
}
func TestShearResistanceCases(t *testing.T) {
for _, bd := range bolt.GetBoltDiameterList() {
for _, bc := range bolt.GetBoltClassList() {
b := bolt.New(bd, bc)
filename := fmt.Sprintf("ShearResistance%s%s", bd, bc)
result := boltShearResistance(b)
testCase(t, filename, result)
}
}
}
func boltTensionResistance(b bolt.Bolt) (s string) {
{
sr := bolt.TensionResistance{B: b, BT: bolt.UsuallyBolt}
s += fmt.Sprintf("%s\n", sr)
}
{
sr := bolt.TensionResistance{B: b, BT: bolt.CountersunkBolt}
s += fmt.Sprintf("%s\n", sr)
}
return
}
func TestTensionResistanceCases(t *testing.T) {
for _, bd := range bolt.GetBoltDiameterList() {
for _, bc := range bolt.GetBoltClassList() {
b := bolt.New(bd, bc)
filename := fmt.Sprintf("TensionResistance%s%s", bd, bc)
result := boltTensionResistance(b)
testCase(t, filename, result)
}
}
}
func TestResistance(t *testing.T) {
eps := 1e-8
b := bolt.New(bolt.D24, bolt.G5p8)
sr := bolt.Resistance{B: b}
if f, _ := sr.Value(0.0, 0.0, bolt.NoView); float64(f) > eps {
t.Errorf("Factor can not be not zero if load is zero")
}
if f, _ := sr.Value(1e10, 1e10, bolt.FullView); float64(f) < 1.0 {
t.Errorf("Factor can not be less 1.0 if load is huge")
}
}