-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistributionClass.vb
More file actions
412 lines (370 loc) · 15.9 KB
/
DistributionClass.vb
File metadata and controls
412 lines (370 loc) · 15.9 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
Imports System.Xml
Imports System.Collections.Generic
Public Class oDistribution
Private m_varname As String
Private m_distribution As String
Private m_varvalue As Double
Private m_mean As Double
Private m_variance As Double
Private m_lbound As Double
Private m_ubound As Double
Private m_alpha As Double
Private m_beta As Double
Private m_mode As Double
Private m_id As Integer
Private m_units As String
Public Sub New()
End Sub
Public Sub New(ByVal varname As String, ByVal units As String, ByVal distribution As String, ByVal varvalue As Double, ByVal mean As Double, ByVal variance As Double, ByVal lbound As Double, ByVal ubound As Double, ByVal mode As Double, ByVal alpha As Double, ByVal beta As Double)
Me.varname = varname
Me.units = units
Me.distribution = distribution
Me.varvalue = varvalue
Me.mean = mean
Me.variance = variance
Me.lbound = lbound
Me.ubound = ubound
Me.mode = mode
Me.alpha = alpha
Me.beta = beta
End Sub
Public Property units() As String
Get
Return m_units
End Get
Set(ByVal value As String)
m_units = value
End Set
End Property
Public Property beta() As Double
Get
Return m_beta
End Get
Set(ByVal value As Double)
m_beta = value
End Set
End Property
Public Property alpha() As Double
Get
Return m_alpha
End Get
Set(ByVal value As Double)
m_alpha = value
End Set
End Property
Public Property mode() As Double
Get
Return m_mode
End Get
Set(ByVal value As Double)
m_mode = value
End Set
End Property
Public Property varname() As String
Get
Return m_varname
End Get
Set(ByVal value As String)
m_varname = value
End Set
End Property
Public Property distribution() As String
Get
Return m_distribution
End Get
Set(ByVal value As String)
m_distribution = value
End Set
End Property
Public Property varvalue() As Double
Get
Return m_varvalue
End Get
Set(ByVal value As Double)
m_varvalue = value
End Set
End Property
Public Property mean() As Double
Get
Return m_mean
End Get
Set(ByVal value As Double)
m_mean = value
End Set
End Property
Public Property variance() As Double
Get
Return m_variance
End Get
Set(ByVal value As Double)
m_variance = value
End Set
End Property
Public Property lbound() As Double
Get
Return m_lbound
End Get
Set(ByVal value As Double)
m_lbound = value
End Set
End Property
Public Property ubound() As Double
Get
Return m_ubound
End Get
Set(ByVal value As Double)
m_ubound = value
End Set
End Property
Public Property id() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
End Class
Public Class DistributionClass
Public Shared Function GetDistributions() As List(Of oDistribution)
'get distribution details from distributions.xml file
Dim oDistributions As New List(Of oDistribution)
If RiskDataDirectory Is Nothing Then
Call New_File()
ProjectDirectory = RiskDataDirectory
End If
ProjectDirectory = RiskDataDirectory
Dim Path As String = ProjectDirectory & "distributions.xml"
Dim xmlIn As New XmlTextReader(Path)
Try
If My.Computer.FileSystem.FileExists(Path) = False Then
MsgBox("The file distributions.xml is missing", MsgBoxStyle.Critical, "Missing File")
xmlIn.Close()
Return oDistributions
Exit Function
End If
If My.Computer.FileSystem.FileExists(Path) Then
xmlIn.WhitespaceHandling = WhitespaceHandling.None
Do While xmlIn.Name <> "Distribution"
xmlIn.Read()
If xmlIn.EOF = True Then 'no distributions
xmlIn.Close()
Return oDistributions
Exit Function
End If
Loop
Do While xmlIn.Name = "Distribution"
Dim oDistribution As New oDistribution
xmlIn.ReadStartElement("Distribution")
oDistribution.id = CSng(xmlIn.ReadElementString("id"))
oDistribution.varname = CStr(xmlIn.ReadElementString("varname"))
oDistribution.units = CStr(xmlIn.ReadElementString("units"))
oDistribution.distribution = CStr(xmlIn.ReadElementString("distribution"))
If oDistribution.distribution = "none" Then oDistribution.distribution = "None"
oDistribution.varvalue = CDbl(xmlIn.ReadElementString("varvalue"))
oDistribution.mean = CDbl(xmlIn.ReadElementString("mean"))
oDistribution.variance = CDbl(xmlIn.ReadElementString("variance"))
oDistribution.lbound = CDbl(xmlIn.ReadElementString("lbound"))
oDistribution.ubound = CDbl(xmlIn.ReadElementString("ubound"))
oDistribution.mode = CDbl(xmlIn.ReadElementString("mode"))
oDistribution.alpha = CDbl(xmlIn.ReadElementString("alpha"))
oDistribution.beta = CDbl(xmlIn.ReadElementString("beta"))
xmlIn.ReadEndElement()
oDistributions.Add(oDistribution)
Loop
'if reading older file, add any missing distributions
If oDistributions.Count = 5 Then
'add Soot Preflashover Yield
Dim oDistribution As New oDistribution With {
.id = 6,
.varname = "Soot Preflashover Yield",
.distribution = "None",
.units = "g/g",
.varvalue = preSoot
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 6 Then
'add CO Preflashover Yield
Dim oDistribution As New oDistribution With {
.id = 7,
.varname = "CO Preflashover Yield",
.distribution = "None",
.units = "g/g",
.varvalue = preCO
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 7 Then
'add sprinkler reliability
Dim oDistribution As New oDistribution With {
.id = 8,
.varname = "Sprinkler Reliability",
.distribution = "None",
.units = "-",
.varvalue = SprReliability
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 8 Then
'add sprinkler supresssion
Dim oDistribution As New oDistribution With {
.id = 9,
.varname = "Sprinkler Suppression Probability",
.distribution = "None",
.units = "-",
.varvalue = SprSuppressionProb
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 9 Then
'add sprinkler cooling coefficient
Dim oDistribution As New oDistribution With {
.id = 10,
.varname = "Sprinkler Cooling Coefficient",
.distribution = "None",
.units = "-",
.varvalue = SprCooling
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 10 Then
'add fuel heat of gasification
Dim oDistribution As New oDistribution With {
.id = 11,
.varname = "Fuel Heat of Gasification",
.distribution = "None",
.units = "kJ/g"
}
'oDistribution.varvalue = FuelHeatofGasification
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 11 Then
'add alpha T
Dim oDistribution As New oDistribution With {
.id = 12,
.varname = "Alpha T",
.distribution = "None",
.units = "kW/s2",
.varvalue = AlphaT
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 12 Then
'add peak hrr
Dim oDistribution As New oDistribution With {
.id = 13,
.varname = "Peak HRR",
.distribution = "None",
.units = "kW",
.varvalue = PeakHRR
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 13 Then
'add sd reliability
Dim oDistribution As New oDistribution With {
.id = 14,
.varname = "Smoke Detector Reliability",
.distribution = "None",
.units = "-",
.varvalue = SDReliability
}
oDistributions.Add(oDistribution)
End If
If oDistributions.Count = 14 Then
'add mech vent reliability
Dim oDistribution As New oDistribution With {
.id = 15,
.varname = "Mechanical Ventilation Reliability",
.distribution = "None",
.units = "-",
.varvalue = FanReliability
}
oDistributions.Add(oDistribution)
End If
Else
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Distribution.xml file is missing")
End If
xmlIn.Close()
Return oDistributions
Exit Function
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Exception in DistributionClass.GetDistributions")
xmlIn.Close()
Return oDistributions
End Try
End Function
Public Shared Sub SaveDistributions(ByVal oDistributions As List(Of oDistribution))
Dim rname As String = RiskDataDirectory & "distributions.xml"
Dim Path As String = rname
Dim xmlOut As New XmlTextWriter(Path, System.Text.Encoding.UTF8)
Try
xmlOut.Formatting = Formatting.Indented
xmlOut.WriteStartDocument()
xmlOut.WriteStartElement("Distributions")
Dim oDistribution As oDistribution
For i As Integer = 0 To oDistributions.Count - 1
oDistribution = CType(oDistributions(i), oDistribution)
xmlOut.WriteStartElement("Distribution")
xmlOut.WriteElementString("id", CStr(i + 1))
xmlOut.WriteElementString("varname", oDistribution.varname.ToString)
xmlOut.WriteElementString("units", oDistribution.units.ToString)
xmlOut.WriteElementString("distribution", oDistribution.distribution.ToString)
xmlOut.WriteElementString("varvalue", oDistribution.varvalue.ToString)
xmlOut.WriteElementString("mean", oDistribution.mean.ToString)
xmlOut.WriteElementString("variance", oDistribution.variance.ToString)
xmlOut.WriteElementString("lbound", oDistribution.lbound.ToString)
xmlOut.WriteElementString("ubound", oDistribution.ubound.ToString)
xmlOut.WriteElementString("mode", oDistribution.mode.ToString)
xmlOut.WriteElementString("alpha", oDistribution.alpha.ToString)
xmlOut.WriteElementString("beta", oDistribution.beta.ToString)
xmlOut.WriteEndElement()
Next
xmlOut.WriteEndElement()
xmlOut.WriteEndDocument()
xmlOut.Close()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.OkOnly, "Exception in DistributionClass.vb SaveDistributions")
xmlOut.WriteEndDocument()
xmlOut.Close()
End Try
End Sub
Public Shared Sub Read_Distributions()
'read data from distribution file to update text boxes when loading a new basefile
Dim odistributions As List(Of oDistribution)
odistributions = DistributionClass.GetDistributions()
For Each oDistribution In odistributions
If oDistribution.varname = "Interior Temperature" Then InteriorTemp = oDistribution.varvalue
If oDistribution.varname = "Exterior Temperature" Then ExteriorTemp = oDistribution.varvalue
If oDistribution.varname = "Relative Humidity" Then RelativeHumidity = oDistribution.varvalue
If oDistribution.varname = "Heat of Combustion PFO" Then HoC_fuel = oDistribution.varvalue
If oDistribution.varname = "Fire Load Energy Density" Then FLED = oDistribution.varvalue
If oDistribution.varname = "Soot Preflashover Yield" Then preSoot = oDistribution.varvalue
If oDistribution.varname = "CO Preflashover Yield" Then preCO = oDistribution.varvalue
If oDistribution.varname = "Sprinkler Reliability" Then SprReliability = CDec(oDistribution.varvalue)
If oDistribution.varname = "Sprinkler Suppression Probability" Then SprSuppressionProb = CDec(oDistribution.varvalue)
If oDistribution.varname = "Sprinkler Cooling Coefficient" Then SprCooling = CDec(oDistribution.varvalue)
If oDistribution.varname = "Alpha T" Then AlphaT = CSng(oDistribution.varvalue)
If oDistribution.varname = "Peak HRR" Then PeakHRR = CSng(oDistribution.varvalue)
If oDistribution.varname = "Smoke Detector Reliability" Then SDReliability = CDec(oDistribution.varvalue)
If oDistribution.varname = "Mechanical Ventilation Reliability" Then FanReliability = CDec(oDistribution.varvalue)
Next
frmOptions1.txtInteriorTemp.Text = InteriorTemp - 273
frmOptions1.txtInteriorTemp.Text = ExteriorTemp - 273
frmOptions1.txtRelativeHumidity.Text = RelativeHumidity * 100
frmOptions1.txtHOCFuel.Text = HoC_fuel
frmItemList.txtFLED.Text = FLED
frmOptions1.txtpreSoot.Text = preSoot
frmOptions1.txtpreCO.Text = preCO
frmSprinklerList.txtSprReliability.Text = CStr(SprReliability)
frmSprinklerList.txtSprSuppressProb.Text = CStr(SprSuppressionProb)
frmSprinklerList.txtSprCoolingCoeff.Text = CStr(SprCooling)
frmPowerlaw.TxtAlphaT.Text = Format(AlphaT, "0.000")
frmPowerlaw.txtPeakHRR.Text = CStr(PeakHRR)
frmSmokeDetList.txtSmokeDetReliability.Text = CStr(SDReliability)
frmFanList.txtFanReliability.Text = CStr(FanReliability)
End Sub
Public Sub New()
End Sub
End Class