Professional Documents
Culture Documents
Dim T As Long
Dim Tstep As Long
Dim ID As String
Dim i, k As Long
Dim val, SumTime As Variant
SumTime = 0
Tstep = 3600
k=1
ENinitH (10)
Do
'run Epanet
ENrunH (T)
'read pressure head values and store them in internal variables
'assumption: simulation times coincide with the reporting times
For i = 1 To nodeCount
' ID = getNodeId(i)
'If ID = i Then
nodePressures(i, k) = EPANetInterface.getNodePressure(i)
Next i
'determine the next time step
val = ENnextH(Tstep)
SumTime = SumTime + Tstep
k = Application.WorksheetFunction.Ceiling(SumTime / 3600, 1) + 1
Loop While (Tstep > 0)
End Sub
Private Function getLinkValue(ByVal linkIndex As Long, ByVal property As Long)
As Single
Dim Value As Single
ERROR = ENgetlinkvalue(linkIndex, property, Value)
getLinkValue = Value
End Function
End Sub
Public Function getNodeHead(ByVal nodeIndex As Long) As Single
getNodeHead = getNodeValue(nodeIndex, EN_HEAD)
End Function
Public Function getNodePressure(ByVal nodeIndex As Long) As Single
getNodePressure = getNodeValue(nodeIndex, EN_PRESSURE)
End Function
Public Function getNodeDemand(ByVal nodeIndex As Long) As Single
getNodeDemand = getNodeValue(nodeIndex, EN_DEMAND)
End Function
Public Function getNodeId(ByVal Index As Long) As String
Dim S As String
S = String$(255, vbNullChar)
ERROR = ENgetnodeid(Index, S)
getNodeId = Left(S, InStr(1, S, vbNullChar) - 1)
End Function
Public Function getLinkId(ByVal Index As Long) As String
Dim S As String
S = String$(255, vbNullChar)
ERROR = ENgetlinkid(Index, S)
getLinkId = Left(S, InStr(1, S, vbNullChar) - 1)
End Function
Public Function getLinkIndex(ByVal LinkID As String) As Long
Dim Index As Long
ERROR = ENgetlinkindex(LinkID, Index)
getLinkIndex = Index
End Function
Public Function getNodeIndex(ByVal NodeID As String) As Long
Dim Index As Long
ERROR = ENgetnodeindex(NodeID, Index)
getNodeIndex = Index
End Function
ActiveSheet.Calculate
' Read link indices from Excel into VBA - whole range is read at once to
improve the performance
Dim diametersArray() As Variant
' Dim nodeHeads() As Double
diametersArray = diamAddr.Value
Next i
'run simulation
EPANetInterface.solve
ActiveSheet.Calculate
're-calcualte the spreadsheet (updates the cell with objective function value)
'
ActiveSheet.Calculate
' Worksheets("Problem").UsedRange.Calculate
'
'read Pressure values and store them to internal variables
' For j = 1 To nodeCount'
' Store original diameters into the worksheet
'
ActiveSheet.Calculate
End Sub
Option Explicit
' read link count and node count from the file
EPANetInterface.linkCount = EPANetInterface.getLinkCount
EPANetInterface.nodeCount = EPANetInterface.getNodeCount
' read original link diameters and write them to column D starting from cell
D10
For i = 1 To EPANetInterface.linkCount
' Store original diameters into the worksheet
r.Offset(i - 1, -3) = EPANetInterface.getLinkId(i)
r.Offset(i - 1, -2) = i
r.Offset(i - 1, 0) = EPANetInterface.getLinkDiameter(i)
r.Offset(i - 1, 1) = EPANetInterface.getLinkLength(i)
Next i
Set r = Range("I10")
For i = 1 To EPANetInterface.nodeCount
' Load node indices
r.Offset(i - 1, -1) = EPANetInterface.getNodeId(i)
r.Offset(i - 1, 0) = i
r.Offset(i - 1, 1) = EPANetInterface.getNodeDemand(i)
Next i
EPANetInterface.selectedLinkCount = Range("B3").Value
End Sub
End Sub
End Sub