Skip to content
Snippets Groups Projects
Commit f39c7d89 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

htc with multiple output sections

parent 12fddbbb
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,13 @@ class HTCContents(object): ...@@ -49,7 +49,13 @@ class HTCContents(object):
name_ = "" name_ = ""
def __setitem__(self, key, value): def __setitem__(self, key, value):
self.contents[key] = value if isinstance(key, str):
self.contents[key] = value
elif isinstance(key, int):
self.values[key] = value
else:
raise NotImplementedError
def __getitem__(self, key): def __getitem__(self, key):
if isinstance(key, str): if isinstance(key, str):
...@@ -161,9 +167,9 @@ class HTCSection(HTCContents): ...@@ -161,9 +167,9 @@ class HTCSection(HTCContents):
return HTCLine.from_lines(lines) return HTCLine.from_lines(lines)
def __str__(self, level=0): def __str__(self, level=0):
s = "%sbegin %s;%s\n" % (" "*level, self.name_, ("", "\t" + self.begin_comments)[bool(self.begin_comments.strip())]) s = "%sbegin %s;%s\n" % (" "*level, self.name_, (("", "\t" + self.begin_comments)[bool(self.begin_comments.strip())]).replace("\t\n","\n"))
s += "".join([c.__str__(level + 1) for c in self]) s += "".join([c.__str__(level + 1) for c in self])
s += "%send %s;%s\n" % (" "*level, self.name_, ("", "\t" + self.end_comments)[self.end_comments.strip() != ""]) s += "%send %s;%s\n" % (" "*level, self.name_, (("", "\t" + self.end_comments)[self.end_comments.strip() != ""]).replace("\t\n","\n"))
return s return s
class HTCLine(HTCContents): class HTCLine(HTCContents):
...@@ -276,7 +282,7 @@ class HTCSensor(HTCLine): ...@@ -276,7 +282,7 @@ class HTCSensor(HTCLine):
self.type = type self.type = type
self.sensor = sensor self.sensor = sensor
self.values = values self.values = values
self.comments = comments self.comments = comments.strip(" \t")
@staticmethod @staticmethod
def from_lines(lines): def from_lines(lines):
......
...@@ -276,9 +276,9 @@ class HTCFile(HTCContents, HTCDefaults): ...@@ -276,9 +276,9 @@ class HTCFile(HTCContents, HTCDefaults):
('new_htc_structure/struct_inertia_output_file_name', 0), ('new_htc_structure/struct_inertia_output_file_name', 0),
('new_htc_structure/body_eigenanalysis_file_name', 0), ('new_htc_structure/body_eigenanalysis_file_name', 0),
('new_htc_structure/constraint_output_file_name', 0), ('new_htc_structure/constraint_output_file_name', 0),
('turb_export/filename_u', 0), ('wind/turb_export/filename_u', 0),
('turb_export/filename_v', 0), ('wind/turb_export/filename_v', 0),
('turb_export/filename_w', 0)]: ('wind/turb_export/filename_w', 0)]:
line = self.get(k) line = self.get(k)
if line: if line:
files.append(line[index]) files.append(line[index])
...@@ -310,16 +310,17 @@ class HTCFile(HTCContents, HTCDefaults): ...@@ -310,16 +310,17 @@ class HTCFile(HTCContents, HTCDefaults):
def res_file_lst(self): def res_file_lst(self):
self.contents # load if not loaded self.contents # load if not loaded
if 'output' not in self: res = []
return [] for output in [self[k] for k in self.keys() if self[k].name_=="output"]:
dataformat = self.output.get('data_format', 'hawc_ascii') dataformat = output.get('data_format', 'hawc_ascii')
res_filename = self.output.filename[0] res_filename = output.filename[0]
if dataformat[0] == "gtsdf" or dataformat[0] == "gtsdf64": if dataformat[0] == "gtsdf" or dataformat[0] == "gtsdf64":
return [res_filename + ".hdf5"] res.append(res_filename + ".hdf5")
elif dataformat[0] == "flex_int": elif dataformat[0] == "flex_int":
return [res_filename + ".int", os.path.join(os.path.dirname(res_filename), 'sensor')] res.extend([res_filename + ".int", os.path.join(os.path.dirname(res_filename), 'sensor')])
else: else:
return [res_filename + ".sel", res_filename + ".dat"] res.extend([res_filename + ".sel", res_filename + ".dat"])
return res
def simulate(self, exe, skip_if_up_to_date=False): def simulate(self, exe, skip_if_up_to_date=False):
......
begin simulation;
time_stop 200;
end simulation;
begin dll;
;
begin type2_dll;
name risoe_controller;
begin output;
general time; [s]
constraint bearing1 shaft_rot 1 only 2; Drivetrain speed [rad/s]
end output;
end type2_dll;
begin type2_dll;
name risoe_controller2;
begin output;
general time; [s]
constraint bearing1 shaft_rot 1 only 2; Drivetrain speed [rad/s]
end output;
end type2_dll;
end dll;
begin output;
filename ./res/output1;
time 100 200;
general time;
end output;
begin output;
filename ./res/output2;
time 100 200;
general time;
end output;
exit;
...@@ -278,7 +278,18 @@ class TestHtcFile(unittest.TestCase): ...@@ -278,7 +278,18 @@ class TestHtcFile(unittest.TestCase):
self.assertRaisesRegex(ValueError, "Modelpath cannot be autodetected", HTCFile, self.testfilepath + "test2.htc") self.assertRaisesRegex(ValueError, "Modelpath cannot be autodetected", HTCFile, self.testfilepath + "test2.htc")
def test_open_eq_save(self):
HTCFile(self.testfilepath + "test3.htc","../").save(self.testfilepath + "tmp.htc")
htcfile = HTCFile(self.testfilepath + "tmp.htc","../")
htcfile.save(self.testfilepath + "tmp.htc")
self.assertEqual(str(htcfile).count("\t"), str(HTCFile(self.testfilepath + "tmp.htc", "../")).count("\t"))
self.assertEqual(str(htcfile), str(HTCFile(self.testfilepath + "tmp.htc", "../")))
def test_2xoutput(self):
htc = HTCFile(self.testfilepath + "test_2xoutput.htc","../")
self.assertEqual(len(htc.res_file_lst()), 4)
if __name__ == "__main__": if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName'] #import sys;sys.argv = ['', 'Test.testName']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment