Skip to content

Commit b88f687

Browse files
Issue #54: enable batch mode for GUI script
Fix iconpath in job_window & hm_cfg check
1 parent 3c19ef8 commit b88f687

File tree

7 files changed

+549
-223
lines changed

7 files changed

+549
-223
lines changed

openradioss_gui/OpenRadioss_gui.bash

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
# Path to the Python script
23+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
python_script_dir=$script_dir
25+
2326
script_path="OpenRadioss_gui.py"
2427
if [ ! -d $HOME/.OpenRadioss_GUI ]
2528
then
@@ -34,4 +37,4 @@ fi
3437
echo $HOME/.OpenRadioss_GUI/__pycache__
3538
export PYTHONPYCACHEPREFIX=$HOME/.OpenRadioss_GUI/__pycache__
3639

37-
python3 "$script_path"
40+
python3 $script_dir/OpenRadioss_gui.py $@
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
echo off
22

3+
setlocal
34
rem create OpenRadioss_GUI folder in AppData : settings and cache will be stored here
45
if not exist C:\Users\%USERNAME%\AppData\Local\OpenRadioss_GUI (
56
mkdir C:\Users\%USERNAME%\AppData\Local\OpenRadioss_GUI
67
)
78
set PYTHONPYCACHEPREFIX=C:\Users\%USERNAME%\AppData\Local\OpenRadioss_GUI\__pycache__
89

9-
python ./Openradioss_gui.py
10+
set SCRIPT_DIR=%~dp0
11+
python %SCRIPT_DIR%OpenRadioss_gui.py %*
1012

11-
set PYTHONPYCACHEPREFIX=
13+
set PYTHONPYCACHEPREFIX=
14+
endlocal

openradioss_gui/OpenRadioss_gui.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1818
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1919
import os
20+
import sys
21+
import argparse
2022
import json
2123
import platform
2224
import tkinter as tk
@@ -42,21 +44,23 @@
4244
except ImportError:
4345
vtkhdfenabled = False
4446
import gui_def
47+
from runopenradioss import RunOpenRadioss
4548

4649

4750
class openradioss_gui:
4851

49-
def __init__(self,debug):
52+
def __init__(self,debug,script_dir):
5053
# Global Variables
5154
self.debug=debug
55+
self.script_dir=script_dir
5256
self.mpi_path = ''
5357
self.current_platform = platform.system()
5458

5559
self.load_config()
5660

5761
self.job_holder = JobHolder(self.debug)
5862
# Check if the user has selected a valid MPI path
59-
self.Window = gui_def.window(vd3penabled, vtkhdfenabled,self.mpi_path,self.single_status,self.starter_status,self.vtk_status,self.csv_status,self.vtkhdf_status,self.d3plot_status)
63+
self.Window = gui_def.window(vd3penabled, vtkhdfenabled,self.mpi_path,self.single_status,self.starter_status,self.vtk_status,self.csv_status,self.vtkhdf_status,self.d3plot_status,script_dir)
6064

6165
self.job_file_entry=self.Window.file('Job file (.rad, .key, or .k, or .inp)', self.select_file, self.Window.icon_folder)
6266

@@ -172,7 +176,7 @@ def check_sp_exes(self):
172176
pass
173177

174178
def check_install(self):
175-
is_installed = "../hm_cfg_files"
179+
is_installed = self.script_dir +os.sep +".."+os.sep+"hm_cfg_files"
176180
if not os.path.exists(is_installed):
177181
messagebox.showinfo('INCORRECT INSTALL LOCATION', 'The guiscripts folder needs to be saved inside\n your OpenRadioss Folder\n (Same Folder Level as exec and hm_cfg_files)')
178182

