Skip to content

Commit 19b324d

Browse files
committed
Adding option to set number of threads when opening the plotter
1 parent cfc56d6 commit 19b324d

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

openmc_plotter/__main__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ def main():
1818
help='Location of model dir (default is current dir)')
1919
ap.add_argument('-e','--ignore-settings', action='store_false',
2020
help='Ignore plot_settings.pkl file if present.')
21+
ap.add_argument('-s', '--threads', type=int, default=None,
22+
help='If present, number of threads used to run OpenMC')
2123

2224
args = ap.parse_args()
2325

2426
os.chdir(args.model_directory)
2527

26-
run_app(use_settings_pkl=args.ignore_settings)
28+
run_app(args)
2729

2830

29-
def run_app(use_settings_pkl=True):
31+
def run_app(user_args):
3032
path_icon = str(Path(__file__).parent / 'assets/openmc_logo.png')
3133
path_splash = str(Path(__file__).parent / 'assets/splash.png')
3234

@@ -47,7 +49,8 @@ def run_app(use_settings_pkl=True):
4749
QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom)
4850
app.processEvents()
4951
# load OpenMC model on another thread
50-
loader_thread = Thread(target=_openmcReload)
52+
openmc_args = {'threads': user_args.threads}
53+
loader_thread = Thread(target=_openmcReload, kwargs=openmc_args)
5154
loader_thread.start()
5255
# while thread is working, process app events
5356
while loader_thread.is_alive():
@@ -62,7 +65,7 @@ def run_app(use_settings_pkl=True):
6265
screen_size = app.primaryScreen().size()
6366
mainWindow = MainWindow(font_metric, screen_size)
6467
# connect splashscreen to main window, close when main window opens
65-
mainWindow.loadGui(use_settings_pkl=use_settings_pkl)
68+
mainWindow.loadGui(use_settings_pkl=user_args.ignore_settings)
6669
mainWindow.show()
6770
splash.close()
6871

openmc_plotter/main_window.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
_COORD_LEVELS = 0
3030

31-
def _openmcReload():
31+
def _openmcReload(threads=None):
3232
# reset OpenMC memory, instances
3333
openmc.lib.reset()
3434
openmc.lib.finalize()
3535
# initialize geometry (for volume calculation)
3636
openmc.lib.settings.output_summary = False
37-
openmc.lib.init(["-c"])
37+
args = ["-c"]
38+
if threads is not None:
39+
args += ["-s", str(threads)]
40+
openmc.lib.init(args)
3841
openmc.lib.settings.verbosity = 1
3942

4043
class MainWindow(QMainWindow):

0 commit comments

Comments
 (0)