-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile_mesh.py
executable file
·77 lines (57 loc) · 2.16 KB
/
compile_mesh.py
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
#!/usr/bin/env python
import argparse
import logging
from os import getcwd, path
import h5py
from tqdm import tqdm
from src.mesh.mesh import Mesh
class CompileMesh:
def __init__(self):
# Parse command line args
parser = argparse.ArgumentParser(description='run TDGL simulations')
parser.add_argument('-v',
'--verbose',
action='store_true',
default=False,
help='run in verbose mode'
)
parser.add_argument('-s',
'--silent',
action='store_true',
default=False,
help='run in silent mode'
)
parser.add_argument('input',
metavar='INPUT',
nargs='+',
type=str,
help='path to the mesh to compile'
)
parser.set_defaults(func=self.compile)
# Get arguments
self.args = parser.parse_args()
# Create a logger
self.logger = logging.getLogger('simulate')
console_stream = logging.StreamHandler()
console_stream.setFormatter(
logging.Formatter('%(levelname)s: %(message)s')
)
self.logger.addHandler(console_stream)
# Set log level to DEBUG in verbose mode and INFO in non-verbose mode
self.logger.setLevel(
logging.DEBUG if self.args.verbose else logging.INFO
)
# Disable logging if silent mode is enabled
self.logger.disabled = self.args.silent
self.args.func()
def compile(self):
for input_file in tqdm(self.args.input):
with h5py.File(path.join(getcwd(), input_file), 'r+') as h5file:
# Mesh is already compiled.
if Mesh.is_restorable(h5file):
continue
mesh = Mesh.load_from_hdf5(h5file)
h5file.clear()
mesh.save_to_hdf5(h5file)
if __name__ == '__main__':
CompileMesh()