Skip to content

Commit 1816993

Browse files
committed
reorg of f06 plot_144
1 parent 25eb2c1 commit 1816993

File tree

5 files changed

+104
-37
lines changed

5 files changed

+104
-37
lines changed

pyNastran/bdf/mesh_utils/export_caero_mesh.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import numpy as np
99

1010
from pyNastran.utils import PathLike
11+
from pyNastran.bdf.mesh_utils.internal_utils import get_bdf_model
1112
from pyNastran.bdf.bdf import read_bdf, BDF, Coord, AELIST
1213
from pyNastran.bdf.cards.aero.aero import CAERO1, CAERO2
1314
from pyNastran.bdf.field_writer_8 import print_card_8
1415

1516

16-
def export_caero_mesh(model: BDF,
17+
def export_caero_mesh(bdf_filename: PathLike | BDF,
1718
caero_bdf_filename: PathLike='caero.bdf',
1819
is_aerobox_model: bool=True,
1920
pid_method: str='aesurf',
@@ -22,7 +23,7 @@ def export_caero_mesh(model: BDF,
2223
"""
2324
Write the CAERO cards as CQUAD4s that can be visualized
2425
25-
model: BDF
26+
model: str | Path | BDF
2627
a valid geometry
2728
caero_bdf_filename : str
2829
the file to write
@@ -43,6 +44,22 @@ def export_caero_mesh(model: BDF,
4344
$$ 1 2 0.0988 0.2500 0.0000 0.0988 0.5000 0.1234
4445
"""
4546
rotate_panel_angle = np.radians(rotate_panel_angle_deg)
47+
48+
cards_to_include = [
49+
'CAERO1', 'CAERO2', 'CAERO3', 'CAERO4', 'CAERO5',
50+
'PAERO1', 'PAERO2', 'PAERO3', 'PAERO4', 'PAERO5',
51+
'SET1', 'SET2', 'SET3',
52+
'SPLINE1', 'SPLINE2', 'SPLINE3', 'SPLINE4', 'SPLINE5',
53+
'AELIST',
54+
# for aero ooord
55+
'AEROS', 'AERO',
56+
'CORD1R', 'CORD1S', 'CORD1C',
57+
'CORD2R', 'CORD2S', 'CORD2C',
58+
'GRID',
59+
]
60+
model = get_bdf_model(
61+
bdf_filename, cards_to_include=cards_to_include,
62+
log=None, debug=False)
4663
if isinstance(model, PathLike):
4764
model = read_bdf(model)
4865
log = model.log

pyNastran/bdf/mesh_utils/internal_utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from io import StringIO
22
from pathlib import PurePath
3-
from pyNastran.bdf.bdf import BDF
3+
from pyNastran.bdf.bdf import BDF, read_bdf
44

55
#def get_model(bdf_filename):
66
#if isinstance(bdf_filename, str):
@@ -17,6 +17,7 @@
1717
def get_bdf_model(bdf_filename: BDF_FILETYPE,
1818
xref: bool=True,
1919
cards_to_skip=None,
20+
cards_to_include=None,
2021
validate: bool=True,
2122
log=None, debug: bool=False) -> BDF:
2223
if isinstance(bdf_filename, (str, StringIO, PurePath)):
@@ -25,11 +26,16 @@ def get_bdf_model(bdf_filename: BDF_FILETYPE,
2526
#read_cards=None,
2627
#encoding=None, log=None,
2728
#debug=True, mode='msc')
28-
model = BDF(log=log, debug=debug)
29-
model.disable_cards(cards_to_skip)
30-
model.read_bdf(bdf_filename, validate=validate, xref=xref,
31-
punch=False, read_includes=True,
32-
save_file_structure=False, encoding=None)
29+
model = read_bdf(
30+
bdf_filename,
31+
validate=validate,
32+
xref=xref,
33+
skip_cards=cards_to_skip,
34+
read_cards=cards_to_include,
35+
punch=False,
36+
#read_includes=True,
37+
save_file_structure=False,
38+
log=log, debug=debug)
3339
elif isinstance(bdf_filename, BDF):
3440
model = bdf_filename
3541
if xref:

pyNastran/f06/f06_to_pressure_loads.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def f06_to_pressure_loads(f06_filename: PathLike,
105105
cpi = np.mean(cps)
106106
cp_list.append(cpi)
107107
cps_list.append(cp_list)
108-
line0 = line0.rstrip(',') + '\n'
108+
109+
line0 = line0.rstrip(',') + '\n'
109110
cp_array = np.column_stack(cps_list)
110111
assert cp_array.shape == (neids, nsubcases), f'actual_shape={cp_array.shape} expected=({neids},{nsubcases})'
111112

pyNastran/f06/test/test_f06_utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,31 @@ def test_f06_trim_bwb(self):
744744
pid_method='caero',
745745
write_panel_xyz=True)
746746

747+
# auto-generated files
747748
trim_results = f06_to_pressure_loads(
748-
f06_filename, aerobox_caero_filename, loads_filename,
749+
f06_filename, aerobox_caero_filename,
750+
loads_filename,
749751
log=None, nlines_max=1_000_000, debug=None)
752+
# set the file names?
750753
trim_results = f06_to_pressure_loads(
751-
f06_filename, aerobox_caero_filename, loads_filename,
754+
f06_filename, aerobox_caero_filename,
755+
loads_filename,
752756
nid_csv_filename=nid_csv_filename,
753757
eid_csv_filename=eid_csv_filename,
754758
log=None, nlines_max=1_000_000, debug=None)
755759

760+
argv = [
761+
'f06', 'plot_144', str(f06_filename),
762+
'--caero', str(aerobox_caero_filename)]
763+
log = get_logger(log=None, level=None, encoding='utf-8')
764+
cmd_line_f06(argv=argv, # plot=IS_MATPLOTLIB,
765+
show=False, log=log)
766+
767+
argv = ['f06', 'plot_144', str(f06_filename)]
768+
cmd_line_f06(argv=argv, # plot=IS_MATPLOTLIB,
769+
show=False, log=log)
770+
771+
756772
def test_f06_trim_freedlm(self):
757773
"""tests read_f06_trim"""
758774
bdf_filename = AERO_PATH / 'freedlm' / 'freedlm.bdf'

pyNastran/f06/utils.py

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
"""
66
from __future__ import annotations
7+
import os
78
import sys
89
from typing import Optional, TYPE_CHECKING
910

@@ -18,36 +19,18 @@
1819
#matplotlib.use(matplotlib_backend)
1920
#from pyNastran.gui.qt_version import qt_version
2021

21-
PLOT_TYPES = '[--eas|--tas|--density|--mach|--alt|--q|--index]'
22-
AXES = '[--xlim XLIM] [--ylimdamp DAMP] [--ylimfreq FREQ]'
23-
EXPORTS = '[--export_csv] [--export_zona] [--export_f06]'
24-
USAGE_145 = (
25-
'Usage:\n'
26-
' f06 plot_145 F06_FILENAME [--modes MODES] [--subcases SUB] '
27-
f'{PLOT_TYPES} [--kfreq] [--rootlocus] '
28-
'[--in_units IN] [--out_units OUT] [--rhoref] '
29-
f'[--vd_limit VD_LIMIT] [--damping_limit DAMPING_LIMIT] {AXES} '
30-
f'[--noline] [--nopoints] [--ncol NCOL] {EXPORTS} '
31-
'[--modal IVEL MODE] [--freq_tol FREQ_TOL] [--freq_tol_remove FREQ_TOL_REMOVE] [--mag_tol MAG_TOL]\n'
32-
)
33-
USAGE_144 = (
34-
'Usage:\n'
35-
' f06 plot_144 F06_FILENAME SUBPANEL_CAERO_FILENAME\n'
36-
)
37-
38-
USAGE_200 = (
39-
'Usage:\n'
40-
' f06 plot_200 F06_FILENAME\n'
41-
)
4222
if TYPE_CHECKING: # pragma: no cover
4323
from cpylog import SimpleLogger
4424
from pyNastran.f06.flutter_response import FlutterResponse
4525

4626

27+
USAGE_144 = (
28+
'Usage:\n'
29+
' f06 plot_144 F06_FILENAME [--caero AEROBOX_CAERO_FILENAME] | [--bdf BDF_FILENAME]\n'
30+
)
4731
def cmd_line_plot_trim(argv=None, plot: bool=True, show: bool=True,
4832
log: Optional[SimpleLogger]=None):
4933
"""the interface to ``f06 plot_144`` on the command line"""
50-
import os
5134
from pyNastran.f06.parse_flutter import plot_flutter_f06, float_types
5235
if argv is None: # pragma: no cover
5336
argv = sys.argv
@@ -69,7 +52,10 @@ def cmd_line_plot_trim(argv=None, plot: bool=True, show: bool=True,
6952

7053
'Positional Arguments:\n'
7154
' F06_FILENAME path to input F06 file\n'
72-
' AEROBOX_CAERO_FILENAME path to input CAERO file\n'
55+
56+
'Options:\n'
57+
' --caero AEROBOX_CAERO_FILENAME path to exported CAERO file\n'
58+
' --bdf BDF_FILENAME path to input BDF file containing CAEROs\n'
7359
'\n'
7460
'Info:\n'
7561
' -h, --help show this help message and exit\n'
@@ -85,14 +71,39 @@ def cmd_line_plot_trim(argv=None, plot: bool=True, show: bool=True,
8571
ver = str(pyNastran.__version__)
8672
assert docopt_version >= '0.9.0', docopt_version
8773
data = docopt(msg, version=ver, argv=argv[1:])
88-
f06_filename = data['F06_FILENAME']
89-
aerobox_caero_filename = data['AEROBOX_CAERO_FILENAME']
74+
if data['--bdf'] is False:
75+
data['--bdf'] = None
9076

77+
# print(data)
78+
f06_filename = data['F06_FILENAME']
79+
aerobox_caero_filename = data['--caero']
80+
bdf_filename = data['--bdf']
81+
82+
from pyNastran.utils import print_bad_path
83+
# print(aerobox_caero_filename)
84+
# print(bdf_filename)
85+
if bdf_filename is None:
86+
base = os.path.splitext(f06_filename)[0]
87+
bdf_filename = base + '.bdf'
88+
assert os.path.exists(bdf_filename), print_bad_path(bdf_filename)
89+
90+
if aerobox_caero_filename is None:
91+
from pyNastran.bdf.mesh_utils.export_caero_mesh import export_caero_mesh
92+
aerobox_caero_filename = 'caero.bdf'
93+
export_caero_mesh(
94+
bdf_filename,
95+
caero_bdf_filename=aerobox_caero_filename,
96+
is_aerobox_model=True,
97+
pid_method='caero',
98+
write_panel_xyz=False)
99+
100+
assert os.path.exists(aerobox_caero_filename), print_bad_path(aerobox_caero_filename)
91101
dirname = os.path.dirname(f06_filename)
92102
loads_filename = os.path.join(dirname, 'loads.inc')
93103
base = os.path.splitext(f06_filename)[0]
94104
if f06_filename.lower().endswith(('.bdf', '.op2')):
95105
f06_filename = base + '.f06'
106+
96107
from pyNastran.f06.f06_to_pressure_loads import f06_to_pressure_loads
97108
nid_csv_filename = os.path.join(dirname, 'nid_pyNastran.csv')
98109
eid_csv_filename = os.path.join(dirname, 'eid_pyNastran.csv')
@@ -107,10 +118,22 @@ def cmd_line_plot_trim(argv=None, plot: bool=True, show: bool=True,
107118
return loads
108119

109120

121+
PLOT_TYPES = '[--eas|--tas|--density|--mach|--alt|--q|--index]'
122+
AXES = '[--xlim XLIM] [--ylimdamp DAMP] [--ylimfreq FREQ]'
123+
EXPORTS = '[--export_csv] [--export_zona] [--export_f06]'
124+
USAGE_145 = (
125+
'Usage:\n'
126+
' f06 plot_145 F06_FILENAME [--modes MODES] [--subcases SUB] '
127+
f'{PLOT_TYPES} [--kfreq] [--rootlocus] '
128+
'[--in_units IN] [--out_units OUT] [--rhoref] '
129+
f'[--vd_limit VD_LIMIT] [--damping_limit DAMPING_LIMIT] {AXES} '
130+
f'[--noline] [--nopoints] [--ncol NCOL] {EXPORTS} '
131+
'[--modal IVEL MODE] [--freq_tol FREQ_TOL] [--freq_tol_remove FREQ_TOL_REMOVE] [--mag_tol MAG_TOL]\n'
132+
)
133+
110134
def cmd_line_plot_flutter(argv=None, plot: bool=True, show: bool=True,
111135
log: Optional[SimpleLogger]=None) -> dict[int, FlutterResponse]:
112136
"""the interface to ``f06 plot_145`` on the command line"""
113-
import os
114137
from pyNastran.f06.parse_flutter import plot_flutter_f06, float_types
115138
if argv is None: # pragma: no cover
116139
argv = sys.argv
@@ -479,6 +502,10 @@ def split_int_colon(modes: str, nmax: int=1000,
479502
return modes
480503

481504

505+
USAGE_200 = (
506+
'Usage:\n'
507+
' f06 plot_200 F06_FILENAME\n'
508+
)
482509
def cmd_line_plot_optimization(argv=None, plot: bool=True, show: bool=True,
483510
log: Optional[SimpleLogger]=None):
484511
"""the interface to ``f06 plot_145`` on the command line"""

0 commit comments

Comments
 (0)