Skip to content

Commit 32be618

Browse files
committed
write_bdf now has a sort_cards flag to speed things up/make diffs easier
1 parent 4d69d2f commit 32be618

File tree

7 files changed

+284
-170
lines changed

7 files changed

+284
-170
lines changed

pyNastran/bdf/bdf_interface/write_mesh.py

Lines changed: 210 additions & 163 deletions
Large diffs are not rendered by default.

pyNastran/bdf/cards/elements/mass.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import numpy as np
1919

2020
from pyNastran.utils.numpy_utils import integer_types
21-
from pyNastran.bdf.field_writer_8 import set_blank_if_default, print_card_8
21+
from pyNastran.bdf.field_writer_8 import (
22+
set_blank_if_default, print_card_8, print_float_8,
23+
print_int_default_8, print_float_default_8)
2224
from pyNastran.bdf.cards.base_card import Element
2325
from pyNastran.bdf.cards.nodes import GRID
2426
from pyNastran.bdf.bdf_interface.internal_get import coord_id
@@ -1684,9 +1686,34 @@ def repr_fields(self) -> list:
16841686
return list_fields
16851687

16861688
def write_card(self, size: int=8, is_double: bool=False) -> str:
1689+
# if 0: # pragma: no cover
1690+
# is_inertia = max(self.I) != 0 or min(self.I) != 0.0
1691+
# if size == 8:
1692+
# x, y, z = self.X
1693+
# msg = 'CONM2 %8d%8d%s%s%s%s%s\n' % (
1694+
# self.eid, self.Nid(),
1695+
# print_int_default_8(self.Cid(), 0),
1696+
# print_float_8(self.mass),
1697+
# print_float_8(x),
1698+
# print_float_8(y),
1699+
# print_float_8(z))
1700+
# if is_inertia:
1701+
# ixx, ixy, iyy, ixz, iyz, izz = self.I
1702+
# msg += ' %s%s%s%s%s%s\n' % (
1703+
# print_float_default_8(ixx, 0.0),
1704+
# print_float_default_8(ixy, 0.0),
1705+
# print_float_default_8(iyy, 0.0),
1706+
# print_float_default_8(ixz, 0.0),
1707+
# print_float_default_8(iyz, 0.0),
1708+
# print_float_default_8(izz, 0.0),
1709+
# )
1710+
# print(msg.rstrip())
1711+
# return self.comment + msg
1712+
1713+
# card = self.raw_fields()
16871714
card = self.repr_fields()
16881715
if size == 8:
1689-
return self.comment + print_card_8(card)
1716+
return self.comment + print_card_8(card)
16901717
return self.comment + print_card_16(card)
16911718

16921719
def write_card_16(self, is_double=False):

pyNastran/bdf/field_writer_8.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ def print_scientific_8(value: float) -> str:
8888
return field
8989

9090

