Skip to content

Commit

Permalink
op2:
Browse files Browse the repository at this point in the history
 - renaming element_forces to force to simplify results supressin
 - cleaning up distinction between eign and eigr for modes (so frequency is correct across results)
 -
  • Loading branch information
SteveDoyle2 committed Dec 1, 2024
1 parent 16714f5 commit 114b9a9
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pyNastran/converters/nastran/gui/nastran_io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ def get_results_to_exclude(nastran_settings: NastranSettings) -> set[str]:
#---------------------------------------------------------------------------
flag = 'force'
if not nastran_settings.force:
exclude_results.add('element_forces')
exclude_results.add(flag)

if not nastran_settings.spring_force:
names = {f'force.{name}_{flag}' for name in spring_types}
Expand Down
11 changes: 6 additions & 5 deletions pyNastran/f06/f06_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,25 @@ def _eigenvalue_header(obj, header, itime: int, ntimes: int, dt):
dt_line = ' %14s = %12.5E\n' % (name, dt)
#elif isinstance(dt, np.complex):
#dt_line = ' %14s = %12.5E %12.5Ej\n' % (name, dt.real, dt.imag)
else:
else: # praga: no cover
raise NotImplementedError(type(dt))
#dt_line = ' %14s = %12.5E %12.5Ej\n' % (name, dt.real, dt.imag)
header[1] = dt_line
codes = getattr(obj, name + 's')
if not len(codes) == ntimes:
msg = (f'{name}s in {obj.__class__.__name__} the wrong size; '
class_name = obj.__class__.__name__
msg = (f'{name}s in {class_name} the wrong size; '
f'ntimes={ntimes}; {name}s={codes}\n')
atts = object_attributes(obj)
msg += f'names={atts}\n'
msg += f'data_names={obj.data_names}\n'
raise IndexError(msg)

if hasattr(obj, 'eigr'):
if hasattr(obj, 'eign'):
try:
eigenvalue_real = obj.eigrs[itime]
eigenvalue_real = obj.eigns[itime]
except IndexError:
msg = 'eigrs[%s] not found; ntimes=%s; eigrs=%s' % (itime, ntimes, obj.eigrs)
msg = f'eigns[{itime}] not found; ntimes={ntimes}; eigns={obj.eigns}'
msg += 'names=%s' % object_attributes(obj)
raise IndexError(msg)
eigr_line = ' %14s = %12.6E\n' % ('EIGENVALUE', eigenvalue_real)
Expand Down
4 changes: 2 additions & 2 deletions pyNastran/f06/f06_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_all_results(self) -> list[str]:
all_results = [
'stress', 'strain', 'stressa',
'elastic_strain', 'plastic_strain', 'thermal_strain', 'creep_strain',
'element_forces', 'constraint_forces', 'thermal_load',
'force', 'constraint_forces', 'thermal_load',
] + self.get_table_types()
return all_results

Expand Down Expand Up @@ -251,7 +251,7 @@ def _add_results(self, results: str | list[str]) -> None:
elif result in ('spc_forces', 'mpc_forces', 'constraint_forces'):
self._results.add('constraint_forces')
elif 'force' in result.lower(): # could use more validation...
self._results.add('element_forces')
self._results.add('force')
# thermalLoad_VU_3D, thermalLoad_1D, conv_thermal_load, thermalLoad_2D_3D
self._results.add(result)
#assert 'displacements' not in self._results.saved, result
Expand Down
3 changes: 2 additions & 1 deletion pyNastran/op2/op2_interface/op2_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def analysis_fmt(self):
fmts = ('int32', 'int64')
else:
assert name in {'freq', 'dt', 'time',
'lsdvmn', 'lftsfq', 'loadFactor', 'load_step', 'loadID', 'thresh'}, name + self.object_stats() # 'eigr', 'eign'
'lsdvmn', 'lftsfq', 'load_factor',
'load_step', 'loadID', 'thresh'}, name + self.object_stats() # 'eigr', 'eign'
fmts = ('float32', 'float64')

