Skip to content

Commit

Permalink
adding job runner
Browse files Browse the repository at this point in the history
gui:
 - saving animation settings
  • Loading branch information
Steve Doyle committed Dec 7, 2024
1 parent e6258d9 commit 3a86a1a
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 150 deletions.
56 changes: 56 additions & 0 deletions pyNastran/bdf/bdf_interface/dev/dedemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import sys
from collections import defaultdict
bdf_filename = sys.argv[1]
base, ext = os.path.splitext(bdf_filename)
bdf_filename_out = base + '.dedmap' + ext

with open(bdf_filename, 'r') as bdf_file:
lines = bdf_file.readlines()
nlines = len(lines)

blocks = defaultdict(list)
i = 0
line = lines[i]
while 'N A S T R A N S O U R C E P R O G R A M C O M P I L A T I O N' not in line:
print(i, line.strip())
i += 1
line = lines[i]

while i < nlines and 'N A S T R A N S O U R C E P R O G R A M C O M P I L A T I O N' in line:
line = lines[i]
print('*', i, line)
source, dmap = line.strip().split('SUBDMAP =')
#dmap = dmap.strip()
print(f'dmap = {dmap!r}')

blocks[dmap].append(line)
i += 1
line = lines[i]

blocks[dmap].append(line)
while 'PAGE' not in line:
blocks[dmap].append(line)
i += 1
line = lines[i]
for j in range(3):
i += 1
line = lines[i]
print('**', i, line.strip())
# i += 2
# line = lines[i]
# print('**', i, line)
print('--------------------------')


with open(bdf_filename_out, 'w') as bdf_file_out:
for block_name, block in blocks.items():
bdf_file_out.write(f'0 N A S T R A N S O U R C E P R O G R A M C O M P I L A T I O N SUBDMAP = {block_name}\n')
bdf_file_out.write(f' OLD NO. NEW NO. ( *I* = INSERTED, *D* = DELETED )\n')
for line in block:
if (line.startswith(' DMAP-DMAP INSTRUCTION') or
'N A S T R A N S O U R C E P R O G R A M C O M P I L A T I O N' in line or
'OLD NO. NEW NO. ( *I* = INSERTED, *D* = DELETED )' in line):
continue
bdf_file_out.write(line)
print(f'finished writing {bdf_filename_out}')
56 changes: 56 additions & 0 deletions pyNastran/bdf/test/run_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
from pathlib import Path
import sys

import argparse
import pyNastran

def run_jobs_cmd_line(argv=None, quiet: bool=False):
"""
run_nastran_job dirname
run_nastran_job filename -x C:\bin\nastran.exe
"""
if argv is None:
argv = sys.argv
parser = argparse.ArgumentParser()

parser.add_argument("bdf_dirname_filename", help='path to Nastran filename')
parser.add_argument('-x', '--exe', help='path to Nastran execuable')
#parent_parser.add_argument('-h', '--help', help='show this help message and exits', action='store_true')
parser.add_argument('-v', '--version', action='version',
version=pyNastran.__version__)

args = parser.parse_args(args=argv[1:])
if not quiet: # pragma: no cover
print(args)

bdf_filename_dirname = Path(args.bdf_dirname_filename)
nastran_exe = args.exe
if nastran_exe is None:
nastran_exe = 'nastran'
elif '.bat' in nastran_exe or '.exe' in nastran_exe:
nastran_exe = Path(nastran_exe)
assert nastran_exe.exists(), nastran_exe
assert nastran_exe.is_file(), nastran_exe

assert bdf_filename_dirname.exists(), bdf_filename_dirname

from pyNastran.utils.nastran_utils import run_nastran
if bdf_filename_dirname.is_dir():
dirname = bdf_filename_dirname
extensions = ['.dat', '.bdf']
bdf_filenames = [dirname / fname.name for fname in dirname.iterdir()
if fname.suffix in extensions and '.test_bdf.' not in fname.name]
print('bdf_filenames =', bdf_filenames)
assert len(bdf_filenames) > 0, dirname
for bdf_filename in bdf_filenames:
run_nastran(bdf_filename, nastran_cmd=nastran_exe, cleanup=True)


elif bdf_filename_dirname.is_file():
run_nastran(bdf_filename_dirname, nastran_cmd=nastran_exe, cleanup=True)
else:
raise NotImplementedError(bdf_filename_dirname)

