Skip to content

Commit 28d459e

Browse files
committed
Fixed bug in node set putting/naming
1 parent 8b93f09 commit 28d459e

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

exodus_helper/core.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ def __init__(self, filename, **kwargs):
278278

279279
for idx in range(dimensions['num_el_blk'].size):
280280
d1 = dataset.createDimension(
281-
f'num_el_in_blk{idx+1}',
281+
f'num_el_in_blk{idx + 1}',
282282
size=num_el_in_blks[idx])
283283
d2 = dataset.createDimension(
284-
f'num_nod_per_el{idx+1}',
284+
f'num_nod_per_el{idx + 1}',
285285
size=num_nodes_per_els[idx])
286286
v = dataset.createVariable(
287-
f'connect{idx+1}',
287+
f'connect{idx + 1}',
288288
self.int_type,
289289
dimensions=(d1.name, d2.name))
290290

@@ -383,10 +383,10 @@ def __init__(self, filename, **kwargs):
383383
# node and side set variables
384384
if self.get_num_node_sets() > 0:
385385
v = variables['ns_prop1']
386-
v[:] = np.arange(dimensions['num_node_sets'].size) + 1
386+
# v[:] = np.arange(dimensions['num_node_sets'].size) + 1
387387
v.setncattr('name', 'ID')
388388
v = variables['ns_status']
389-
v[:] = [1] * dimensions['num_node_sets'].size
389+
v[:] = [0] * dimensions['num_node_sets'].size
390390

391391
if self.get_num_side_sets() > 0:
392392
v = variables['ss_prop1']
@@ -2423,16 +2423,23 @@ def put_node_set_params(self, id_ns, num_nodes, numSetDistFacts=0) -> bool:
24232423
"""
24242424
try:
24252425
dataset = self.dataset
2426-
d = dataset.createDimension(f'num_nod_ns{id_ns}', size=num_nodes)
2426+
if id_ns in dataset.variables['ns_prop1']:
2427+
idx = list(dataset.variables['ns_prop1']).index(id_ns)
2428+
else:
2429+
idx = np.argwhere(dataset.variables['ns_status'][:] == 0)[0][0]
2430+
dataset.variables['ns_prop1'][idx] = id_ns
2431+
dataset.variables['ns_status'][idx] = 1
2432+
2433+
d = dataset.createDimension(f'num_nod_ns{idx + 1}', size=num_nodes)
24272434
dataset.createVariable(
2428-
f'node_ns{id_ns}', self.int_type, dimensions=d.name)
2435+
f'node_ns{idx + 1}', self.int_type, dimensions=d.name)
24292436
if numSetDistFacts > 0:
24302437
d = dataset.createDimension(
2431-
f'num_df_ns{id_ns}', size=num_nodes)
2438+
f'num_df_ns{idx + 1}', size=num_nodes)
24322439
dataset.createVariable(
2433-
f'dist_fact_ns{id_ns}', np.dtype('float'),
2440+
f'dist_fact_ns{idx + 1}', np.dtype('float'),
24342441
dimensions=d.name)
2435-
dataset.variables[f'dist_fact_ns{id_ns}'][:] = 1.
2442+
dataset.variables[f'dist_fact_ns{idx + 1}'][:] = 1.
24362443
except RuntimeError as exc:
24372444
raise DatabaseError from exc
24382445
return True

exodus_helper/dir_exodus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
# _attr_inputs['get_side_set_ids'] = []
376376
_attr_inputs['get_side_set_name'] = [1]
377377
# _attr_inputs['get_side_set_names'] = []
378-
# _attr_inputs['get_side_set_node_list'] = []
378+
_attr_inputs['get_side_set_node_list'] = [1]
379379
_attr_inputs['get_side_set_params'] = [1]
380380
# _attr_inputs['get_side_set_property_names'] = []
381381
_attr_inputs['get_side_set_property_value'] = [1, 'ID']

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = 'poetry.core.masonry.api'
44

55
[tool.poetry]
66
name = 'exodus_helper'
7-
version = '1.3.2'
7+
version = '1.3.3'
88
description = 'A package for manipulating ExodusII databases'
99
license = 'BSD-3-Clause'
1010
authors = ['Coleman Alleman <callema@sandia.gov>']

tests/test_exodus_helper.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,23 @@ def test_get_node_set_ids(mesh):
684684
assert np.all(ids == np.arange(1, len(ids) + 1))
685685

686686

687-
def test_get_node_set_name(mesh):
687+
def test_get_node_set_name(dir_test_file, monkeypatch):
688688
# Put and get a node set name
689-
assert mesh.put_node_set_name(1, 'test_ns_name1')
690-
assert mesh.get_node_set_name(1) == 'test_ns_name1'
689+
690+
try:
691+
file_path = os.path.join(dir_test_file, 'delete_me.g')
692+
monkeypatch.setattr('builtins.input', lambda _: 'y')
693+
mesh = exodus_helper.Exodus(file_path, mode='w', numNodeSets=2)
694+
mesh.put_node_set_params(99, 1)
695+
mesh.put_node_set_name(99, 'test_ns_name1')
696+
assert mesh.get_node_set_name(99) == 'test_ns_name1'
697+
finally:
698+
mesh.close()
699+
os.remove(file_path)
691700

692701

693702
def test_get_node_set_names(mesh):
703+
assert mesh.put_node_set_name(1, 'test_ns_name1')
694704
assert mesh.put_node_set_name(2, 'test_ns_name2')
695705
names = mesh.get_node_set_names()
696706
assert names[0] == 'test_ns_name1'
@@ -1472,7 +1482,7 @@ def test_put_node_set_params(dir_test_file, monkeypatch):
14721482
# Params can only be used once on a fresh mesh
14731483
file_path = os.path.join(dir_test_file, 'delete_me.g')
14741484
monkeypatch.setattr('builtins.input', lambda _: 'y')
1475-
mesh = exodus_helper.Exodus(file_path, mode='w')
1485+
mesh = exodus_helper.Exodus(file_path, mode='w', numNodeSets=1)
14761486
mesh.put_node_set_params(1, 1, numSetDistFacts=1)
14771487

14781488
# Assert that dimensions and variables were created properly

0 commit comments

Comments
 (0)