Skip to content

Commit

Permalink
Improved FBD scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
imirzov committed Apr 29, 2021
1 parent dc16ec8 commit 82f53b8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
3 changes: 2 additions & 1 deletion config/colors.fbd → config/cgx_colors.fbd
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Read config to register additional colors
# Those colors are needed to paint sets and surfaces
col blue0 0.30 0.60 0.90
col blue1 0.25 0.50 0.75
col blue2 0.20 0.40 0.60
col blue3 0.15 0.30 0.45
col blue4 0.10 0.20 0.30

col pink1 0.20 0.05 0.20
col pink4 0.35 0.10 0.35
col pink2 0.50 0.15 0.50
Expand Down
4 changes: 4 additions & 0 deletions config/cgx_iso.fbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Read config to align model to iso view
rot -z
rot r 45
rot u 45
7 changes: 7 additions & 0 deletions config/cgx_start.fbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Startup commands for CGX
ALLOW_SYS
cmap viridis
steps 7
view elem
view sh
frame
3 changes: 0 additions & 3 deletions config/iso.fbd

This file was deleted.

60 changes: 26 additions & 34 deletions src/gui/cgx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""
# Paint element sets in default CGX colors
def paint_elsets_old(w, elsets):
def paint_elsets_old(f, elsets):
colors = 'rgbymntk'
i = 0
for i in range(len(elsets)):
Expand All @@ -21,74 +21,66 @@ def paint_elsets_old(w, elsets):
break
if len(elsets) > 1:
for elset in elsets:
w.connections[1].post('plus e {} {}'.format(elset, colors[i]))
f.connections[1].post('plus e {} {}'.format(elset, colors[i]))
i = (i + 1) % len(colors)
"""

# Paint element sets in CGX
def paint_elsets(w, m):
w.connections[1].post('plot e all')
w.connections[1].post('minus e all')
def paint_elsets(f, m):
f.connections[1].post('plot e all')
f.connections[1].post('minus e all')
elsets = [e.name for e in m.Mesh.elsets.values()]
i = 0
for elset in elsets:
if elset.upper() == 'ALL':
continue
w.connections[1].post('plus e {} blue{}'.format(elset, i))
f.connections[1].post('plus e {} blue{}'.format(elset, i))
i = (i + 1) % 5

# Paint surfaces in CGX
def paint_surfaces(w, m):
w.connections[1].post('plot e all')
w.connections[1].post('minus e all')
def paint_surfaces(f, m):
f.connections[1].post('plot e all')
f.connections[1].post('minus e all')
surfaces = [s.name for s in m.Mesh.surfaces.values()]
i = 0
for surf in surfaces:
if surf.upper() == 'ALL':
continue
w.connections[1].post('plus f {} pink{}'.format(surf, i))
f.connections[1].post('plus f {} pink{}'.format(surf, i))
i = (i + 1) % 5

# Open INP model in GraphiX
def open_inp(w, inp_file, has_nodes=0):
def open_inp(f, inp_file, has_nodes=0):
if os.path.isfile(inp_file):
w.kill_slave() # close old CGX
f.kill_slave() # close old CGX
if not has_nodes:
logging.warning('Empty mesh, CGX will not start!')
return
cmd = w.p.path_cgx + ' -c ' + inp_file
cmd = f.p.path_cgx + ' -c ' + inp_file
slave_title = 'CalculiX GraphiX'
w.run_slave(cmd, slave_title)
align_model_to_iso_view(w)
register_additional_colors(w)
f.run_slave(cmd, slave_title)
read_fbd_file(f, 'cgx_start.fbd')
read_fbd_file(f, 'cgx_iso.fbd')
read_fbd_file(f, 'cgx_colors.fbd')
else:
logging.error('File not found:\n' + inp_file)

# Open FRD results in GraphiX
def open_frd(w, frd_file):
def open_frd(f, frd_file):
if os.path.isfile(frd_file):
cmd = w.p.path_cgx + ' -o ' + frd_file
cmd = f.p.path_cgx + ' -o ' + frd_file
slave_title = 'CalculiX GraphiX'
w.run_slave(cmd, slave_title)
align_model_to_iso_view(w)
f.run_slave(cmd, slave_title)
read_fbd_file(f, 'cgx_start.fbd')
read_fbd_file(f, 'cgx_iso.fbd')
else:
logging.error('File not found:\n' \
+ frd_file \
+ '\nSubmit analysis first.')

# Read config to align model to iso view
def align_model_to_iso_view(w):
file_name = os.path.join(w.p.config, 'iso.fbd')
def read_fbd_file(f, basename):
file_name = os.path.join(f.p.config, basename)
if os.path.isfile(file_name):
w.connections[1].post('read ' + file_name)
f.connections[1].post('read ' + file_name)
else:
logging.error('No config file iso.fbd')

# Read config to register additional colors
# Those colors are needed to paint sets and surfaces
def register_additional_colors(w):
file_name = os.path.join(w.p.config, 'colors.fbd')
if os.path.isfile(file_name):
w.connections[1].post('read ' + file_name)
else:
logging.error('No config file colors.fbd')
logging.error('No config file ' + basename)

0 comments on commit 82f53b8

Please sign in to comment.