From c832fed36b404483ef14dc21536ca01abb8acd61 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 10 Dec 2024 14:43:15 +0100 Subject: [PATCH 1/2] Update valid function types in dataset_58.py Include '0' as a valid function type in the dataset_58 writer.Function Type: 0 - General or Unknown --- pyuff/datasets/dataset_58.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyuff/datasets/dataset_58.py b/pyuff/datasets/dataset_58.py index 4251a05..9924628 100644 --- a/pyuff/datasets/dataset_58.py +++ b/pyuff/datasets/dataset_58.py @@ -827,7 +827,7 @@ def get_structure_58(raw=False): def _write58(fh, dset, mode='add', _filename=None, force_double=True): """Writes function at nodal DOF - data-set 58 - to an open file fh.""" try: - if not (dset['func_type'] in [1, 2, 3, 4, 6, 9]): + if not (dset['func_type'] in [0, 1, 2, 3, 4, 6, 9]): raise ValueError('Unsupported function type') # handle optional fields - only those that are not calculated # automatically From 3d0c35cba7fbf544db2ce3281325df0ef99fc00f Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 10 Dec 2024 15:00:52 +0100 Subject: [PATCH 2/2] Add test for handling `func_type=0` in _write58 This new test validates the correct behavior of `_write58` when `func_type=0` (general or unknown data) is used. It includes dataset preparation, writing to a UFF file, reading back, and verifying both metadata and data consistency. --- tests/test_58.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/test_58.py b/tests/test_58.py index 9342f9e..2370cc3 100644 --- a/tests/test_58.py +++ b/tests/test_58.py @@ -228,8 +228,68 @@ def test_fix_58b(): if os.path.exists('./data/MPSTD#Set001_2024_10_08_10_27_07_fixed.uff'): os.remove('./data/MPSTD#Set001_2024_10_08_10_27_07_fixed.uff') +def test_write_read_func_type_0(): + """ + Test that func_type=0 is handled correctly in _write58. + """ + save_to_file = './data/test_func_type_0.uff' + + # Remove the file if it already exists + if os.path.exists(save_to_file): + os.remove(save_to_file) + + # Prepare a dataset with func_type=0 + test_data = np.array([1.0, 2.0, 3.0, 4.0]) + test_x = np.array([0.0, 1.0, 2.0, 3.0]) + dataset = pyuff.prepare_58( + binary=0, + func_type=0, # General or unknown data + rsp_node=0, + rsp_dir=0, + ref_node=0, + ref_dir=0, + data=test_data, + x=test_x, + id1='TestFuncType0', + rsp_ent_name='TestEntity', + ref_ent_name='TestEntity', + abscissa_spacing=1, + abscissa_spec_data_type=17, # Time + ordinate_spec_data_type=2, # Real + orddenom_spec_data_type =0 + ) + + # Write the dataset to a UFF file + uff_writer = pyuff.UFF(save_to_file) + uff_writer.write_sets([dataset], mode='overwrite') + + # Read the dataset back + uff_reader = pyuff.UFF(save_to_file) + read_data = uff_reader.read_sets() + + # Clean up the file + if os.path.exists(save_to_file): + os.remove(save_to_file) + + # Validate the content + assert read_data, "Expected one dataset to be read." + # No need to index; use read_data directly + read_dataset = read_data + + # Check basic metadata + np.testing.assert_equal(read_dataset['func_type'], 0) + np.testing.assert_string_equal(read_dataset['id1'], 'TestFuncType0') + np.testing.assert_string_equal(read_dataset['rsp_ent_name'], 'TestEntity') + np.testing.assert_string_equal(read_dataset['ref_ent_name'], 'TestEntity') + + # Validate data content + np.testing.assert_array_equal(read_dataset['data'], test_data) + np.testing.assert_array_equal(read_dataset['x'], test_x) + + if __name__ == '__main__': test_read_write_read_given_data() + test_write_read_func_type_0() if __name__ == '__mains__': np.testing.run_module_suite() \ No newline at end of file