13
13
import scisave
14
14
import pypeec
15
15
16
+ # crash on warnings and ignore deprecation
17
+ warnings .filterwarnings ("error" )
18
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
19
+ warnings .filterwarnings ("ignore" , category = PendingDeprecationWarning )
20
+
16
21
# disable logging
17
22
scilogger .disable ()
18
23
19
24
# get the path the folder
20
25
PATH_ROOT = os .path .dirname (__file__ )
21
26
22
27
23
- def _create_temp_file ( ):
28
+ def _get_run_mesher ( use_script , file_geometry , file_voxel ):
24
29
"""
25
- Get a temporary file .
30
+ Run the mesher .
26
31
"""
27
32
28
- (_ , filename ) = tempfile .mkstemp (suffix = ".mpk" )
29
-
30
- return filename
33
+ if use_script :
34
+ status = pypeec .run_arguments (
35
+ [
36
+ "--quiet" ,
37
+ "mesher" ,
38
+ "--geometry" ,
39
+ file_geometry ,
40
+ "--voxel" ,
41
+ file_voxel ,
42
+ ]
43
+ )
44
+ if status != 0 :
45
+ raise RuntimeError ("invalid return code for the mesher" )
46
+ else :
47
+ pypeec .run_mesher_file (
48
+ file_geometry = file_geometry ,
49
+ file_voxel = file_voxel ,
50
+ )
31
51
32
52
33
- def _delete_temp_file ( filename ):
53
+ def _get_run_solver ( use_script , file_problem , file_tolerance , file_voxel , file_solution ):
34
54
"""
35
- Delete a temporary file .
55
+ Run the solver .
36
56
"""
37
57
38
- try :
39
- os .remove (filename )
40
- except OSError :
41
- pass
42
-
58
+ if use_script :
59
+ status = pypeec .run_arguments (
60
+ [
61
+ "--quiet" ,
62
+ "solver" ,
63
+ "--voxel" ,
64
+ file_voxel ,
65
+ "--problem" ,
66
+ file_problem ,
67
+ "--tolerance" ,
68
+ file_tolerance ,
69
+ "--solution" ,
70
+ file_solution ,
71
+ ]
72
+ )
73
+ if status != 0 :
74
+ raise RuntimeError ("invalid return code for the solver" )
75
+ else :
76
+ pypeec .run_solver_file (
77
+ file_voxel = file_voxel ,
78
+ file_problem = file_problem ,
79
+ file_tolerance = file_tolerance ,
80
+ file_solution = file_solution ,
81
+ )
82
+
83
+
84
+ def _get_run_viewer (use_script , file_viewer , file_voxel ):
85
+ """
86
+ Run the viewer.
87
+ """
43
88
44
- def _run_script (argv ):
89
+ if use_script :
90
+ status = pypeec .run_arguments (
91
+ [
92
+ "--quiet" ,
93
+ "viewer" ,
94
+ "--voxel" ,
95
+ file_voxel ,
96
+ "--viewer" ,
97
+ file_viewer ,
98
+ "--plot_mode" ,
99
+ "debug" ,
100
+ ]
101
+ )
102
+ if status != 0 :
103
+ raise RuntimeError ("invalid return code for the viewer" )
104
+ else :
105
+ pypeec .run_viewer_file (
106
+ file_voxel = file_voxel ,
107
+ file_viewer = file_viewer ,
108
+ plot_mode = "debug" ,
109
+ )
110
+
111
+
112
+ def _get_run_plotter (use_script , file_plotter , file_solution ):
45
113
"""
46
- Run the command line script with arguments .
114
+ Run the plotter .
47
115
"""
48
116
49
- status = pypeec .run_arguments (argv )
50
- if status != 0 :
51
- raise RuntimeError ("invalid return code for the script" )
117
+ if use_script :
118
+ status = pypeec .run_arguments (
119
+ [
120
+ "--quiet" ,
121
+ "plotter" ,
122
+ "--solution" ,
123
+ file_solution ,
124
+ "--plotter" ,
125
+ file_plotter ,
126
+ "--plot_mode" ,
127
+ "debug" ,
128
+ ]
129
+ )
130
+ if status != 0 :
131
+ raise RuntimeError ("invalid return code for the plotter" )
132
+ else :
133
+ pypeec .run_plotter_file (
134
+ file_solution = file_solution ,
135
+ file_plotter = file_plotter ,
136
+ plot_mode = "debug" ,
137
+ )
52
138
53
139
54
140
def run_workflow (name , use_script ):
55
141
"""
56
142
Run the complete workflow:
57
143
- Run the mesher.
58
- - Run the viewer.
59
144
- Run the solver.
145
+ - Run the viewer.
60
146
- Run the plotter.
61
147
62
148
The intermediate file are stored with temporary files.
@@ -67,11 +153,6 @@ def run_workflow(name, use_script):
67
153
- With the API (pypeec.main).
68
154
"""
69
155
70
- # crash on warnings and ignore deprecation
71
- warnings .filterwarnings ("error" )
72
- warnings .filterwarnings ("ignore" , category = DeprecationWarning )
73
- warnings .filterwarnings ("ignore" , category = PendingDeprecationWarning )
74
-
75
156
# construct the folder path for the examples
76
157
folder_examples = os .path .join (PATH_ROOT , ".." , ".." , "examples" )
77
158
@@ -85,88 +166,23 @@ def run_workflow(name, use_script):
85
166
file_tolerance = os .path .join (folder_examples , "config" , "tolerance.yaml" )
86
167
87
168
# get the temporary files
88
- file_voxel = _create_temp_file ( )
89
- file_solution = _create_temp_file ( )
169
+ ( _ , file_voxel ) = tempfile . mkstemp ( suffix = ".mpk" )
170
+ ( _ , file_solution ) = tempfile . mkstemp ( suffix = ".mpk" )
90
171
91
- # run the code
172
+ # run the workflow and load the results
92
173
try :
93
174
# run the workflow
94
- if use_script :
95
- # get the arguments
96
- argv_me = [
97
- "--quiet" ,
98
- "mesher" ,
99
- "--geometry" ,
100
- file_geometry ,
101
- "--voxel" ,
102
- file_voxel ,
103
- ]
104
- argv_vi = [
105
- "--quiet" ,
106
- "viewer" ,
107
- "--voxel" ,
108
- file_voxel ,
109
- "--viewer" ,
110
- file_viewer ,
111
- "--plot_mode" ,
112
- "debug" ,
113
- ]
114
- argv_so = [
115
- "--quiet" ,
116
- "solver" ,
117
- "--voxel" ,
118
- file_voxel ,
119
- "--problem" ,
120
- file_problem ,
121
- "--tolerance" ,
122
- file_tolerance ,
123
- "--solution" ,
124
- file_solution ,
125
- ]
126
- argv_pl = [
127
- "--quiet" ,
128
- "plotter" ,
129
- "--solution" ,
130
- file_solution ,
131
- "--plotter" ,
132
- file_plotter ,
133
- "--plot_mode" ,
134
- "debug" ,
135
- ]
136
-
137
- # run the scripts
138
- _run_script (argv_me )
139
- _run_script (argv_vi )
140
- _run_script (argv_so )
141
- _run_script (argv_pl )
142
- else :
143
- pypeec .run_mesher_file (
144
- file_geometry = file_geometry ,
145
- file_voxel = file_voxel ,
146
- )
147
- pypeec .run_solver_file (
148
- file_voxel = file_voxel ,
149
- file_problem = file_problem ,
150
- file_tolerance = file_tolerance ,
151
- file_solution = file_solution ,
152
- )
153
- pypeec .run_viewer_file (
154
- file_voxel = file_voxel ,
155
- file_viewer = file_viewer ,
156
- plot_mode = "debug" ,
157
- )
158
- pypeec .run_plotter_file (
159
- file_solution = file_solution ,
160
- file_plotter = file_plotter ,
161
- plot_mode = "debug" ,
162
- )
175
+ _get_run_mesher (use_script , file_geometry , file_voxel )
176
+ _get_run_solver (use_script , file_problem , file_tolerance , file_voxel , file_solution )
177
+ _get_run_plotter (use_script , file_plotter , file_solution )
178
+ _get_run_viewer (use_script , file_viewer , file_voxel )
163
179
164
180
# load the files
165
181
data_voxel = scisave .load_data (file_voxel )
166
182
data_solution = scisave .load_data (file_solution )
167
183
finally :
168
184
# close the temporary files
169
- _delete_temp_file (file_voxel )
170
- _delete_temp_file (file_solution )
185
+ os . remove (file_voxel )
186
+ os . remove (file_solution )
171
187
172
188
return data_voxel , data_solution
0 commit comments