Skip to content

Commit 79ce8e6

Browse files
committed
Merge branch 'main' into release/0.52
2 parents 20a379e + 3c54e59 commit 79ce8e6

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

ansys/mapdl/reader/rst.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,32 @@ def _load_materials(self):
381381
def read_mat_data(ptr):
382382
"""reads double precision material data given an offset from ptrMAT"""
383383
arr, sz = self.read_record(self._geometry_header["ptrMAT"] + ptr, True)
384-
arr = arr[arr != 0]
385-
if arr.size == 1:
386-
return arr[0]
384+
is_single_value = arr[arr != 0].size == 1
385+
386+
if is_single_value:
387+
return arr[arr != 0][0]
388+
else:
389+
# We need to account for 0 at the temp and properties.
390+
temps_ = arr[:sz]
391+
values_ = arr[-1 : -1 * (sz + 1) : -1]
392+
393+
prop_ = np.vstack((temps_, values_))
394+
for each in range(prop_.shape[1] - 1, -1, -1):
395+
# checking that two records are empty starting from the end.
396+
if (
397+
temps_[each] == 0
398+
and values_[each] == 0
399+
and temps_[each - 1] == 0
400+
and values_[each - 1] == 0
401+
):
402+
continue # they are zero, so we keep going.
403+
else:
404+
# found a non-zero report
405+
break
406+
407+
prop_ = prop_[:, :each]
408+
prop_[1, :] = prop_[1, ::-1]
409+
return prop_
387410

388411
mat_table = self.read_record(self._geometry_header["ptrMAT"])
389412
if mat_table[0] != -101: # pragma: no cover
@@ -423,9 +446,7 @@ def read_mat_data(ptr):
423446
self._cfile._seekg(fs)
424447
material[key] = np.fromstring(self._cfile._read(8))[0]
425448
else:
426-
for i in range(-5, 10):
427-
material[key] = read_mat_data(ptr)
428-
# print(read_mat_data(ptr))
449+
material[key] = read_mat_data(ptr)
429450

430451
# documentation for this is hard to follow, but it boils down to
431452
# the fact that "The record includes MP pointers followed by TB

tests/test_rst.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,18 @@ def test_materials_v150():
636636
ans_mat = rst.materials[mat_type]
637637
for key, value in known_material.items():
638638
assert pytest.approx(ans_mat[key]) == known_material[key]
639+
640+
641+
def test_temperature_dependent_properties():
642+
path_rth = os.path.join(testfiles_path, "temp_dependent_results.rth")
643+
rst = pymapdl_reader.read_binary(path_rth)
644+
mats = rst.materials
645+
kxx = mats[1]["KXX"]
646+
expected_value = np.array(
647+
[[-100.0, 0.0, 100.0, 200.0], [114.0, 144.0, 165.0, 175.0]]
648+
)
649+
650+
assert kxx is not None
651+
assert isinstance(kxx, np.ndarray)
652+
assert kxx.size > 0
653+
assert np.allclose(kxx, expected_value)
1.75 MB
Binary file not shown.

0 commit comments

Comments
 (0)