c2e2wrapper.py 1.23 KB
Newer Older
navidmokh's avatar
navidmokh committed
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
# This is file contains wrapper function for c2e2 compiled simulation function
import os

OUTPUTFILE = './output.txt'
CONFILE = './config'
ABSERROR = '1.00000e-10'
REFERROR ='1.00000e-09'

# The config file is in following stanard
# time
# point info dim1
# point info dim2
# ....
# abserror
# referror
# timestep
# timehorizon
# mode num

def invokeSimulator(modeNum, simFile, initial, timeStep, remainTime):
	# Compose the config file
	f = open(CONFILE, 'w')
	# write 0.0 as initial time since we do not have it in DRYVR
	f.write('0.0'+'\n')
	for pt in initial:
		f.write(str(pt) + '\n')

	f.write(ABSERROR+'\n')
	f.write(REFERROR+'\n')
	f.write(str(timeStep)+'\n')
	f.write(str(remainTime)+'\n')
	f.write(str(modeNum))
	f.close()
	commandStr = simFile+ ' <' + CONFILE + ' >' + OUTPUTFILE
	os.system(commandStr)

	# read output file back
	# c2e2 simulator represent simu result as a hyper box
	# we need to get rid of it
	f = open(OUTPUTFILE)
	result = []
	for line in f:
		line = map(float,line.strip().split(' '))
li213's avatar
li213 committed
44
		line = list(line)
navidmokh's avatar
navidmokh committed
45
46
47
48
49
50
51
52
53
54
55
56
57
		if not result:
			result.append(line)
		elif line[0] == result[-1][0]:
			continue
		else:
			result.append(line)
	return result

if __name__ == '__main__':
	invokeSimulator(1, './bruss/simu', [2.5, 1.25], 0.01, 10.0)