-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
117 lines (93 loc) · 2.99 KB
/
run.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
fracture: Simulation of a scalar fracture model based on Freitas (2007).
Copyright (C) 2017 Italo Silva
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import argparse
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
from subprocess import run, DEVNULL
opt = argparse.ArgumentParser(
description='Execute fracture simulations.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
opt.add_argument(
'-g', '--geometry',
nargs='+',
choices=['t', 'h', 's'],
default=['t']
)
opt.add_argument(
'-l', '--length',
nargs='+',
type=int,
default=[14]
)
opt.add_argument(
'-d', '--disorder',
nargs='+',
type=float,
default=[0, 0.2, 0.4, 0.6, 1.0]
)
opt.add_argument(
'--show',
action='store_true'
)
opt.add_argument(
'--graph',
action='store_true'
)
datafolder = 'data'
pdffolder = 'pdf'
graphfolder = 'graphs'
results = 'output.csv'
pdf = 'output.pdf'
pdf2 = 'result.pdf'
graph = 'graph-begin.dot'
graphend = 'graph-end.dot'
os.makedirs(datafolder, exist_ok=True)
os.makedirs(pdffolder, exist_ok=True)
os.makedirs(graphfolder, exist_ok=True)
exename = 'fracture'
if sys.platform == 'win32':
exename += '.exe'
exe = os.path.join('out', exename)
plt.style.use('ggplot')
args = opt.parse_args();
for G in args.geometry:
for L in args.length:
print('')
plt.figure()
plt.suptitle(f'L = {L}, G = {G}')
for D in args.disorder:
run(f'{exe} {L} {D} {G}')
if args.graph:
begin_path = os.path.join(pdffolder, str(D) + pdf)
run(f'dot {graph} -Tpdf -o{begin_path}')
os.remove(graph)
run(f'start {begin_path}', shell=True)
end_path = os.path.join(pdffolder, str(D) + pdf2)
run(f'dot {graphend} -Tpdf -o{end_path}')
os.remove(graphend)
run(f'start {end_path}', shell=True)
result_path = os.path.join(datafolder, f'{L}.{G}.{D}.csv')
os.replace(results, result_path)
out = np.genfromtxt(result_path, delimiter=',',
skip_header=1, names=['V', 'I'])
plt.plot(out['V'], out['I'], label=f'D={int(D*100)}%')
plt.legend(loc='upper left')
if args.show:
plt.show()
fig_path = os.path.join(graphfolder, f'{G}.{L}.png')
plt.savefig(fig_path, bbox_inches='tight')