Skip to content
Snippets Groups Projects
Commit f3012cf8 authored by mads's avatar mads
Browse files

added set_time in htcfile and improved general set-function

parent b1044933
No related branches found
No related tags found
No related merge requests found
......@@ -104,16 +104,28 @@ class HTCFile(HTCContents, HTCDefaults):
with open(filename, 'w', encoding='utf-8') as fid:
fid.write(str(self))
def set_name(self, name, folder="htc/"):
def set_name(self, name, htc_folder="htc", log_folder="log", res_folder="res"):
#if os.path.isabs(folder) is False and os.path.relpath(folder).startswith("htc" + os.path.sep):
folder = "./" + os.path.relpath(folder).replace("\\", "/")
fmt_folder = lambda folder : "./" + os.path.relpath(folder).replace("\\", "/")
self.filename = os.path.relpath(os.path.join(self.modelpath, folder, "%s.htc" % name)).replace("\\", "/")
self.filename = os.path.abspath(os.path.join(self.modelpath, fmt_folder(htc_folder), "%s.htc" % name)).replace("\\", "/")
if 'simulation' in self and 'logfile' in self.simulation:
self.simulation.logfile = os.path.join(folder.replace("htc", "log", 1), "%s.log" % name).replace("\\", "/")
elif 'test_structure' in self and 'logfile' in self.test_structure:
self.test_structure.logfile = os.path.join(folder.replace("htc", "log", 1), "%s.log" % name).replace("\\", "/")
self.output.filename = os.path.join(folder.replace("htc", "res", 1), "%s" % name).replace("\\", "/")
self.simulation.logfile = os.path.join(fmt_folder(log_folder), "%s.log" % name).replace("\\", "/")
elif 'test_structure' in self and 'logfile' in self.test_structure: # hawc2aero
self.test_structure.logfile = os.path.join(fmt_folder(log_folder), "%s.log" % name).replace("\\", "/")
self.output.filename = os.path.join(fmt_folder(res_folder), "%s" % name).replace("\\", "/")
def set_time(self, start=None, stop=None, step=None):
if stop is not None:
self.simulation.time_stop = stop
else:
stop = self.simulation.time_stop[0]
if step is not None:
self.simulation.newmark.deltat = step
if start is not None:
self.output.time = start, stop
if "wind" in self and self.wind.turb_format[0] > 0:
self.wind.scale_time_start = start
def input_files(self):
files = self.htc_inputfiles
......
......@@ -84,6 +84,14 @@ class TestHtcFile(unittest.TestCase):
self.assertEqual(htcfile.simulation.time_stop[0], 2 * time_stop)
self.assertEqual(htcfile.simulation.time_stop.__class__, HTCLine)
htcfile.output.time = 10, 20
self.assertEqual(htcfile.output.time[:2], [10, 20])
self.assertEqual(str(htcfile.output.time), "time\t10 20;\n")
htcfile.output.time = [11, 21]
self.assertEqual(htcfile.output.time[:2], [11, 21])
htcfile.output.time = "12 22"
self.assertEqual(htcfile.output.time[:2], [12, 22])
def test_htc_file_set_key(self):
htcfile = HTCFile(self.testfilepath + "test.htc")
htcfile.simulation.name = "value"
......@@ -99,9 +107,21 @@ class TestHtcFile(unittest.TestCase):
pass
def test_htcfile_setname(self):
htcfile = HTCFile()
htcfile.set_name("mytest")
self.assertEqual(htcfile.filename, '../htc/mytest.htc')
htcfile = HTCFile(self.testfilepath + "test.htc")
htcfile.set_name("mytest", htc_folder="htcfiles")
self.assertEqual(os.path.relpath(htcfile.filename, self.testfilepath), r'mytest.htc')
self.assertEqual(htcfile.simulation.logfile[0], './log/mytest.log')
self.assertEqual(htcfile.output.filename[0], './res/mytest')
def test_set_time(self):
htcfile = HTCFile(self.testfilepath + "test.htc")
htcfile.set_time(10, 20, 0.2)
self.assertEqual(htcfile.simulation.time_stop[0], 20)
self.assertEqual(htcfile.simulation.newmark.deltat[0], 0.2)
self.assertEqual(htcfile.wind.scale_time_start[0], 10)
self.assertEqual(htcfile.output.time[:2], [10, 20])
......@@ -124,7 +144,7 @@ class TestHtcFile(unittest.TestCase):
box_dim_u\t4096 1.4652;
box_dim_v\t32 3.2258;
box_dim_w\t32 3.2258;
std_scaling\t1.000000 0.800000 0.500000;"""
std_scaling\t1 0.8 0.5;"""
for a, b in zip(s.split("\n"), str(htcfile.wind.mann).split("\n")):
self.assertEqual(a.strip(), b.strip())
self.assertEqual(htcfile.wind.turb_format[0], 1)
......@@ -223,6 +243,7 @@ class TestHtcFile(unittest.TestCase):
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
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