@@ -282,4 +286,56 @@ def load_config(self):
282286
if __name__ == "__main__":
283287
#----------------------------- GUI Elements #--------------------------------
284288
# File Menu
285-
gui= openradioss_gui(0)
289+
num_args = len(sys.argv) - 1
290+
parser = argparse.ArgumentParser(description='OpenRadioss GUI')
291+
parser.add_argument('-gui', '--gui',action='store_true', default=False, help='Enable GUI mode')
292+
parser.add_argument('-i', '--input', type=str, help='The input file to process in form: filename<.k|.key>, filename_<runnumber 4 digits>.rad or filename.inp')
293+
parser.add_argument('-nt', '--nt', type=int, metavar='n', help='Number of threads')
294+
parser.add_argument('-np', '--np', type=int, metavar='p', help='Number of MPI process')
295+
parser.add_argument('-sp', '--sp', action='store_true', default=False, help='Enable Extended Single precision mode (default is double precision)')
296+
parser.add_argument('-starter', '--starter_only', action='store_true', default=False, help='Enable Starter Only mode')
297+
parser.add_argument('-th_to_csv', '--th_to_csv', action='store_true', default=False, help='Enable TH to CSV conversion')
298+
parser.add_argument('-anim_to_vtk', '--anim_to_vtk', action='store_true', default=False, help='Enable Animation to VTK conversion')
299+
parser.add_argument('-anim_to_d3plot', '--anim_to_d3plot', action='store_true', default=False, help='Enable Animation to D3plot conversion (need VortexRadioss installed)')
300+
parser.add_argument('-anim_to_vtkhdf', '--anim_to_vtkhdf', action='store_true', default=False, help='Enable Animation to VTKHDF conversion (need VTKHDF installed)')
301+
parser.add_argument('-mpi_path', '--mpi_path', type=str, help='Path to MPI installation')
302+
parser.add_argument('-d', '--debug',action='store_true', default=False, help='Enable debug mode')
303+
args = parser.parse_args()
304+
305+
script_dir = os.path.abspath(__file__)
306+
script_dir = os.path.dirname(script_dir)+os.sep
307+
if num_args > 0:
308+
if args.gui:
309+
debug=1 if args.debug else 0
310+
gui= openradioss_gui(debug,script_dir)
311+
exit(0)
312+
if not args.input:
313+
print(" ")
314+
print("Error: Input file is required in non-GUI mode.")
315+
print(" ")
316+
317+
parser.print_help()
318+
exit(1)
319+
320+
if not args.nt: args.nt=1
321+
if not args.np: args.np=1
322+
323+
command = []
324+
command.append(args.input)
325+
command.append(str(args.nt))
326+
command.append(str(args.np))
327+
command.append("sp" if args.sp else "dp") # precision
328+
command.append("yes" if args.anim_to_vtk else "no") # anim_to_vtk
329+
command.append("yes" if args.th_to_csv else "no") # th_to_csv
330+
command.append("yes" if args.starter_only else "no") # starter_only
331+
command.append("yes" if args.anim_to_d3plot else "no") # anim_to_d3plot
332+
command.append("yes" if args.anim_to_vtkhdf else "no") # anim_to_vtkhdf
333+
command.append(args.mpi_path if args.mpi_path else "") # mpi_path
334+
335+
Run_OR= RunOpenRadioss(command, debug=1 if args.debug else 0)
336+
Run_OR.batch_run()
337+
338+
else:
339+
script_dir = os.path.abspath(__file__)
340+
script_dir = os.path.dirname(script_dir)+os.sep
341+
gui= openradioss_gui(0,script_dir)

openradioss_gui/README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ It is a simple Python/tk based tool to execute OpenRadioss, queue jobs and conve
66