91+
def print_int_default_8(value: int, default: int) -> str:
92+
"""combine set_blank_if_default and print_field"""
93+
if value == default:
94+
return ' '
95+
return '%8d' % value
96+
97+
98+
def print_float_default_8(value: float, default: float) -> str:
99+
"""combine set_blank_if_default and print_float_8"""
100+
if value == default:
101+
return ' '
102+
return print_float_8(value)
103+
104+
91105
def print_float_8(value: float) -> str:
92106
"""
93107
Prints a float in nastran 8-character width syntax using the

pyNastran/bdf/mesh_utils/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,10 @@ def _add_parser_arguments(parser, args: list[str]) -> None:
16811681
parser.add_argument('--punch', action='store_true', help='assume a punch file')
16821682
elif arg == '--lax':
16831683
parser.add_argument('--lax', action='store_true', help='lax card parser')
1684+
elif arg == '--nosort':
1685+
parser.add_argument(
1686+
'--nosort', action='store_false',
1687+
help='Dont sort the nodes, elements, ... (default=False -> sort)')
16841688
elif arg == '--allow_dup':
16851689
parser.add_argument('--allow_dup', help='allow duplicate cards -> "GRID,CONM2"')
16861690
else:

pyNastran/bdf/test/bdf_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def run(regenerate: bool=True, run_nastran: bool=False, debug: bool=False,
4141
run_skin_solids: bool=True,
4242
run_export_caero: bool=True,
4343
allow_similar_eid: bool=True,
44+
sort_cards: bool=True,
4445
xref: bool=True, is_lax_parser: bool=False,
4546
crash_cards=None):
4647
"""Runs the full BDF test suite"""
@@ -120,6 +121,7 @@ def run(regenerate: bool=True, run_nastran: bool=False, debug: bool=False,
120121
run_export_caero=run_export_caero,
121122
run_skin_solids=run_skin_solids,
122123
allow_similar_eid=allow_similar_eid,
124+
sort_cards=sort_cards,
123125
encoding='latin1', crash_cards=crash_cards,
124126
dev=True, run_pickle=True)
125127
ntotal = len(files)
@@ -141,7 +143,7 @@ def main():
141143
#is_release = False
142144
skips = '[--skip_loads] [--skip_mass] [--skip_mcid] [--skip_aero] [--skip_skin] [--no_similar_eid]'
143145
msg = (
144-
f'Usage: bdf_test [-r] [-n] [-s S...] [-e E] [-x] [-c C] [--safe] [--lax] {skips}\n'
146+
f'Usage: bdf_test [-r] [-n] [-s S...] [-e E] [-x] [-c C] [--safe] [--lax] [--nosort] {skips}\n'
145147
' bdf_test -h | --help\n'
146148
' bdf_test -v | --version\n'
147149
'\n'
@@ -163,6 +165,7 @@ def main():
163165
' --skip_skin Disables solid skinning\n'
164166
' --no_similar_eid No duplicate eids among elements, rigids, and masses\n'
165167
' --lax Use the lax card parser (default=False)\n'
168+
' --nosort Dont sort the nodes, elements, ... (default=False -> nosort)\n'
166169
)
167170
if len(sys.argv) == 0:
168171
sys.exit(msg)
@@ -178,6 +181,7 @@ def main():
178181
run_export_caero = not data['--skip_aero']
179182
allow_similar_eid = not data['--no_similar_eid']
180183
xref = not data['--xref']
184+
sort_cards = not data['--nosort']
181185
is_lax_parser = data['--lax']
182186

183187
crash_cards = []
@@ -190,6 +194,7 @@ def main():
190194
run_export_caero=run_export_caero,
191195
run_skin_solids=run_skin_solids,
192196
is_lax_parser=is_lax_parser,
197+
sort_cards=sort_cards,
193198
xref=xref, crash_cards=crash_cards)
194199

195200

pyNastran/bdf/test/test_bdf.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def run_lots_of_files(filenames: list[str], folder: str='',
9090
run_export_caero: bool=True,
9191
run_skin_solids: bool=True,
9292
allow_similar_eid: bool=True,
93+
sort_cards: bool=True,
9394
dev: bool=True,
9495
crash_cards: Optional[list[str]]=None,
9596
run_pickle: bool=True, quiet: bool=False) -> list[str]:
@@ -214,6 +215,7 @@ def run_lots_of_files(filenames: list[str], folder: str='',
214215
run_export_caero=run_export_caero,
215216
run_skin_solids=run_skin_solids,
216217
allow_similar_eid=allow_similar_eid,
218+
sort_cards=sort_cards,
217219

218220
dev=dev,
219221
crash_cards=crash_cards,
@@ -291,6 +293,7 @@ def run_bdf(folder: str, bdf_filename: PathLike,
291293
is_lax_parser: bool=False,
292294
allow_duplicates: bool=False,
293295
allow_similar_eid: bool=True,
296+
sort_cards: bool=True,
294297
stop: bool=False, nastran: str='', post: int=-1,
295298
dynamic_vars=None,
296299
quiet: bool=False, dumplines: bool=False, dictsort: bool=False,
@@ -400,6 +403,7 @@ def run_bdf(folder: str, bdf_filename: PathLike,
400403
sum_load=sum_load, size=size, is_double=is_double,
401404
is_lax_parser=is_lax_parser,
402405
allow_similar_eid=allow_similar_eid,
406+
sort_cards=sort_cards,
403407
allow_tabs=allow_tabs,
404408
allow_duplicates=allow_duplicates,
405409
stop=stop, nastran=nastran, post=post, hdf5=hdf5,
@@ -444,6 +448,7 @@ def run_and_compare_fems(
444448
allow_tabs: bool=True,
445449
allow_duplicates: bool=False,
446450
allow_similar_eid: bool=True,
451+
sort_cards: bool=True,
447452
stop: bool=False,
448453
nastran: str='',
449454
post: int=-1,
@@ -520,6 +525,7 @@ def run_and_compare_fems(
520525
save_file_structure=save_file_structure,
521526
hdf5=hdf5,
522527
encoding=encoding, crash_cards=crash_cards, safe_xref=safe_xref,
528+
sort_cards=sort_cards,
523529
limit_mesh_opt=limit_mesh_opt,
524530
run_pickle=run_pickle, stop=stop, name=name)
525531

@@ -700,6 +706,7 @@ def run_fem1(fem1: BDF, bdf_filename: str, out_model: str, mesh_form: str,
700706
encoding: Optional[str]=None,
701707
crash_cards: Optional[list[str]]=None,
702708
limit_mesh_opt: bool=False,
709+
sort_cards: bool=True,
703710
safe_xref: bool=True, run_pickle: bool=False, stop: bool=False,
704711
name: str='') -> BDF:
705712
"""
@@ -832,12 +839,17 @@ def run_fem1(fem1: BDF, bdf_filename: str, out_model: str, mesh_form: str,
832839
hdf5_filename = f'{out_model}{name}.h5'
833840
_test_hdf5(fem1, hdf5_filename)
834841

842+
args = {
843+
'size': size,
844+
'is_double': is_double,
845+
'sort_cards': sort_cards,
846+
}
835847
if mesh_form is None:
836848
pass
837849
elif mesh_form == 'combined':
838-
fem1.write_bdf(out_model, interspersed=True, size=size, is_double=is_double)
850+
fem1.write_bdf(out_model, interspersed=True, **args)
839851
elif mesh_form == 'separate':
840-
fem1.write_bdf(out_model, interspersed=False, size=size, is_double=is_double)
852+
fem1.write_bdf(out_model, interspersed=False, **args)
841853
else:
842854
msg = "mesh_form=%r; allowed_mesh_forms=['combined','separate']" % mesh_form
843855
raise NotImplementedError(msg)
@@ -2270,6 +2282,10 @@ def test_bdf_argparse(argv=None):
22702282

22712283
parent_parser.add_argument('--lax', action='store_true',
22722284
help='use the lax card parser (default=False)')
2285+
parent_parser.add_argument(
2286+
'--nosort', action='store_false',
2287+
help='Dont sort the nodes, elements, ... (default=False -> sort)')
2288+
22732289
parent_parser.add_argument('--duplicate', action='store_true',
22742290
help='overwrite duplicates; takes the later card (default=False)')
22752291
parent_parser.add_argument('-q', '--quiet', action='store_true',
@@ -2375,7 +2391,7 @@ def get_test_bdf_usage_args_examples(encoding):
23752391
options = (
23762392
'\n [options] = [-e E] [--encoding ENCODE] [-q] [--dumplines] [--dictsort]\n'
23772393
f' [--ignore I] [--crash C] [--pickle] [--profile] [--hdf5] [{formats}] [--filter]\n'
2378-
' [--skip_loads] [--skip_mass] [--lax] [--duplicate]\n'
2394+
' [--skip_loads] [--skip_mass] [--lax] [--nosort] [--duplicate]\n'
23792395
)
23802396
usage = (
23812397
"Usage:\n"
@@ -2406,6 +2422,7 @@ def get_test_bdf_usage_args_examples(encoding):
24062422
' every element/property to test them. May fails if a \n'
24072423
' card is fully not supported (default=False)\n'
24082424
' --lax dont be strict on float parsing\n'
2425+
' --nosort Dont sort the nodes, elements, ... (default=False -> nosort)\n'
24092426
' --duplicate overwrite duplicate GRIDs\n'
24102427
' -l, --large writes the BDF in large field, single precision format (default=False)\n'
24112428
' -d, --double writes the BDF in large field, double precision format (default=False)\n'

pyNastran/op2/writer/geom2_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def write_geom2(op2_file: BinaryIO, op2_ascii,
123123
#continue
124124

125125
cards_written[name] = nelements
126-
log.warning(f'GEOM2: {name}')
126+
# log.warning(f'GEOM2: {name}')
127127
if name in GEOM2_MAP:
128128
func = GEOM2_MAP[name]
129129
assert name not in geom2_key_mapper, name

0 commit comments

Comments
 (0)