Trisurf Monte Carlo simulator
Samo Penic
2016-03-03 bd69936da8e1f59147b7e2dde0f53067ee1ff94a
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python3
 
import configobj
import xml.etree.ElementTree as ET
import base64
import zlib
import io
 
 
'''
This is a trisurf instance manager written in python
 
 
Invoke with:
tsmgr [-t tape | -r snapshot.vtu] [-s subdirectory]
 
If tape is specified, the trisurf wilt start from tape with initial distribution, if snapshot is specified the trisurf will be restored from given snapshot file and simulation will continue.
 
'''
 
 
 
class Tape:
    '''Has all the info on the tape'''
 
    def __init__(self):
        return
 
    def readTape(self, tape='tape'):
        try:
            self.config=configobj.ConfigObj(tape)
        except:
            print("Error reading or parsing tape file!\n")
            exit(1)
    
 
    def setTape(self, string):
        self.config=configobj.ConfigObj(io.StringIO(string))
        return
 
    def getValue(self,key):
        return self.config[key]
 
 
 
class Runner:
    '''
    Class Runner consists of a single running or terminated instance of the trisurf
    '''
    def initFromTape(self, tape):
        self.tape=Tape()
        self.tape.readTape(tape)
 
    def initFromSnapshot(self, snapshotfile):
        try:
            tree = ET.parse(snapshotfile)
        except:
            print("Error reading snapshot file")
            exit(1)
 
        root = tree.getroot()
        tapetxt=root.find('tape')
        version=root.find('trisurfversion')
        #print("Reading snapshot made from: "+version.text)
        self.tape=Tape()
        #print(tapetxt.text)
        self.tape.setTape(tapetxt.text)
 
    def __init__(self, subdir='run0', tape='', snapshot=''):
        self.subdir=subdir
        if(tape!=''):
            self.initFromTape(tape)
        if(snapshot!=''):
            self.initFromSnapshot(snapshot)
 
        return
 
    def getStatus(self):
        pass
 
    def start(self):
        pass
 
    def stop(self):
        pass
 
    def __str__(self):
        return("Running instance")