Skip to content
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

Adding temperature dependent properties (arrays). #150

Merged
merged 4 commits into from
Aug 30, 2022
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
33 changes: 27 additions & 6 deletions ansys/mapdl/reader/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,32 @@ def _load_materials(self):
def read_mat_data(ptr):
"""reads double precision material data given an offset from ptrMAT"""
arr, sz = self.read_record(self._geometry_header["ptrMAT"] + ptr, True)
arr = arr[arr != 0]
if arr.size == 1:
return arr[0]
is_single_value = arr[arr != 0].size == 1

if is_single_value:
return arr[arr != 0][0]
else:
# We need to account for 0 at the temp and properties.
temps_ = arr[:sz]
values_ = arr[-1 : -1 * (sz + 1) : -1]

prop_ = np.vstack((temps_, values_))
for each in range(prop_.shape[1] - 1, -1, -1):
# checking that two records are empty starting from the end.
if (
temps_[each] == 0
and values_[each] == 0
and temps_[each - 1] == 0
and values_[each - 1] == 0
):
continue # they are zero, so we keep going.
else:
# found a non-zero report
break

prop_ = prop_[:, :each]
prop_[1, :] = prop_[1, ::-1]
return prop_

mat_table = self.read_record(self._geometry_header["ptrMAT"])
if mat_table[0] != -101: # pragma: no cover
Expand Down Expand Up @@ -423,9 +446,7 @@ def read_mat_data(ptr):
self._cfile._seekg(fs)
material[key] = np.fromstring(self._cfile._read(8))[0]
else:
for i in range(-5, 10):
material[key] = read_mat_data(ptr)
# print(read_mat_data(ptr))
material[key] = read_mat_data(ptr)

# documentation for this is hard to follow, but it boils down to
# the fact that "The record includes MP pointers followed by TB
Expand Down
15 changes: 15 additions & 0 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,18 @@ def test_materials_v150():
ans_mat = rst.materials[mat_type]
for key, value in known_material.items():
assert pytest.approx(ans_mat[key]) == known_material[key]


def test_temperature_dependent_properties():
path_rth = os.path.join(testfiles_path, "temp_dependent_results.rth")
rst = pymapdl_reader.read_binary(path_rth)
mats = rst.materials
kxx = mats[1]["KXX"]
expected_value = np.array(
[[-100.0, 0.0, 100.0, 200.0], [114.0, 144.0, 165.0, 175.0]]
)

assert kxx is not None
assert isinstance(kxx, np.ndarray)
assert kxx.size > 0
assert np.allclose(kxx, expected_value)
Binary file added tests/testfiles/temp_dependent_results.rth
Binary file not shown.