77
The D3plot converter can be found at: [Vortex-CAE GitHub repository](https://github.com/Vortex-CAE/Vortex-Radioss)
88

9+
* [Installation](#installation)
10+
* [Execution using GUI Mode](#execution-using-gui-mode)
11+
* [Execution using Batch Mode](#execution-using-batch-mode)
12+
913
## Installation
1014

1115
* Python3 must be installed on the system.
@@ -30,7 +34,7 @@ The D3plot converter can be found at: [Vortex-CAE GitHub repository](https://git
3034

3135
* Copy the contents of openradioss_gui folder in an OpenRadioss Release Download.
3236

33-
## Execution
37+
## Execution using GUI Mode
3438

3539
* Launch the **OpenRadioss_gui.vbs** on Windows
3640
* Launch the **OpenRadioss_gui.bash** on Linux
@@ -106,3 +110,67 @@ it is possible to submit further jobs from the submission gui after the first an
106110
The Job Queue shows jobs queued along with the options chosen, with the buttons in the window it is possible to cancel the next or last job from the queue, or to manually start the next or last job from the queue (this happens in addition to the queue being processed, jobs will open another run window and run at same time as any running job, queue will continue to automatically run any remaining jobs only when 1st one finishes)
107111

108112
![image](./icon/queue_window.png)
113+
114+
## Execution using Batch Mode
115+
116+
OpenRadioss GUI can be used in batch mode for scripting
117+
118+
Launch
119+
120+
* **[Path to OpenRadioss]/openradioss_gui/OpenRadioss_gui.bash -h** on Linux
121+
* **[Path to OpenRadioss]\openradioss_gui\OpenRadioss_gui.bat -h** on Windows
122+
123+
To obtain the command line help:
124+
125+
usage: OpenRadioss_gui.py [-h] [-gui] [-i INPUT] [-nt n] [-np p] [-sp] [-starter]
126+
[-th_to_csv] [-anim_to_vtk] [-anim_to_d3plot]
127+
[-anim_to_vtkhdf] [-mpi_path MPI_PATH] [-d]
128+
129+
OpenRadioss GUI
130+
131+
options:
132+
-h, --help show this help message and exit
133+
-gui, --gui Enable GUI mode
134+
-i, --input INPUT The input file to process in form: filename<.k|.key>, filename_<runnumber 4 digits>.rad or filename.inp
135+
-nt, --nt n Number of threads
136+
-np, --np p Number of MPI process
137+
-sp, --sp Enable Extended Single precision mode (default is double precision)
138+
-starter, --starter_only Enable Starter Only mode
139+
-th_to_csv, --th_to_csv Enable TH to CSV conversion
140+
-anim_to_vtk, --anim_to_vtk Enable Animation to VTK conversion
141+
-anim_to_d3plot, --anim_to_d3plot Enable Animation to D3plot conversion (need VortexRadioss installed)
142+
-anim_to_vtkhdf, --anim_to_vtkhdf Enable Animation to VTKHDF conversion (need VTKHDF installed)
143+
-mpi_path, --mpi_path MPI_PATH Path to MPI installation
144+
-d, --debug Enable debug mode
145+
146+
### Typical launch method in SMP
147+
148+
1. Enter the execution directory (where the input deck is)
149+
2. [Path to OpenRadioss]/openradioss_gui/OpenRadioss_gui.bash -i [Input_Deck] -nt [t]
150+
151+
### Typical launch method in MPI
152+
153+
Check your MPI settings in the Shell:
154+
155+
* $PATH & $LD_LIBRARY_PATH for Linux
156+
* %PATH% & %I_MPI_ROOT% for Windows
157+
158+
#### If MPI settings are already set in shell
159+
160+
1. Enter the execution directory (where the input deck is)
161+
2. [Path to OpenRadioss]/openradioss_gui/OpenRadioss_gui.bash -i [Input_Deck] -np [p]
162+
163+
#### If MPI settings are not set in the shell
164+
165+
1. Enter the execution directory (where the input deck is)
166+
2. [Path to OpenRadioss]/openradioss_gui/OpenRadioss_gui.bash -i [Input_Deck] -np [p] -mpi_path [path to MPI installation]
167+
168+
**Example**:
169+
170+
* On Windows:
171+
172+
OpenRadioss_gui.bat -i CRA2V44_0000.rad -np 4 -mpi_path "c:\Program Files (x86)\Intel\oneAPI\mpi\2021.16"
173+
174+
* On Linux
175+
176+
OpenRadioss_gui.bash -i CRA2V44_0000.rad -np 4 -mpi_path=/opt/openmpi

openradioss_gui/gui_def.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1717
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1818
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19-
19+
import os
2020
import tkinter as tk
2121
from tkinter import messagebox, simpledialog
2222
import platform
@@ -32,7 +32,7 @@
3232
button_width=8
3333

3434
class window:
35-
def __init__(self, vd3penabled, vtkhdfenabled,mpi_path,sp_status,starter_status,vtk_status,csv_status,vtkhdf_status,d3plot_status):
35+
def __init__(self, vd3penabled, vtkhdfenabled,mpi_path,sp_status,starter_status,vtk_status,csv_status,vtkhdf_status,d3plot_status,script_dir):
3636

3737
self.root = tk.Tk()
3838
self.root.title('OpenRadioss')
@@ -50,12 +50,12 @@ def __init__(self, vd3penabled, vtkhdfenabled,mpi_path,sp_status,starter_status,
5050

5151
# Icons
5252
if arch == 'Windows':
53-
self.root.iconbitmap('./icon/ross.ico')
54-
self.icon_folder = tk.PhotoImage(file='./icon/or_folder.png')
53+
self.root.iconbitmap(script_dir+'icon'+os.sep+'ross.ico')
54+
self.icon_folder = tk.PhotoImage(file=script_dir+'icon'+os.sep+'or_folder.png')
5555
elif arch == 'Linux':
56-
icon_image = tk.PhotoImage(file='./icon/ross.png')
56+
icon_image = tk.PhotoImage(file=script_dir+'icon'+os.sep+'ross.png')
5757
self.root.iconphoto(True, icon_image)
58-
self.icon_folder = tk.PhotoImage(file='./icon/or_folder.png')
58+
self.icon_folder = tk.PhotoImage(file=script_dir+'icon'+os.sep+'or_folder.png')
5959

6060
# Dropdown Variables
6161
self.variables = {

0 commit comments

Comments
 (0)