Skip to content

Fix func type 0 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyuff/datasets/dataset_58.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions tests/test_58.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()