From 8709a850c6866db30a38371ec3dfa1e357c0a635 Mon Sep 17 00:00:00 2001 From: NArnold Date: Wed, 16 Aug 2023 10:49:26 +0200 Subject: [PATCH 1/9] Corrected dataset 2412 for recognizing rods (3-line elements) --- pyuff/datasets/dataset_2412.py | 49 +++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index ea46379..014c3ec 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -38,10 +38,38 @@ def _extract2412(block_data): try: split_data = block_data.splitlines() split_data = [a.split() for a in split_data][2:] - # Extract Record 1 - rec1 = np.array(split_data[::2], dtype=int) + # Extract Records + rec1 = np.array([]) + rec2 = [] + dataset = [] + i = 0 + while i < len(split_data): + dict_tmp = dict() + line = split_data[i] + dict_tmp['element_num'] = line[0] + dict_tmp['f_descriptor'] = line[1] + dict_tmp['phys_table'] = line[2] + dict_tmp['mat_table'] = line[3] + dict_tmp['color'] = line[4] + dict_tmp['num_nodes'] = line[5] + if dict_tmp['f_descriptor'] == 11: + # element is a rod and covers 3 lines + dict_tmp['beam_orientation'] = split_data[i+1][0] + dict_tmp['beam_foreend_cross'] = split_data[i + 1][1] + dict_tmp['beam_aftend_cross'] = split_data[i + 1][2] + dict_tmp['nodes_nums'] = split_data[i + 2] + i += 3 + else: + # element is no rod and covers 2 lines + dict_tmp['nodes_nums'] = split_data[i + 1] + i += 2 + dataset.append(dict_tmp) + return dataset + + + #rec1 = np.array(split_data[::2], dtype=int) # Extract Record 2 - rec2 = split_data[1::2] + #rec2 = split_data[1::2] # Look for the different types of elements stored in the dataset elts_types = list(set(rec1[:,5])) for elt_type in elts_types: @@ -67,6 +95,9 @@ def prepare_2412( color=None, num_nodes=None, nodes_nums=None, + beam_orientation=None, + beam_foreend_cross=None, + beam_aftend_cross=None, return_full_dict=False): """Name: Elements @@ -78,7 +109,10 @@ def prepare_2412( :param mat_table: R1 F4, Material property table number :param color: R1 F5, Color, optional :param num_nodes: R1 F6, Number of nodes on element - :param nodes_nums: R2 F1, Node labels defining element + :param nodes_nums: R2 F1 (R3 FOR RODS), Node labels defining element + :param beam_orientation: R2 F1 FOR RODS ONLY, beam orientation node number + :param beam_foreend_cross: R2 F2 FOR RODS ONLY, beam fore-end cross section number + :param beam_aftend_cross: R2 F3 FOR RODS ONLY, beam aft-end cross section number :param return_full_dict: If True full dict with all keys is returned, else only specified arguments are included **Test prepare_2412** @@ -113,6 +147,13 @@ def prepare_2412( raise TypeError('num_nodes must be integer') if np.array(nodes_nums).dtype != int and nodes_nums != None: raise TypeError('nodes_nums must be integer') + if np.array(beam_orientation).dtype != int and beam_orientation != None: + raise TypeError('beam_orientation must be integer') + if np.array(beam_foreend_cross).dtype != int and beam_foreend_cross != None: + raise TypeError('beam_foreend_cross must be integer') + if np.array(beam_aftend_cross).dtype != int and beam_aftend_cross != None: + raise TypeError('beam_aftend_cross must be integer') + dataset={ 'type': 2412, From a1fc92e46a087532eaaf8ca393b8e706bfed072f Mon Sep 17 00:00:00 2001 From: NArnold Date: Wed, 16 Aug 2023 13:37:35 +0200 Subject: [PATCH 2/9] Correct set 2412 reading and datastruct --- pyuff/datasets/dataset_2412.py | 48 ++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index 014c3ec..d61cdc2 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -44,26 +44,52 @@ def _extract2412(block_data): dataset = [] i = 0 while i < len(split_data): + print(f"Starting loop with i={i}") dict_tmp = dict() line = split_data[i] - dict_tmp['element_num'] = line[0] - dict_tmp['f_descriptor'] = line[1] - dict_tmp['phys_table'] = line[2] - dict_tmp['mat_table'] = line[3] - dict_tmp['color'] = line[4] - dict_tmp['num_nodes'] = line[5] + print(f"line={line}") + dict_tmp['element_num'] = int(line[0]) + dict_tmp['f_descriptor'] = int(line[1]) + dict_tmp['phys_table'] = int(line[2]) + dict_tmp['mat_table'] = int(line[3]) + dict_tmp['color'] = int(line[4]) + dict_tmp['num_nodes'] = int(line[5]) if dict_tmp['f_descriptor'] == 11: # element is a rod and covers 3 lines - dict_tmp['beam_orientation'] = split_data[i+1][0] - dict_tmp['beam_foreend_cross'] = split_data[i + 1][1] - dict_tmp['beam_aftend_cross'] = split_data[i + 1][2] - dict_tmp['nodes_nums'] = split_data[i + 2] + dict_tmp['beam_orientation'] = int(split_data[i+1][0]) + dict_tmp['beam_foreend_cross'] = int(split_data[i + 1][1]) + dict_tmp['beam_aftend_cross'] = int(split_data[i + 1][2]) + dict_tmp['nodes_nums'] = [int(e) for e in split_data[i+2]] i += 3 else: # element is no rod and covers 2 lines - dict_tmp['nodes_nums'] = split_data[i + 1] + dict_tmp['nodes_nums'] = [int(e) for e in split_data[i+1]] i += 2 + desc = dict_tmp['f_descriptor'] + if not desc in dset: + dset[desc] = [] + dset[desc].append(dict_tmp) dataset.append(dict_tmp) + return dset + #test = [e['f_descriptor'] for e in dataset] + #test = set(test) + #test = list(test) + desc_list = [e['f_descriptor'] for e in dataset] + elts_types = list(set(desc_list)) + for elt_type in elts_types: + ind = list(np.where(np.array(desc_list) == elt_type)[0]) + dict_tmp = dict() + #test = [e for dataset if ] #dataset[ind] + test = dataset[ind] + dict_tmp['element_nums'] = [e['element_num'] for e in dataset[ind]]#]dataset[ind]['element_num'].copy() + dict_tmp['fe_descriptor'] = dataset[ind, 'fe_descriptor'].copy() + dict_tmp['phys_table'] = dataset[ind, 'phys_table'].copy() + dict_tmp['mat_table'] = dataset[ind, 'mat_table'].copy() + dict_tmp['color'] = dataset[ind, 'color'].copy() + #dict_tmp['nodes_nums'] = np.array([rec2[i] for i in ind], dtype=int).copy().reshape((-1, elt_type)) + dict_tmp['nodes_nums'] = dataset[ind, 'color'].copy() + #dset[elt_type_dict[str(elt_type)]] = dict_tmp + dset[elt_type] = dict_tmp return dataset From 57a71b1cce55746f5347d8ae188a1b468678d923 Mon Sep 17 00:00:00 2001 From: NArnold Date: Thu, 17 Aug 2023 08:10:38 +0200 Subject: [PATCH 3/9] Fix dataset 2412 write --- pyuff/datasets/dataset_2412.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index d61cdc2..3a89510 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -10,17 +10,26 @@ def _write2412(fh, dset): if elt_type == "type": pass else: - for i in range(len(dset[elt_type]['element_nums'])): + #for i in range(len(dset[elt_type]['element_nums'])): + for elem in dset['all']: fh.write('%10i%10i%10i%10i%10i%10i\n' % ( - dset[elt_type]['element_nums'][i], - dset[elt_type]['fe_descriptor'][i], - dset[elt_type]['phys_table'][i], - dset[elt_type]['mat_table'][i], - dset[elt_type]['color'][i], - elt_type_dict[elt_type], + elem['element_nums'], + elem['fe_descriptor'], + elem['phys_table'], + elem['mat_table'], + elem['color'], + elem[elt_type], )) - for ii in range(elt_type_dict[elt_type]): - fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) + if elem['f_descriptor'] == 11: + # rods have to be written in 3 lines + fh.write('%10i%10i%10i\n' % ( + elem['beam_orientation'], + elem['beam_foreend_cross'], + elem['beam_aftend_cross'] + )) + for ii in elem['nodes_nums']: + #fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) + fh.write(' '.join(elem)) fh.write('\n') fh.write('%6i\n' % -1) @@ -30,7 +39,7 @@ def _write2412(fh, dset): def _extract2412(block_data): """Extract element data - data-set 2412.""" - dset = {'type': 2412} + dset = {'type': 2412, 'all': None} # Define dictionary of possible elements types # Only 2D non-quadratic elements are supported elt_type_dict = {'3': 'triangle', '4': 'quad'} @@ -44,10 +53,8 @@ def _extract2412(block_data): dataset = [] i = 0 while i < len(split_data): - print(f"Starting loop with i={i}") dict_tmp = dict() line = split_data[i] - print(f"line={line}") dict_tmp['element_num'] = int(line[0]) dict_tmp['f_descriptor'] = int(line[1]) dict_tmp['phys_table'] = int(line[2]) @@ -70,6 +77,7 @@ def _extract2412(block_data): dset[desc] = [] dset[desc].append(dict_tmp) dataset.append(dict_tmp) + dset['all'] = dataset return dset #test = [e['f_descriptor'] for e in dataset] #test = set(test) From 24fdcac2e46e1fe84dbfe126ccd94388a11ad92f Mon Sep 17 00:00:00 2001 From: NArnold Date: Thu, 17 Aug 2023 10:25:01 +0200 Subject: [PATCH 4/9] Daily --- pyuff/datasets/dataset_2412.py | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index 3a89510..05178de 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -6,31 +6,31 @@ def _write2412(fh, dset): try: elt_type_dict = {'triangle': 3, 'quad': 4} fh.write('%6i\n%6i%74s\n' % (-1, 2412, ' ')) - for elt_type in dset: - if elt_type == "type": - pass - else: + #for elt_type in dset: + # if elt_type == "type": + # pass + # else: #for i in range(len(dset[elt_type]['element_nums'])): - for elem in dset['all']: - fh.write('%10i%10i%10i%10i%10i%10i\n' % ( - elem['element_nums'], - elem['fe_descriptor'], - elem['phys_table'], - elem['mat_table'], - elem['color'], - elem[elt_type], - )) - if elem['f_descriptor'] == 11: - # rods have to be written in 3 lines - fh.write('%10i%10i%10i\n' % ( - elem['beam_orientation'], - elem['beam_foreend_cross'], - elem['beam_aftend_cross'] - )) - for ii in elem['nodes_nums']: - #fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) - fh.write(' '.join(elem)) - fh.write('\n') + for elem in dset['all']: + fh.write('%10i%10i%10i%10i%10i%10i\n' % ( + elem['element_num'], + elem['f_descriptor'], + elem['phys_table'], + elem['mat_table'], + elem['color'], + elem['num_nodes'], + )) + if elem['f_descriptor'] == 11: + # rods have to be written in 3 lines + fh.write('%10i%10i%10i\n' % ( + elem['beam_orientation'], + elem['beam_foreend_cross'], + elem['beam_aftend_cross'] + )) + for ii in elem['nodes_nums']: + #fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) + fh.write(' '.join(elem)) + fh.write('\n') fh.write('%6i\n' % -1) except: From f282d441056f888fc01f4dba35b40be4be312ad6 Mon Sep 17 00:00:00 2001 From: NArnold Date: Thu, 17 Aug 2023 11:19:29 +0200 Subject: [PATCH 5/9] Fix element notation inside dataset 2412 write function --- pyuff/datasets/dataset_2412.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index 05178de..8731e01 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -29,7 +29,8 @@ def _write2412(fh, dset): )) for ii in elem['nodes_nums']: #fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) - fh.write(' '.join(elem)) + fh.write('%10i' % ii) + #fh.write(' '.join([str(e) for e in elem['nodes_nums']])) fh.write('\n') fh.write('%6i\n' % -1) From 86040b0d3d33622ddb0c7e68ae0ae3dd9f50b55e Mon Sep 17 00:00:00 2001 From: NArnold Date: Tue, 5 Sep 2023 08:43:18 +0200 Subject: [PATCH 6/9] fix dataset 2412 support for rods --- pyuff/datasets/dataset_2412.py | 50 ++++------------------------------ 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index 8731e01..818ffe2 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -6,11 +6,7 @@ def _write2412(fh, dset): try: elt_type_dict = {'triangle': 3, 'quad': 4} fh.write('%6i\n%6i%74s\n' % (-1, 2412, ' ')) - #for elt_type in dset: - # if elt_type == "type": - # pass - # else: - #for i in range(len(dset[elt_type]['element_nums'])): + for elem in dset['all']: fh.write('%10i%10i%10i%10i%10i%10i\n' % ( elem['element_num'], @@ -28,9 +24,7 @@ def _write2412(fh, dset): elem['beam_aftend_cross'] )) for ii in elem['nodes_nums']: - #fh.write('%10i' % dset[elt_type]['nodes_nums'][i][ii]) fh.write('%10i' % ii) - #fh.write(' '.join([str(e) for e in elem['nodes_nums']])) fh.write('\n') fh.write('%6i\n' % -1) @@ -42,7 +36,6 @@ def _extract2412(block_data): """Extract element data - data-set 2412.""" dset = {'type': 2412, 'all': None} # Define dictionary of possible elements types - # Only 2D non-quadratic elements are supported elt_type_dict = {'3': 'triangle', '4': 'quad'} # Read data try: @@ -80,43 +73,7 @@ def _extract2412(block_data): dataset.append(dict_tmp) dset['all'] = dataset return dset - #test = [e['f_descriptor'] for e in dataset] - #test = set(test) - #test = list(test) - desc_list = [e['f_descriptor'] for e in dataset] - elts_types = list(set(desc_list)) - for elt_type in elts_types: - ind = list(np.where(np.array(desc_list) == elt_type)[0]) - dict_tmp = dict() - #test = [e for dataset if ] #dataset[ind] - test = dataset[ind] - dict_tmp['element_nums'] = [e['element_num'] for e in dataset[ind]]#]dataset[ind]['element_num'].copy() - dict_tmp['fe_descriptor'] = dataset[ind, 'fe_descriptor'].copy() - dict_tmp['phys_table'] = dataset[ind, 'phys_table'].copy() - dict_tmp['mat_table'] = dataset[ind, 'mat_table'].copy() - dict_tmp['color'] = dataset[ind, 'color'].copy() - #dict_tmp['nodes_nums'] = np.array([rec2[i] for i in ind], dtype=int).copy().reshape((-1, elt_type)) - dict_tmp['nodes_nums'] = dataset[ind, 'color'].copy() - #dset[elt_type_dict[str(elt_type)]] = dict_tmp - dset[elt_type] = dict_tmp - return dataset - - - #rec1 = np.array(split_data[::2], dtype=int) - # Extract Record 2 - #rec2 = split_data[1::2] - # Look for the different types of elements stored in the dataset - elts_types = list(set(rec1[:,5])) - for elt_type in elts_types: - ind = np.where(np.array(rec1[:,5]) == elt_type)[0] - dict_tmp = dict() - dict_tmp['element_nums'] = rec1[ind,0].copy() - dict_tmp['fe_descriptor'] = rec1[ind,1].copy() - dict_tmp['phys_table'] = rec1[ind,2].copy() - dict_tmp['mat_table'] = rec1[ind,3].copy() - dict_tmp['color'] = rec1[ind,4].copy() - dict_tmp['nodes_nums'] = np.array([rec2[i] for i in ind], dtype=int).copy().reshape((-1,elt_type)) - dset[elt_type_dict[str(elt_type)]] = dict_tmp + except: raise Exception('Error reading data-set #2412') return dset @@ -198,6 +155,9 @@ def prepare_2412( 'mat_table': mat_table, 'color': color, 'num_nodes': num_nodes, + 'beam_orientation': beam_orientation, + 'beam_foreend_cross': beam_foreend_cross, + 'beam_aftend_cross': beam_aftend_cross, 'nodes_nums': nodes_nums } From e410efee756119ffda2e6bdad19a0cb199a9c940 Mon Sep 17 00:00:00 2001 From: NArnold Date: Tue, 5 Sep 2023 11:03:45 +0200 Subject: [PATCH 7/9] Correct testing for dataset 2412 --- tests/test_2412.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/test_2412.py b/tests/test_2412.py index 2cf9cc4..dc73e93 100644 --- a/tests/test_2412.py +++ b/tests/test_2412.py @@ -6,18 +6,19 @@ import pyuff def test_read_2412(): - uff_ascii = pyuff.UFF('./data/mesh_Oros-modal_uff15_uff2412.uff') - a = uff_ascii.read_sets(2) - np.testing.assert_array_equal(a['quad']['nodes_nums'][0], np.array([1, 25, 48, 24])) - np.testing.assert_array_equal(a['quad']['nodes_nums'][-1], np.array([50, 74, 73, 49])) + uff_ascii = pyuff.UFF('./data/heat_engine_housing.uff') + a = uff_ascii.read_sets(3) + np.testing.assert_array_equal(a[111][-1]['nodes_nums'], np.array([1, 3, 9, 10])) + np.testing.assert_array_equal(a[91][-1]['nodes_nums'], np.array([2, 3, 8])) def test_read_write_2412_mixed(): # Read dataset 2412 in test file - uff_ascii = pyuff.UFF('./data/mesh_test_uff2412_mixed.uff') - a = uff_ascii.read_sets(2) + #uff_ascii = pyuff.UFF('./data/mesh_test_uff2412_mixed.uff') + uff_ascii = pyuff.UFF('./data/heat_engine_housing.uff') + a = uff_ascii.read_sets(3) # Test - np.testing.assert_array_equal(a['triangle']['nodes_nums'][-1], np.array([3, 6, 11])) - np.testing.assert_array_equal(a['quad']['nodes_nums'][-1], np.array([3, 4, 5, 6])) + np.testing.assert_array_equal(a[111][-1]['nodes_nums'], np.array([1, 3, 9, 10])) + np.testing.assert_array_equal(a[91][-1]['nodes_nums'], np.array([2, 3, 8])) # Write dataset 2412 uff_write = pyuff.UFF('./data/tmp.uff') @@ -27,21 +28,24 @@ def test_read_write_2412_mixed(): uff_ascii = pyuff.UFF('./data/tmp.uff') b = uff_ascii.read_sets(0) # Test - np.testing.assert_array_equal(a['triangle']['nodes_nums'], b['triangle']['nodes_nums']) - np.testing.assert_array_equal(a['quad']['nodes_nums'], b['quad']['nodes_nums']) + np.testing.assert_array_equal(a[111], b[111]) + np.testing.assert_array_equal(a[91], b[91]) def test_prepare_2412(): dict_2412 = pyuff.prepare_2412(return_full_dict=True) x = sorted(list(dict_2412.keys())) - y = sorted(['type', + y = sorted(['beam_aftend_cross', + 'beam_foreend_cross', + 'beam_orientation', + 'color', 'element_nums', 'fe_descriptor', - 'phys_table', 'mat_table', - 'color', + 'nodes_nums', 'num_nodes', - 'nodes_nums']) + 'phys_table', + 'type']) np.testing.assert_array_equal(x,y) #empty dictionary test @@ -53,4 +57,5 @@ def test_prepare_2412(): if __name__ == '__main__': # test_read_2412() - test_read_write_2412_mixed() \ No newline at end of file + test_prepare_2412() + test_read_write_2412_mixed() From 0062c9f318df0c4916800c8869b5d30d5669cfc2 Mon Sep 17 00:00:00 2001 From: nico-arnold Date: Thu, 21 Sep 2023 10:09:50 +0200 Subject: [PATCH 8/9] Fix 2412 reading for rods add testcase --- pyuff/datasets/dataset_2412.py | 81 ++++++++++++++++++++-------------- tests/test_2412.py | 46 ++++++++++++------- 2 files changed, 77 insertions(+), 50 deletions(-) diff --git a/pyuff/datasets/dataset_2412.py b/pyuff/datasets/dataset_2412.py index 818ffe2..adedc1c 100644 --- a/pyuff/datasets/dataset_2412.py +++ b/pyuff/datasets/dataset_2412.py @@ -1,61 +1,64 @@ import numpy as np +import itertools from ..tools import _opt_fields, _parse_header_line, check_dict_for_none def _write2412(fh, dset): try: - elt_type_dict = {'triangle': 3, 'quad': 4} fh.write('%6i\n%6i%74s\n' % (-1, 2412, ' ')) - - for elem in dset['all']: - fh.write('%10i%10i%10i%10i%10i%10i\n' % ( - elem['element_num'], - elem['f_descriptor'], - elem['phys_table'], - elem['mat_table'], - elem['color'], - elem['num_nodes'], - )) - if elem['f_descriptor'] == 11: - # rods have to be written in 3 lines - fh.write('%10i%10i%10i\n' % ( - elem['beam_orientation'], - elem['beam_foreend_cross'], - elem['beam_aftend_cross'] + for el_type in dset: + if type(el_type) is not int: + # Skip 'type', 'triangle' and 'quad' indices + continue + for elem in dset[el_type]: + fh.write('%10i%10i%10i%10i%10i%10i\n' % ( + elem['element_nums'], + elem['fe_descriptor'], + elem['phys_table'], + elem['mat_table'], + elem['color'], + elem['num_nodes'], )) - for ii in elem['nodes_nums']: - fh.write('%10i' % ii) - fh.write('\n') + if elem['fe_descriptor'] == 11: + # Rods have to be written in 3 lines - ad additional line here + fh.write('%10i%10i%10i\n' % ( + elem['beam_orientation'], + elem['beam_foreend_cross'], + elem['beam_aftend_cross'] + )) + for ii in elem['nodes_nums']: + fh.write('%10i' % ii) + fh.write('\n') fh.write('%6i\n' % -1) - except: raise Exception('Error writing data-set #2412') def _extract2412(block_data): """Extract element data - data-set 2412.""" - dset = {'type': 2412, 'all': None} - # Define dictionary of possible elements types - elt_type_dict = {'3': 'triangle', '4': 'quad'} + dset = {'type': 2412} + # Define dictionary of possible elements types for legacy interface + elt_type_dict = {41: 'triangle', 44: 'quad'} + # Elements that are seen as rods and read as 3 lines + rods_dict = {11, 21, 22, 23, 24} + # Read data try: split_data = block_data.splitlines() split_data = [a.split() for a in split_data][2:] + # Extract Records - rec1 = np.array([]) - rec2 = [] - dataset = [] i = 0 while i < len(split_data): dict_tmp = dict() line = split_data[i] - dict_tmp['element_num'] = int(line[0]) - dict_tmp['f_descriptor'] = int(line[1]) + dict_tmp['element_nums'] = int(line[0]) + dict_tmp['fe_descriptor'] = int(line[1]) dict_tmp['phys_table'] = int(line[2]) dict_tmp['mat_table'] = int(line[3]) dict_tmp['color'] = int(line[4]) dict_tmp['num_nodes'] = int(line[5]) - if dict_tmp['f_descriptor'] == 11: + if dict_tmp['fe_descriptor'] in rods_dict: # element is a rod and covers 3 lines dict_tmp['beam_orientation'] = int(split_data[i+1][0]) dict_tmp['beam_foreend_cross'] = int(split_data[i + 1][1]) @@ -66,17 +69,27 @@ def _extract2412(block_data): # element is no rod and covers 2 lines dict_tmp['nodes_nums'] = [int(e) for e in split_data[i+1]] i += 2 - desc = dict_tmp['f_descriptor'] + desc = dict_tmp['fe_descriptor'] if not desc in dset: dset[desc] = [] dset[desc].append(dict_tmp) - dataset.append(dict_tmp) - dset['all'] = dataset + for num, name in elt_type_dict.items(): + # if we have one of the keys that are enabled for the legacy interface, add everything for that here + if num in dset.keys(): + dset[name] = { + 'element_nums': [e['element_nums'] for e in dset[num]], + 'fe_descriptor': [e['fe_descriptor'] for e in dset[num]], + 'phys_table': [e['phys_table'] for e in dset[num]], + 'mat_table': [e['mat_table'] for e in dset[num]], + 'color': [e['color'] for e in dset[num]], + 'num_nodes': [e['num_nodes'] for e in dset[num]], + 'nodes_nums': [e['nodes_nums'] for e in dset[num]], + } + return dset except: raise Exception('Error reading data-set #2412') - return dset def prepare_2412( diff --git a/tests/test_2412.py b/tests/test_2412.py index dc73e93..7c489a4 100644 --- a/tests/test_2412.py +++ b/tests/test_2412.py @@ -6,19 +6,37 @@ import pyuff def test_read_2412(): - uff_ascii = pyuff.UFF('./data/heat_engine_housing.uff') - a = uff_ascii.read_sets(3) - np.testing.assert_array_equal(a[111][-1]['nodes_nums'], np.array([1, 3, 9, 10])) - np.testing.assert_array_equal(a[91][-1]['nodes_nums'], np.array([2, 3, 8])) + # -- Load small test file + uff_ascii = pyuff.UFF('./data/mesh_Oros-modal_uff15_uff2412.uff') + a = uff_ascii.read_sets(2) + + # -- Test legacy interface + np.testing.assert_array_equal(a['quad']['nodes_nums'][0], np.array([1, 25, 48, 24])) + np.testing.assert_array_equal(a['quad']['nodes_nums'][-1], np.array([50, 74, 73, 49])) + # -- Test new interface + np.testing.assert_array_equal(a[44][0]['nodes_nums'], np.array([1, 25, 48, 24])) + np.testing.assert_array_equal(a[44][-1]['nodes_nums'], np.array([50, 74, 73, 49])) + + # -- Load bigger test file with rods + uff_ascii = pyuff.UFF('./data/simcenter_exported_result.uff') + a = uff_ascii.read_sets(2) + + # -- Test new interface + assert all(['type' in a, 21 in a, 91 in a, 94 in a, len(a) == 4]) + np.testing.assert_array_equal(a[21][0]['nodes_nums'], np.array([1894, 1443])) + np.testing.assert_array_equal(a[94][0]['nodes_nums'], np.array([1870, 1046, 1, 946])) + assert sorted(list(a[21][0].keys())) == ['beam_aftend_cross', 'beam_foreend_cross', 'beam_orientation', 'color', 'element_nums', 'fe_descriptor', 'mat_table', 'nodes_nums', 'num_nodes', 'phys_table'] + + def test_read_write_2412_mixed(): # Read dataset 2412 in test file - #uff_ascii = pyuff.UFF('./data/mesh_test_uff2412_mixed.uff') - uff_ascii = pyuff.UFF('./data/heat_engine_housing.uff') - a = uff_ascii.read_sets(3) + uff_ascii = pyuff.UFF('./data/mesh_test_uff2412_mixed.uff') + a = uff_ascii.read_sets(2) + # Test - np.testing.assert_array_equal(a[111][-1]['nodes_nums'], np.array([1, 3, 9, 10])) - np.testing.assert_array_equal(a[91][-1]['nodes_nums'], np.array([2, 3, 8])) + np.testing.assert_array_equal(a['triangle']['nodes_nums'][-1], np.array([3, 6, 11])) + np.testing.assert_array_equal(a['quad']['nodes_nums'][-1], np.array([3, 4, 5, 6])) # Write dataset 2412 uff_write = pyuff.UFF('./data/tmp.uff') @@ -27,9 +45,10 @@ def test_read_write_2412_mixed(): # Read dataset 2412 in written file uff_ascii = pyuff.UFF('./data/tmp.uff') b = uff_ascii.read_sets(0) + # Test - np.testing.assert_array_equal(a[111], b[111]) - np.testing.assert_array_equal(a[91], b[91]) + np.testing.assert_array_equal(a[41], b[41]) + np.testing.assert_array_equal(a[44], b[44]) def test_prepare_2412(): dict_2412 = pyuff.prepare_2412(return_full_dict=True) @@ -54,8 +73,3 @@ def test_prepare_2412(): raise Exception('Not correct keys') if x2['type'] != 2412: raise Exception('Not correct type') - -if __name__ == '__main__': - # test_read_2412() - test_prepare_2412() - test_read_write_2412_mixed() From c299bf3986bed709e3864cbd3bbe6c4080de6449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Slavi=C4=8D?= Date: Sat, 23 Sep 2023 06:37:01 +0200 Subject: [PATCH 9/9] added back debugging part --- tests/test_2412.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_2412.py b/tests/test_2412.py index 7c489a4..2a32794 100644 --- a/tests/test_2412.py +++ b/tests/test_2412.py @@ -73,3 +73,8 @@ def test_prepare_2412(): raise Exception('Not correct keys') if x2['type'] != 2412: raise Exception('Not correct type') + + +if __name__ == '__main__': + # test_read_2412() + test_read_write_2412_mixed() \ No newline at end of file