if __name__ == '__main__':
run_jobs_cmd_line()
46 changes: 23 additions & 23 deletions pyNastran/converters/nastran/gui/menus/element_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,31 @@ def main(): # pragma: no cover
'icase_disp' : 2,
'icase_vector' : 3,

'name' : 'cat',
'time' : 2,
'frames/sec' : 30,
'resolution' : 1,
'iframe' : 0,
'is_scale' : False,
'dirname' : os.getcwd(),
'scale' : 2.0,
'default_scale' : 10,

'arrow_scale' : 3.0,
'default_arrow_scale' : 30,
'name': 'cat',
'time': 2,
'frames/sec': 30,
'resolution': 1,
'iframe': 0,
'is_scale': False,
'dirname': os.getcwd(),
'scale': 2.0,
'default_scale': 10,

'arrow_scale': 3.0,
'default_arrow_scale': 30,

#'phase' : 0.,
'phase' : None,
'default_phase' : 120.,
#'default_phase' : None,

#'start_time' : 0.,
#'end_time' : 0.,
'default_time' : 0.,
'icase_start' : 10,
'icase_delta' : 3,
'stress_min' : 0.,
'stress_max' : 1000.,
'phase': None,
'default_phase': 120.,
#'default_phase': None,

#'start_time': 0.,
#'end_time': 0.,
'default_time': 0.,
'icase_start': 10,
'icase_delta': 3,
'stress_min': 0.,
'stress_max': 1000.,
}
data2['phase'] = 0. # uncomment for phase

Expand Down
14 changes: 14 additions & 0 deletions pyNastran/gui/gui_objects/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
MAGNIFY_MIN = 1
MAGNIFY_MAX = 10

ANIMATION_FRAME_RATE = 30
ANIMATION_TIME = 2.0

PLOTEL_COLOR = RED_FLOAT
CAERO_COLOR = YELLOW_FLOAT
RBE_LINE_COLOR = LIGHT_GREEN_FLOAT
Expand Down Expand Up @@ -469,6 +472,9 @@ def reset_settings(self, resize: bool=True,
self.coord_text_scale = COORD_TEXT_SCALE # float
self.coord_linewidth = 2.0

self.animation_frame_rate = ANIMATION_FRAME_RATE
self.animation_time = ANIMATION_TIME

# string
self.colormap = 'jet' # 'viridis'

Expand Down Expand Up @@ -683,6 +689,12 @@ def load(self, settings: QSettings) -> bool:
self.shear_moment_torque_line_width,
min_value=LINE_WIDTH_MIN, max_value=LINE_WIDTH_MAX)

# animation
self._set_setting(settings, setting_keys, ['animation_time'],
default=ANIMATION_TIME, save=True, auto_type=float)
self._set_setting(settings, setting_keys, ['animation_frame_rate'],
default=ANIMATION_FRAME_RATE, save=True, auto_type=int)

