energyplus 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/energyplus.rb +13 -0
- data/lib/energyplus/DDYFile.rb +176 -0
- data/lib/energyplus/EpErrFile.rb +123 -0
- data/lib/energyplus/EpImfFile.rb +93 -0
- data/lib/energyplus/EpwFile.rb +120 -0
- data/lib/energyplus/EsoFile.rb +129 -0
- data/lib/energyplus/IdfObject.rb +55 -0
- data/lib/energyplus/KmlFile.rb +168 -0
- data/lib/energyplus/ResultsLog.rb +99 -0
- data/lib/energyplus/SchedulesCSV.rb +169 -0
- data/lib/energyplus/SlabGtpFile.rb +100 -0
- data/lib/energyplus/SlabIdfFile.rb +78 -0
- data/lib/energyplus/StatFile.rb +192 -0
- data/lib/energyplus/version.rb +22 -0
- metadata +77 -0
data/lib/energyplus.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'energyplus/DDYFile'
|
2
|
+
require 'energyplus/EpErrFile'
|
3
|
+
require 'energyplus/EpImfFile'
|
4
|
+
require 'energyplus/EpwFile'
|
5
|
+
require 'energyplus/EsoFile'
|
6
|
+
require 'energyplus/IdfObject'
|
7
|
+
require 'energyplus/KmlFile'
|
8
|
+
require 'energyplus/ResultsLog'
|
9
|
+
#require 'energyplus/SchedulesCSV'
|
10
|
+
require 'energyplus/SlabGtpFile'
|
11
|
+
require 'energyplus/SlabIdfFile'
|
12
|
+
require 'energyplus/StatFile'
|
13
|
+
require 'energyplus/version'
|
@@ -0,0 +1,176 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
######################################################################
|
19
|
+
|
20
|
+
module EnergyPlus
|
21
|
+
|
22
|
+
class DDYFile
|
23
|
+
def initialize(path)
|
24
|
+
@path = path
|
25
|
+
@lines = []
|
26
|
+
if File.exists?(@path)
|
27
|
+
File.open(@path) do |f|
|
28
|
+
while line = f.gets
|
29
|
+
@lines << line.chomp
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def objects
|
36
|
+
objects = []
|
37
|
+
object_fields = []
|
38
|
+
object_type = ''
|
39
|
+
inobject = false
|
40
|
+
object_comment = nil
|
41
|
+
@lines.each_index do |i|
|
42
|
+
if not inobject and @lines[i] =~ /^\s*\w/
|
43
|
+
object_fields = []
|
44
|
+
inobject = true
|
45
|
+
object_type = @lines[i]
|
46
|
+
if @lines[i-1] =~ /^\s*!/
|
47
|
+
object_comment = @lines[i-1]
|
48
|
+
end
|
49
|
+
elsif inobject and @lines[i] =~ /^[^!]*;/
|
50
|
+
object_fields << @lines[i]
|
51
|
+
inobject = false
|
52
|
+
objects << IdfObject.new(object_type,object_fields,object_comment)
|
53
|
+
elsif inobject
|
54
|
+
object_fields << @lines[i]
|
55
|
+
else
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return objects
|
59
|
+
end
|
60
|
+
|
61
|
+
def findObjectByComment(comment)
|
62
|
+
comment = Regexp.new(comment)
|
63
|
+
objects().each do |object|
|
64
|
+
if object.comment =~ comment
|
65
|
+
return object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
|
72
|
+
#returns an array of "data source, year, and type
|
73
|
+
def get_data_source
|
74
|
+
#! Using Design Conditions from "Climate Design Data 2005 ASHRAE Handbook"
|
75
|
+
#! Using Design Conditions from "Climate Design Data 2009 ASHRAE Handbook"
|
76
|
+
src_s = ""
|
77
|
+
@lines.each_index do |i|
|
78
|
+
if @lines[i] =~ /Climate Design Data [0-9]{4} ASHRAE Handbook/
|
79
|
+
src_s = @lines[i]
|
80
|
+
break
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
src = []
|
85
|
+
src << src_s.match("Climate Design Data [0-9]{4} ASHRAE Handbook")[0]
|
86
|
+
src << src_s.match("[0-9]{4}")[0]
|
87
|
+
src << "ASHRAE Handbook"
|
88
|
+
|
89
|
+
return src
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def write_idf_snippet(filename, ddyobj)
|
94
|
+
if not ddyobj.nil?
|
95
|
+
File.delete(filename) if File.exists?(filename)
|
96
|
+
File.open(filename, 'w') do |fl|
|
97
|
+
#add version identifier to file
|
98
|
+
fl << "\nVersion,\n 7.1; ! Version Identifier \n\n"
|
99
|
+
fl << ddyobj
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
#updated for ddy for EP 7.1 2012
|
105
|
+
def get_indicating_type(ddyobj)
|
106
|
+
val = ddyobj.fieldString(8).downcase
|
107
|
+
if val == "dewpoint"
|
108
|
+
res = []
|
109
|
+
res << val
|
110
|
+
res << ddyobj.fieldValue(9)
|
111
|
+
res << "C"
|
112
|
+
elsif val == "wetbulb"
|
113
|
+
res = []
|
114
|
+
res << val
|
115
|
+
res << ddyobj.fieldValue(9)
|
116
|
+
res << "C"
|
117
|
+
elsif val == "enthalpy"
|
118
|
+
res = []
|
119
|
+
res << val
|
120
|
+
res << ddyobj.fieldValue(12)
|
121
|
+
res << "kJ/kg"
|
122
|
+
end
|
123
|
+
return res
|
124
|
+
end
|
125
|
+
|
126
|
+
#untyped enumerations for heating, cooling, and humidification
|
127
|
+
#make this an array, the first column of the array is the ep object,
|
128
|
+
#the remaining items are the "attributes and tags"
|
129
|
+
def heating(typestr)
|
130
|
+
search = "Annual Heating " + typestr
|
131
|
+
|
132
|
+
obj = findObjectByComment(search)
|
133
|
+
|
134
|
+
puts "[DDYFile] #{File.basename(@path.to_s)} missing heating #{typestr}" if obj.nil?
|
135
|
+
|
136
|
+
ddyinfo = []
|
137
|
+
ddyinfo << search.gsub("\\","")
|
138
|
+
ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
|
139
|
+
ddyinfo << obj
|
140
|
+
|
141
|
+
return ddyinfo
|
142
|
+
end
|
143
|
+
|
144
|
+
def humidification(typestr)
|
145
|
+
search = "Annual Humidification " + typestr
|
146
|
+
|
147
|
+
obj = findObjectByComment(search)
|
148
|
+
|
149
|
+
puts "[DDYFile] #{File.basename(@path.to_s)} missing humidification #{typestr}" if obj.nil?
|
150
|
+
|
151
|
+
ddyinfo = []
|
152
|
+
ddyinfo << search.gsub("\\","")
|
153
|
+
ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
|
154
|
+
ddyinfo << obj
|
155
|
+
|
156
|
+
return ddyinfo
|
157
|
+
end
|
158
|
+
|
159
|
+
def cooling(typestr)
|
160
|
+
search = "Annual Cooling " + typestr
|
161
|
+
|
162
|
+
obj = findObjectByComment(search)
|
163
|
+
|
164
|
+
puts "[DDYFile] #{File.basename(@path.to_s)} missing cooling #{typestr}" if obj.nil?
|
165
|
+
|
166
|
+
ddyinfo = []
|
167
|
+
ddyinfo << search.gsub("\\","")
|
168
|
+
ddyinfo << search.gsub("\\","").gsub(" ","_").gsub(".","_").gsub("%","").gsub("=>","_").gsub("__","_")
|
169
|
+
ddyinfo << obj
|
170
|
+
|
171
|
+
return ddyinfo
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end #moduel
|
@@ -0,0 +1,123 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
######################################################################
|
19
|
+
|
20
|
+
module EnergyPlus
|
21
|
+
|
22
|
+
class EpErrFile
|
23
|
+
|
24
|
+
def initialize(path)
|
25
|
+
@path = path.expand_path
|
26
|
+
@warnings = []
|
27
|
+
@severe_errors = []
|
28
|
+
@fatal_errors = []
|
29
|
+
@initialized = false
|
30
|
+
@successful = false
|
31
|
+
end
|
32
|
+
|
33
|
+
def init
|
34
|
+
@initialized = true
|
35
|
+
|
36
|
+
if @path.exist?
|
37
|
+
File.open(@path) do |f|
|
38
|
+
text = ''
|
39
|
+
text << f.read
|
40
|
+
@valid = true
|
41
|
+
@warnings = parse("Warning", text)
|
42
|
+
@severe_errors = parse("Severe", text)
|
43
|
+
@fatal_errors = parse("Fatal", text)
|
44
|
+
if text =~ /\s\*{13} EnergyPlus Completed Successfully/
|
45
|
+
@successful = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def valid?
|
52
|
+
init if not initialized?
|
53
|
+
@valid
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialized?
|
57
|
+
@initialized
|
58
|
+
end
|
59
|
+
|
60
|
+
def path
|
61
|
+
@path
|
62
|
+
end
|
63
|
+
|
64
|
+
def dirname
|
65
|
+
@path.dirname
|
66
|
+
end
|
67
|
+
|
68
|
+
def warnings
|
69
|
+
init if not initialized?
|
70
|
+
@warnings
|
71
|
+
end
|
72
|
+
|
73
|
+
def severe_errors
|
74
|
+
init if not initialized?
|
75
|
+
@severe_errors
|
76
|
+
end
|
77
|
+
|
78
|
+
def fatal_errors
|
79
|
+
init if not initialized?
|
80
|
+
@fatal_errors
|
81
|
+
end
|
82
|
+
|
83
|
+
# just a warning
|
84
|
+
def warning_count
|
85
|
+
init if not initialized?
|
86
|
+
warnings.size
|
87
|
+
end
|
88
|
+
|
89
|
+
# severe errors are not as bad as fatal
|
90
|
+
def severe_error_count
|
91
|
+
init if not initialized?
|
92
|
+
@severe_errors.size
|
93
|
+
end
|
94
|
+
|
95
|
+
# the worst error
|
96
|
+
def fatal_error_count
|
97
|
+
init if not initialized?
|
98
|
+
@fatal_errors.size
|
99
|
+
end
|
100
|
+
|
101
|
+
# work horse
|
102
|
+
def parse(id, text)
|
103
|
+
storage = []
|
104
|
+
this_text = text
|
105
|
+
# match first id label and continue matching across lines while seeing the continue label "** ~~~ **"
|
106
|
+
regex = /\*\*\s*#{id}\s*\*\*.*?\n(\s+\*\*\s\s\s~~~\s\s\s\*\*.*?\n)*/m
|
107
|
+
while match_data = this_text.match(regex)
|
108
|
+
this_string = match_data.to_s.gsub(/.*\*\*\s*#{id}\s*\*\*/, '').gsub(/.*\*\*\s\s\s~~~\s\s\s\*\*/, '').gsub(/\s*\n/, "\n")
|
109
|
+
storage.push(this_string)
|
110
|
+
this_text = match_data.post_match
|
111
|
+
end
|
112
|
+
return storage.uniq
|
113
|
+
end
|
114
|
+
|
115
|
+
def successful?
|
116
|
+
init if not initialized?
|
117
|
+
@successful
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end #module
|
@@ -0,0 +1,93 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
######################################################################
|
19
|
+
|
20
|
+
module EnergyPlus
|
21
|
+
|
22
|
+
class EpImfFile
|
23
|
+
attr_accessor :locations
|
24
|
+
|
25
|
+
def initialize(path)
|
26
|
+
puts 'parsing ' + path
|
27
|
+
@path = path.expand_path
|
28
|
+
@text = ''
|
29
|
+
@locations = []
|
30
|
+
|
31
|
+
if @path.exist?
|
32
|
+
File.open(@path) do |f|
|
33
|
+
@text << f.read
|
34
|
+
parse
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def savefileas(path)
|
40
|
+
File.open(path, "w") do |f|
|
41
|
+
@locations.each do |loc|
|
42
|
+
f << "##def " + loc[0] + "[]\n"
|
43
|
+
f << loc[1]
|
44
|
+
f << "##enddef\n\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse
|
51
|
+
this_text = @text
|
52
|
+
|
53
|
+
locations = Hash.new
|
54
|
+
|
55
|
+
regex = /##def.*?##enddef/im
|
56
|
+
while match_data = this_text.match(regex)
|
57
|
+
#Grab the name of the location
|
58
|
+
regex2 = /##def (.*?)\[\]$/im
|
59
|
+
|
60
|
+
location_name = match_data.to_s.match(regex2)[1].lstrip.rstrip
|
61
|
+
|
62
|
+
#remove the header/footer from imf snippet
|
63
|
+
regex3 = /##def (.*?)\[\]\n*/im
|
64
|
+
regex4 = /##enddef(.*)\n*/im
|
65
|
+
imf_data = match_data.to_s.gsub(regex3, "").gsub(regex4, "")
|
66
|
+
|
67
|
+
#clean up the IMF (which is really idf data at this point)
|
68
|
+
imf_data.gsub!(/^( )/,"")
|
69
|
+
|
70
|
+
location = [location_name, imf_data]
|
71
|
+
@locations.push(location)
|
72
|
+
|
73
|
+
this_text = match_data.post_match
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def location_sort(x,y)
|
78
|
+
if x[0].include?('ShowHeader')
|
79
|
+
return -1
|
80
|
+
elsif y[0].include?('ShowHeader')
|
81
|
+
return 1
|
82
|
+
else
|
83
|
+
return x[0] <=> y[0]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def sort
|
88
|
+
@locations.sort! {|x,y| location_sort(x,y)}
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end #module
|
@@ -0,0 +1,120 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
######################################################################
|
19
|
+
|
20
|
+
require 'pathname'
|
21
|
+
require 'csv'
|
22
|
+
|
23
|
+
module EnergyPlus
|
24
|
+
|
25
|
+
class EpwFile
|
26
|
+
attr_accessor :path
|
27
|
+
attr_accessor :city
|
28
|
+
attr_accessor :state
|
29
|
+
attr_accessor :country
|
30
|
+
attr_accessor :typ
|
31
|
+
attr_accessor :wmo
|
32
|
+
attr_accessor :lat
|
33
|
+
attr_accessor :lon
|
34
|
+
attr_accessor :gmt
|
35
|
+
attr_accessor :elevation
|
36
|
+
attr_accessor :url
|
37
|
+
|
38
|
+
def initialize(path)
|
39
|
+
@path = Pathname.new(path)
|
40
|
+
@city = ""
|
41
|
+
@state = ""
|
42
|
+
@country = ""
|
43
|
+
@typ = ""
|
44
|
+
@wmo = ""
|
45
|
+
@lat = ""
|
46
|
+
@lon = ""
|
47
|
+
@gmt = ""
|
48
|
+
@elevation = ""
|
49
|
+
@url = ""
|
50
|
+
init
|
51
|
+
end
|
52
|
+
|
53
|
+
def toKml(xml)
|
54
|
+
xml.Placemark {
|
55
|
+
xml.name @city
|
56
|
+
xml.visibility "0"
|
57
|
+
xml.description {
|
58
|
+
xml.cdata!("<img src=\"kml/ep_header8.png\" width=180 align=right><br><table><tr><td colspan=\"2\">"+
|
59
|
+
"<b>#{@city}</b></href></td></tr>\n"+
|
60
|
+
#"<tr><td></td><td><b>Data Type</td></tr>\n"+
|
61
|
+
"<tr><td></td><td>WMO <b>#{@wmo}</b></td></tr>\n"+
|
62
|
+
#"<tr><td></td><td>E 3� 15' N 36� 43'</td></tr>\n"+
|
63
|
+
#"<tr><td></td><td><b>25</b> m</td></tr>\n"+
|
64
|
+
"<tr><td></td><td>Time Zone GMT <b>#{@gmt}</b> hours</td></tr>\n"+
|
65
|
+
#"<tr><td></td><td>ASHRAE Std 169 Climate Zone <b>4A - Mixed - Humid</b></td></tr>\n"+
|
66
|
+
#"<tr><td></td><td>99% Heating DB=<b>3.1</b>, 1% Cooling DB=<b>33.2</b></td></tr>\n"+
|
67
|
+
#"<tr><td></td><td>HDD18 <b>1019</b>, CDD10 <b>2849</b></td></tr>\n"+
|
68
|
+
"<tr><td></td><td>URL #{@url}</td></tr></table>")
|
69
|
+
}
|
70
|
+
xml.styleUrl "#weatherlocation"
|
71
|
+
xml.Point {
|
72
|
+
xml.altitudeMode "absolute"
|
73
|
+
xml.coordinates "#{@lon},#{@lat},#{elevation}"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def valid?
|
79
|
+
return @valid
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
# the mean of the mean monthly dry bulbs
|
85
|
+
private
|
86
|
+
|
87
|
+
# initialize
|
88
|
+
def init
|
89
|
+
if @path.exist?
|
90
|
+
rowCount = 0
|
91
|
+
CSV.open(@path, 'r') do |row|
|
92
|
+
rowCount += 1
|
93
|
+
|
94
|
+
# LOCATION,Adak Nas,AK,USA,TMY3,704540,51.88,-176.65,-10.0,5.0
|
95
|
+
@valid = true
|
96
|
+
|
97
|
+
# process only header row
|
98
|
+
if rowCount == 1
|
99
|
+
@city = row[1].gsub("/","-")
|
100
|
+
@state = row[2]
|
101
|
+
@country = row[3]
|
102
|
+
@typ = row[4]
|
103
|
+
@wmo = row[5]
|
104
|
+
@wmo = "wmoundefined" if @wmo.nil?
|
105
|
+
@lat = row[6]
|
106
|
+
@lon = row[7]
|
107
|
+
@gmt = row[8]
|
108
|
+
@elevation = row[9]
|
109
|
+
break
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end #module
|