elif self.analysis_code in [1, 7, 11]:
Expand Down
5 changes: 3 additions & 2 deletions pyNastran/op2/op2_interface/op2_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ def _unpack_data_parameter(self, datai: bytes, var_name: str,
raise IndexError(msg)
return value

def apply_data_code_value(self, name: str, value: int | float | str) -> None:
def apply_data_code_value(self, name: str,
value: int | float | str | list[str]) -> None:
self.data_code[name] = value

def setNullNonlinearFactor(self) -> None:
Expand Down Expand Up @@ -2478,7 +2479,7 @@ def parse_fba_subcase(title: str, subtitle: str, label: str,
comp_grid_1, comp_num_1 = label_num.split('/')
except ValueError:
log.error(f'label={label!r}')
log.error(f'label2={label2!r}')
#log.error(f'label2={label2!r}')
log.error(f'label_num={label_num!r}')
log.error(f'unit={unit!r}')
log.error(f'label_num={label_num!r}')
Expand Down
8 changes: 5 additions & 3 deletions pyNastran/op2/tables/oee_energy/oee_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RealStrainEnergyArray(BaseElement):
13 1.582968E+07 1.6124 1.055312E+02
14 6.576075E+07 6.6982 3.288037E+02
"""
def __init__(self, data_code, is_sort1, isubcase, dt):
def __init__(self, data_code, is_sort1: bool, isubcase: int, dt):
self.element_type = None
self.element_name = None
BaseElement.__init__(self, data_code, isubcase)
Expand Down Expand Up @@ -595,7 +595,8 @@ def write_f06(self, f06_file, header=None, page_stamp='PAGE %s',
break
return page_num - 1

def write_op2(self, op2_file, op2_ascii, itable: int, new_result, date,
def write_op2(self, op2_file, op2_ascii, itable: int,
new_result, date,
is_mag_phase: bool=False, endian: str='>'):
"""writes an OP2"""
import inspect
Expand Down Expand Up @@ -674,7 +675,8 @@ def write_op2(self, op2_file, op2_ascii, itable: int, new_result, date,
new_result = False
return itable

def _write_table_3(self, op2_file, op2_ascii, new_result, itable, itime): #itable=-3, itime=0):
def _write_table_3(self, op2_file, op2_ascii, new_result,
itable, itime): #itable=-3, itime=0):
import inspect
from struct import pack
frame = inspect.currentframe()
Expand Down
66 changes: 31 additions & 35 deletions pyNastran/op2/tables/oee_energy/onr.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_onr_prefix_postfix(self) -> tuple[str, str]:
MODCON OSTRMC Modal contributions
"""
op2 = self.op2
prefix = ''
#prefix = ''
postfix = ''
if op2.table_name in [b'ONRGY1', b'ONRGY2', b'ONRGY']:
prefix = 'strain_energy.'
Expand All @@ -127,7 +127,7 @@ def get_onr_prefix_postfix(self) -> tuple[str, str]:
op2.format_code = 1
op2.sort_bits[0] = 0 # real
prefix = 'RANCONS.'
else:
else: # pragma: no cover
raise NotImplementedError(op2.table_name)
op2.data_code['sort_bits'] = op2.sort_bits
op2.data_code['nonlinear_factor'] = op2.nonlinear_factor
Expand All @@ -140,10 +140,10 @@ def _read_onr1_3(self, data: bytes, ndata: int):
op2 = self.op2
op2._analysis_code_fmt = b'i'
op2.words = [
'aCode', 'tCode', 'eTotal', 'isubcase',
'aCode', 'tCode', 'etotal', 'isubcase',
'???', '???', 'element_name', 'load_set',
'format_code', 'num_wide', 'cvalres', 'setID',
'setID', 'eigenReal', 'eigenImag', 'rmssf',
'format_code', 'num_wide', 'cvalres', 'set_id',
'eign', 'eigr', 'eigi', 'rmssf',
'etotpos', 'etotneg', 'thresh', '???',
'???', '???', '???', '???',
'???', 'Title', 'subtitle', 'label']
Expand Down Expand Up @@ -173,13 +173,13 @@ def _read_onr1_3(self, data: bytes, ndata: int):
op2.set_id = op2.add_data_parameter(data, 'set_id', b'i', 13, False)

#: Natural eigenvalue - real part
op2.eigen_real = op2.add_data_parameter(data, 'eigen_real', b'f', 14, False)
#op2.eigen_real = op2.add_data_parameter(data, 'eigen_real', b'f', 14, False)

#: Natural eigenvalue - imaginary part
op2.eigen_imag = op2.add_data_parameter(data, 'eigen_imag', b'f', 15, False)
#op2.eigen_imag = op2.add_data_parameter(data, 'eigen_imag', b'f', 15, False)

#: Natural frequency
op2.freq = op2.add_data_parameter(data, 'freq', b'f', 16, False)
#op2.freq = op2.add_data_parameter(data, 'freq', b'f', 16, False)

#: RMS and CRMS scale factor - NX
op2.rmssf = op2.add_data_parameter(data, 'rmssf', b'f', 17)
Expand All @@ -203,15 +203,13 @@ def _read_onr1_3(self, data: bytes, ndata: int):
op2.setNullNonlinearFactor()
elif op2.analysis_code == 2: # real eigenvalues
op2.mode = op2.add_data_parameter(data, 'mode', b'i', 5) ## mode number
#op2.mode_cycle1 = op2.add_data_parameter(data, 'mode', b'i', 7)
#op2.mode_cycle2 = op2.add_data_parameter(data, 'mode', b'f', 7)
#print('mode = ', op2.mode)
#print('mode_cycle1 = ', op2.mode_cycle1)
#print('mode_cycle2 = ', op2.mode_cycle2)
op2.eign = op2.add_data_parameter(data, 'eign', b'f', 6, False)
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'f', 7, False) # radians
#self.show_data(data)
#op2.cycle = 0.
#self.reader_oug.update_mode_cycle('cycle')
op2.data_names = op2.apply_data_code_value('data_names', ['mode', 'freq'])
#print(f'mode={op2.mode} eign={op2.eign} mode_cycle={op2.mode_cycle}')
op2._op2_readers.reader_oug.update_mode_cycle('mode_cycle')
#print(f'{op2.isubcase}: mode={op2.mode} eign={op2.eign:g} mode_cycle={op2.mode_cycle:g}')
op2.data_names = op2.apply_data_code_value('data_names', ['mode', 'eign', 'mode_cycle'])
#print("mode(5)=%s eign(6)=%s mode_cycle(7)=%s" % (
#op2.mode, self.eign, op2.mode_cycle))
#elif op2.analysis_code == 3: # differential stiffness
Expand All @@ -232,14 +230,12 @@ def _read_onr1_3(self, data: bytes, ndata: int):
op2.data_names = op2.apply_data_code_value('data_names', ['mode'])
elif op2.analysis_code == 9: # complex eigenvalues
op2.mode = op2.add_data_parameter(data, 'mode', b'i', 5) ## mode number
op2.eigr = op2.eigen_real
op2.eigi = op2.eigen_imag
op2.data_code['eigr'] = op2.eigr
op2.data_code['eigi'] = op2.eigi
op2.eigr = op2.add_data_parameter(data, 'eigr', b'f', 14, False)
op2.eigi = op2.add_data_parameter(data, 'eigi', b'f', 15, False)
op2.data_names = op2.apply_data_code_value('data_names', ['mode', 'eigr', 'eigi'])
elif op2.analysis_code == 10: # nonlinear statics
self.loadFactor = op2.add_data_parameter(data, 'loadFactor', b'f', 5) ## load factor
op2.data_names = op2.apply_data_code_value('data_names', ['loadFactor'])
self.load_factor = op2.add_data_parameter(data, 'load_factor', b'f', 5) ## load factor
op2.data_names = op2.apply_data_code_value('data_names', ['load_factor'])
#elif op2.analysis_code == 11: # old geometric nonlinear statics
#op2.data_names = op2.apply_data_code_value('data_names',['lsdvmn'])
elif op2.analysis_code == 12: # contran ? (may appear as aCode=6) --> straight from DMAP...grrr...
Expand All @@ -257,7 +253,7 @@ def _read_onr1_3(self, data: bytes, ndata: int):
op2._read_title(data)
op2._write_debug_bits()

def _onr_element_name(self, data: bytes) -> str:
def _onr_element_name(self, data: bytes) -> None:
op2 = self.op2
#field_num = 6
#datai = data[4 * (field_num - 1) : 4 * (field_num + 1)]
Expand Down Expand Up @@ -293,12 +289,12 @@ def _read_onr2_3(self, data: bytes, ndata: int):
op2.nonlinear_factor = np.nan
op2.is_table_1 = False
op2.is_table_2 = True
unused_three = op2.parse_approach_code(data)
op2.parse_approach_code(data)
op2.words = [
'aCode', 'tCode', 'eTotal', 'isubcase',
'aCode', 'tCode', 'etotal', 'isubcase',
'???', '???', 'element_name', 'load_set',
'format_code', 'num_wide', 'cvalres', 'setID',
'setID', 'eigenReal', 'eigenImag', 'rmssf',
'format_code', 'num_wide', 'cvalres', 'set_id',
'eign', 'eigr', 'eigi', 'rmssf',
'etotpos', 'etotneg', 'thresh', '???',
'???', '???', '???', '???',
'???', 'Title', 'subtitle', 'label']
Expand Down Expand Up @@ -357,11 +353,10 @@ def _read_onr2_3(self, data: bytes, ndata: int):
op2.mode = op2.add_data_parameter(data, 'mode', b'i', 5)
op2._analysis_code_fmt = b'i'
## real eigenvalue
op2.eigr = op2.add_data_parameter(data, 'eigr', b'f', 6, False)
## mode or cycle .. todo:: confused on the type - F1???
op2.eigr = op2.add_data_parameter(data, 'eign', b'f', 6, False)
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'f', 7, False)
op2.data_names = op2.apply_data_code_value('data_names',
['node_id', 'eigr', 'mode_cycle'])
['node_id', 'eign', 'mode_cycle'])
op2.apply_data_code_value('analysis_method', 'mode')
#elif op2.analysis_code == 3: # differential stiffness
#op2.lsdvmn = self.get_values(data, b'i', 5) ## load set number
Expand Down Expand Up @@ -623,7 +618,7 @@ def _read_element_strain_energy(self, data: bytes, ndata: int) -> int:

elif op2.format_code == 1 and op2.num_wide == 6: ## TODO: figure this out...
ntotal = 24
nnodes = ndata // ntotal
nelements = ndata // ntotal
auto_return, is_vectorized = op2._create_oes_object4(
nelements, result_name, slot, RealStrainEnergyArray)

Expand Down Expand Up @@ -656,16 +651,16 @@ def _read_element_strain_energy(self, data: bytes, ndata: int) -> int:
obj.ielement = ielement2
else:
struct1 = Struct(op2._endian + b'i8s3f')
for unused_i in range(nnodes):
edata = data[n:n+24]
for unused_i in range(nelements): # TODO: is this nnodes?
edata = data[n:n+ntotal]
out = struct1.unpack(edata)
(word, energy, percent, density) = out # TODO: this has to be wrong...
word = word.strip()
#print "eType=%s" % (eType)
#print "%s" %(self.get_element_type(self.element_type)), data_in
#eid = op2.obj.add_new_eid_sort1(out)
if op2.is_debug_file:
op2.binary_debug.write(' eid=%s; %s\n' % (eid, str(out)))
op2.binary_debug.write(' word=%s; %s\n' % (word, str(out)))
obj.add_sort1(dt, word, energy, percent, density)
n += ntotal
elif op2.format_code in [2, 3] and op2.num_wide == 4:
Expand Down Expand Up @@ -782,7 +777,7 @@ def real_strain_energy_4(op2: OP2,
assert eid_device == 0, eid_device
if sort_method == 1:
eid = eid_device // 10
else:
else: # pragma: no cover
raise NotImplementedError(sort_method)
#eid = op2.nonlinear_factor
#dt = eid_device
Expand Down Expand Up @@ -822,6 +817,7 @@ def complex_strain_energy_4(op2: OP2, data: bytes, sort_method: int,
word = word.strip()
if op2.is_debug_file:
op2.binary_debug.write(' eid/word=%r; %s\n' % (word, str(out)))
#dt, eid, energyr, energyi, percenti, densityi
obj.add_sort1(dt, word, energy, percent, density)
n += ntotal
return n
6 changes: 3 additions & 3 deletions pyNastran/op2/tables/oef_forces/oef.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def _read_oef2_4(self, data: bytes, ndata: int):
def _read_oef1_thermal(self, data: bytes, ndata: int):
"""Table 4 parser for OEF1 thermal table"""
op2 = self.op2
if op2._results.is_not_saved('element_forces'):
if op2._results.is_not_saved('force'):
return ndata
prefix, postfix = self.get_oef_prefix_postfix()

Expand Down Expand Up @@ -934,7 +934,7 @@ def new_func(self, data):
def _read_oef1_loads_nasa95(self, data: bytes, ndata: int):
"""Reads the OEF1 table for NASA 95 Nastran"""
op2 = self.op2
if op2._results.is_not_saved('element_forces'):
if op2._results.is_not_saved('forces'):
return ndata

prefix, postfix = self.get_oef_prefix_postfix()
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def _read_oef1_loads(self, data: bytes, ndata: int):
"""Reads the OEF1 table; stores the element forces/heat flux."""
op2 = self.op2
#self._apply_oef_ato_crm_psd_rms_no('') # TODO: just testing
if op2._results.is_not_saved('element_forces'):
if op2._results.is_not_saved('forces'):
return ndata

prefix, postfix = self.get_oef_prefix_postfix()
Expand Down
1 change: 1 addition & 0 deletions pyNastran/op2/tables/oes_stressStrain/oes.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def _read_oes2_3(self, data, unused_ndata):
op2._analysis_code_fmt = b'i'
op2.eign = op2.add_data_parameter(data, 'eign', b'f', 6, False)
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'i', 7, False) # mode or cycle .. todo:: confused on the type - F1???
op2._op2_readers.reader_oug.update_mode_cycle('cycle')
op2.data_names = op2.apply_data_code_value('data_names', ['element_id', 'eign', 'mode_cycle'])
elif op2.analysis_code == 5: # frequency
op2._analysis_code_fmt = b'f'
Expand Down
5 changes: 3 additions & 2 deletions pyNastran/op2/tables/opg_appliedLoads/opg.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ def _read_opg2_3(self, data: bytes, ndata: int):
op2.mode = op2.add_data_parameter(data, 'mode', b'i', 5)
op2._analysis_code_fmt = b'i'
## real eigenvalue
op2.eigr = op2.add_data_parameter(data, 'eigr', b'f', 6, False)
op2.eigr = op2.add_data_parameter(data, 'eign', b'f', 6, False)
## mode or cycle .. todo:: confused on the type - F1???
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'f', 7, False)
op2._op2_readers.reader_oug.update_mode_cycle('mode_cycle')
op2.data_names = op2.apply_data_code_value('data_names',
['node_id', 'eigr', 'mode_cycle'])
['node_id', 'eign', 'mode_cycle'])
op2.apply_data_code_value('analysis_method', 'mode')
#elif op2.analysis_code == 3: # differential stiffness
#op2.lsdvmn = self.get_values(data, b'i', 5) ## load set number
Expand Down
1 change: 1 addition & 0 deletions pyNastran/op2/tables/opr.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def _read_opr2_3(self, data: bytes, ndata: int) -> None:
# mode or cycle .. todo:: confused on the type - F1???
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'i', 7, False)
#op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'f', 7, False)
self.update_mode_cycle('mode_cycle')
op2.data_names = op2.apply_data_code_value('data_names', ['node_id', 'eigr', 'mode_cycle'])
op2.apply_data_code_value('analysis_method', 'mode')
#elif op2.analysis_code == 3: # differential stiffness
Expand Down
5 changes: 3 additions & 2 deletions pyNastran/op2/tables/oqg_constraintForces/oqg.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,12 @@ def _read_oqg2_3(self, data: bytes, ndata: int) -> None:
op2.mode = op2.add_data_parameter(data, 'mode', b'i', 5)
op2._analysis_code_fmt = b'i'
## real eigenvalue
op2.eigr = op2.add_data_parameter(data, 'eigr', b'f', 6, False)
op2.eign = op2.add_data_parameter(data, 'eign', b'f', 6, False)
## mode or cycle .. todo:: confused on the type - F1???
op2.mode_cycle = op2.add_data_parameter(data, 'mode_cycle', b'f', 7, False)
op2._op2_readers.reader_oug.update_mode_cycle('mode_cycle')
op2.data_names = op2.apply_data_code_value('data_names',
['node_id', 'eigr', 'mode_cycle'])
['node_id', 'eign', 'mode_cycle'])
op2.apply_data_code_value('analysis_method', 'mode')
#elif op2.analysis_code == 3: # differential stiffness
#op2.lsdvmn = self.get_values(data, b'i', 5) ## load set number
Expand Down
Loading

0 comments on commit 114b9a9

Please sign in to comment.