# displacement_model_scale - unused
self._set_setting(settings, setting_keys, ['displacement_model_scale'],
default=DISPLACEMENT_MODEL_SCALE, save=True, auto_type=float)
Expand Down Expand Up @@ -892,6 +904,8 @@ def save(self, settings: QSettings,

# float
settings.setValue('displacement_model_scale', self.displacement_model_scale)
settings.setValue('animation_time', self.animation_time),
settings.setValue('animation_frame_rate', self.animation_frame_rate),

# logging
settings.setValue('show_info', self.show_info)
Expand Down
60 changes: 30 additions & 30 deletions pyNastran/gui/menus/calculator/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,36 +374,36 @@ def main(): # pragma: no cover

#from pyNastran.gui.menus.legend.animation import AnimationWindow
data2 = {
'font_size' : 8,
'icase_fringe' : 1,
'icase_disp' : 2,
'icase_vector' : 3,

'title' : 'cat',
'time' : 2,
'frames/sec' : 30,
'resolution' : 1,
'iframe' : 0,
'is_scale' : False,
'dirname' : os.getcwd(),
'scale' : 2.0,
'default_scale' : 10,

'arrow_scale' : 3.0,
'default_arrow_scale' : 30,

#'phase' : 0.,
'phase' : None,
'default_phase' : 120.,
#'default_phase' : None,

#'start_time' : 0.,
#'end_time' : 0.,
'default_time' : 0.,
'icase_start' : 10,
'icase_delta' : 3,
'stress_min' : 0.,
'stress_max' : 1000.,
'font_size': 8,
'icase_fringe': 1,
'icase_disp': 2,
'icase_vector': 3,

'title': 'cat',
'time': 2,
'frames/sec': 30,
'resolution': 1,
'iframe': 0,
'is_scale': False,
'dirname': os.getcwd(),
'scale': 2.0,
'default_scale': 10,

'arrow_scale': 3.0,
'default_arrow_scale': 30,

#'phase': 0.,
'phase': None,
'default_phase': 120.,
#'default_phase': None,

#'start_time': 0.,
#'end_time': 0.,
'default_time': 0.,
'icase_start': 10,
'icase_delta': 3,
'stress_min': 0.,
'stress_max': 1000.,
}
data2['phase'] = 0. # uncomment for phase

Expand Down
86 changes: 54 additions & 32 deletions pyNastran/gui/menus/legend/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from __future__ import annotations
import os
from typing import TYPE_CHECKING
from typing import Any, TYPE_CHECKING

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
Expand Down Expand Up @@ -1306,6 +1306,9 @@ def on_validate(self, wipe: bool=False) -> tuple[bool,
scale, flag1 = check_float(self.scale_edit)
time, flag2 = check_float(self.time_edit)
fps, flag3 = check_float(self.fps_edit)
self.time = time
self.fps = fps
self._set_settings()

min_value = max_value = None
flag4 = flag5 = True
Expand Down Expand Up @@ -1343,8 +1346,27 @@ def on_validate(self, wipe: bool=False) -> tuple[bool,
#self.close()
##self.destroy()

def settings(self) -> dict[str, Any]:
if self.is_gui:
out = self.win_parent.settings
else:
out = {}
return out

def _set_settings(self) -> None:
if not self.is_gui:
return
time, flag2 = check_float(self.time_edit)
fps, flag3 = check_float(self.fps_edit)
if flag2 and flag3:
self._default_time = time
self._default_fps = fps
self.settings.animation_time = time
self.settings.animation_frame_rate = fps

def on_cancel(self) -> None:
"""click the Cancel button"""
self._set_settings()
self.on_stop()
self.out_data['close'] = True
self.close()
Expand All @@ -1370,36 +1392,36 @@ def main(): # pragma: no cover

#from pyNastran.gui.menus.legend.animation import AnimationWindow
data2 = {
'font_size' : 8,
'icase_fringe' : 1,
'icase_disp' : 2,
'icase_vector' : 3,

'title' : 'cat',
'time' : 2,
'frames/sec' : 30,
'resolution' : 1,
'iframe' : 0,
'is_scale' : False,
'dirname' : os.getcwd(),
'scale' : 2.0,
'default_scale' : 10,

'arrow_scale' : 3.0,
'default_arrow_scale' : 30,

#'phase' : 0.,
'phase' : None,
'default_phase' : 120.,
#'default_phase' : None,

#'start_time' : 0.,
#'end_time' : 0.,
'default_time' : 0.,
'icase_start' : 10,
'icase_delta' : 3,
'stress_min' : 0.,
'stress_max' : 1000.,
'font_size': 8,
'icase_fringe': 1,
'icase_disp': 2,
'icase_vector': 3,

'title': 'cat',
'time': 2,
'frames/sec': 30,
'resolution': 1,
'iframe': 0,
'is_scale': False,
'dirname': os.getcwd(),
'scale': 2.0,
'default_scale': 10,

'arrow_scale': 3.0,
'default_arrow_scale': 30,

#'phase': 0.,
'phase': None,
'default_phase': 120.,
#'default_phase': None,

#'start_time': 0.,
#'end_time': 0.,
'default_time': 0.,
'icase_start': 10,
'icase_delta': 3,
'stress_min': 0.,
'stress_max': 1000.,
}
data2['phase'] = 0. # uncomment for phase

Expand All @@ -1425,5 +1447,5 @@ def main(): # pragma: no cover
app.exec_()


if __name__ == "__main__": # pragma: no cover
if __name__ == "__main__": # pragma: no cover
main()
Loading

0 comments on commit 3a86a1a

Please sign in to comment.